pval.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #ifndef _ASTERISK_PVAL_H
  2. #define _ASTERISK_PVAL_H
  3. /* whatever includes this, better include asterisk/lock.h and asterisk/hashtab.h */
  4. typedef enum
  5. {
  6. PV_WORD, /* an ident, string, name, label, etc. A user-supplied string. */ /* 0 */
  7. PV_MACRO, /* 1 */
  8. PV_CONTEXT, /* 2 */
  9. PV_MACRO_CALL, /* 3 */
  10. PV_APPLICATION_CALL, /* 4 */
  11. PV_CASE, /* 5 */
  12. PV_PATTERN, /* 6 */
  13. PV_DEFAULT, /* 7 */
  14. PV_CATCH, /* 8 */
  15. PV_SWITCHES, /* 9 */
  16. PV_ESWITCHES, /* 10 */
  17. PV_INCLUDES, /* 11 */
  18. PV_STATEMENTBLOCK, /* 12 */
  19. PV_VARDEC, /* you know, var=val; */ /* 13 */
  20. PV_GOTO, /* 14 */
  21. PV_LABEL, /* 15 */
  22. PV_FOR, /* 16 */
  23. PV_WHILE, /* 17 */
  24. PV_BREAK, /* 18 */
  25. PV_RETURN, /* 19 */
  26. PV_CONTINUE, /* 20 */
  27. PV_IF, /* 21 */
  28. PV_IFTIME, /* 22 */
  29. PV_RANDOM, /* 23 */
  30. PV_SWITCH, /* 24 */
  31. PV_EXTENSION, /* 25 */
  32. PV_IGNOREPAT, /* 26 */
  33. PV_GLOBALS, /* 27 */
  34. PV_LOCALVARDEC, /* 28 */
  35. } pvaltype;
  36. /* why this horrible mess? It's always been a tradeoff-- tons of structs,
  37. each storing it's specific lists of goodies, or a 'simple' single struct,
  38. with lots of fields, that catches all uses at once. Either you have a long
  39. list of struct names and subnames, or you have a long list of field names,
  40. and where/how they are used. I'm going with a single struct, using unions
  41. to reduce storage. Some simple generalizations, and a long list of types,
  42. and a book about what is used with what types.... Sorry!
  43. */
  44. struct pval
  45. {
  46. pvaltype type;
  47. int startline;
  48. int endline;
  49. int startcol;
  50. int endcol;
  51. char *filename;
  52. union
  53. {
  54. char *str; /* wow, used almost everywhere! */
  55. struct pval *list; /* used in SWITCHES, ESWITCHES, INCLUDES, STATEMENTBLOCK, GOTO */
  56. struct pval *statements;/* used in EXTENSION */
  57. char *for_init; /* used in FOR */
  58. } u1;
  59. struct pval *u1_last; /* to build in-order lists -- looks like we only need one */
  60. union
  61. {
  62. struct pval *arglist; /* used in macro_call, application_call, MACRO def, also attached to PWORD, the 4 timevals for includes */
  63. struct pval *statements; /* used in case, default, catch, while's statement, CONTEXT elements, GLOBALS */
  64. char *val; /* used in VARDEC */
  65. char *for_test; /* used in FOR */
  66. struct pval *goto_target; /* used in GOTO */
  67. } u2;
  68. union
  69. {
  70. char *for_inc; /* used in FOR */
  71. struct pval *else_statements; /* used in IF */
  72. struct pval *macro_statements; /* used in MACRO */
  73. int abstract; /* used for context 1=abstract; 2=extend; 3=both */
  74. char *hints; /* used in EXTENSION */
  75. int goto_target_in_case; /* used in GOTO */
  76. struct ael_extension *compiled_label;
  77. struct pval *extend; /* to link extended contexts to the 'original' */
  78. } u3;
  79. union
  80. {
  81. struct pval *for_statements; /* used in PV_FOR */
  82. int regexten; /* used in EXTENSION */
  83. } u4;
  84. struct pval *next; /* the pval at the end of this ptr will ALWAYS be of the same type as this one!
  85. EXCEPT for objects of the different types, that are in the same list, like contexts & macros, etc */
  86. struct pval *dad; /* the 'container' of this struct instance */
  87. struct pval *prev; /* the opposite of the 'next' pointer */
  88. } ;
  89. typedef struct pval pval;
  90. #ifndef AAL_ARGCHECK
  91. /* for the time being, short circuit all the AAL related structures
  92. without permanently removing the code; after/during the AAL
  93. development, this code can be properly re-instated
  94. */
  95. /* null definitions for structs passed down the infrastructure */
  96. struct argapp
  97. {
  98. struct argapp *next;
  99. };
  100. #endif
  101. struct ast_context;
  102. #ifdef AAL_ARGCHECK
  103. int option_matches_j( struct argdesc *should, pval *is, struct argapp *app);
  104. int option_matches( struct argdesc *should, pval *is, struct argapp *app);
  105. int ael_is_funcname(char *name);
  106. #endif
  107. int do_pbx_load_module(void);
  108. int count_labels_in_current_context(char *label);
  109. int check_app_args(pval *appcall, pval *arglist, struct argapp *app);
  110. void check_pval(pval *item, struct argapp *apps, int in_globals);
  111. void check_pval_item(pval *item, struct argapp *apps, int in_globals);
  112. void check_switch_expr(pval *item, struct argapp *apps);
  113. void ast_expr_register_extra_error_info(char *errmsg);
  114. void ast_expr_clear_extra_error_info(void);
  115. int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan);
  116. struct pval *find_macro(char *name);
  117. struct pval *find_context(char *name);
  118. struct pval *find_context(char *name);
  119. struct pval *find_macro(char *name);
  120. struct ael_priority *new_prio(void);
  121. struct ael_extension *new_exten(void);
  122. void linkprio(struct ael_extension *exten, struct ael_priority *prio, struct ael_extension *mother_exten);
  123. void destroy_extensions(struct ael_extension *exten);
  124. /* static void linkexten(struct ael_extension *exten, struct ael_extension *add);
  125. static void gen_prios(struct ael_extension *exten, char *label, pval *statement, struct ael_extension *mother_exten, struct ast_context *context ); */
  126. void set_priorities(struct ael_extension *exten);
  127. void add_extensions(struct ael_extension *exten);
  128. int ast_compile_ael2(struct ast_context **local_contexts, struct ast_hashtab *local_table, struct pval *root);
  129. void destroy_pval(pval *item);
  130. void destroy_pval_item(pval *item);
  131. int is_float(char *arg );
  132. int is_int(char *arg );
  133. int is_empty(char *arg);
  134. /* PVAL PI */
  135. pval *pvalCreateNode( pvaltype type );
  136. pvaltype pvalObjectGetType( pval *p );
  137. void pvalWordSetString( pval *p, char *str);
  138. char *pvalWordGetString( pval *p );
  139. void pvalMacroSetName( pval *p, char *name);
  140. char *pvalMacroGetName( pval *p );
  141. void pvalMacroSetArglist( pval *p, pval *arglist );
  142. void pvalMacroAddArg( pval *p, pval *arg );
  143. pval *pvalMacroWalkArgs( pval *p, pval **arg );
  144. void pvalMacroAddStatement( pval *p, pval *statement );
  145. pval *pvalMacroWalkStatements( pval *p, pval **next_statement );
  146. void pvalContextSetName( pval *p, char *name);
  147. char *pvalContextGetName( pval *p );
  148. void pvalContextSetAbstract( pval *p );
  149. void pvalContextUnsetAbstract( pval *p );
  150. int pvalContextGetAbstract( pval *p );
  151. void pvalContextAddStatement( pval *p, pval *statement);
  152. pval *pvalContextWalkStatements( pval *p, pval **statements );
  153. void pvalMacroCallSetMacroName( pval *p, char *name );
  154. char* pvalMacroCallGetMacroName( pval *p );
  155. void pvalMacroCallSetArglist( pval *p, pval *arglist );
  156. void pvalMacroCallAddArg( pval *p, pval *arg );
  157. pval *pvalMacroCallWalkArgs( pval *p, pval **args );
  158. void pvalAppCallSetAppName( pval *p, char *name );
  159. char* pvalAppCallGetAppName( pval *p );
  160. void pvalAppCallSetArglist( pval *p, pval *arglist );
  161. void pvalAppCallAddArg( pval *p, pval *arg );
  162. pval *pvalAppCallWalkArgs( pval *p, pval **args );
  163. void pvalCasePatSetVal( pval *p, char *val );
  164. char* pvalCasePatGetVal( pval *p );
  165. void pvalCasePatDefAddStatement( pval *p, pval *statement );
  166. pval *pvalCasePatDefWalkStatements( pval *p, pval **statement );
  167. void pvalCatchSetExtName( pval *p, char *name );
  168. char* pvalCatchGetExtName( pval *p );
  169. void pvalCatchSetStatement( pval *p, pval *statement );
  170. pval *pvalCatchGetStatement( pval *p );
  171. void pvalSwitchesAddSwitch( pval *p, char *name );
  172. char* pvalSwitchesWalkNames( pval *p, pval **next_item );
  173. void pvalESwitchesAddSwitch( pval *p, char *name );
  174. char* pvalESwitchesWalkNames( pval *p, pval **next_item );
  175. void pvalIncludesAddInclude( pval *p, const char *include );
  176. void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range );
  177. void pvalIncludeGetTimeConstraints( pval *p, char **hour_range, char **dom_range, char **dow_range, char **month_range );
  178. char* pvalIncludesWalk( pval *p, pval **next_item );
  179. void pvalStatementBlockAddStatement( pval *p, pval *statement);
  180. pval *pvalStatementBlockWalkStatements( pval *p, pval **next_statement);
  181. void pvalVarDecSetVarname( pval *p, char *name );
  182. void pvalVarDecSetValue( pval *p, char *value );
  183. char* pvalVarDecGetVarname( pval *p );
  184. char* pvalVarDecGetValue( pval *p );
  185. void pvalGotoSetTarget( pval *p, char *context, char *exten, char *label );
  186. void pvalGotoGetTarget( pval *p, char **context, char **exten, char **label );
  187. void pvalLabelSetName( pval *p, char *name );
  188. char* pvalLabelGetName( pval *p );
  189. void pvalForSetInit( pval *p, char *init );
  190. void pvalForSetTest( pval *p, char *test );
  191. void pvalForSetInc( pval *p, char *inc );
  192. void pvalForSetStatement( pval *p, pval *statement );
  193. char* pvalForGetInit( pval *p );
  194. char* pvalForGetTest( pval *p );
  195. char* pvalForGetInc( pval *p );
  196. pval* pvalForGetStatement( pval *p );
  197. void pvalIfSetCondition( pval *p, char *expr );
  198. char* pvalIfGetCondition( pval *p );
  199. void pvalIfTimeSetCondition( pval *p, char *hour_range, char *dow_range, char *dom_range, char *mon_range ); /* time range format: 24-hour format begin-end|dow range|dom range|month range */
  200. void pvalIfTimeGetCondition( pval *p, char **hour_range, char **dow_range, char **dom_range, char **month_range );
  201. void pvalRandomSetCondition( pval *p, char *percent );
  202. char* pvalRandomGetCondition( pval *p );
  203. void pvalConditionalSetThenStatement( pval *p, pval *statement );
  204. void pvalConditionalSetElseStatement( pval *p, pval *statement );
  205. pval* pvalConditionalGetThenStatement( pval *p );
  206. pval* pvalConditionalGetElseStatement( pval *p );
  207. void pvalSwitchSetTestexpr( pval *p, char *expr );
  208. char* pvalSwitchGetTestexpr( pval *p );
  209. void pvalSwitchAddCase( pval *p, pval *Case );
  210. pval* pvalSwitchWalkCases( pval *p, pval **next_case );
  211. void pvalExtenSetName( pval *p, char *name );
  212. char *pvalExtenGetName( pval *p );
  213. void pvalExtenSetRegexten( pval *p );
  214. void pvalExtenUnSetRegexten( pval *p );
  215. int pvalExtenGetRegexten( pval *p );
  216. void pvalExtenSetHints( pval *p, char *hints );
  217. char* pvalExtenGetHints( pval *p );
  218. void pvalExtenSetStatement( pval *p, pval *statement );
  219. pval* pvalExtenGetStatement( pval *p );
  220. void pvalIgnorePatSetPattern( pval *p, char *pat );
  221. char* pvalIgnorePatGetPattern( pval *p );
  222. void pvalGlobalsAddStatement( pval *p, pval *statement );
  223. pval* pvalGlobalsWalkStatements( pval *p, pval **next_statement );
  224. void pvalTopLevAddObject( pval *p, pval *contextOrObj );
  225. pval* pvalTopLevWalkObjects( pval *p, pval **next_obj );
  226. int pvalCheckType( pval *p, char *funcname, pvaltype type );
  227. #endif