favour user-requested notification validity (backport from trunk)
authorAleš Křenek <ljocha@ics.muni.cz>
Wed, 20 May 2009 13:52:04 +0000 (13:52 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Wed, 20 May 2009 13:52:04 +0000 (13:52 +0000)
org.glite.lb.server/src/lb_proto.c
org.glite.lb.server/src/lb_xml_parse.c.T
org.glite.lb.server/src/lb_xml_parse.h
org.glite.lb.server/src/notification.c

index db72568..0a37569 100644 (file)
@@ -742,7 +742,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                        
                        
                        if (parseNotifRequest(ctx, messageBody, &function, &notifId, 
-                                               &address, &op, &conditions))
+                                               &address, &op, &validity, &conditions))
                                ret = HTTP_BADREQ;
                        else {
                                int     fatal = 0, err = 0;
index d454af6..b29433b 100644 (file)
@@ -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;
        }
 
index 0d2821e..0b74925 100644 (file)
@@ -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 **);
index 032940e..fe52e21 100644 (file)
@@ -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))) )
        {