Work in progress on L&B Proxy logging library. Mostly done,
authorJan Pospíšil <honik@ntc.zcu.cz>
Fri, 29 Oct 2004 09:47:16 +0000 (09:47 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Fri, 29 Oct 2004 09:47:16 +0000 (09:47 +0000)
compiles, but not tested yet.

org.glite.lb.client/Makefile
org.glite.lb.client/src/prod_proto.c
org.glite.lb.client/src/prod_proto.h
org.glite.lb.client/src/producer.c

index 1d849f3..ba64e6b 100644 (file)
@@ -91,7 +91,8 @@ PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la
 THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la
 
 TOOLS:=dump load purge
-EXAMPLES:=feed_shark
+#EXAMPLES:=feed_shark
+EXAMPLES:=
 
 ${LIB}: ${LIBOBJS}
        ${LINK} -o $@ ${LIBLOBJS} -rpath ${glite_location}/lib -lglite_lb_common_${nothrflavour}
index 5ed120d..109eb2c 100644 (file)
@@ -4,6 +4,8 @@
 #include "glite/lb/producer.h"
 #include "glite/lb/escape.h"
 #include "glite/lb/lb_gss.h"
+#include "glite/lb/lb_plain_io.h"
+#include "glite/lb/il_string.h"
 
 #include <signal.h>
 #include <string.h>
@@ -12,7 +14,8 @@
 /*
  *----------------------------------------------------------------------
  *
- * edg_wll_log_proto_client - handle outgoing data
+ * edg_wll_log_proto_client - client part of the logging protocol
+ *   used when sending messages to local logger
  *
  * Returns: 0 if done properly or errno
  *
@@ -154,3 +157,148 @@ int edg_wll_log_proto_client_failure(edg_wll_Context context, int code, edg_wll_
        }
        return ret;
 }
+
+/*
+ * Read reply from server.
+ *  Returns: -1       - error reading message, 
+ *           code > 0 - error code from server
+ */
+static
+int
+get_reply(edg_wll_Context context, int sock, char **buf, int *code_min)
+{
+       char buffer[17];
+       char *msg, *p;
+       int len, code;
+
+       code = 0;
+       /* get message header */
+       len = edg_wll_plain_read_fullbuf(sock, buffer, 17, &context->p_tmp_timeout);
+       if(len < 0) {
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading message header");
+               goto get_reply_end;
+       }
+
+       buffer[16] = 0;
+
+       sscanf(buffer, "%d", &len);
+       if(len > MAXLEN) {
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading message body length");
+               goto get_reply_end;
+       }
+
+       /* allocate room for message body */
+       if((msg = malloc(len)) == NULL) {
+               edg_wll_SetError(context,ENOMEM,"get_reply(): no room for message body");
+               goto get_reply_end;
+       }
+
+       /* read all the data */
+       len = edg_wll_plain_read_fullbuf(sock, msg, len, &context->p_tmp_timeout);
+       if(len < 0) {
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading message body");
+               goto get_reply_end;
+       }
+
+       p = msg;
+       p = get_int(p, &code);
+       if(p == NULL) {
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading result code");
+               free(msg);
+               goto get_reply_end;
+       }
+       p = get_int(p, code_min);
+       if(p == NULL) {
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading result code minor");
+               free(msg);
+               goto get_reply_end;
+       }
+       p = get_string(p, buf);
+       if(p == NULL) {
+               if(*buf) {
+                       free(*buf);
+                       *buf = NULL;
+               }
+               edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading result string");
+               free(msg);
+               goto get_reply_end;
+       }
+
+get_reply_end:
+       if(msg) free(msg);
+       return edg_wll_Error(context,NULL,NULL);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * edg_wll_log_proto_client_proxy - client part of the logging protocol
+ *   used when sending messages to L&B Proxy
+ *
+ * Returns: 0 if done properly or errno
+ *
+ * Calls:
+ *
+ * Algorithm:
+ *
+ *----------------------------------------------------------------------
+ */
+int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_LogLine logline)
+{
+       char *p;  int  len;
+       char *ucs = "honik6";
+       char *buffer,*answer;
+       int     err;
+       int     code;
+       int     count;
+       int     size;
+
+       errno = err = code = count = 0;
+       edg_wll_ResetError(context);
+
+       /* allocate enough room to hold the message */
+       len = 17 + len_string(ucs) + len_string(logline);
+       if((buffer = malloc(len)) == NULL) {
+               edg_wll_SetError(context,ENOMEM,"get_reply(): no room for message body");
+               goto edg_wll_log_proto_client_proxy_end;
+       }
+       p = buffer;
+
+       /* write header */
+       sprintf(p, "%16d\n", len - 17);
+       p += 17;
+
+       /* write rest of the message */
+       p = put_string(p, ucs);
+       p = put_string(p, logline);
+
+       /* send message */
+#ifdef EDG_WLL_LOG_STUB
+       fprintf(stderr,"Sending message to socket...\n");
+#endif
+       if (( count = edg_wll_plain_write_full(socket, buffer, size, &context->p_tmp_timeout)) < 0) {
+               edg_wll_SetError(context,LB_PROTO,"edg_wll_log_proto_client_proxy(): error sending message to socket");
+               goto edg_wll_log_proto_client_proxy_end;
+       }
+
+       /* get answer */
+#ifdef EDG_WLL_LOG_STUB
+       fprintf(stderr,"Reading answer from server...\n");
+#endif
+       count = 0;
+       if ((err = get_reply(context, socket, &answer, &code)) < 0 ) {
+               edg_wll_SetError(context,LB_PROTO,"edg_wll_log_proto_client_proxy(): error reading answer from L&B proxy server");
+       } else {
+#ifdef EDG_WLL_LOG_STUB
+               fprintf(stderr,"Read answer \"%d: %s\"\n",code,answer);
+#endif
+               edg_wll_SetError(context,code,"answer read from L&B proxy server");
+       }
+
+edg_wll_log_proto_client_proxy_end:
+
+       if (buffer) free(buffer);
+       if (answer) free(answer);
+       return edg_wll_Error(context,NULL,NULL);
+}
+
index ef90710..c220594 100644 (file)
@@ -20,6 +20,7 @@ extern "C" {
 
 int edg_wll_log_proto_client(edg_wll_Context context, edg_wll_GssConnection *con, edg_wll_LogLine logline/*, int priority,*/);
 int edg_wll_log_proto_client_failure(edg_wll_Context context, int code, edg_wll_GssStatus *gss_code, const char *text);
+int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_LogLine logline);
 
 #ifdef __cplusplus
 }
