Browse code

core: added rpc command core.ppdefines

- list preprocessor defines enabled in config

Daniel-Constantin Mierla authored on 10/08/2017 07:04:29
Showing 4 changed files
... ...
@@ -210,9 +210,9 @@ MAX_LEN			"max_len"
210 210
 /* condition keywords */
211 211
 METHOD	method
212 212
 /* hack -- the second element in first line is referable
213
-   as either uri or status; it only would makes sense to
214
-   call it "uri" from route{} and status from onreply_route{}
215
-*/
213
+ * as either uri or status; it only would makes sense to
214
+ * call it "uri" from route{} and status from onreply_route{}
215
+ */
216 216
 URI		"uri"|"status"
217 217
 FROM_URI	"from_uri"
218 218
 TO_URI		"to_uri"
... ...
@@ -964,10 +964,10 @@ IMPORTFILE      "import_file"
964 964
 
965 965
 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
966 966
 <SELECT>{ID}		{ count(); addstr(&s_buf, yytext, yyleng);
967
-                          yylval.strval=s_buf.s;
968
-                          memset(&s_buf, 0, sizeof(s_buf));
969
-                          return ID;
970
-                        }
967
+						yylval.strval=s_buf.s;
968
+						memset(&s_buf, 0, sizeof(s_buf));
969
+						return ID;
970
+					}
971 971
 <SELECT>{DOT}           { count(); return DOT; }
972 972
 <SELECT>{LBRACK}        { count(); return LBRACK; }
973 973
 <SELECT>{RBRACK}        { count(); return RBRACK; }
... ...
@@ -1023,7 +1023,7 @@ IMPORTFILE      "import_file"
1023 1023
 								}
1024 1024
 							}
1025 1025
 	/* eat everything between 2 () and return PVAR token and a string
1026
-	   containing everything (including $ and ()) */
1026
+	 * containing everything (including $ and ()) */
1027 1027
 <PVAR_P>{RPAREN}			{	p_nest--;
1028 1028
 								if (p_nest==0){
1029 1029
 									count();
... ...
@@ -1078,7 +1078,7 @@ IMPORTFILE      "import_file"
1078 1078
 	/* avp prefix detected -> go to avp mode */
1079 1079
 <AVP_PVAR>{AVP_PREF}		|
1080 1080
 <AVP_PVAR>{ID}{LBRACK}		{ state = ATTR_S; BEGIN(ATTR); yyless(1); count();
1081
-							  return ATTR_MARK; }
1081
+								return ATTR_MARK; }
1082 1082
 <AVP_PVAR>{ID}{LPAREN}		{ state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
1083 1083
 								yymore(); }
1084 1084
 <AVP_PVAR>{ID}				{	count(); addstr(&s_buf, yytext, yyleng);
... ...
@@ -1166,8 +1166,8 @@ IMPORTFILE      "import_file"
1166 1166
 <STRING1>\\\\		{ count_more(); addchar(&s_buf, '\\'); }
1167 1167
 <STRING1>\\x{HEX}{1,2}	{ count_more(); addchar(&s_buf,
1168 1168
 											(char)strtol(yytext+2, 0, 16)); }
1169
- /* don't allow \[0-7]{1}, it will eat the backreferences from
1170
-    subst_uri if allowed (although everybody should use '' in subt_uri) */
1169
+	/* don't allow \[0-7]{1}, it will eat the backreferences from
1170
+	 * subst_uri if allowed (although everybody should use '' in subt_uri) */
1171 1171
 <STRING1>\\[0-7]{2,3}	{ count_more(); addchar(&s_buf,
1172 1172
 											(char)strtol(yytext+1, 0, 8));  }
1173 1173
 <STRING1>\\{CR}		{ count_more(); } /* eat escaped CRs */
... ...
@@ -1175,11 +1175,11 @@ IMPORTFILE      "import_file"
1175 1175
 
1176 1176
 <STR_BETWEEN>{EAT_ABLE}|{CR}	{ count_ignore(); }
1177 1177
 <STR_BETWEEN>{QUOTES}			{ count_more(); state=STRING_S;
1178
-								  BEGIN(STRING1);}
1178
+									BEGIN(STRING1);}
1179 1179
 <STR_BETWEEN>.					{
1180 1180
 									yyless(0); /* reparse it */
1181 1181
 									/* ignore the whitespace now that is
1182
-									  counted, return saved string value */
1182
+									 * counted, return saved string value */
1183 1183
 									state=old_state; BEGIN(old_initial);
1184 1184
 									r = pp_subst_run(&s_buf.s);
1185 1185
 									yylval.strval=s_buf.s;
... ...
@@ -1250,8 +1250,8 @@ IMPORTFILE      "import_file"
1250 1250
 									exit(-1);
1251 1251
 								}
1252 1252
 <IFDEF_ID>{ID}                { count();
1253
-                                pp_ifdef_var(yyleng, yytext);
1254
-                                state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); }
1253
+								pp_ifdef_var(yyleng, yytext);
1254
+								state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); }
1255 1255
 <IFDEF_EOL>{EAT_ABLE}*{CR}    { count(); pp_ifdef(); }
