Query attribute name definitions moved from lb.server to lb.common
authorZdeněk Šustr <sustr4@cesnet.cz>
Fri, 3 Aug 2012 14:59:18 +0000 (14:59 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Fri, 3 Aug 2012 14:59:18 +0000 (14:59 +0000)
  - At least three other places where the names are used can be rid of duplicate literals
Stub for the "?query" query string in URLs

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

index bffe71a..9c1623b 100644 (file)
@@ -78,6 +78,15 @@ typedef enum _edg_wll_QueryAttr{
 /*     if adding new attribute, add conversion string to common/xml_conversions.c too !! */
 } edg_wll_QueryAttr;
 
+/**
+ * Names for the predefined types of query attributes
+ */
+extern char     *edg_wll_QueryAttrNames[];
+
+/**
+ * Names for the predefined types of query operands
+ */
+extern char     *edg_wll_QueryOpNames[];
 
 /**
  * Predefined types for query operands
index d4e6be3..e7de9bb 100644 (file)
@@ -26,6 +26,21 @@ limitations under the License.
 #include "glite/jobid/cjobid.h"
 #include "query_rec.h"
 
+/**
+ * Names for the predefined types of query attributes
+ */
+char     *edg_wll_QueryAttrNames[] = {    "jobid","owner","status","location","destination",
+                                "donecode","usertag","time","level","host","source",
+                                "instance","type","chkpt_tag", "resubmitted", "parent_job",
+                                "exitcode", "jdl", "stateentertime", "lastupdatetime",
+                                "networkserver"  };
+
+/**
+ * Names for the predefined types of query operands
+ */
+char     *edg_wll_QueryOpNames[] = { "equal","less","greater","within","unequal","changed" };
+
+
 /*
  * edg_wll_QueryRec manipulation routines
  */
index 950f10d..b0d9708 100644 (file)
@@ -677,7 +677,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
        char **response,char ***headersOut,char **bodyOut,
        int *httpErr)
 {
-       char *requestPTR = NULL, *message = NULL, *requestMeat = NULL;
+       char *requestPTR = NULL, *message = NULL, *requestMeat = NULL, *querystr, *queryconds = NULL;
        int     ret = HTTP_OK;
        int     html = outputHTML(headers);
        int     text = 0; //XXX: Plain text communication is special case of html here, hence when text=1, html=1 too
@@ -737,6 +737,16 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                        if (check_request_for_query(requestPTR, "?all")) adm_opt = HTTP_ADMIN_OPTION_ALL;
                        else if (check_request_for_query(requestPTR, "?foreign")) adm_opt = HTTP_ADMIN_OPTION_FOREIGN;
 
+                       if ((querystr = strstr(requestPTR, "?query="))) {
+                               int len = strcspn(querystr+strlen("?query="),"? \f\n\r\t\v");
+                               if (len) {
+                                       extra_opt = HTTP_EXTRA_OPTION_QUERY;
+                                       queryconds = (char*)calloc((len+1),sizeof(char));
+                                       queryconds = strncpy(queryconds, querystr+strlen("?query="), len);
+                                       glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG,
+                                               "Query over HTML \"%s\"", queryconds);
+                               }
+                       }
                        strip_request_of_queries(requestPTR);
                }
 
@@ -750,7 +760,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                }
 
        /* GET /: Current User Jobs */
-               else if ((!strcmp(requestMeat, "/")) && (extra_opt == HTTP_EXTRA_OPTION_NONE)) {
+               else if ((!strcmp(requestMeat, "/")) && ((extra_opt == HTTP_EXTRA_OPTION_NONE) || ( extra_opt == HTTP_EXTRA_OPTION_QUERY))) {
                        edg_wlc_JobId *jobsOut = NULL;
                        edg_wll_JobStat *statesOut = NULL;
                        int     i, flags;
@@ -1492,6 +1502,8 @@ err:      asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret));
        else
                *bodyOut = message;
 
