[asterisk-commits] murf: branch murf/bug_7638 r52241 - in /team/murf/bug_7638: include/asterisk/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jan 25 11:23:20 MST 2007


Author: murf
Date: Thu Jan 25 12:23:19 2007
New Revision: 52241

URL: http://svn.digium.com/view/asterisk?view=rev&rev=52241
Log:
OK, there's some trouble with the time spec in includes, but at least I know what it is, I'll fix tomm.

Modified:
    team/murf/bug_7638/include/asterisk/pval.h
    team/murf/bug_7638/main/pval.c
    team/murf/bug_7638/utils/conf2ael.c

Modified: team/murf/bug_7638/include/asterisk/pval.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/include/asterisk/pval.h?view=diff&rev=52241&r1=52240&r2=52241
==============================================================================
--- team/murf/bug_7638/include/asterisk/pval.h (original)
+++ team/murf/bug_7638/include/asterisk/pval.h Thu Jan 25 12:23:19 2007
@@ -201,9 +201,9 @@
 void pvalESwitchesAddSwitch( pval *p, char *name );
 char* pvalESwitchesWalkNames( pval *p, pval **next_item );
 
-void pvalIncludesAddInclude( pval *p, char *include );
-
-void pvalIncludeAddIncludeWithTimeConstraints( pval *p, char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range );
+void pvalIncludesAddInclude( pval *p, const char *include );
+
+void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range );
 void pvalIncludeGetTimeConstraints( pval *p, char **hour_range, char **dom_range, char **dow_range, char **month_range );
 char* pvalIncludesWalk( pval *p, pval **next_item );
 

Modified: team/murf/bug_7638/main/pval.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/main/pval.c?view=diff&rev=52241&r1=52240&r2=52241
==============================================================================
--- team/murf/bug_7638/main/pval.c (original)
+++ team/murf/bug_7638/main/pval.c Thu Jan 25 12:23:19 2007
@@ -229,8 +229,8 @@
 				fprintf(fin,"\t"); /* depth == indentation */
 			}
 			fprintf(fin,"%s", lp->u1.str); /* usually, words are encapsulated in something else */
