From 7d3ca2d19f404da540a9827063b05efa9e8f54e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Voc=C5=AF?= Date: Fri, 11 Feb 2005 13:04:36 +0000 Subject: [PATCH] * prod_proto.c (logging client) now uses IL communication library for proxy and direct calls * readers return -1 as they should in notification.c --- org.glite.lb.client/src/notification.c | 6 +- org.glite.lb.client/src/prod_proto.c | 191 +++++++++++---------------------- 2 files changed, 63 insertions(+), 134 deletions(-) diff --git a/org.glite.lb.client/src/notification.c b/org.glite.lb.client/src/notification.c index acce61d..0e4f6cf 100644 --- a/org.glite.lb.client/src/notification.c +++ b/org.glite.lb.client/src/notification.c @@ -460,13 +460,13 @@ static int gss_reader(char *buffer, int max_len) if(ret < 0) switch(ret) { case EDG_WLL_GSS_ERROR_TIMEOUT: - ret = edg_wll_SetError(tmp_ctx, ETIMEDOUT, "read message"); + edg_wll_SetError(tmp_ctx, ETIMEDOUT, "read message"); break; case EDG_WLL_GSS_ERROR_EOF: - ret = edg_wll_SetError(tmp_ctx, ENOTCONN, NULL); + edg_wll_SetError(tmp_ctx, ENOTCONN, NULL); break; default: - ret = edg_wll_SetError(tmp_ctx, EDG_WLL_ERROR_GSS, "read message"); + edg_wll_SetError(tmp_ctx, EDG_WLL_ERROR_GSS, "read message"); break; } diff --git a/org.glite.lb.client/src/prod_proto.c b/org.glite.lb.client/src/prod_proto.c index 870b16f..55be913 100644 --- a/org.glite.lb.client/src/prod_proto.c +++ b/org.glite.lb.client/src/prod_proto.c @@ -5,6 +5,7 @@ #include "glite/lb/escape.h" #include "glite/lb/lb_gss.h" #include "glite/lb/lb_plain_io.h" +#include "glite/lb/il_msg.h" #include "glite/lb/il_string.h" #include @@ -63,6 +64,23 @@ int edg_wll_log_proto_handle_gss_failures(edg_wll_Context context, int code, edg return ret; } + +static edg_wll_Context tmp_context; +static edg_wll_PlainConnection *tmp_conn; + +static +int +plain_reader(char *buffer, int max_len) +{ + int len; + + len = edg_wll_plain_read_full(tmp_conn, buffer, max_len, &tmp_context->p_tmp_timeout); + if(len < 0) + edg_wll_SetError(tmp_context, LB_PROTO, "get_reply_plain(): error reading message data"); + + return(len); +} + /* *---------------------------------------------------------------------- * get_reply_plain, get_reply_gss - read reply from server @@ -75,130 +93,63 @@ static int get_reply_plain(edg_wll_Context context, edg_wll_PlainConnection *conn, char **buf, int *code_min) { - char buffer[17]; - char *msg, *p; + char *msg; int len, code; code = 0; - /* get message header */ - len = edg_wll_plain_read_full(conn, buffer, 17, &context->p_tmp_timeout); - if(len < 0) { - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading message header"); - goto get_reply_plain_end; - } - - buffer[16] = 0; - - sscanf(buffer, "%d", &len); - if(len > MAXLEN) { - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading message body length"); + tmp_context = context; + tmp_conn = conn; + len = read_il_data(&msg, plain_reader); + if(len < 0) goto get_reply_plain_end; - } - /* allocate room for message body */ - if((msg = malloc(len)) == NULL) { - edg_wll_SetError(context,ENOMEM,"get_reply_plain(): no room for message body"); + if(decode_il_reply(&code, code_min, buf, msg) < 0) { + edg_wll_SetError(context, LB_PROTO, "get_reply_plain(): error decoding message"); goto get_reply_plain_end; } - /* read all the data */ - len = edg_wll_plain_read_full(conn, msg, len, &context->p_tmp_timeout); - if(len < 0) { - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading message body"); - goto get_reply_plain_end; - } - - p = msg; - p = get_int(p, &code); - if(p == NULL) { - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading result code"); - free(msg); - goto get_reply_plain_end; - } - p = get_int(p, code_min); - if(p == NULL) { - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading result code minor"); - free(msg); - goto get_reply_plain_end; - } - p = get_string(p, buf); - if(p == NULL) { - if(*buf) { - free(*buf); - *buf = NULL; - } - edg_wll_SetError(context,LB_PROTO,"get_reply_plain(): error reading result string"); - free(msg); - goto get_reply_plain_end; - } get_reply_plain_end: if(msg) free(msg); return edg_wll_Error(context,NULL,NULL); } -static + +static edg_wll_GssConnection *tmp_gss_conn; + +static int -get_reply_gss(edg_wll_Context context, edg_wll_GssConnection *conn, char **buf, int *code_min) +gss_reader(char *buffer, int max_len) { - char buffer[17]; - char *msg, *p; - int len, code, answer; + int ret, len; edg_wll_GssStatus gss_code; - code = len = answer = 0; - - /* get message header */ - code = edg_wll_gss_read_full(conn, buffer, 17, &context->p_tmp_timeout, &len, &gss_code); - if(code < 0) { - answer = edg_wll_log_proto_handle_gss_failures(context,code,&gss_code,"edg_wll_gss_read_full()"); - edg_wll_UpdateError(context,LB_PROTO,"get_reply_gss(): error reading message header"); - goto get_reply_gss_end; + ret = edg_wll_gss_read_full(tmp_gss_conn, buffer, max_len, &tmp_context->p_tmp_timeout, + &len, &gss_code); + if(ret < 0) { + edg_wll_log_proto_handle_gss_failures(tmp_context, ret, &gss_code, "edg_wll_gss_read_full"); + edg_wll_UpdateError(tmp_context, LB_PROTO, "get_reply_gss(): error reading message"); } - buffer[16] = 0; + return(ret); +} - sscanf(buffer, "%d", &len); - if(len > MAXLEN) { - edg_wll_SetError(context,LB_PROTO,"get_reply_gss(): error reading message body length"); - goto get_reply_gss_end; - } - /* allocate room for message body */ - if((msg = malloc(len)) == NULL) { - edg_wll_SetError(context,ENOMEM,"get_reply_gss(): no room for message body"); - goto get_reply_gss_end; - } +static +int +get_reply_gss(edg_wll_Context context, edg_wll_GssConnection *conn, char **buf, int *code_min) +{ + char *msg; + int code; - /* read all the data */ - code = edg_wll_gss_read_full(conn, msg, len, &context->p_tmp_timeout, &len, &gss_code); - if(code < 0) { - answer = edg_wll_log_proto_handle_gss_failures(context,code,&gss_code,"edg_wll_gss_read_full()"); - edg_wll_SetError(context,LB_PROTO,"get_reply_gss(): error reading message body"); + tmp_context = context; + tmp_gss_conn = conn; + code = read_il_data(&msg, gss_reader); + if(code < 0) goto get_reply_gss_end; - } - p = msg; - p = get_int(p, &code); - if(p == NULL) { - edg_wll_SetError(context,LB_PROTO,"get_reply_gss(): error reading result code"); - free(msg); - goto get_reply_gss_end; - } - p = get_int(p, code_min); - if(p == NULL) { - edg_wll_SetError(context,LB_PROTO,"get_reply_gss(): error reading result code minor"); - free(msg); - goto get_reply_gss_end; - } - p = get_string(p, buf); - if(p == NULL) { - if(*buf) { - free(*buf); - *buf = NULL; - } - edg_wll_SetError(context,LB_PROTO,"get_reply_gss(): error reading result string"); - free(msg); + if(decode_il_reply(&code, code_min, buf, msg) < 0) { + edg_wll_SetError(context, LB_PROTO, "get_reply_gss(): error decoding reply"); goto get_reply_gss_end; } @@ -317,8 +268,7 @@ edg_wll_log_proto_client_end: */ int edg_wll_log_proto_client_proxy(edg_wll_Context context, edg_wll_PlainConnection *conn, edg_wll_LogLine logline) { - char *p; int len; - char *ucs = "honik6"; + int len; char *buffer,*answer = NULL; static char et[256]; int err; @@ -328,21 +278,11 @@ int edg_wll_log_proto_client_proxy(edg_wll_Context context, edg_wll_PlainConnect 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,"edg_wll_log_proto_client_proxy(): no room for message body"); + len = encode_il_msg(&buffer, logline); + if(len < 0) { + edg_wll_SetError(context,ENOMEM,"edg_wll_log_proto_client_proxy(): error encoding message"); 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 @@ -388,8 +328,7 @@ edg_wll_log_proto_client_proxy_end: */ int edg_wll_log_proto_client_direct(edg_wll_Context context, edg_wll_GssConnection *con, edg_wll_LogLine logline) { - char *p; int len; - char *ucs = "honik6"; + int len; char *buffer,*answer = NULL; static char et[256]; int err; @@ -400,23 +339,13 @@ int edg_wll_log_proto_client_direct(edg_wll_Context context, edg_wll_GssConnecti 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,"edg_wll_log_proto_client_direct(): no room for message body"); + /* encode message */ + len = encode_il_msg(&buffer, logline); + if(len < 0) { + edg_wll_SetError(context, ENOMEM, "edg_wll_log_proto_client_direct(): error encoding message"); goto edg_wll_log_proto_client_direct_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,"log_proto_client_direct: sending message...\n"); #endif -- 1.8.2.3