From: Pekka Riikonen Date: Wed, 14 Feb 2007 14:49:00 +0000 (+0000) Subject: Implemented SILC_ATTRIBUTE_PHONE_NUMBER (SILC Protocol 1.3 change). X-Git-Tag: silc.client.1.1.beta1~17 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=f21e21461fc8efa225fa515dd4a51db8be87d531 Implemented SILC_ATTRIBUTE_PHONE_NUMBER (SILC Protocol 1.3 change). --- diff --git a/lib/silccore/silcattrs.c b/lib/silccore/silcattrs.c index ebef5eec..077d867d 100644 --- a/lib/silccore/silcattrs.c +++ b/lib/silccore/silcattrs.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2006 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 @@ -195,6 +195,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: { @@ -353,7 +374,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)); @@ -610,6 +632,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: { diff --git a/lib/silccore/silcattrs.h b/lib/silccore/silcattrs.h index a7b38d5e..4886dbde 100644 --- a/lib/silccore/silcattrs.h +++ b/lib/silccore/silcattrs.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2006 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 @@ -83,6 +83,7 @@ typedef SilcUInt8 SilcAttribute; #define SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE 14 /* SilcAttributeObjPk */ #define SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE 15 /* SilcAttributeObjPk */ #define SILC_ATTRIBUTE_USER_ICON 16 /* SilcMime */ +#define SILC_ATTRIBUTE_PHONE_NUMBER 17 /* SilcAttributeObjPN */ /***/ /* Maximum length of attribute request packet */ @@ -182,6 +183,25 @@ typedef enum { } SilcAttributeDevice; /***/ +/****d* silccore/SilcAttributesAPI/SilcAttributePNFormat + * + * NAME + * + * typedef enum { ... } SilcAttributePNFormat; + * + * DESCRIPTION + * + * The defined phone number formats. + * + * SOURCE + */ +typedef enum { + SILC_ATTRIBUTE_NUMBER_ITU_E164 = 0, /* ITU E.164 */ + SILC_ATTRIBUTE_NUMBER_ITU_E123_PHONE = 1, /* ITU E.123 */ + SILC_ATTRIBUTE_NUMBER_ENUM = 2, /* ENUM, RFC 3761 */ +} SilcAttributePNFormat; +/***/ + /****f* silccore/SilcAttributesAPI/silc_attribute_payload_alloc * * SYNOPSIS @@ -475,6 +495,25 @@ typedef struct SilcAttributeObjPkStruct { } SilcAttributeObjPk; /***/ +/****s* silccore/SilcAttributesAPI/SilcAttributeObjPN + * + * NAME + * + * typedef struct { ... } SilcAttributeObjPN; + * + * DESCRIPTION + * + * SILC_ATTRIBUTE_PHONE_NUMBER type object. The caller must free the + * phone number string inside the structure. + * + * SOURCE + */ +typedef struct SilcAttributeObjPNStruct { + SilcAttributePNFormat format; /* Phone number format */ + char *number; /* Phone number */ +} SilcAttributeObjPN; +/***/ + /****f* silccore/SilcAttributesAPI/silc_attribute_get_object * * SYNOPSIS