- Avoid using sizeof()/sizeof() to determine array length
authorZdeněk Šustr <sustr4@cesnet.cz>
Mon, 6 Aug 2012 14:46:15 +0000 (14:46 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Mon, 6 Aug 2012 14:46:15 +0000 (14:46 +0000)
- Harmonize literal names with corresponding enum values

org.glite.lb.common/interface/query_rec.h
org.glite.lb.common/src/query_rec.c
org.glite.lb.server/src/lb_xml_parse.c.T

index 9c1623b..4bb1144 100644 (file)
@@ -99,6 +99,7 @@ typedef enum _edg_wll_QueryOp{
        EDG_WLL_QUERY_OP_UNEQUAL,       /**< attribute is not equal to the operand value \see _edg_wll_QueryRec */
        EDG_WLL_QUERY_OP_CHANGED,       /**< attribute has changed from last check; supported only in notification matching 
                                                \see _edg_wll_QueryRec */
+       EDG_WLL_QUERY_OP__LAST
 } edg_wll_QueryOp;
 
 
index e7de9bb..6dd6d35 100644 (file)
@@ -28,8 +28,9 @@ limitations under the License.
 
 /**
  * Names for the predefined types of query attributes
+ * NOTE: FOR HISTORIC REASONS, The NAME INDEX IS ONE LESS than the corresponding enum value!
  */
-char     *edg_wll_QueryAttrNames[] = {    "jobid","owner","status","location","destination",
+char     *edg_wll_QueryAttrNames[] = {    "undef", "jobid","owner","status","location","destination",
                                 "donecode","usertag","time","level","host","source",
                                 "instance","type","chkpt_tag", "resubmitted", "parent_job",
                                 "exitcode", "jdl", "stateentertime", "lastupdatetime",
index f6b3c04..d775b9c 100644 (file)
@@ -101,9 +101,9 @@ static void startJobQueryRec(void *data, const char *el, const char **attr)
                        }
                        break;
                case 2:
-                       for (i=0; i<sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0]); i++)
+                       for (i=0; i<EDG_WLL_QUERY_OP__LAST; i++)
                                if (!strcasecmp(el,edg_wll_QueryOpNames[i])) break;
-                       if (i == sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0])) unexp()
+                       if (i == EDG_WLL_QUERY_OP__LAST) unexp()
                        else {
                                if (!XMLCtx->job_conditions) break;
 
@@ -115,30 +115,30 @@ static void startJobQueryRec(void *data, const char *el, const char **attr)
                                XMLCtx->bound = 0;
                        }
                        break;
-               case 3: for (i=0; i<sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0]) && 
+               case 3: for (i=1; i<EDG_WLL_QUERY_ATTR__LAST && 
                                strcasecmp(el,edg_wll_QueryAttrNames[i]); i++);
-                       if (i == sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0])) unexp()
+                       if (i == EDG_WLL_QUERY_ATTR__LAST) unexp()
                        else {
                                if (!XMLCtx->job_conditions) break;
                                if (!XMLCtx->job_conditions[XMLCtx->row]) break;
 
-                               if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
+                               if ( (i) == EDG_WLL_QUERY_ATTR_USERTAG) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                        if (strcmp(attr[0],"name")) { unexp() break;}
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
                                } 
-                               else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME ) {
+                               else if ( (i) == EDG_WLL_QUERY_ATTR_TIME ) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                         if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
                                }
-                               if ( (i+1) == EDG_WLL_QUERY_ATTR_JDL_ATTR) {
+                               if ( (i) == EDG_WLL_QUERY_ATTR_JDL_ATTR) {
                                        if (!attr[0] || !attr[1]) 
                                                XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = NULL;
                                        else if (strcmp(attr[0],"name")) { unexp() break;}
                                        else XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
                                } 
-                               XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
+                               XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i;
                        }               
                        break;
                default: unexp(); break;
@@ -224,9 +224,9 @@ static void startQueryEventsRequest(void *data, const char *el, const char **att
                        else unexp()
                        break;
                case 3:
-                       for (i=0; i<sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0]); i++)
+                       for (i=0; i<EDG_WLL_QUERY_OP__LAST; i++)
                                if (!strcasecmp(el,edg_wll_QueryOpNames[i])) break;
-                       if (i == sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0])) unexp()
+                       if (i == EDG_WLL_QUERY_OP__LAST) unexp()
                        else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
                                if (!XMLCtx->job_conditions) break;
 
@@ -248,37 +248,37 @@ static void startQueryEventsRequest(void *data, const char *el, const char **att
                        }
                        
                        break;
-               case 4: for (i=0; i<sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0]) && 
+               case 4: for (i=1; i<EDG_WLL_QUERY_ATTR__LAST && 
                                strcasecmp(el,edg_wll_QueryAttrNames[i]); i++);
-                       if (i == sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0])) unexp()
+                       if (i == EDG_WLL_QUERY_ATTR__LAST) unexp()
                        else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) { 
                                if (!XMLCtx->job_conditions[XMLCtx->row]) break;
-                               if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
+                               if ( (i) == EDG_WLL_QUERY_ATTR_USERTAG) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                        if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
                                } 
-                               else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME ) {
+                               else if ( (i) == EDG_WLL_QUERY_ATTR_TIME ) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                         if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
                                        //printf("\nchecking time attr\n%s = %s (%d)\n\n", attr[0], attr[1], edg_wll_StringToStat(attr[1]));
                                }
-                               XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
+                               XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i;
                        }
                        else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
                                if (!XMLCtx->event_conditions[XMLCtx->row2]) break;
-                               if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
+                               if ( (i) == EDG_WLL_QUERY_ATTR_USERTAG) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                        if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
                                        XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.tag = strdup(attr[1]);
                                } 
-                               else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME ) {
+                               else if ( (i) == EDG_WLL_QUERY_ATTR_TIME ) {
                                        if (!attr[0] || !attr[1]) { unexp() break;}
                                         if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
                                        XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
                                }
-                               XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr = i+1;
+                               XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr = i;
                        }
                        break;
                default: unexp(); break;