diff options
author | Youness Alaoui <kakaroto@kakaroto.(none)> | 2008-06-06 18:32:16 -0400 |
---|---|---|
committer | Youness Alaoui <kakaroto@kakaroto.(none)> | 2008-06-06 18:32:16 -0400 |
commit | b9669017120b3dc12aa14e548201168e0e93f801 (patch) | |
tree | 7aece344441d63274fdcbd7e2d6f4dadab59d717 /stun/stunmessage.h | |
parent | c07afc9a4bcd0557cecc2b4de8e8834f67c0844e (diff) | |
download | libnice-b9669017120b3dc12aa14e548201168e0e93f801.tar.gz |
Updating stun to include an agent
Diffstat (limited to 'stun/stunmessage.h')
-rw-r--r-- | stun/stunmessage.h | 133 |
1 files changed, 73 insertions, 60 deletions
diff --git a/stun/stunmessage.h b/stun/stunmessage.h index fdcc8c7..8428d32 100644 --- a/stun/stunmessage.h +++ b/stun/stunmessage.h @@ -41,12 +41,7 @@ #include <stdbool.h> #include "constants.h" -typedef struct { - uint8_t *buffer; - size_t buffer_len; - bool message_id_validated; -} StunMessage; - +typedef struct stun_message_t StunMessage; /* Message classes */ typedef enum @@ -78,65 +73,65 @@ typedef enum { /* Mandatory attributes */ /* 0x0000 */ /* reserved */ - STUN_MAPPED_ADDRESS=0x0001, /* RFC3489bis-11 */ - STUN_OLD_RESPONSE_ADDRESS=0x0002, /* old RFC3489 */ - STUN_OLD_CHANGE_REQUEST=0x0003, /* old RFC3489 */ - STUN_OLD_SOURCE_ADDRESS=0x0004, /* old RFC3489 */ - STUN_OLD_CHANGED_ADDRESS=0x0005, /* old RFC3489 */ - STUN_USERNAME=0x0006, /* RFC3489bis-11 */ - STUN_OLD_PASSWORD=0x0007, /* old RFC3489 */ - STUN_MESSAGE_INTEGRITY=0x0008, /* RFC3489bis-11 */ - STUN_ERROR_CODE=0x0009, /* RFC3489bis-11 */ - STUN_UNKNOWN_ATTRIBUTES=0x000A, /* RFC3489bis-11 */ - STUN_OLD_REFLECTED_FROM=0x000B, /* old RFC3489 */ + STUN_ATTRIBUTE_MAPPED_ADDRESS=0x0001, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_OLD_RESPONSE_ADDRESS=0x0002, /* old RFC3489 */ + STUN_ATTRIBUTE_OLD_CHANGE_REQUEST=0x0003, /* old RFC3489 */ + STUN_ATTRIBUTE_OLD_SOURCE_ADDRESS=0x0004, /* old RFC3489 */ + STUN_ATTRIBUTE_OLD_CHANGED_ADDRESS=0x0005, /* old RFC3489 */ + STUN_ATTRIBUTE_USERNAME=0x0006, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_OLD_PASSWORD=0x0007, /* old RFC3489 */ + STUN_ATTRIBUTE_MESSAGE_INTEGRITY=0x0008, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_ERROR_CODE=0x0009, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_UNKNOWN_ATTRIBUTES=0x000A, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_OLD_REFLECTED_FROM=0x000B, /* old RFC3489 */ /* 0x000C */ /* reserved */ - STUN_LIFETIME=0x000D, /* TURN-04 */ + STUN_ATTRIBUTE_LIFETIME=0x000D, /* TURN-04 */ /* 0x000E */ /* reserved */ /* 0x000F */ /* reserved */ - STUN_BANDWIDTH=0x0010, /* TURN-04 */ + STUN_ATTRIBUTE_BANDWIDTH=0x0010, /* TURN-04 */ /* 0x0011 */ /* reserved */ - STUN_REMOTE_ADDRESS=0x0012, /* TURN-04 */ - STUN_DATA=0x0013, /* TURN-04 */ - STUN_REALM=0x0014, /* RFC3489bis-11 */ - STUN_NONCE=0x0015, /* RFC3489bis-11 */ - STUN_RELAY_ADDRESS=0x0016, /* TURN-04 */ - STUN_REQUESTED_ADDRESS_TYPE=0x0017, /* TURN-IPv6-03 */ - STUN_REQUESTED_PORT_PROPS=0x0018, /* TURN-04 */ - STUN_REQUESTED_TRANSPORT=0x0019, /* TURN-04 */ + STUN_ATTRIBUTE_REMOTE_ADDRESS=0x0012, /* TURN-04 */ + STUN_ATTRIBUTE_DATA=0x0013, /* TURN-04 */ + STUN_ATTRIBUTE_REALM=0x0014, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_NONCE=0x0015, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_RELAY_ADDRESS=0x0016, /* TURN-04 */ + STUN_ATTRIBUTE_REQUESTED_ADDRESS_TYPE=0x0017, /* TURN-IPv6-03 */ + STUN_ATTRIBUTE_REQUESTED_PORT_PROPS=0x0018, /* TURN-04 */ + STUN_ATTRIBUTE_REQUESTED_TRANSPORT=0x0019, /* TURN-04 */ /* 0x001A */ /* reserved */ /* 0x001B */ /* reserved */ /* 0x001C */ /* reserved */ /* 0x001D */ /* reserved */ /* 0x001E */ /* reserved */ /* 0x001F */ /* reserved */ - STUN_XOR_MAPPED_ADDRESS=0x0020, /* RFC3489bis-11 */ - STUN_TIMER_VAL=0x0021, /* TURN-04 */ - STUN_REQUESTED_IP=0x0022, /* TURN-04 */ - STUN_CONNECT_STAT=0x0023, /* TURN-04 */ - STUN_PRIORITY=0x0024, /* ICE-18 */ - STUN_USE_CANDIDATE=0x0025, /* ICE-18 */ + STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS=0x0020, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_TIMER_VAL=0x0021, /* TURN-04 */ + STUN_ATTRIBUTE_REQUESTED_IP=0x0022, /* TURN-04 */ + STUN_ATTRIBUTE_CONNECT_STAT=0x0023, /* TURN-04 */ + STUN_ATTRIBUTE_PRIORITY=0x0024, /* ICE-18 */ + STUN_ATTRIBUTE_USE_CANDIDATE=0x0025, /* ICE-18 */ /* 0x0026 */ /* reserved */ /* 0x0027 */ /* reserved */ /* 0x0028 */ /* reserved */ - STUN_XOR_INTERNAL_ADDRESS=0x0029, /* wing-nat-control-04 */ + STUN_ATTRIBUTE_XOR_INTERNAL_ADDRESS=0x0029, /* wing-nat-control-04 */ /* 0x002A-0x7fff */ /* reserved */ /* Optional attributes */ /* 0x8000-0x8021 */ /* reserved */ - STUN_SERVER=0x8022, /* RFC3489bis-11 */ - STUN_ALTERNATE_SERVER=0x8023, /* RFC3489bis-11 */ - STUN_REFRESH_INTERVAL=0x8024, /* wing-nat-control-04 */ + STUN_ATTRIBUTE_SERVER=0x8022, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_ALTERNATE_SERVER=0x8023, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_REFRESH_INTERVAL=0x8024, /* wing-nat-control-04 */ /* 0x8025 */ /* reserved */ /* 0x8026 */ /* reserved */ /* 0x8027 */ /* reserved */ - STUN_FINGERPRINT=0x8028, /* RFC3489bis-11 */ - STUN_ICE_CONTROLLED=0x8029, /* ICE-18 */ - STUN_ICE_CONTROLLING=0x802A, /* ICE-18 */ + STUN_ATTRIBUTE_FINGERPRINT=0x8028, /* RFC3489bis-11 */ + STUN_ATTRIBUTE_ICE_CONTROLLED=0x8029, /* ICE-18 */ + STUN_ATTRIBUTE_ICE_CONTROLLING=0x802A, /* ICE-18 */ /* 0x802B-0xFFFF */ /* reserved */ } stun_attr_type_t; -typedef uint8_t stun_transid_t[12]; +typedef uint8_t stun_transid_t[STUN_MESSAGE_TRANS_ID_LEN]; /** @@ -145,32 +140,41 @@ typedef uint8_t stun_transid_t[12]; */ typedef enum { - STUN_TRY_ALTERNATE=300, /* RFC3489bis-11 */ - STUN_BAD_REQUEST=400, /* RFC3489bis-11 */ - STUN_UNAUTHORIZED=401, /* RFC3489bis-11 */ - STUN_UNKNOWN_ATTRIBUTE=420, /* RFC3489bis-11 */ - STUN_NO_BINDING=437, /* TURN-04 */ - STUN_STALE_NONCE=438, /* RFC3489bis-11 */ - STUN_ACT_DST_ALREADY=439, /* TURN-04 */ - STUN_UNSUPP_FAMILY=440, /* TURN-IPv6-03 */ - STUN_UNSUPP_TRANSPORT=442, /* TURN-04 */ - STUN_INVALID_IP=443, /* TURN-04 */ - STUN_INVALID_PORT=444, /* TURN-04 */ - STUN_OP_TCP_ONLY=445, /* TURN-04 */ - STUN_CONN_ALREADY=446, /* TURN-04 */ - STUN_ALLOC_OVER_QUOTA=486, /* TURN-04 */ - STUN_ROLE_CONFLICT=487, /* ICE-18 */ - STUN_SERVER_ERROR=500, /* RFC3489bis-11 */ - STUN_SERVER_CAPACITY=507, /* TURN-04 */ + STUN_ERROR_TRY_ALTERNATE=300, /* RFC3489bis-11 */ + STUN_ERROR_BAD_REQUEST=400, /* RFC3489bis-11 */ + STUN_ERROR_UNAUTHORIZED=401, /* RFC3489bis-11 */ + STUN_ERROR_UNKNOWN_ATTRIBUTE=420, /* RFC3489bis-11 */ + STUN_ERROR_NO_BINDING=437, /* TURN-04 */ + STUN_ERROR_STALE_NONCE=438, /* RFC3489bis-11 */ + STUN_ERROR_ACT_DST_ALREADY=439, /* TURN-04 */ + STUN_ERROR_UNSUPP_FAMILY=440, /* TURN-IPv6-03 */ + STUN_ERROR_UNSUPP_TRANSPORT=442, /* TURN-04 */ + STUN_ERROR_INVALID_IP=443, /* TURN-04 */ + STUN_ERROR_INVALID_PORT=444, /* TURN-04 */ + STUN_ERROR_OP_TCP_ONLY=445, /* TURN-04 */ + STUN_ERROR_CONN_ALREADY=446, /* TURN-04 */ + STUN_ERROR_ALLOC_OVER_QUOTA=486, /* TURN-04 */ + STUN_ERROR_ROLE_CONFLICT=487, /* ICE-18 */ + STUN_ERROR_SERVER_ERROR=500, /* RFC3489bis-11 */ + STUN_ERROR_SERVER_CAPACITY=507, /* TURN-04 */ STUN_ERROR_MAX=699 } stun_error_t; +#include "stunagent.h" #include "stunhmac.h" #include "stuncrc32.h" #include "utils.h" #include "stun3489bis.h" +struct stun_message_t { + StunAgent *agent; + uint8_t *buffer; + size_t buffer_len; + uint8_t *key; + size_t key_len; +}; + /** * Initializes a STUN message buffer, with no attributes. * @param c STUN message class (host byte order) @@ -281,7 +285,7 @@ int stun_message_find_xor_addr (const StunMessage *msg, stun_attr_type_t type, struct sockaddr *restrict addr, socklen_t *restrict addrlen); -int stun_message_find_errno (const StunMessage *msg, int *restrict code); +int stun_message_find_error (const StunMessage *msg, int *restrict code); void *stun_message_append (StunMessage *msg, stun_attr_type_t type, size_t length); @@ -368,7 +372,16 @@ int stun_message_append_xor_addr (StunMessage * msg, stun_attr_type_t type, */ int stun_message_append_error (StunMessage * msg, stun_error_t code); -bool stun_message_is_valid (const uint8_t *msg, size_t length); +#define STUN_MESSAGE_BUFFER_INCOMPLETE 0 +#define STUN_MESSAGE_BUFFER_INVALID -1 + + +int stun_message_validate_buffer_length (const uint8_t *msg, size_t length); + +void stun_message_id (const StunMessage *msg, stun_transid_t id); +stun_class_t stun_message_get_class (const StunMessage *msg); +stun_method_t stun_message_get_method (const StunMessage *msg); +bool stun_message_has_attribute (const StunMessage *msg, stun_attr_type_t type); #endif /* _STUN_MESSAGE_H */ |