1256 1256
 
1257 1257
 <INITIAL,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR}    { count(); pp_else(); }
... ...
@@ -1259,10 +1259,10 @@ IMPORTFILE      "import_file"
1259 1259
 <INITIAL,IFDEF_SKIP>{PREP_START}{ENDIF}{EAT_ABLE}*{CR}    { count();
1260 1260
 															pp_endif(); }
1261 1261
 
1262
- /* we're in an ifdef that evaluated to false -- throw it away */
1262
+	/* we're in an ifdef that evaluated to false -- throw it away */
1263 1263
 <IFDEF_SKIP>.|{CR}    { count(); }
1264 1264
 
1265
- /* this is split so the shebangs match more, giving them priority */
1265
+	/* this is split so the shebangs match more, giving them priority */
1266 1266
 <INITIAL>{COM_LINE}        { count(); state = LINECOMMENT_S;
1267 1267
 								BEGIN(LINECOMMENT); }
1268 1268
 <LINECOMMENT>.*{CR}        { count(); state = INITIAL_S; BEGIN(INITIAL); }
... ...
@@ -1283,7 +1283,8 @@ IMPORTFILE      "import_file"
1283 1283
 									memset(&s_buf, 0, sizeof(s_buf));
1284 1284
 									return NUM_ID; }
1285 1285
 
1286
-<SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
1286
+<SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); }
1287
+							/* Rescan the token in INITIAL state */
1287 1288
 
1288 1289
 <INCLF>[ \t]*      /* eat the whitespace */