-			if ( lp->u2.arglist )
-				fprintf(fin,"|%s|%s|%s|%s", 
+			if (lp->u2.arglist)
+				fprintf(fin,"-|'%s'|'%s'|'%s'|'%s'", 
 						lp->u2.arglist->u1.str,
 						lp->u2.arglist->next->u1.str,
 						lp->u2.arglist->next->next->u1.str,
@@ -239,7 +239,6 @@
 			fprintf(fin,";\n"); /* usually, words are encapsulated in something else */
 		}
 		
-		print_pval_list(fin,item->u1.list,depth+1);
 		for (i=0; i<depth; i++) {
 			fprintf(fin,"\t"); /* depth == indentation */
 		}
@@ -4278,125 +4277,6 @@
 
 /* PVAL PI */
 
-
-pval *pvalCreateNode( pvaltype type );
-pvaltype pvalObjectGetType( pval *p );
-
-void pvalWordSetString( pval *p, char *str);
-char *pvalWordGetString( pval *p );
-
-void pvalMacroSetName( pval *p, char *name);
-char *pvalMacroGetName( pval *p );
-void pvalMacroSetArglist( pval *p, pval *arglist );
-void pvalMacroAddArg( pval *p, pval *arg );
-pval *pvalMacroWalkArgs( pval *p, pval **arg );
-void pvalMacroAddStatement( pval *p, pval *statement );
-pval *pvalMacroWalkStatements( pval *p, pval **next_statement );
-
-void pvalContextSetName( pval *p, char *name);
-char *pvalContextGetName( pval *p );
-void pvalContextSetAbstract( pval *p );
-void pvalContextUnsetAbstract( pval *p );
-int  pvalContextGetAbstract( pval *p );
-void pvalContextAddStatement( pval *p, pval *statement);
-pval *pvalContextWalkStatements( pval *p, pval **statements );
-
-void pvalMacroCallSetMacroName( pval *p, char *name );
-char* pvalMacroCallGetMacroName( pval *p );
-void pvalMacroCallSetArglist( pval *p, pval *arglist );
-void pvalMacroCallAddArg( pval *p, pval *arg );
-pval *pvalMacroCallWalkArgs( pval *p, pval **args );
-
-void pvalAppCallSetAppName( pval *p, char *name );
-char* pvalAppCallGetAppName( pval *p );
-void pvalAppCallSetArglist( pval *p, pval *arglist );
-void pvalAppCallAddArg( pval *p, pval *arg );
-pval *pvalAppCallWalkArgs( pval *p, pval **args );
-
-void pvalCasePatSetVal( pval *p, char *val );
-char* pvalCasePatGetVal( pval *p );
-void pvalCasePatDefAddStatement( pval *p, pval *statement );
-pval *pvalCasePatDefWalkStatements( pval *p, pval **statement );
-
-void pvalCatchSetExtName( pval *p, char *name );
-char* pvalCatchGetExtName( pval *p );
-void pvalCatchSetStatement( pval *p, pval *statement );
-pval *pvalCatchGetStatement( pval *p );
-
-void pvalSwitchesAddSwitch( pval *p, char *name );
-char* pvalSwitchesWalkNames( pval *p, pval **next_item );
-void pvalESwitchesAddSwitch( pval *p, char *name );
-char* pvalESwitchesWalkNames( pval *p, pval **next_item );
-
-void pvalIncludesAddInclude( pval *p, char *include );
-
-void pvalIncludeAddIncludeWithTimeConstraints( pval *p, char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range );
-void pvalIncludeGetTimeConstraints( pval *p, char **hour_range, char **dom_range, char **dow_range, char **month_range );
-char* pvalIncludesWalk( pval *p, pval **next_item );
-
-void pvalStatementBlockAddStatement( pval *p, pval *statement);
-pval *pvalStatementBlockWalkStatements( pval *p, pval **next_statement);
-
-void pvalVarDecSetVarname( pval *p, char *name );
-void pvalVarDecSetValue( pval *p, char *value );
-char* pvalVarDecGetVarname( pval *p );
-char* pvalVarDecGetValue( pval *p );
-
-void pvalGotoSetTarget( pval *p, char *context, char *exten, char *label );
-void pvalGotoGetTarget( pval *p, char **context, char **exten, char **label );
-
-void pvalLabelSetName( pval *p, char *name );
-char* pvalLabelGetName( pval *p );
-
-void pvalForSetInit( pval *p, char *init );
-void pvalForSetTest( pval *p, char *test );
-void pvalForSetInc( pval *p, char *inc );
-void pvalForSetStatement( pval *p, pval *statement );
-char* pvalForGetInit( pval *p );
-char* pvalForGetTest( pval *p );
-char* pvalForGetInc( pval *p );
-pval* pvalForGetStatement( pval *p );
-
-
-void pvalIfSetCondition( pval *p, char *expr );
-char* pvalIfGetCondition( pval *p );
-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 */
-void pvalIfTimeGetCondition( pval *p, char **hour_range, char **dow_range, char **dom_range, char **month_range );
-void pvalRandomSetCondition( pval *p, char *percent );
-char* pvalRandomGetCondition( pval *p );
-void pvalConditionalSetThenStatement( pval *p, pval *statement );
-void pvalConditionalSetElseStatement( pval *p, pval *statement );
-pval* pvalConditionalGetThenStatement( pval *p );
-pval* pvalConditionalGetElseStatement( pval *p );
-
-void pvalSwitchSetTestexpr( pval *p, char *expr );
-char* pvalSwitchGetTestexpr( pval *p );
-void pvalSwitchAddCase( pval *p, pval *Case );
-pval* pvalSwitchWalkCases( pval *p, pval **next_case );
-
-void pvalExtenSetName( pval *p, char *name );
-char *pvalExtenGetName( pval *p );
-void pvalExtenSetRegexten( pval *p );
-void pvalExtenUnSetRegexten( pval *p );
-int pvalExtenGetRegexten( pval *p );
-void pvalExtenSetHints( pval *p, char *hints );
-char* pvalExtenGetHints( pval *p );
-void pvalExtenSetStatement( pval *p, pval *statement );
-pval* pvalExtenGetStatement( pval *p );
-
-void pvalIgnorePatSetPattern( pval *p, char *pat );
-char* pvalIgnorePatGetPattern( pval *p );
-
-void pvalGlobalsAddStatement( pval *p, pval *statement );
-pval* pvalGlobalsWalkStatements( pval *p, pval **next_statement );
-
-void pvalTopLevAddObject( pval *p, pval *contextOrObj );
-pval* pvalTopLevWalkObjects( pval *p, pval **next_obj );
-
-int  pvalCheckType( pval *p, char *funcname, pvaltype type );
-
-
-
 /* ----------------- implementation ------------------- */
 
 
@@ -4760,36 +4640,41 @@
 }
 
 
