Partially removed quadratic complexity of the string assembly in HTML and text interface.
authorJiří Filipovič <fila@ics.muni.cz>
Thu, 4 Dec 2008 11:50:22 +0000 (11:50 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Thu, 4 Dec 2008 11:50:22 +0000 (11:50 +0000)
org.glite.lb.server/src/lb_html.c
org.glite.lb.server/src/lb_text.c

index ce6baaa..cff5c3c 100644 (file)
@@ -96,7 +96,7 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu
 }
 
 int edg_wll_UserNotifsToHTML(edg_wll_Context ctx UNUSED_VAR, char **notifids, char **message){
-       char *pomA = NULL, *pomB;
+       char *pomA = NULL, *pomB = NULL;
         pomB = strdup("");
 
        int i = 0;
@@ -126,27 +126,22 @@ int edg_wll_UserNotifsToHTML(edg_wll_Context ctx UNUSED_VAR, char **notifids, ch
        return 0;
 }
 
-#define TR(name,type,field)             \
-        if (field) {            \
-                asprintf(&pomA,"%s<tr><th align=\"left\">" name ":</th>"        \
-                        "<td>" type "</td></tr>",pomB,(field)); \
-                free(pomB);                                     \
-                pomB = pomA;                                    \
-        }
-
-#define GS(string){    \
-       asprintf(&pomA, "%s %s", pomB, (string)); \
-       free(pomB); \
-       pomB = pomA; \
-}
+#define TR(name,type,field) \
+       if (field){ \
+               int l = asprintf(&pomA,"<tr><th align=\"left\">" name ":</th>" \
+               "<td>" type "</td></tr>", (field)); \
+               pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \
+               strcpy(pomB+pomL, pomA); \
+               pomL += l; \
+               free(pomA); pomA=NULL; \
+       }
 
 int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){
-       char *pomA = NULL, *pomB, *flags, *cond;
-
+       char *pomA = NULL, *pomB = NULL, *flags, *cond;
+       int pomL = 0;
 
-       pomB = strdup("");
        flags = edg_wll_stat_flags_to_string(ni->flags);
-printf("flags %d - %s", ni->flags, flags);
+       printf("flags %d - %s", ni->flags, flags);
 
        TR("Destination", "%s", ni->destination);
        TR("Valid until", "%s", ni->valid);
@@ -176,15 +171,14 @@ printf("flags %d - %s", ni->flags, flags);
 /* construct Message-Body of Response-Line for edg_wll_JobStatus */
 int edg_wll_JobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
 {
-        char *pomA, *pomB;
+        char *pomA = NULL, *pomB = NULL;
+       int pomL = 0;
        char    *chid,*chstat;
        char    *jdl,*rsl;
 
        jdl = strdup("");
        rsl = strdup("");
        
-       pomB = strdup("");
-
         chid = edg_wlc_JobIdUnparse(stat.jobId);
 
        TR("Status","%s",(chstat = edg_wll_StatToString(stat.state)));
index e0b1c9b..7bd1e49 100644 (file)
@@ -56,14 +56,23 @@ int edg_wll_QueryToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut
        return -1;
 }
 
-#define TR(name,type,field) \
+/*#define TR(name,type,field) \
         if (field) { \
                 asprintf(&a,"%s%s=" type "\n", \
                         b, name, field); \
                 free(b); \
                 b = a; \
-        }
-
+        }*/
+#define TR(name,type,field) \
+        if (field){ \
+               int l = asprintf(&a,"%s=" type "\n", \
+                       name, field); \
+               printf("a = %s l = %i\n", a, l); \
+               b = realloc(b, sizeof(*b)*(pomL+l+1)); \
+               strcpy(b+pomL, a); \
+               pomL += l; \
+               free(a); a=NULL; \
+       }
 
 int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
 {
@@ -122,20 +131,22 @@ int edg_wll_UserNotifsToText(edg_wll_Context ctx, char **notifids, char **messag
 }
 
 int edg_wll_NotificationToText(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){
-       char *a = NULL, *b, *cond, *flags;
-       b = strdup("");
+       char *a = NULL, *b = NULL, *cond, *flags;
+       int pomL = 0;
 
        TR("Notif_id", "%s", ni->notifid);
        TR("Destination", "%s", ni->destination);
        TR("Valid_until", "%s", ni->valid);
-       if (! edg_wll_Condition_Dump(ni, &cond, 1))
+       if (! edg_wll_Condition_Dump(ni, &cond, 1)){
                TR("Conditions", "%s", cond);
+       }
        free(cond);
        flags = edg_wll_stat_flags_to_string(ni->flags);
        TR("Flags", "%s", flags);
        free(flags);
 
-       *message = a;
+       *message = b;
+       printf("Returning message: %s\n", a);
 
        return 0;
 }
@@ -143,14 +154,14 @@ int edg_wll_NotificationToText(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, ch
 /* construct Message-Body of Response-Line for edg_wll_JobStatus */
 int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
 {
-       char *a, *b;
+       char *a = NULL, *b = NULL;
        char    *chid,*chstat;
         char    *jdl,*rsl;
 
        jdl = strdup("");
        rsl = strdup("");
        
-       b = strdup("");
+       int pomL = 0;
 
         chid = edg_wlc_JobIdUnparse(stat.jobId);
 
@@ -224,3 +235,4 @@ char *edg_wll_ErrorToText(edg_wll_Context ctx,int code)
        free(et); free(ed);
        return out;
 }
+