1289 1290
 <INCLF>[^ \t\r\n]+   { /* get the include file name */
... ...
@@ -1460,7 +1461,7 @@ static void count()
1460 1461
 
1461 1462
 
1462 1463
 /** record discarded stuff (not contained in the token) so that
1463
-    the next token position can be adjusted properly*/
1464
+ * the next token position can be adjusted properly */
1464 1465
 static void count_ignore()
1465 1466
 {
1466 1467
 	count_lc(&ign_lines, &ign_columns);
... ...
@@ -1691,6 +1692,13 @@ static int pp_define_index = -1;
1691 1692
 static int pp_ifdef_stack[MAX_IFDEFS];
1692 1693
 static int pp_sptr = 0; /* stack pointer */
1693 1694
 
1695
+str* pp_get_define_name(int idx)
1696
+{
1697
+	if(idx<0 || idx>=pp_num_defines)
1698
+		return NULL;
1699
+	return &pp_defines[idx][0];
1700
+}
1701
+
1694 1702
 static int pp_lookup(int len, const char * text)
1695 1703
 {
1696 1704
 	str var = {(char *)text, len};
... ...
@@ -1749,6 +1757,7 @@ int pp_define(int len, const char * text)
1749 1757
 		return -1;
1750 1758
 	}
1751 1759
 	memcpy(pp_defines[pp_num_defines][0].s, text, len);
1760
+	pp_defines[pp_num_defines][0].s[len] = '\0';
1752 1761
 	pp_defines[pp_num_defines][1].len = 0;
1753 1762
 	pp_defines[pp_num_defines][1].s = NULL;
1754 1763
 	pp_define_index = pp_num_defines;
... ...
@@ -45,6 +45,7 @@
45 45
 #include "tcp_options.h"
46 46
 #include "core_cmd.h"
47 47
 #include "cfg_core.h"
48
+#include "ppcfg.h"
48 49
 
49 50
 #ifdef USE_DNS_CACHE
50 51
 void dns_cache_debug(rpc_t* rpc, void* ctx);
... ...
@@ -269,7 +270,7 @@ static void system_methodHelp(rpc_t* rpc, void* c)
269 270
 		rpc->fault(c, 400, "Method Name Expected");
270 271
 		return;
271 272
 	}
272
-	
273
+
273 274
 	r=rpc_lookup(name, strlen(name));
274 275
 	if (r==0){
275 276
 		rpc->fault(c, 400, "command not found");
... ...
@@ -446,23 +447,23 @@ static const char* core_pwd_doc[] = {
446 447
 
447 448
 static void core_pwd(rpc_t* rpc, void* c)
448 449
 {
449
-        char *cwd_buf;
450
-        int max_len;
451
-
452
-        max_len = pathmax();
453
-        cwd_buf = pkg_malloc(max_len);
454
-        if (!cwd_buf) {
455
-                ERR("core_pwd: No memory left\n");
456
-                rpc->fault(c, 500, "Server Ran Out of Memory");
450
+	char *cwd_buf;
451
+	int max_len;
452
+
453
+	max_len = pathmax();
454
+	cwd_buf = pkg_malloc(max_len);
455
+	if (!cwd_buf) {
456
+		ERR("core_pwd: No memory left\n");
457
+		rpc->fault(c, 500, "Server Ran Out of Memory");
457 458
 		return;
458
-        }
459
+	}
459 460
 
460
-        if (getcwd(cwd_buf, max_len)) {
461
+	if (getcwd(cwd_buf, max_len)) {
461 462
 		rpc->add(c, "s", cwd_buf);
462
-        } else {
463
+	} else {
463 464
 		rpc->fault(c, 500, "getcwd Failed");
464
-        }
465
-        pkg_free(cwd_buf);
465
+	}
466
+	pkg_free(cwd_buf);
466 467
 }
467 468
 
468 469
 
... ...
@@ -474,11 +475,11 @@ static const char* core_arg_doc[] = {
474 475
 
475 476
 static void core_arg(rpc_t* rpc, void* c)
476 477
 {
477
-        int p;
478
+	int p;
478 479
 
479
-        for (p = 0; p < my_argc; p++) {
480
+	for (p = 0; p < my_argc; p++) {
480 481
 		if (rpc->add(c, "s", my_argv[p]) < 0) return;
481
-        }
482
+	}
482 483
 }
483 484
 
484 485
 
... ...
@@ -955,6 +956,27 @@ static void core_sockets_list(rpc_t* rpc, void* c)
955 956
 	} while((proto=next_proto(proto)));
956 957
 }
957 958
 
959
+/**
960
+ *
961
+ */
962
+static const char* core_ppdefines_doc[] = {
963
+	"List preprocessor defines",    /* Documentation string */
964
+	0                               /* Method signature(s) */
965
+};
966
+
967
+/**
968
+ * list listen sockets for SIP server
969
+ */
970
+static void core_ppdefines(rpc_t* rpc, void* c)
971
+{
972
+	str *ppdef;
973
+	int i=0;
974
+
975
+	while((ppdef=pp_get_define_name(i))!=NULL) {
976
+		if (rpc->add(c, "s", ppdef->s) < 0) return;
977
+		i++;
978
+	}
979
+}
958 980
 
959 981
 /*
960 982
  * RPC Methods exported by core
... ...
@@ -990,8 +1012,9 @@ static rpc_export_t core_rpc_methods[] = {
990 1012
 	{"core.tcp_list",          core_tcp_list,          core_tcp_list_doc,0},
991 1013
 	{"core.udp4_raw_info",     core_udp4rawinfo,       core_udp4rawinfo_doc,
992 1014
 		0},
993
-	{"core.aliases_list",      core_aliases_list,      core_aliases_list_doc,   0},
994
-	{"core.sockets_list",      core_sockets_list,      core_sockets_list_doc,   0},
1015
+	{"core.aliases_list",      core_aliases_list,      core_aliases_list_doc, 0},
1016
+	{"core.sockets_list",      core_sockets_list,      core_sockets_list_doc, 0},
1017
+	{"core.ppdefines",         core_ppdefines,         core_ppdefines_doc,    RET_ARRAY},
995 1018
 #ifdef USE_DNS_CACHE
996 1019
 	{"dns.mem_info",          dns_cache_mem_info,     dns_cache_mem_info_doc,
997 1020
 		0	},
... ...
@@ -1069,8 +1092,7 @@ int register_core_rpcs(void)
1069 1092
 		BUG("failed to register core RPCs\n");
1070 1093
 		goto error;
1071 1094
 	}else if (i>0){
1072
-		ERR("%d duplicate RPCs name detected while registering core RPCs\n",
1073
-			 i);
1095
+		ERR("%d duplicate RPCs name detected while registering core RPCs\n", i);
1074 1096
 		goto error;
1075 1097
 	}
1076 1098
 	return 0;
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
3 3
  *
4 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
3 3
  *
4 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -23,6 +23,10 @@
23 23
 #ifndef _PPCFG_H_
24 24
 #define _PPCFG_H_
25 25
 
26
+#include "str.h"
27
+
28
+str* pp_get_define_name(int idx);
29
+
26 30
 int pp_subst_add(char *data);
27 31
 int pp_substdef_add(char *data, int mode);
28 32
 int pp_subst_run(char **data);