Added SILC Server library.
[silc.git] / lib / silccore / silcattrs.h
index 32c7040f417bc2e5c069337ff6c5e581fbaec61d..b51ca8243b28447fe742a44b7b42db1cd5db36c5 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcattrs.h 
+  silcattrs.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 Pekka Riikonen
+  Copyright (C) 2002 - 2005 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
@@ -33,7 +33,7 @@
 /****s* silccore/SilcAttributesAPI/SilcAttributePayload
  *
  * NAME
- * 
+ *
  *    typedef struct SilcAttributePayloadStruct *SilcAttributePayload;
  *
  * DESCRIPTION
@@ -49,7 +49,7 @@ typedef struct SilcAttributePayloadStruct *SilcAttributePayload;
 /****d* silccore/SilcAttributesAPI/SilcAttribute
  *
  * NAME
- * 
+ *
  *    typedef SilcUInt8 SilcAttribute;
  *
  * DESCRIPTION
@@ -66,22 +66,23 @@ typedef SilcUInt8 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 /* SilcVCard */
-#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_NONE                   0
+#define SILC_ATTRIBUTE_USER_INFO              1   /* SilcVCard */
+#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   /* SilcMime */
+#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  /* SilcMime */
+#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 */
+#define SILC_ATTRIBUTE_USER_ICON             16  /* SilcMime */
 /***/
 
 /* Maximum length of attribute request packet */
@@ -90,7 +91,7 @@ typedef SilcUInt8 SilcAttribute;
 /****d* silccore/SilcAttributesAPI/SilcAttributeFlags
  *
  * NAME
- * 
+ *
  *    typedef SilcUInt8 SilcAttributeFlags;
  *
  * DESCRIPTION
@@ -110,7 +111,7 @@ typedef SilcUInt8 SilcAttributeFlags;
 /****d* silccore/SilcAttributesAPI/SilcAttributeMood
  *
  * NAME
- * 
+ *
  *    typedef enum { ... } SilcAttributeMood;
  *
  * DESCRIPTION
@@ -139,7 +140,7 @@ typedef enum {
 /****d* silccore/SilcAttributesAPI/SilcAttributeContact
  *
  * NAME
- * 
+ *
  *    typedef enum { ... } SilcAttributeContact;
  *
  * DESCRIPTION
@@ -157,13 +158,14 @@ typedef enum {
   SILC_ATTRIBUTE_CONTACT_SMS     = 0x00000008,   /* SMS preferred */
   SILC_ATTRIBUTE_CONTACT_MMS     = 0x00000010,   /* MMS preferred */
   SILC_ATTRIBUTE_CONTACT_CHAT    = 0x00000020,   /* chatting preferred */
+  SILC_ATTRIBUTE_CONTACT_VIDEO   = 0x00000040,   /* video conferencing */
 } SilcAttributeContact;
 /***/
 
 /****d* silccore/SilcAttributesAPI/SilcAttributeDevice
  *
  * NAME
- * 
+ *
  *    typedef enum { ... } SilcAttributeDevice;
  *
  * DESCRIPTION
@@ -350,13 +352,37 @@ SilcAttributeFlags silc_attribute_get_flags(SilcAttributePayload payload);
 const unsigned char *silc_attribute_get_data(SilcAttributePayload payload,
                                             SilcUInt32 *data_len);
 
+/****f* silccore/SilcAttributesAPI/silc_attribute_get_verify_data
+ *
+ * SYNOPSIS
+ *
+ *    unsigned char *
+ *    silc_attribute_get_verify_data(SilcDList attrs,
+ *                                   SilcBool server_verification,
+ *                                   SilcUInt32 *data_len);
+ *
+ * DESCRIPTION
+ *
+ *    Constructs the data to be verified with the sender's digital
+ *    signature and sender's public key.  This allocates the data from
+ *    the list of attribute payloads and returns the buffer.  The caller
+ *    must free it.  If `server_verification' is FALSE then data is
+ *    constructed for user's digital signature verification, if it is
+ *    TRUE then it is constructed for server's digital signature
+ *    verification.
+ *
+ ***/
+unsigned char *silc_attribute_get_verify_data(SilcDList attrs,
+                                             SilcBool server_verification,
+                                             SilcUInt32 *data_len);
+
 /* Object structures */
 
-/****s* silccore/SilcAttributesAPI/SilcAttributesObjService
+/****s* silccore/SilcAttributesAPI/SilcAttributeObjService
  *
  * NAME
- * 
- *    typedef struct { ... } SilcAttributesObjService;
+ *
+ *    typedef struct { ... } SilcAttributeObjService;
  *
  * DESCRIPTION
  *
@@ -364,37 +390,20 @@ const unsigned char *silc_attribute_get_data(SilcAttributePayload payload,
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcAttributeObjServiceStruct {
   SilcUInt32 port;             /* IANA specified service port */
+  SilcUInt32 idle;             /* Idle time in the service */
+  char signon[64];             /* Signon date and time (UTC) */
   char address[256];           /* service address */
-  bool status;                 /* online status (TRUE present in service) */
+  SilcBool status;             /* online status (TRUE present in service) */
 } SilcAttributeObjService;
 /***/
 
