factorize index parsing code for reuse
authorAleš Křenek <ljocha@ics.muni.cz>
Mon, 19 Nov 2007 17:28:35 +0000 (17:28 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Mon, 19 Nov 2007 17:28:35 +0000 (17:28 +0000)
org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/index.c.T

index e1be53d..38490c8 100644 (file)
@@ -298,6 +298,7 @@ static char *db_col_type(const edg_wll_QueryRec *r)
                case EDG_WLL_QUERY_ATTR_USERTAG:
                case EDG_WLL_QUERY_ATTR_HOST:
                case EDG_WLL_QUERY_ATTR_CHKPT_TAG:
+               case EDG_WLL_QUERY_ATTR_NETWORK_SERVER:
                        /* XXX: 255 may not be enough for location or destination */
                        return "varchar(255) binary null"; 
 
@@ -315,7 +316,7 @@ static void do_exit(edg_wll_Context ctx,int code)
        char    *et,*ed;
 
        edg_wll_Error(ctx,&et,&ed);
-       fprintf(stderr,"edg-bkindex: %s (%s)\n",et,ed);
+       fprintf(stderr,"glite-lb-bkindex: %s (%s)\n",et,ed);
        edg_wll_Close(ctx);
        edg_wll_FreeContext(ctx);
        exit(code);
index 031efc6..2886dc1 100644 (file)
@@ -12,33 +12,52 @@ extern int debug;
 
 #define const_len(c)   (sizeof((c))-1)
 
-/* TODO: 
-   - better error recovery (skip unrecognised indices etc.)
-   - leaks memory on errors
-*/
+static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,const char **built_in_indices,edg_wll_QueryRec *** index_out,char ***keys_out);
 
 int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out)
 {
-       edg_wll_QueryRec        **idx = NULL;
-
        static const char *built_in_indices[] = {
                "PRIMARY",
                "parent_job",
                NULL
        };
-
        char    **keys = NULL;
-       int     *cols = NULL;
        char    ***column_names = NULL;
 
+       if (glite_lbu_QueryIndices(ctx->dbctx, "states", &keys, &column_names) != 0) {
+               edg_wll_SetErrorDB(ctx);
+               return EIO;
+       }
+
+       if (!keys) {
+               *index_out = NULL;
+               if (keys_out) *keys_out = NULL;
+               return edg_wll_ResetError(ctx);
+       }
+
+/* XXX: keys are passed up or freed, column_names are freed there */
+       if (parse_indices(ctx,keys,column_names,built_in_indices,index_out,keys_out)) 
+               return edg_wll_Error(ctx,NULL,NULL);
+       else return edg_wll_ResetError(ctx);
+
+}
+
+/* TODO: 
+   - better error recovery (skip unrecognised indices etc.)
+   - leaks memory on errors
+*/
+
+static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,const char **built_in_indices,edg_wll_QueryRec *** index_out,char ***keys_out)
+{
+
+       edg_wll_QueryRec        **idx = NULL;
+
+       int     *cols = NULL;
+
        int     i, j;
        int     nkeys = 0;
 
 
-       if (glite_lbu_QueryIndices(ctx->dbctx, "states", &keys, &column_names) != 0) {
-               edg_wll_SetErrorDB(ctx);
-               return -1;
-       }
 
        for (i = 0; keys[i]; i++) {
                // skip builtin indices