X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcattrs.c;h=796f6255d3318732c0ffbe7ba47191c8d8c165ed;hb=52e57c880aba9c5e89f59d962eb9af75670b76e0;hp=27f25f7373ebea728ba10e1c984ce7d5e9bca532;hpb=40f8443d8d3a6577336ee66d18e04d9ac4d956bb;p=silc.git diff --git a/lib/silccore/silcattrs.c b/lib/silccore/silcattrs.c index 27f25f73..796f6255 100644 --- a/lib/silccore/silcattrs.c +++ b/lib/silccore/silcattrs.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2005 Pekka Riikonen + Copyright (C) 2002 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,6 +76,8 @@ silc_attribute_payload_encode_int(SilcAttribute attribute, len = strlen(service->address); len2 = strlen(service->signon); tmpbuf = silc_buffer_alloc_size(13 + len + len2); + if (!tmpbuf) + return NULL; silc_buffer_format(tmpbuf, SILC_STR_UI_INT(service->port), SILC_STR_UI_SHORT(len), @@ -127,6 +129,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute, str = silc_mime_encode(mime, &object_size); if (!str) return NULL; + object = str; } break; @@ -193,6 +196,27 @@ silc_attribute_payload_encode_int(SilcAttribute attribute, } break; + case SILC_ATTRIBUTE_PHONE_NUMBER: + { + SilcAttributeObjPN *pn = object; + if (object_size != sizeof(*pn)) + return NULL; + if (!pn->number || strlen(pn->number) < 5) + return NULL; + tmpbuf = silc_buffer_alloc(0); + if (!tmpbuf) + return NULL; + if (silc_buffer_format(tmpbuf, + SILC_STR_UI_INT(pn->format), + SILC_STR_UI_SHORT(strlen(pn->number)), + SILC_STR_UI16_STRING(pn->number), + SILC_STR_END) < 0) + return NULL; + object = tmpbuf->data; + object_size = silc_buffer_len(tmpbuf); + } + break; + case SILC_ATTRIBUTE_USER_PUBLIC_KEY: case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: { @@ -351,7 +375,8 @@ SilcBuffer silc_attribute_payload_encode_data(SilcBuffer attrs, len = 4 + (SilcUInt16)data_len; buffer = silc_buffer_realloc(buffer, - (buffer ? silc_buffer_truelen(buffer) + len : len)); + (buffer ? silc_buffer_truelen(buffer) + + len : len)); if (!buffer) return NULL; silc_buffer_pull(buffer, silc_buffer_len(buffer)); @@ -466,7 +491,7 @@ unsigned char *silc_attribute_get_verify_data(SilcDList attrs, /* Return parsed attribute object */ SilcBool silc_attribute_get_object(SilcAttributePayload payload, - void *object, SilcUInt32 object_size) + void *object, SilcUInt32 object_size) { SilcUInt16 len; SilcBool ret = FALSE; @@ -608,6 +633,28 @@ SilcBool silc_attribute_get_object(SilcAttributePayload payload, } break; + case SILC_ATTRIBUTE_PHONE_NUMBER: + { + SilcAttributeObjPN *pn = object; + SilcBufferStruct buffer; + SilcUInt32 pn_format; + int res; + if (object_size != sizeof(*pn)) + break; + silc_buffer_set(&buffer, (unsigned char *)payload->data, + payload->data_len); + res = + silc_buffer_unformat(&buffer, + SILC_STR_UI_INT(&pn_format), + SILC_STR_UI16_STRING_ALLOC(&pn->number), + SILC_STR_END); + if (res == -1) + break; + pn->format = pn_format; + ret = TRUE; + } + break; + case SILC_ATTRIBUTE_USER_PUBLIC_KEY: case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: {