From c1c5fd2be36a9b146e7b476016bae18d5687720e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Thu, 4 Dec 2008 11:50:22 +0000 Subject: [PATCH] Partially removed quadratic complexity of the string assembly in HTML and text interface. --- org.glite.lb.server/src/lb_html.c | 36 +++++++++++++++--------------------- org.glite.lb.server/src/lb_text.c | 30 +++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index ce6baaa..cff5c3c 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -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" name ":" \ - "" type "",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,"" name ":" \ + "" type "", (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))); diff --git a/org.glite.lb.server/src/lb_text.c b/org.glite.lb.server/src/lb_text.c index e0b1c9b..7bd1e49 100644 --- a/org.glite.lb.server/src/lb_text.c +++ b/org.glite.lb.server/src/lb_text.c @@ -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; } + -- 1.8.2.3