+       free(queryconds);
+
        if (requestPTR) free(requestPTR);
        if (requestMeat) free(requestMeat);
 
index b55f59b..b56410d 100644 (file)
@@ -65,6 +65,7 @@ typedef enum _http_extra_option{
        HTTP_EXTRA_OPTION_VERSION,
        HTTP_EXTRA_OPTION_CONFIGURATION,
        HTTP_EXTRA_OPTION_STATS,
+       HTTP_EXTRA_OPTION_QUERY,
         HTTP_EXTRA_OPTION_LAST
 } http_extra_option;
 
index afde05d..f6b3c04 100644 (file)
@@ -29,6 +29,7 @@ limitations under the License.
 
 #include "glite/lb/context-int.h"
 #include "glite/lb/xml_conversions.h"
+#include "glite/lb/query_rec.h"
 
 #include "lb_xml_parse.h"
 
@@ -63,14 +64,6 @@ limitations under the License.
 #define USERJOBS_BEGIN         "<edg_wll_UserJobs"
 #define USERJOBS_END           "</edg_wll_UserJobs>\r\n"
 
-
-static char    *ops[] = { "equal","less","greater","within","unequal","changed" },
-               *attrs[] = {    "jobid","owner","status","location","destination",
-                               "donecode","usertag","time","level","host","source",
-                               "instance","type","chkpt_tag", "resubmitted", "parent_job",
-                               "exitcode", "jdl", "stateentertime", "lastupdatetime", 
-                               "networkserver"  };
-
 static const struct timeval null_timeval = {0,0};
 
 #define unexp() {\
@@ -108,9 +101,9 @@ static void startJobQueryRec(void *data, const char *el, const char **attr)
                        }
                        break;
                case 2:
-                       for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
-                               if (!strcasecmp(el,ops[i])) break;
-                       if (i == sizeof(ops)/sizeof(ops[0])) unexp()
+                       for (i=0; i<sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0]); i++)
+                               if (!strcasecmp(el,edg_wll_QueryOpNames[i])) break;
+                       if (i == sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0])) unexp()
                        else {
                                if (!XMLCtx->job_conditions) break;
 
@@ -122,9 +115,9 @@ static void startJobQueryRec(void *data, const char *el, const char **attr)
                                XMLCtx->bound = 0;
                        }
                        break;
-               case 3: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) && 
-                               strcasecmp(el,attrs[i]); i++);
-                       if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
+               case 3: for (i=0; i<sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0]) && 
+                               strcasecmp(el,edg_wll_QueryAttrNames[i]); i++);
+                       if (i == sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0])) unexp()
                        else {
                                if (!XMLCtx->job_conditions) break;
                                if (!XMLCtx->job_conditions[XMLCtx->row]) break;
@@ -231,9 +224,9 @@ static void startQueryEventsRequest(void *data, const char *el, const char **att
                        else unexp()
                        break;
                case 3:
-                       for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
-                               if (!strcasecmp(el,ops[i])) break;
-                       if (i == sizeof(ops)/sizeof(ops[0])) unexp()
+                       for (i=0; i<sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0]); i++)
+                               if (!strcasecmp(el,edg_wll_QueryOpNames[i])) break;
+                       if (i == sizeof(edg_wll_QueryOpNames)/sizeof(edg_wll_QueryOpNames[0])) unexp()
                        else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
                                if (!XMLCtx->job_conditions) break;
 
@@ -255,9 +248,9 @@ static void startQueryEventsRequest(void *data, const char *el, const char **att
                        }
                        
                        break;
-               case 4: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) && 
-                               strcasecmp(el,attrs[i]); i++);
-                       if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
+               case 4: for (i=0; i<sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0]) && 
+                               strcasecmp(el,edg_wll_QueryAttrNames[i]); i++);
+                       if (i == sizeof(edg_wll_QueryAttrNames)/sizeof(edg_wll_QueryAttrNames[0])) 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) {