index d00ccad..69fc1df 100644 (file)
@@ -352,7 +352,6 @@ edg_wll_logeventmaster_end:
  * Formats a logging message and sends it to L&B Proxy
  * \brief master proxy logging event function
  * \param context      INOUT context to work with,
- * \param priority     IN priority flag (0 for async, 1 for sync)
  * \param event                IN type of the event,
  * \param fmt          IN printf()-like format string,
  * \param ...          IN event specific values/data according to fmt.
@@ -360,7 +359,6 @@ edg_wll_logeventmaster_end:
  */
 static int edg_wll_LogEventMasterProxy(
        edg_wll_Context context,
-       int priority,
        edg_wll_EventCode event,
        char *fmt, ...)
 {
@@ -388,70 +386,63 @@ static int edg_wll_LogEventMasterProxy(
        gettimeofday(&start_time,0);
        if (edg_wll_ULMTimevalToDate(start_time.tv_sec,start_time.tv_usec,date) != 0) {
                edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): edg_wll_ULMTimevalToDate() error"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
        }
        source = edg_wll_SourceToString(context->p_source);
        lvl = edg_wll_LevelToString(context->p_level);
        eventName = edg_wll_EventToString(event);
        if (!eventName) { 
                edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): event name not specified"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
        }
        if (!(fullid = edg_wlc_JobIdUnparse(context->p_jobid))) { 
                edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): edg_wlc_JobIdUnparse() error"); 
-               goto edg_wll_logeventmaster_end;
+               goto edg_wll_logeventmasterproxy_end;
        }
        seq = edg_wll_GetSequenceCode(context);
        if (edg_wll_IncSequenceCode(context)) {
                ret = EINVAL;
-               goto edg_wll_logeventmaster_end;
+               goto edg_wll_logeventmasterproxy_end;
        }
        if (trio_asprintf(&fix,EDG_WLL_FORMAT_COMMON,
-                       date,context->p_host,lvl,priority,
+                       date,context->p_host,lvl,1,
                        source,context->p_instance ? context->p_instance : "",
                        eventName,fullid,seq) == -1) {
                edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): trio_asprintf() error"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
        }
        if (trio_vasprintf(&var,fmt,fmt_args) == -1) { 
                edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): trio_vasprintf() error"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
        }
         /* format the DG.USER string */
 /* XXX: put user credentials here probably from context */
         name_esc = edg_wll_LogEscape("User credentials should go here");
         if (asprintf(&dguser,"DG.USER=\"%s\" ",name_esc) == -1) {
                edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): asprintf() error"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
         }
        if (asprintf(&out,"%s%s%s\n",dguser,fix,var) == -1) { 
                edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): asprintf() error"); 
-               goto edg_wll_logeventmaster_end; 
+               goto edg_wll_logeventmasterproxy_end; 
        }
        size = strlen(out);
 
-       if (priority && (size > EDG_WLL_LOG_SYNC_MAXMSGSIZE)) {
+       if (size > EDG_WLL_LOG_SYNC_MAXMSGSIZE) {
                edg_wll_SetError(context,ret = ENOSPC,"edg_wll_LogEventMasterProxy(): Message size too large for synchronous transfer");
-               goto edg_wll_logeventmaster_end;
+               goto edg_wll_logeventmasterproxy_end;
        }
 
 #ifdef EDG_WLL_LOG_STUB
 //     fprintf(stderr,"edg_wll_LogEvent (%d chars): %s",size,out);
 #endif
        
-       context->p_tmp_timeout.tv_sec = 0;
-       context->p_tmp_timeout.tv_usec = 0;
-       if (priority) {
-               context->p_tmp_timeout = context->p_sync_timeout;
-       }
-       else {
-               context->p_tmp_timeout = context->p_log_timeout;
-       }
+       context->p_tmp_timeout = context->p_sync_timeout;
 
    /* and send the message to the L&B Proxy: */
-       ret = edg_wll_DoLogEventProxy(context, /* priority,*/ out);
+       ret = edg_wll_DoLogEventProxy(context, out);
 
-edg_wll_logeventmaster_end:
+edg_wll_logeventmasterproxy_end:
        va_end(fmt_args);
        if (seq) free(seq); 
        if (fix) free(fix); 
@@ -561,7 +552,7 @@ int edg_wll_LogEventProxy(
                 goto edg_wll_logevent_end;
         }
 
-        ret=edg_wll_LogEventMasterProxy(context,0,event,"%s",list);
+        ret=edg_wll_LogEventMasterProxy(context,event,"%s",list);
 
 edg_wll_logevent_end:
         va_end(fmt_args);