-/****s* silccore/SilcAttributesAPI/SilcAttributesObjMime
+/****s* silccore/SilcAttributesAPI/SilcAttributeObjGeo
  *
  * NAME
- * 
- *    typedef struct { ... } SilcAttributesObjMime;
  *
- * DESCRIPTION
- *
- *    Data type for MIME object as attribute.  The data in the structure
- *    is valid as long as the payload structure is valid.
- *
- * SOURCE
- */
-typedef struct {
-  const unsigned char *mime;   /* MIME buffer */
-  SilcUInt32 mime_len;         /* length of the MIME buffer */
-} SilcAttributeObjMime;
-/***/
-
-/****s* silccore/SilcAttributesAPI/SilcAttributesObjGeo
- *
- * NAME
- * 
- *    typedef struct { ... } SilcAttributesObjGeo;
+ *    typedef struct { ... } SilcAttributeObjGeo;
  *
  * DESCRIPTION
  *
@@ -403,7 +412,7 @@ typedef struct {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcAttributeObjGeoStruct {
   char *longitude;             /* Longitude */
   char *latitude;              /* Latitude */
   char *altitude;              /* Altitude */
@@ -411,11 +420,11 @@ typedef struct {
 } SilcAttributeObjGeo;
 /***/
 
-/****s* silccore/SilcAttributesAPI/SilcAttributesObjDevice
+/****s* silccore/SilcAttributesAPI/SilcAttributeObjDevice
  *
  * NAME
- * 
- *    typedef struct { ... } SilcAttributesObjDevice;
+ *
+ *    typedef struct { ... } SilcAttributeObjDevice;
  *
  * DESCRIPTION
  *
@@ -424,7 +433,7 @@ typedef struct {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcAttributeObjDeviceStruct {
   SilcAttributeDevice type;    /* device type */
   char *manufacturer;          /* manufacturer of the device */
   char *version;               /* device version string */
@@ -433,20 +442,33 @@ typedef struct {
 } SilcAttributeObjDevice;
 /***/
 
-/****s* silccore/SilcAttributesAPI/SilcAttributesObjPk
+/****s* silccore/SilcAttributesAPI/SilcAttributeObjPk
  *
  * NAME
- * 
- *    typedef struct { ... } SilcAttributesObjPk;
+ *
+ *    typedef struct { ... } SilcAttributeObjPk;
  *
  * DESCRIPTION
  *
  *    Data type for public key, certificate or digital signatures.  The
- *    caller must free the data inside the structure.
+ *    caller must free the data inside the structure.  The 'type' is one
+ *    of following: "silc-rsa", "silc-dss, "ssh-rsa", "ssh-dss",
+ *    "pgp-sign-rsa", "pgp-sign-dss", "x509v3-sign-rsa", "x509v3-sign-dss".
+ *    See the draft-riikonen-precense-attrs draft for more detailed
+ *    information.  The 'type' is NULL when this structure includes a
+ *    digital signature.
+ *
+ *    In SILC, at least the "silc-rsa" must be supported.  In this case
+ *    the key is normal SILC Public key.  To verify a signature with the
+ *    SILC Public key, construct the signature data with the
+ *    silc_attribute_get_verify_data and verify the signature with
+ *    for example silc_pkcs_verify_with_hash function.  The public key
+ *    to the verification is the `data' and `data_len', and can be decoded
+ *    with silc_pkcs_public_key_decode function.
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcAttributeObjPkStruct {
   char *type;                  /* public key/certificate type, NULL
                                   when contains digital signature. */
   unsigned char *data;         /* public key/cert/signature data. The
@@ -459,9 +481,9 @@ typedef struct {
  *
  * SYNOPSIS
  *
- *    bool silc_attribute_get_object(SilcAttributePayload payload,
- *                                   void **object,
- *                                   SilcUInt32 object_size);
+ *    SilcBool silc_attribute_get_object(SilcAttributePayload payload,
+ *                                       void *object,
+ *                                       SilcUInt32 object_size);
  *
  * DESCRIPTION
  *
@@ -476,8 +498,24 @@ typedef struct {
  *    You can use silc_attribute_get_attribute to get the SilcAttribute
  *    type from the `payload'.
  *
+ * EXAMPLE
+ *
+ *    SilcAttributeObjDevice dev;
+ *
+ *    ...
+ *    case SILC_ATTRIBUTE_DEVICE_INFO:
+ *    memset(&dev, 0, sizeof(dev));
+ *    if (!silc_attribute_get_object(payload, (void *)&dev, sizeof(dev)))
+ *      error();
+ *
+ *    case SILC_ATTRIBUTE_USER_ICON:
+ *    mime = silc_mime_alloc();
+ *    if (!silc_attribute_get_object(payload, (void *)mime, sizeof(*mime)))
+ *      error();
+ *    ...
+ *
  ***/
-bool silc_attribute_get_object(SilcAttributePayload payload,
-                              void **object, SilcUInt32 object_size);
+SilcBool silc_attribute_get_object(SilcAttributePayload payload,
+                                  void *object, SilcUInt32 object_size);
 
 #endif /* SILCATTRS_H */