-void pvalIncludesAddInclude( pval *p, char *include )
+void pvalIncludesAddInclude( pval *p, const char *include )
 {
 	if (!pvalCheckType(p, "pvalIncludesAddSwitch", PV_INCLUDES))
 		return;
 	pval *s = pvalCreateNode(PV_WORD);
-	s->u1.str = include;
+	s->u1.str = (char *)include;
 	p->u1.list = linku1(p->u1.list, s);
 }
  /* an include is a WORD with string set to path */
 
-void pvalIncludeAddIncludeWithTimeConstraints( pval *p, char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range )
+void pvalIncludesAddIncludeWithTimeConstraints( pval *p, const char *include, char *hour_range, char *dom_range, char *dow_range, char *month_range )
 {
 	pval *hr = pvalCreateNode(PV_WORD);
 	pval *dom = pvalCreateNode(PV_WORD);
 	pval *dow = pvalCreateNode(PV_WORD);
 	pval *mon = pvalCreateNode(PV_WORD);
-	
-	if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_WORD))
-		return;
+	pval *s = pvalCreateNode(PV_WORD);
+	
+	if (!pvalCheckType(p, "pvalIncludeAddIncludeWithTimeConstraints", PV_INCLUDES))
+		return;
+
+	s->u1.str = (char *)include;
+	p->u1.list = linku1(p->u1.list, s);
 
 	hr->u1.str = hour_range;
 	dom->u1.str = dom_range;
 	dow->u1.str = dow_range;
 	mon->u1.str = month_range;
-	
-	p->u2.arglist = hr;
+
+	s->u2.arglist = hr;
+
 	hr->next = dom;
 	dom->next = dow;
 	dow->next = mon;
-	
+	mon->next = 0;
 }
  /* is this right??? come back and correct it */ /*the ptr is to the WORD */
 void pvalIncludeGetTimeConstraints( pval *p, char **hour_range, char **dom_range, char **dow_range, char **month_range )

Modified: team/murf/bug_7638/utils/conf2ael.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/utils/conf2ael.c?view=diff&rev=52241&r1=52240&r2=52241
==============================================================================
--- team/murf/bug_7638/utils/conf2ael.c (original)
+++ team/murf/bug_7638/utils/conf2ael.c Thu Jan 25 12:23:19 2007
@@ -310,6 +310,7 @@
 	struct ast_exten *next;		/*!< Extension with a greater ID */
 	char stuff[0];
 };
