From: Pekka Riikonen Date: Thu, 22 Feb 2007 14:32:51 +0000 (+0000) Subject: Rewrote WHOIS command and attributes handling. X-Git-Tag: autodist.1.3.1~3 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=b9fde2a2a32801d3eecba020927c94cb4838de72 Rewrote WHOIS command and attributes handling. --- diff --git a/lib/silcclient/client_attrs.c b/lib/silcclient/client_attrs.c index 8f131559..a7825270 100644 --- a/lib/silcclient/client_attrs.c +++ b/lib/silcclient/client_attrs.c @@ -35,6 +35,7 @@ static void silc_client_attributes_process_foreach(void *key, void *context, SilcAttributePayload attr = context; SilcAttrForeach *f = user_context; const unsigned char *data; + unsigned char tmp[32]; SilcUInt32 data_len; if (!context) { @@ -54,17 +55,17 @@ static void silc_client_attributes_process_foreach(void *key, void *context, SILC_LOG_DEBUG(("Attribute %d found", attribute)); data = silc_attribute_get_data(attr, &data_len); -#if 0 /* We replace the TIMEZONE with valid value here */ if (attribute == SILC_ATTRIBUTE_TIMEZONE) { - data = (const unsigned char *)silc_get_time(0); - data_len = strlen(data); - f->buffer = silc_attribute_payload_encode(f->buffer, attribute, - SILC_ATTRIBUTE_FLAG_VALID, - (void *)data, data_len); + if (silc_timezone(tmp, sizeof(tmp))) { + data = tmp; + data_len = strlen(tmp); + f->buffer = silc_attribute_payload_encode(f->buffer, attribute, + SILC_ATTRIBUTE_FLAG_VALID, + (void *)data, data_len); + } return; } -#endif f->buffer = silc_attribute_payload_encode_data(f->buffer, attribute, SILC_ATTRIBUTE_FLAG_VALID, @@ -89,8 +90,10 @@ SilcBuffer silc_client_attributes_process(SilcClient client, /* If nothing is set by application assume that we don't want to use attributes, ignore the request. */ - if (!conn->internal->attrs) + if (!conn->internal->attrs) { + SILC_LOG_DEBUG(("User has not set any attributes")); return NULL; + } /* Always put our public key. */ pk.type = "silc-rsa"; diff --git a/lib/silcclient/client_internal.h b/lib/silcclient/client_internal.h index c1208fba..4af35450 100644 --- a/lib/silcclient/client_internal.h +++ b/lib/silcclient/client_internal.h @@ -186,5 +186,8 @@ silc_client_add_connection(SilcClient client, char *remote_host, int port, SilcClientConnectCallback callback, void *context); +SilcBuffer silc_client_attributes_process(SilcClient client, + SilcClientConnection conn, + SilcDList attrs); #endif /* CLIENT_INTERNAL_H */ diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 080962a2..f221b374 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -2807,7 +2807,6 @@ static void silc_client_command_process_whois(SilcClient client, SilcCommandPayload payload, SilcArgumentPayload args) { -#if 0 SilcDList attrs; unsigned char *tmp; SilcUInt32 tmp_len; @@ -2831,18 +2830,25 @@ static void silc_client_command_process_whois(SilcClient client, return; } - /* Send the attributes back */ + /* Send the attributes back in COMMAND_REPLY packet */ packet = silc_command_reply_payload_encode_va(SILC_COMMAND_WHOIS, SILC_STATUS_OK, 0, silc_command_get_ident(payload), - 1, 11, buffer->data, buffer->len); - silc_client_packet_send(client, sock, SILC_PACKET_COMMAND_REPLY, - NULL, 0, NULL, NULL, packet->data, - packet->len, TRUE); + 1, 11, buffer->data, + silc_buffer_len(buffer)); + if (!packet) { + silc_buffer_free(buffer); + return; + } + + SILC_LOG_DEBUG(("Sending back requested WHOIS attributes")); + + silc_packet_send(conn->stream, SILC_PACKET_COMMAND_REPLY, 0, + silc_buffer_datalen(packet)); + silc_buffer_free(packet); silc_buffer_free(buffer); -#endif /* 0 */ } /* Client is able to receive some command packets even though they are