From 820448d00fac6199a22758d21e95d5d412c3fbc4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Mon, 17 Mar 2008 11:32:32 +0000 Subject: [PATCH] enable to pass notification validity from client to server --- org.glite.lb.client/interface/notification.h | 9 +++++---- org.glite.lb.client/src/notification.c | 10 +++++----- org.glite.lb.client/src/notify.c | 29 ++++++++++++++++++++-------- org.glite.lb.server/src/lb_proto.c | 2 +- org.glite.lb.server/src/lb_xml_parse.c.T | 9 +++++++-- org.glite.lb.server/src/lb_xml_parse.h | 2 +- org.glite.lb.server/src/notification.c | 12 ++++++------ 7 files changed, 46 insertions(+), 27 deletions(-) diff --git a/org.glite.lb.client/interface/notification.h b/org.glite.lb.client/interface/notification.h index 791c691..7b52973 100644 --- a/org.glite.lb.client/interface/notification.h +++ b/org.glite.lb.client/interface/notification.h @@ -34,7 +34,9 @@ extern "C" { * \param[in] address_override if not NULL, use this address instead of extracting it * from the connection (useful when multiple interfaces are present, * circumventing NAT problems etc.) - * \param[in] valid until when the registration is valid (NULL means no interest in + * \param[in,out] valid until when the registration is valid + in: requested validity (NULL means 'give me server defaults') + out: value really set on the server * \param[out] id_out returened NotifId * the value * \retval 0 OK @@ -58,7 +60,7 @@ int edg_wll_NotifNew( * \param[in] id notification ID you are binding to * \param[in] fd same as for \ref edg_wll_NotifNew * \param[in] address_override same as for \ref edg_wll_NotifNew - * \param[in] valid same as for \ref edg_wll_NotifNew + * \param[in,out] valid same as for \ref edg_wll_NotifNew */ int edg_wll_NotifBind( @@ -91,8 +93,7 @@ int edg_wll_NotifChange( /** Refresh the registration, i.e. extend its validity period. * \param[in,out] context context to work with * \param[in] id notification ID you are working with - * \param[in] valid until when the registration is valid (NULL means no interest in - * the value + * \param[in,out] valid same as for \ref edg_wll_NotifNew */ int edg_wll_NotifRefresh( diff --git a/org.glite.lb.client/src/notification.c b/org.glite.lb.client/src/notification.c index e49d371..1017e9e 100644 --- a/org.glite.lb.client/src/notification.c +++ b/org.glite.lb.client/src/notification.c @@ -242,7 +242,7 @@ int edg_wll_NotifNew( goto err; if ( (ret = edg_wll_NotifRequestToXML(ctx, "New", notifId, address, - EDG_WLL_NOTIF_NOOP, conditions, &send_mess)) ) + EDG_WLL_NOTIF_NOOP, *valid, conditions, &send_mess)) ) goto err; ctx->p_tmp_timeout = ctx->p_notif_timeout; @@ -305,7 +305,7 @@ int edg_wll_NotifBind( goto err; if (edg_wll_NotifRequestToXML(ctx, "Bind", id, address, - EDG_WLL_NOTIF_NOOP, NULL, &send_mess)) + EDG_WLL_NOTIF_NOOP, *valid, NULL, &send_mess)) goto err; ctx->p_tmp_timeout = ctx->p_notif_timeout; @@ -347,7 +347,7 @@ int edg_wll_NotifChange( goto err; if (edg_wll_NotifRequestToXML(ctx, "Change", id, NULL, - op, conditions, &send_mess)) + op, -1, conditions, &send_mess)) goto err; ctx->p_tmp_timeout = ctx->p_notif_timeout; @@ -386,7 +386,7 @@ int edg_wll_NotifRefresh( goto err; if (edg_wll_NotifRequestToXML(ctx, "Refresh", id, NULL, - EDG_WLL_NOTIF_NOOP, NULL, &send_mess)) + EDG_WLL_NOTIF_NOOP, *valid, NULL, &send_mess)) goto err; ctx->p_tmp_timeout = ctx->p_notif_timeout; @@ -425,7 +425,7 @@ int edg_wll_NotifDrop( goto err; if (edg_wll_NotifRequestToXML(ctx, "Drop", id, NULL, - EDG_WLL_NOTIF_NOOP, NULL, &send_mess)) + EDG_WLL_NOTIF_NOOP, -1, NULL, &send_mess)) goto err; ctx->p_tmp_timeout = ctx->p_notif_timeout; diff --git a/org.glite.lb.client/src/notify.c b/org.glite.lb.client/src/notify.c index bd5b1c5..0e8c226 100644 --- a/org.glite.lb.client/src/notify.c +++ b/org.glite.lb.client/src/notify.c @@ -45,13 +45,13 @@ static void usage(char *cmd) me); } if ( !cmd || !strcmp(cmd, "new") ) - fprintf(stderr,"\n'new' command usage: %s new [ { -s socket_fd | -a fake_addr } ] {-j jobid | -o owner | -n network_server | -v virtual_organization}\n" + fprintf(stderr,"\n'new' command usage: %s new [ { -s socket_fd | -a fake_addr } -t requested_validity ] {-j jobid | -o owner | -n network_server | -v virtual_organization }\n" " jobid job ID to connect notif. reg. with\n" " owner match this owner DN\n" " network_server match only this networ server (WMS entry point)\n\n" , me); if ( !cmd || !strcmp(cmd, "bind") ) - fprintf(stderr,"\n'bind' command usage: %s bind [ { -s socket_fd | -a fake_addr } ] notifid\n" + fprintf(stderr,"\n'bind' command usage: %s bind [ { -s socket_fd | -a fake_addr } -t requested_validity ] notifid\n" " notifid Notification ID\n" " fake_addr Fake the client address\n", me); /* UNIMPL @@ -61,7 +61,7 @@ static void usage(char *cmd) " jobid Job ID to connect notif. reg. with.\n", me); */ if ( !cmd || !strcmp(cmd, "refresh") ) - fprintf(stderr,"\n'refresh' command usage: %s refresh notifid\n" + fprintf(stderr,"\n'refresh' command usage: %s refresh [-t requested_validity ] notifid\n" " notifid Notification ID.\n", me); if ( !cmd || !strcmp(cmd, "receive") ) fprintf(stderr,"\n'receive' command usage: %s receive [ { -s socket_fd | -a fake_addr } ] [-t timeout] [-f field1,field2,...] [notifid]\n" @@ -78,7 +78,7 @@ int main(int argc,char **argv) { edg_wll_Context ctx; edg_wll_QueryRec **conditions = NULL; - time_t valid; + time_t valid = 0; char *errt, *errd; struct timeval tout = {220, 0}; void *fields = NULL; @@ -108,7 +108,7 @@ int main(int argc,char **argv) char *arg = NULL; int attr = 0; - while ((c = getopt(argc-1,argv+1,"j:o:v:n:s:a:")) > 0) switch (c) { + while ((c = getopt(argc-1,argv+1,"j:o:v:n:s:a:t:")) > 0) switch (c) { case 'j': if (arg) { usage("new"); return EX_USAGE; } attr = EDG_WLL_QUERY_ATTR_JOBID; @@ -131,6 +131,8 @@ int main(int argc,char **argv) case 'a': if (sock >= 0) { usage("new"); return EX_USAGE; } fake_addr = optarg; break; + case 't': + valid = atol(optarg); break; default: usage("new"); return EX_USAGE; } @@ -167,13 +169,15 @@ int main(int argc,char **argv) edg_wll_NotifId nid; int c; - while ((c = getopt(argc-1,argv+1,"s:a:")) > 0) switch (c) { + while ((c = getopt(argc-1,argv+1,"s:a:t:")) > 0) switch (c) { case 's': if (fake_addr) { usage("bind"); return EX_USAGE; } sock = atoi(optarg); break; case 'a': if (sock >= 0) { usage("bind"); return EX_USAGE; } fake_addr = optarg; break; + case 't': + valid = atol(optarg); break; default: usage("bind"); return EX_USAGE; } @@ -323,13 +327,22 @@ receive_err: else if ( !strcmp(argv[1], "refresh") ) { edg_wll_NotifId nid; + int c; - if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) ) + while ((c = getopt(argc-1,argv+1,"t:")) > 0) switch (c) { + case 't': + valid = atol(optarg); break; + default: + usage("refresh"); return EX_USAGE; + } + + if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) ) { - fprintf(stderr,"Notification ID parameter not set propperly!\n"); + fprintf(stderr,"Notification ID parameter not set propperly!\n\n"); usage("refresh"); return EX_USAGE; } + if ( !edg_wll_NotifRefresh(ctx, nid, &valid) ) printf("valid until: %s (%ld)\n", TimeToStr(valid), valid); edg_wll_NotifIdFree(nid); diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index efaaf09..37732b8 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -761,7 +761,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 3d1db75..7986e1b 100644 --- a/org.glite.lb.server/src/lb_xml_parse.c.T +++ b/org.glite.lb.server/src/lb_xml_parse.c.T @@ -372,7 +372,7 @@ static void startNotifRequest(void *data, const char *el, const char **attr) XMLCtx->jobQueryRec_begin = XML_GetCurrentByteIndex(XMLCtx->p); } else if ( (strcasecmp(el,"notifId")) && (strcasecmp(el,"clientAddress")) && - (strcasecmp(el,"notifChangeOp")) ) unexp() + (strcasecmp(el,"notifChangeOp")) && (strcasecmp(el,"requestedValidity")) ) unexp() break; case 2: /* fall through */ case 3: /* do not check xml tags, processed in startJobQueryRec */ @@ -844,6 +844,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; @@ -1325,7 +1328,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; @@ -1385,12 +1388,14 @@ int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, e *notifId = NULL; *address = NULL; *op = EDG_WLL_NOTIF_NOOP; + *validity = 0; *conditions = NULL; } else { *function = XMLCtx.notifFunction; *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 e924de9..2eaccf7 100644 --- a/org.glite.lb.server/src/lb_xml_parse.h +++ b/org.glite.lb.server/src/lb_xml_parse.h @@ -20,7 +20,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 68584ff..dbb8275 100644 --- a/org.glite.lb.server/src/notification.c +++ b/org.glite.lb.server/src/notification.c @@ -82,8 +82,8 @@ int edg_wll_NotifNewServer( /* Format time of validity */ -/* XXX: until valid works [inout] */ - *valid = time(NULL) + ctx->notifDuration; + if (*valid == 0) + *valid = time(NULL) + ctx->notifDuration; adjust_validity(ctx,valid); glite_lbu_TimeToDB(*valid, &time_s); @@ -193,8 +193,8 @@ int edg_wll_NotifBindServer( /* Format time of validity */ -/* XXX: until valid works [inout] */ - *valid = time(NULL) + ctx->notifDuration; + if (*valid == 0) + *valid = time(NULL) + ctx->notifDuration; adjust_validity(ctx,valid); glite_lbu_TimeToDB(*valid, &time_s); @@ -357,8 +357,8 @@ int edg_wll_NotifRefreshServer( /* Format time of validity */ -/* XXX: until valid works [inout] */ - *valid = time(NULL) + ctx->notifDuration; + if (*valid == 0) + *valid = time(NULL) + ctx->notifDuration; adjust_validity(ctx,valid); glite_lbu_TimeToDB(*valid, &time_s); -- 1.8.2.3