From: Pekka Riikonen Date: Sun, 8 Sep 2002 15:55:01 +0000 (+0000) Subject: Implemented the draft-riikonen-presence-attrs and Attribute X-Git-Tag: silc.server.0.9.5~11 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=81a20cc52aceb480932652db71f9622e4a5030e1 Implemented the draft-riikonen-presence-attrs and Attribute Payload. --- diff --git a/CHANGES b/CHANGES index e6e65d8f..335577e2 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +Sun Sep 8 18:39:25 EEST 2002 Pekka Riikonen + + * Implemented the draft-riikonen-precense-attrs draft and + the Attribute Payload into the lib/silccore/silcattrs.[ch]. + Sun Sep 8 13:13:44 EEST 2002 Pekka Riikonen * Distribute the SERVER_SIGNOFF notify also to local backup diff --git a/TODO b/TODO index 3e8e5a89..09bc7249 100644 --- a/TODO +++ b/TODO @@ -11,6 +11,9 @@ TODO/bugs in Irssi SILC client TODO/bugs In SILC Client Library ================================ + o Add support for the in WHOIS. Sending and + reception should be added. + o The PRIVATE_MESSAGE_KEY packet is not handled (it is implemented though). This should be added and perhaps new client operation should be added to notify application that it was received and @@ -27,9 +30,8 @@ TODO/bugs In SILC Server when some server is connecting and connecting fails (like too many connections, etc). Some weird crashes relating to this occurred. - o Implement the and the Attribute Payload to - the core library, client and server. Maybe implementations of - RFC 2425 and RFC 2426 to make it complete. + o Add support for the in WHOIS. Sending and + reception, with clients and servers should be added. o Backup router related issues: diff --git a/doc/draft-riikonen-presence-attrs-00.nroff b/doc/draft-riikonen-presence-attrs-00.nroff index 811ec637..90f4dfb8 100644 --- a/doc/draft-riikonen-presence-attrs-00.nroff +++ b/doc/draft-riikonen-presence-attrs-00.nroff @@ -539,7 +539,7 @@ multiple same attributes in the packet. provided references. -16 ATTRIBUTE_SERVER_DIGITAL_SIGNATURE +15 ATTRIBUTE_SERVER_DIGITAL_SIGNATURE This attribute value includes digital signature of all Attribute Payloads except this attribute, but including the attribute diff --git a/includes/silcincludes.h b/includes/silcincludes.h index a098bca6..aa53ee74 100644 --- a/includes/silcincludes.h +++ b/includes/silcincludes.h @@ -264,6 +264,7 @@ extern "C" { #include "silcmode.h" #include "silcauth.h" #include "silcprivate.h" +#include "silcattrs.h" #ifdef SILC_SIM /* SILC Module library includes */ diff --git a/lib/silccore/DIRECTORY b/lib/silccore/DIRECTORY index 5c089628..26f07763 100644 --- a/lib/silccore/DIRECTORY +++ b/lib/silccore/DIRECTORY @@ -11,6 +11,7 @@ @LINK=silcidcache.html:SILC ID Cache Interface @LINK=silcargument.html:SILC Argument Interface @LINK=silcprivate.html:SILC Private Message Interface +@LINK=silcattrs.html:SILC Attributes Interface @LINK=silcpacket.html:Packet Protocol Interface --> diff --git a/lib/silccore/Makefile.am b/lib/silccore/Makefile.am index 0864b51e..920b7c88 100644 --- a/lib/silccore/Makefile.am +++ b/lib/silccore/Makefile.am @@ -3,12 +3,11 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2000 Pekka Riikonen +# Copyright (C) 2000 - 2002 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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -29,6 +28,7 @@ libsilccore_a_SOURCES = \ silcargument.c \ silcnotify.c \ silcauth.c \ + silcattrs.c \ silcprivate.c if SILC_DIST_TOOLKIT @@ -43,6 +43,7 @@ include_HEADERS = \ silcpacket.h \ silcargument.h \ silcstatus.h \ + silcattrs.h \ silcprivate.h endif diff --git a/lib/silccore/silcargument.h b/lib/silccore/silcargument.h index 62c945fc..bb38c75f 100644 --- a/lib/silccore/silcargument.h +++ b/lib/silccore/silcargument.h @@ -29,6 +29,22 @@ #ifndef SILCPAYLOAD_H #define SILCPAYLOAD_H +/****s* silccore/SilcArgumentAPI/SilcArgumentPayload + * + * NAME + * + * typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; + * + * DESCRIPTION + * + * This context is the actual Argument Payload and is allocated + * by silc_argument_payload_parse and given as argument usually to + * all silc_argument_payload_* functions. It is freed by the + * silc_argument_payload_free function. + * + ***/ +typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; + /****f* silccore/SilcArgumentAPI/silc_argument_payload_parse * * SYNOPSIS diff --git a/lib/silccore/silcattrs.c b/lib/silccore/silcattrs.c new file mode 100644 index 00000000..652333e3 --- /dev/null +++ b/lib/silccore/silcattrs.c @@ -0,0 +1,408 @@ +/* + + silcattrs.c + + Author: Pekka Riikonen + + Copyright (C) 2002 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ +/* Implementation of Attribute Payload routines */ +/* $Id$ */ + +#include "silcincludes.h" +#include "silcattrs.h" + +/****************************************************************************** + + Attribute Payload + +******************************************************************************/ + +struct SilcAttributePayloadStruct { + SilcAttribute attribute; + SilcAttributeFlags flags; + SilcUInt16 data_len; + unsigned char *data; +}; + +/* Parse one attribute payload */ + +SilcAttributePayload +silc_attribute_payload_parse(const unsigned char *payload, + SilcUInt32 payload_len) +{ + SilcBufferStruct buffer; + SilcAttributePayload newp; + int ret; + + SILC_LOG_DEBUG(("Parsing attribute payload")); + + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); + newp = silc_calloc(1, sizeof(*newp)); + if (!newp) + return NULL; + + /* Parse the Attribute Payload. */ + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_CHAR(&newp->attribute), + SILC_STR_UI_CHAR(&newp->flags), + SILC_STR_UI16_NSTRING_ALLOC(&newp->data, + &newp->data_len), + SILC_STR_END); + if (ret == -1) + goto err; + + if (newp->data_len > buffer.len - 4) { + SILC_LOG_ERROR(("Incorrect attribute payload")); + goto err; + } + + return newp; + + err: + silc_attribute_payload_free(newp); + return NULL; +} + +/* Encode one attribute payload */ + +SilcBuffer silc_attribute_payload_encode(SilcAttribute attribute, + SilcAttributeFlags flags, + const unsigned char *data, + SilcUInt32 data_len) +{ + SilcBuffer buffer; + + SILC_LOG_DEBUG(("Encoding Attribute Payload")); + + buffer = silc_buffer_alloc_size(4 + data_len); + if (!buffer) + return NULL; + + /* Encode the Attribute Payload */ + silc_buffer_format(buffer, + SILC_STR_UI_CHAR(attribute), + SILC_STR_UI_CHAR(flags), + SILC_STR_UI_SHORT((SilcUInt16)data_len), + SILC_STR_UI_XNSTRING(data, data_len), + SILC_STR_END); + + return buffer; +} + +/* Parse list of payloads */ + +SilcDList silc_attribute_payload_parse_list(const unsigned char *payload, + SilcUInt32 payload_len) +{ + SilcBufferStruct buffer; + SilcDList list; + SilcAttributePayload newp; + int len, ret; + + SILC_LOG_DEBUG(("Parsing Attribute Payload list")); + + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); + list = silc_dlist_init(); + + while (buffer.len) { + newp = silc_calloc(1, sizeof(*newp)); + if (!newp) + goto err; + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_CHAR(&newp->attribute), + SILC_STR_UI_CHAR(&newp->flags), + SILC_STR_UI16_NSTRING_ALLOC(&newp->data, + &newp->data_len), + SILC_STR_END); + if (ret == -1) + goto err; + + if (newp->data_len > buffer.len) { + SILC_LOG_ERROR(("Incorrect attribute payload in list")); + goto err; + } + + len = 4 + newp->data_len; + if (buffer.len < len) + break; + silc_buffer_pull(&buffer, len); + + silc_dlist_add(list, newp); + } + + return list; + + err: + silc_attribute_payload_list_free(list); + return NULL; +} + +/* Encode list of payloads */ + +SilcBuffer silc_attribute_payload_encode_list(SilcUInt32 num_attrs, ...) +{ + SilcBuffer buffer = NULL; + va_list ap; + int i, len = 0; + SilcAttribute attribute; + SilcAttributeFlags flags; + unsigned char *data; + SilcUInt32 data_len; + + if (!num_attrs) + return NULL; + + va_start(ap, num_attrs); + for (i = 0; i < num_attrs; i++) { + attribute = va_arg(ap, SilcUInt32); + flags = va_arg(ap, SilcUInt32); + data = va_arg(ap, unsigned char *); + data_len = va_arg(ap, SilcUInt32); + + if (data || !data_len) + continue; + + len = 4 + data_len; + buffer = silc_buffer_realloc(buffer, + (buffer ? buffer->truelen + len : len)); + silc_buffer_pull_tail(buffer, (buffer->end - buffer->data)); + silc_buffer_format(buffer, + SILC_STR_UI_CHAR(attribute), + SILC_STR_UI_CHAR(flags), + SILC_STR_UI_SHORT((SilcUInt16)data_len), + SILC_STR_UI_XNSTRING(data, data_len), + SILC_STR_END); + silc_buffer_pull(buffer, len); + } + va_end(ap); + + if (buffer) + silc_buffer_push(buffer, buffer->data - buffer->head); + + return buffer; +} + +/* Free Attribute Payload */ + +void silc_attribute_payload_free(SilcAttributePayload payload) +{ + silc_free(payload->data); + silc_free(payload); +} + +/* Free's list of Attribute Payloads */ + +void silc_attribute_payload_list_free(SilcDList list) +{ + SilcAttributePayload entry; + + silc_dlist_start(list); + while ((entry = silc_dlist_get(list)) != SILC_LIST_END) { + silc_attribute_payload_free(entry); + silc_dlist_del(list, entry); + } + + silc_dlist_uninit(list); +} + +/* Return attribute type */ + +SilcAttribute silc_attribute_get_attribute(SilcAttributePayload payload) +{ + return payload->attribute; +} + +/* Return attribute flags */ + +SilcAttributeFlags silc_attribute_get_flags(SilcAttributePayload payload) +{ + return payload->flags; +} + +/* Return attribute data from the payload */ + +const unsigned char *silc_attribute_get_data(SilcAttributePayload payload, + SilcUInt32 *data_len) +{ + if (data_len) + *data_len = payload->data_len; + return (const unsigned char *)payload->data; +} + +/* Return parsed attribute object */ + +bool silc_attribute_get_object(SilcAttributePayload payload, + SilcAttribute attribute, + void **object, SilcUInt32 object_size) +{ + SilcUInt16 len; + bool ret = FALSE; + + if (!attribute || !object || !(*object)) + return FALSE; + + switch (attribute) { + case SILC_ATTRIBUTE_USER_INFO: + SILC_NOT_IMPLEMENTED("SILC_ATTRIBUTE_USER_INFO"); + break; + + case SILC_ATTRIBUTE_SERVICE: + { + SilcAttributeObjService *service = *object; + if (object_size != sizeof(*service)) + break; + if (payload->data_len < 7) + break; + SILC_GET32_MSB(service->port, payload->data); + SILC_GET16_MSB(len, payload->data + 4); + if (payload->data_len < 7 + len) + break; + memcpy(service->address, payload->data + 6, + (len < sizeof(service->address) - 1 ? len : + sizeof(service->address) - 1)); + service->status = payload->data[6 + len] ? TRUE : FALSE; + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_STATUS_MOOD: + case SILC_ATTRIBUTE_PREFERRED_CONTACT: + { + SilcUInt32 *mask = *object; + if (object_size != sizeof(SilcUInt32)) + break; + if (payload->data_len < 4) + break; + SILC_GET32_MSB(*mask, payload->data); + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_STATUS_FREETEXT: + case SILC_ATTRIBUTE_PREFERRED_LANGUAGE: + case SILC_ATTRIBUTE_TIMEZONE: + { + char *string = *object; + if (payload->data_len < 2) + break; + SILC_GET16_MSB(len, payload->data); + if (payload->data_len < 2 + len) + break; + if (object_size < len) + break; + memcpy(string, payload->data + 2, len); + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_STATUS_MESSAGE: + case SILC_ATTRIBUTE_EXTENSION: + { + SilcAttributeObjMime *mime = *object; + if (object_size != sizeof(*mime)) + break; + mime->mime = silc_memdup(payload->data, payload->data_len); + mime->mime_len = payload->data_len; + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_GEOLOCATION: + { + SilcAttributeObjGeo *geo = *object; + SilcBufferStruct buffer; + int res; + if (object_size != sizeof(*geo)) + break; + silc_buffer_set(&buffer, (unsigned char *)payload->data, + payload->data_len); + res = silc_buffer_unformat(&buffer, + SILC_STR_UI16_STRING_ALLOC(&geo->longitude), + SILC_STR_UI16_STRING_ALLOC(&geo->latitude), + SILC_STR_UI16_STRING_ALLOC(&geo->altitude), + SILC_STR_UI16_STRING_ALLOC(&geo->accuracy), + SILC_STR_END); + if (res == 1) + break; + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_DEVICE_INFO: + { + SilcAttributeObjDevice *dev = *object; + SilcBufferStruct buffer; + SilcUInt32 type; + int res; + if (object_size != sizeof(*dev)) + break; + silc_buffer_set(&buffer, (unsigned char *)payload->data, + payload->data_len); + res = + silc_buffer_unformat(&buffer, + SILC_STR_UI_INT(&type), + SILC_STR_UI16_STRING_ALLOC(&dev->manufacturer), + SILC_STR_UI16_STRING_ALLOC(&dev->version), + SILC_STR_UI16_STRING_ALLOC(&dev->model), + SILC_STR_UI16_STRING_ALLOC(&dev->language), + SILC_STR_END); + if (res == 1) + break; + dev->type = type; + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_USER_PUBLIC_KEY: + case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: + { + SilcAttributeObjPk *pk = *object; + SilcBufferStruct buffer; + int res; + if (object_size != sizeof(*pk)) + break; + silc_buffer_set(&buffer, (unsigned char *)payload->data, + payload->data_len); + res = + silc_buffer_unformat(&buffer, + SILC_STR_UI16_NSTRING_ALLOC(&pk->type, &len), + SILC_STR_END); + if (res == 1) + break; + pk->data = silc_memdup(payload->data + 2 + len, + payload->data_len - 2 - len); + pk->data_len = payload->data_len - 2 - len; + ret = TRUE; + } + break; + + case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE: + case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE: + { + SilcAttributeObjPk *pk = *object; + if (object_size != sizeof(*pk)) + break; + pk->type = NULL; + pk->data = silc_memdup(payload->data, payload->data_len); + pk->data_len = payload->data_len; + ret = TRUE; + } + break; + + default: + break; + } + + return ret; +} diff --git a/lib/silccore/silcattrs.h b/lib/silccore/silcattrs.h new file mode 100644 index 00000000..3038c34f --- /dev/null +++ b/lib/silccore/silcattrs.h @@ -0,0 +1,458 @@ +/* + + silcattrs.h + + Author: Pekka Riikonen + + Copyright (C) 2002 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/****h* silccore/SILC Attribute Interface + * + * DESCRIPTION + * + * Implementation of the Attribute Payload that may be used to send and + * retrieve user online precense information in the SILC network. This + * implements the draft-riikonen-precense-attrs draft. + * + ***/ + +#ifndef SILCATTRS_H +#define SILCATTRS_H + +/****s* silccore/SilcAttributesAPI/SilcAttributePayload + * + * NAME + * + * typedef struct SilcAttributePayloadStruct *SilcAttributePayload; + * + * DESCRIPTION + * + * This context is the actual Attribute Payload and is allocated + * by silc_attribute_payload_parse and given as attribute usually to + * all silc_attribute_payload_* functions. It is freed by the + * silc_attribute_payload_free function. + * + ***/ +typedef struct SilcAttributePayloadStruct *SilcAttributePayload; + +/****d* silccore/SilcAttributesAPI/SilcAttribute + * + * NAME + * + * typedef unsigned char SilcAttribute; + * + * DESCRIPTION + * + * The SilcAttribute type definition and the attributes. The attributes + * listed here are the official attributes defined in the internet + * draft. They define the contents of the attribute payload and the + * type of the attribute. + * + * SOURCE + */ +typedef unsigned char SilcAttribute; + +/* All defined attributes. See the specs for detailed information. The + comment is the structure or data type that must be used with the + silc_attribute_get_object function to fetch parsed attribute. */ +#define SILC_ATTRIBUTE_NONE 0 +#define SILC_ATTRIBUTE_USER_INFO 1 +#define SILC_ATTRIBUTE_SERVICE 2 /* SilcAttributeObjService */ +#define SILC_ATTRIBUTE_STATUS_MOOD 3 /* SilcAttributeMood */ +#define SILC_ATTRIBUTE_STATUS_FREETEXT 4 /* char * (UTF-8 string) */ +#define SILC_ATTRIBUTE_STATUS_MESSAGE 5 /* SilcAttributeObjMime */ +#define SILC_ATTRIBUTE_PREFERRED_LANGUAGE 6 /* char * (UTF-8 string) */ +#define SILC_ATTRIBUTE_PREFERRED_CONTACT 7 /* SilcAttributeContact */ +#define SILC_ATTRIBUTE_TIMEZONE 8 /* char * (UTF-8 string */ +#define SILC_ATTRIBUTE_GEOLOCATION 9 /* SilcAttributeObjGeo */ +#define SILC_ATTRIBUTE_DEVICE_INFO 10 /* SilcAttributeObjDevice */ +#define SILC_ATTRIBUTE_EXTENSION 11 /* SilcAttributeObjMime */ +#define SILC_ATTRIBUTE_USER_PUBLIC_KEY 12 /* SilcAttributeObjPk */ +#define SILC_ATTRIBUTE_SERVER_PUBLIC_KEY 13 /* SilcAttributeObjPk */ +#define SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE 14 /* SilcAttributeObjPk */ +#define SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE 15 /* SilcAttributeObjPk */ +/***/ + +/****d* silccore/SilcAttributesAPI/SilcAttributeFlags + * + * NAME + * + * typedef unsigned char SilcAttributeFlags; + * + * DESCRIPTION + * + * Attribute Payload flags defined by the specification. + * + * SOURCE + */ +typedef unsigned char SilcAttributeFlags; + +/* All defined flags */ +#define SILC_ATTRIBUTE_FLAG_NONE 0x00 /* No flags */ +#define SILC_ATTRIBUTE_FLAG_INVALID 0x01 /* Invalid attribute */ +#define SILC_ATTRIBUTE_FLAG_VALID 0x02 /* Valid attribute */ +/***/ + +/****d* silccore/SilcAttributesAPI/SilcAttributeMood + * + * NAME + * + * typedef enum { ... } SilcAttributeMood; + * + * DESCRIPTION + * + * The user mood indicators defined by the specification. This is + * bit mask. + * + * SOURCE + */ +typedef enum { + SILC_ATTRIBUTE_MOOD_NORMAL = 0x00000000, /* normal mood */ + SILC_ATTRIBUTE_MOOD_HAPPY = 0x00000001, /* user feel happy */ + SILC_ATTRIBUTE_MOOD_SAD = 0x00000002, /* user feel sad */ + SILC_ATTRIBUTE_MOOD_ANGRY = 0x00000004, /* user feel angry */ + SILC_ATTRIBUTE_MOOD_JEALOUS = 0x00000008, /* user feel jealous */ + SILC_ATTRIBUTE_MOOD_ASHAMED = 0x00000010, /* user feel ashamed */ + SILC_ATTRIBUTE_MOOD_INVINCIBLE = 0x00000020, /* user feel invincible */ + SILC_ATTRIBUTE_MOOD_INLOVE = 0x00000040, /* user feel in love */ + SILC_ATTRIBUTE_MOOD_SLEEPY = 0x00000080, /* user feel sleepy */ + SILC_ATTRIBUTE_MOOD_BORED = 0x00000100, /* user feel bored */ + SILC_ATTRIBUTE_MOOD_EXCITED = 0x00000200, /* user feel exited */ + SILC_ATTRIBUTE_MOOD_ANXIOUS = 0x00000400, /* user feel anxious */ +} SilcAttributeMood; +/***/ + +/****d* silccore/SilcAttributesAPI/SilcAttributeContact + * + * NAME + * + * typedef enum { ... } SilcAttributeContact; + * + * DESCRIPTION + * + * The defined preferred contact methods defined by the specification. + * This is bit mask. + * + * SOURCE + */ +typedef enum { + SILC_ATTRIBUTE_CONTACT_NONE = 0x00000000, /* no specific method */ + SILC_ATTRIBUTE_CONTACT_EMAIL = 0x00000001, /* email preferred */ + SILC_ATTRIBUTE_CONTACT_CALL = 0x00000002, /* phone call preferred */ + SILC_ATTRIBUTE_CONTACT_PAGE = 0x00000004, /* "paging" preferred */ + SILC_ATTRIBUTE_CONTACT_SMS = 0x00000008, /* SMS preferred */ + SILC_ATTRIBUTE_CONTACT_MMS = 0x00000010, /* MMS preferred */ + SILC_ATTRIBUTE_CONTACT_CHAT = 0x00000020, /* chatting preferred */ +} SilcAttributeContact; +/***/ + +/****d* silccore/SilcAttributesAPI/SilcAttributeDevice + * + * NAME + * + * typedef enum { ... } SilcAttributeDevice; + * + * DESCRIPTION + * + * The defined device types defined by the specification. + * + * SOURCE + */ +typedef enum { + SILC_ATTRIBUTE_DEVICE_COMPUTER = 0, /* device is computer */ + SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE = 1, /* device is mobile phone */ + SILC_ATTRIBUTE_DEVICE_PDA = 2, /* device is PDA */ + SILC_ATTRIBUTE_DEVICE_TERMINAL = 3, /* device is terminal */ +} SilcAttributeDevice; +/***/ + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_parse + * + * SYNOPSIS + * + * SilcAttributePayload + * silc_attribute_payload_parse(const unsigned char *payload, + * SilcUInt32 payload_len); + * + * DESCRIPTION + * + * Parses one attribute payload sent as argument and saves it to + * SilcAttributePayload context. The new allocated context is returned. + ***/ +SilcAttributePayload +silc_attribute_payload_parse(const unsigned char *payload, + SilcUInt32 payload_len); + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_encode + * + * SYNOPSIS + * + * SilcBuffer silc_attribute_payload_encode(SilcAttribute attribute, + * SilcAttributeFlags flags, + * const unsigned char *data, + * SilcUInt32 data_len); + * + * DESCRIPTION + * + * Encodes one attribute payload and returns allocated buffer. The + * `attributes' is the attribute type with `flags' and the actual + * attribute data indicated by `data' and `data_len'. + * + ***/ +SilcBuffer silc_attribute_payload_encode(SilcAttribute attribute, + SilcAttributeFlags flags, + const unsigned char *data, + SilcUInt32 data_len); + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_parse_list + * + * SYNOPSIS + * + * SilcDList + * silc_attribute_payload_parse_list(const unsigned char *payload, + * SilcUInt32 payload_len); + * + * DESCRIPTION + * + * Parses list of Attribute payloads returning list of payloads. This + * is equivalent to the silc_attribute_payload_parse except that the + * `buffer' now includes multiple Attribute Payloads one after the other. + * You can produce such a list with silc_attribute_payload_encode_list + * function. + * + ***/ +SilcDList silc_attribute_payload_parse_list(const unsigned char *payload, + SilcUInt32 payload_len); + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_encode_list + * + * SYNOPSIS + * + * SilcBuffer silc_attribute_payload_encode(SilcUInt32 num_attrs, ...); + * + * DESCRIPTION + * + * Encodes a list of Attribute payloads. The `num_attrs' indicates the + * number of attributes sent as argument. The variable argument list + * sent as argument includes the attribute, attribute flags, attribute + * data and attribute data length. One attribute is one of these + * { attribute, attribute flags, data and data length } arguments. + * Returns the attribute payloads in data buffer one after the other. + * You can parse such list with silc_attribute_payload_parse_list + * function. + * + ***/ +SilcBuffer silc_attribute_payload_encode_list(SilcUInt32 num_attrs, ...); + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_free + * + * SYNOPSIS + * + * void silc_attribute_payload_free(SilcAttributePayload payload); + * + * DESCRIPTION + * + * Frees the Attribute Payload and all data in it. + * + ***/ +void silc_attribute_payload_free(SilcAttributePayload payload); + +/****f* silccore/SilcAttributesAPI/silc_attribute_payload_list_free + * + * SYNOPSIS + * + * void silc_attribute_payload_list_free(SilcDList list); + * + * DESCRIPTION + * + * Frees list of Attribute Payloads and all data in them. + * + ***/ +void silc_attribute_payload_list_free(SilcDList list); + +/****f* silccore/SilcAttributesAPI/silc_attribute_get_attribute + * + * SYNOPSIS + * + * SilcAttribute silc_attribute_get_attribute(SilcAttributePayload payload); + * + * DESCRIPTION + * + * Return the attribute type from the payload indicated by `payload'. + * + ***/ +SilcAttribute silc_attribute_get_attribute(SilcAttributePayload payload); + +/****f* silccore/SilcAttributesAPI/silc_attribute_get_flags + * + * SYNOPSIS + * + * SilcAttributeFlags + * silc_attribute_get_flags(SilcAttributePayload payload); + * + * DESCRIPTION + * + * Return the attribute flags from the payload indicated by `payload'. + * + ***/ +SilcAttributeFlags silc_attribute_get_flags(SilcAttributePayload payload); + +/****f* silccore/SilcAttributesAPI/silc_attribute_get_data + * + * SYNOPSIS + * + * const unsigned char * + * silc_attribute_get_data(SilcAttributePayload payload, + * SilcUInt32 *data_len); + * + * DESCRIPTION + * + * Returns the attribute data from the payload indicated by the `payload' + * The caller must not free the returned data pointer. + * + ***/ +const unsigned char *silc_attribute_get_data(SilcAttributePayload payload, + SilcUInt32 *data_len); + +/* Object structures */ + +/****s* silccore/SilcAttributesAPI/SilcAttributesObjService + * + * NAME + * + * typedef struct { ... } SilcAttributesObjService; + * + * DESCRIPTION + * + * SILC_ATTRIBUTE_SERVICE type object structure. + * + * SOURCE + */ +typedef struct { + SilcUInt32 port; /* IANA specified service port */ + char address[256]; /* service address */ + bool status; /* online status (TRUE present in service) */ +} SilcAttributeObjService; +/***/ + +/****s* silccore/SilcAttributesAPI/SilcAttributesObjMime + * + * NAME + * + * typedef struct { ... } SilcAttributesObjMime; + * + * DESCRIPTION + * + * Data type for MIME object as attribute. Caller must free the + * MIME data buffer inside the structure. + * + * SOURCE + */ +typedef struct { + unsigned char *mime; /* allocated MIME buffer */ + SilcUInt32 mime_len; /* length of the allocated MIME buffer */ +} SilcAttributeObjMime; +/***/ + +/****s* silccore/SilcAttributesAPI/SilcAttributesObjGeo + * + * NAME + * + * typedef struct { ... } SilcAttributesObjGeo; + * + * DESCRIPTION + * + * SILC_ATTRIBUTE_GEOLOCATION type object. The caller must free the + * strings inside the structure. + * + * SOURCE + */ +typedef struct { + char *longitude; /* Longitude */ + char *latitude; /* Latitude */ + char *altitude; /* Altitude */ + char *accuracy; /* Accuracy in meters */ +} SilcAttributeObjGeo; +/***/ + +/****s* silccore/SilcAttributesAPI/SilcAttributesObjDevice + * + * NAME + * + * typedef struct { ... } SilcAttributesObjDevice; + * + * DESCRIPTION + * + * SILC_ATTRIBUTE_DEVICE_INFO type object. The caller must free the + * strings inside the structure. + * + * SOURCE + */ +typedef struct { + SilcAttributeDevice type; /* device type */ + char *manufacturer; /* manufacturer of the device */ + char *version; /* device version string */ + char *model; /* device model string */ + char *language; /* device language (ISO 639-2/T) */ +} SilcAttributeObjDevice; +/***/ + +/****s* silccore/SilcAttributesAPI/SilcAttributesObjPk + * + * NAME + * + * typedef struct { ... } SilcAttributesObjPk; + * + * DESCRIPTION + * + * Data type for public key, certificate or digital signatures. The + * caller must free the data inside the structure. + * + * SOURCE + */ +typedef struct { + char *type; /* public key/certificate type, NULL + when contains digital signature. */ + unsigned char *data; /* public key/cert/signature data. The + encoding depends of the `type'. */ + SilcUInt32 data_len; /* data length */ +} SilcAttributeObjPk; +/***/ + +/****f* silccore/SilcAttributesAPI/silc_attribute_get_object + * + * SYNOPSIS + * + * bool silc_attribute_get_object(SilcAttributePayload payload, + * SilcAttribute attribute, + * const void **object, + * SilcUInt32 object_size); + * + * DESCRIPTION + * + * Returns the already parsed attribute object by the attribute type + * indicated by `attribute'. Copies the data into the `object' which + * must be sent as argument (and must be of correct type and size). + * The `object_size' indicates the size of the `*object' sent. + * Returns TRUE if the `attribute' attribute was found and FALSE + * if such attribute is not present in the `payload', or the `object_size' + * is not sufficient. See the definition of SilcAttribute for the + * list attributes and the required object types for attributes. + * + ***/ +bool silc_attribute_get_object(SilcAttributePayload payload, + SilcAttribute attribute, + void **object, SilcUInt32 object_size); + +#endif /* SILCATTRS_H */ diff --git a/lib/silccore/silccommand.h b/lib/silccore/silccommand.h index 3fbda03a..b864a426 100644 --- a/lib/silccore/silccommand.h +++ b/lib/silccore/silccommand.h @@ -154,7 +154,6 @@ typedef unsigned char SilcCommand; /* Private range start */ #define SILC_COMMAND_PRIVATE 200 - #define SILC_COMMAND_PRIV_CONNECT 200 #define SILC_COMMAND_PRIV_CLOSE 201 #define SILC_COMMAND_PRIV_SHUTDOWN 202 diff --git a/lib/silccore/silcid.h b/lib/silccore/silcid.h index 855d5470..4a042d16 100644 --- a/lib/silccore/silcid.h +++ b/lib/silccore/silcid.h @@ -85,22 +85,6 @@ typedef SilcUInt16 SilcIdType; ***/ typedef struct SilcIDPayloadStruct *SilcIDPayload; -/****s* silccore/SilcIDAPI/SilcArgumentPayload - * - * NAME - * - * typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; - * - * DESCRIPTION - * - * This context is the actual Argument Payload and is allocated - * by silc_argument_payload_parse and given as argument usually to - * all silc_argument_payload_* functions. It is freed by the - * silc_argument_payload_free function. - * - ***/ -typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; - /* Prototypes */ /****f* silccore/SilcIDAPI/silc_id_payload_parse