From c9002220a982c8a018c0c8168b38dfda3d2991ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Wed, 20 May 2009 13:52:04 +0000 Subject: [PATCH] favour user-requested notification validity (backport from trunk) --- org.glite.lb.server/src/lb_proto.c | 2 +- org.glite.lb.server/src/lb_xml_parse.c.T | 6 +++- org.glite.lb.server/src/lb_xml_parse.h | 2 +- org.glite.lb.server/src/notification.c | 48 ++++++++++++++++++++------------ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index db72568..0a37569 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -742,7 +742,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, if (parseNotifRequest(ctx, messageBody, &function, ¬ifId, - &address, &op, &conditions)) + &address, &op, &validity, &conditions)) ret = HTTP_BADREQ; else { int fatal = 0, err = 0; diff --git a/org.glite.lb.server/src/lb_xml_parse.c.T b/org.glite.lb.server/src/lb_xml_parse.c.T index d454af6..b29433b 100644 --- a/org.glite.lb.server/src/lb_xml_parse.c.T +++ b/org.glite.lb.server/src/lb_xml_parse.c.T @@ -835,6 +835,9 @@ static void endNotifRequest(void *data, const char *el UNUSED_VAR) XMLCtx->notifChangeOp = edg_wll_StringToNotifChangeOp(pom); free(pom); } + else if (!strcmp(XMLCtx->element,"requestedValidity")) { + XMLCtx->notifValidity = edg_wll_from_string_to_time_t(XMLCtx); + } else if (!strcmp(el,"and")) { long len = (XML_GetCurrentByteIndex(XMLCtx->p) + XML_GetCurrentByteCount(XMLCtx->p)) - XMLCtx->jobQueryRec_begin; @@ -1316,7 +1319,7 @@ int parseStatsRequest(edg_wll_Context ctx, char *messageBody, char **function, e return ret; } /* parse Notif request from client */ -int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, edg_wll_QueryRec ***conditions) +int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, time_t *validity,edg_wll_QueryRec ***conditions) { int ret; edg_wll_XML_ctx XMLCtx; @@ -1382,6 +1385,7 @@ int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, e *notifId = XMLCtx.notifId; *address = XMLCtx.notifClientAddress; *op = XMLCtx.notifChangeOp; + *validity = XMLCtx.notifValidity; *conditions = XMLCtx.job_conditions; } diff --git a/org.glite.lb.server/src/lb_xml_parse.h b/org.glite.lb.server/src/lb_xml_parse.h index 0d2821e..0b74925 100644 --- a/org.glite.lb.server/src/lb_xml_parse.h +++ b/org.glite.lb.server/src/lb_xml_parse.h @@ -21,7 +21,7 @@ int parseQueryEventsRequest(edg_wll_Context ctx, char *messageBody, edg_wll_Quer int parsePurgeRequest(edg_wll_Context ctx, char *messageBody, int (*tagToIndex)(), edg_wll_PurgeRequest *request); int parseDumpRequest(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request); int parseLoadRequest(edg_wll_Context ctx, char *messageBody, edg_wll_LoadRequest *request); -int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, edg_wll_QueryRec ***conditions); +int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, time_t *validity,edg_wll_QueryRec ***conditions); int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wlc_JobId *jobId, char **source); int edg_wll_QueryEventsToXML(edg_wll_Context, edg_wll_Event *, char **); int edg_wll_QueryJobsToXML(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **); diff --git a/org.glite.lb.server/src/notification.c b/org.glite.lb.server/src/notification.c index 032940e..fe52e21 100644 --- a/org.glite.lb.server/src/notification.c +++ b/org.glite.lb.server/src/notification.c @@ -23,6 +23,24 @@ static int update_notif(edg_wll_Context, const edg_wll_NotifId, const char *, const char *, const char *); +static void adjust_validity(edg_wll_Context ctx,time_t *valid) +{ + time_t now; + + time(&now); + + if (*valid <= 0) { + *valid = now + ctx->notifDuration; + } + + if (ctx->peerProxyValidity && ctx->peerProxyValidity < *valid) + *valid = ctx->peerProxyValidity; + + if (*valid - now > ctx->notifDuration) + *valid = now + ctx->notifDuration; +} + + int edg_wll_NotifNewServer( edg_wll_Context ctx, edg_wll_QueryRec const * const *conditions, @@ -72,12 +90,11 @@ int edg_wll_NotifNewServer( /* Format time of validity */ - *valid = time(NULL); - if ( ctx->peerProxyValidity - && (ctx->peerProxyValidity - *valid) < ctx->notifDuration ) - *valid = ctx->peerProxyValidity; - else - *valid += ctx->notifDuration; + + if (*valid <= 0) + *valid = time(NULL) + ctx->notifDuration; + adjust_validity(ctx,valid); + if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) { @@ -178,12 +195,9 @@ int edg_wll_NotifBindServer( /* Format time of validity */ - *valid = time(NULL); - if ( ctx->peerProxyValidity - && (ctx->peerProxyValidity - *valid) < ctx->notifDuration ) - *valid = ctx->peerProxyValidity; - else - *valid += ctx->notifDuration; + if (*valid <= 0) + *valid = time(NULL) + ctx->notifDuration; + adjust_validity(ctx,valid); if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) { @@ -333,12 +347,10 @@ int edg_wll_NotifRefreshServer( /* Format time of validity */ - *valid = time(NULL); - if ( ctx->peerProxyValidity - && (ctx->peerProxyValidity - *valid) < ctx->notifDuration ) - *valid = ctx->peerProxyValidity; - else - *valid += ctx->notifDuration; + if (*valid <= 0) + *valid = time(NULL) + ctx->notifDuration; + adjust_validity(ctx,valid); + if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) { -- 1.8.2.3