+
 
 /*! \brief ast_include: include= support in extensions.conf */
 struct ast_include {
@@ -1385,9 +1386,9 @@
 void ast_context_destroy(struct ast_context *con, const char *registrar)
 {
 	struct ast_context *tmp, *tmpl=NULL;
+	struct ast_exten *e, *el, *en;
 	struct ast_include *tmpi;
 	struct ast_sw *sw;
-	struct ast_exten *e, *el, *en;
 	struct ast_ignorepat *ipi;
 
 	for (tmp = contexts; tmp; ) {
@@ -2794,13 +2795,63 @@
 {
 }
 
+static int bit_at(unsigned int *word, int bitsperword, int bitnum);
+static void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end);
+static int all_bits_set(unsigned int *word, int bitsperword, int totalbits);
+
+static int bit_at(unsigned int *word, int bitsperword, int bitnum)
+{
+	return word[bitnum/bitsperword] & (1 << (bitnum % bitsperword));
+}
+
+static void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end)
+{
+	int i;
+	int thisbit, thatbit = bit_at(word, bitsperword, totalbits-1);
+	
+	for (i=0; i<totalbits; i++) {
+		thisbit = bit_at(word, bitsperword, i);
+		
+		if (thisbit != thatbit ) {
+			if (thisbit) { /* a zero->one transition; We are starting a time range */
+				*start = i;
+			} else {  /* a one -> zero transition; we are ending a time range */
+				*end = i;
+			}
+		}
+		thatbit = thisbit;
+	}
+}
+
+static int all_bits_set(unsigned int *word, int bitsperword, int totalbits )
+{
+	/* if all the bits in all the words are set, then return 1 */
+	int i, total=totalbits/bitsperword,bitmask = 0;
+	
+	for (i=0; i<bitsperword; i++)
+	{
+		bitmask |= (1 << i);
+	}
+	
+	for (i=0; i<total; i++)
+	{
+		if (word[i] != bitmask)
+			return 0;
+	}
+	return 1;
+}
+
 
 int main(int argc, char **argv)
 {
 	struct ast_context *tmp;
 	struct ast_exten *e, *eroot;
 	pval *tree, *tmptree;
-	
+	struct ast_include *tmpi;
+	struct ast_sw *sw = 0;
+	struct ast_ignorepat *ipi;
+	pval *incl=0;
+
 	tree = 0;
 	tmptree = 0;
 	
@@ -2869,9 +2920,85 @@
 				pvalAppCallAddArg(statemnt, args);
 				pvalExtenSetStatement(exten, statemnt);
 			}
+
+			printf("   extension: %s\n", eroot->exten);
+		}
+		if (tmp->includes) {
+			incl = pvalCreateNode(PV_INCLUDES);
+			pvalContextAddStatement(tmptree, incl);
+		}
+		for (tmpi = tmp->includes; tmpi; ) { /* includes */
+			if (tmpi->hastime)
+			{
+				char timerange[15];
+				char dowrange[10];
+				char domrange[10];
+				char monrange[10];
+				int startbit=0, endbit=0;
+				
+				if (all_bits_set(tmpi->timing.minmask, 30, 720))
+					strcpy(timerange, "*");
+				else {
+					int hr, min;
+					char tbuf[20];
+					get_start_stop(tmpi->timing.minmask, 30, 720, &startbit, &endbit);
+					hr = startbit/30;
+					min = (startbit % 30) * 2;
+					sprintf(tbuf,"%02d:%02d", hr, min);
+					strcpy(timerange, tbuf);
+					hr = endbit/30;
+					min = (endbit % 30) * 2;
+					sprintf(tbuf,"%02d:%02d", hr, min);
+					strcat(timerange,"-");
+					strcat(timerange,tbuf);
+				}
+				
+				if (all_bits_set(&tmpi->timing.dowmask, 7, 7))
+					strcpy(dowrange, "*");
+				else {
+					get_start_stop(&tmpi->timing.dowmask, 7, 7, &startbit, &endbit);
+					strcpy(dowrange, days[startbit]);
+					strcat(dowrange,"-");
+					strcat(dowrange, days[endbit]);
+				}
+
+				if (all_bits_set(&tmpi->timing.monthmask, 12, 12))
+					strcpy(monrange, "*");
+				else {
+					get_start_stop(&tmpi->timing.monthmask, 12, 12, &startbit, &endbit);
+					strcpy(monrange, months[startbit]);
+					strcat(monrange,"-");
+					strcat(monrange, months[endbit]);
+				}
+
+				if (all_bits_set(&tmpi->timing.daymask, 31, 31))
+					strcpy(domrange, "*");
+				else {
+					char tbuf[20];
+					get_start_stop(&tmpi->timing.daymask, 31, 31, &startbit, &endbit);
+					sprintf(tbuf,"%d", startbit);
+					strcpy(domrange, tbuf);
+					strcat(domrange,"-");
+					sprintf(tbuf,"%d", endbit);
+					strcat(domrange, tbuf);
+				}
+				/* now all 4 fields are set; what do we do? */
+				pvalIncludesAddIncludeWithTimeConstraints(incl, tmpi->name, timerange, domrange, dowrange, monrange);
+
+			} else {
+				pvalIncludesAddInclude(incl, tmpi->name);
+			}
 			
-			printf("   extension: %s\n", eroot->exten);
-		}
+			
+			tmpi = tmpi->next;
+		}
+		for (ipi = tmp->ignorepats; ipi; ) { /* ignorepats */
+			incl = pvalCreateNode(PV_IGNOREPAT);
+			pvalIgnorePatSetPattern(incl,(char *)ipi->pattern);
+			pvalContextAddStatement(tmptree, incl);
+			ipi = ipi->next;
+		}
+		sw = 0;
 	}
 	
 	ael2_print("aelout.ael", tree);



More information about the asterisk-commits mailing list