diff options
Diffstat (limited to 'decoders/sip/sip_internal.h')
| -rw-r--r-- | decoders/sip/sip_internal.h | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/decoders/sip/sip_internal.h b/decoders/sip/sip_internal.h new file mode 100644 index 0000000..4acd653 --- /dev/null +++ b/decoders/sip/sip_internal.h @@ -0,0 +1,193 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "uthash/uthash.h" + +#ifndef UNUSED +#define UNUSED(x) (void)(x) +#endif +#define SIP_DIM(a) (sizeof (a) / sizeof ((a)[0])) + +#define timeval_usec(t) ((t).tv_usec) +#define timeval_sec(t) ((t).tv_sec) +#define timeval_add(a, b, r) \ + do { \ + (r).tv_sec = (a).tv_sec + (b).tv_sec; \ + (r).tv_usec = (a).tv_usec + (b).tv_usec; \ + } while (0) +#define timeval_cmp(a, b, CMP) \ + ((timeval_sec(a) == timeval_sec(b)) ? (timeval_usec(a) CMP timeval_usec(b)) \ + : (timeval_sec(a) CMP timeval_sec(b))) +#define timeval_cmp_gte(a, b) timeval_cmp((a), (b), >=) +#define timeval_cmp_gt(a, b) timeval_cmp((a), (b), >) +#define timeval_cmp_lt(a, b) timeval_cmp((a), (b), <) +#define timeval_cmp_lte(a, b) timeval_cmp((a), (b), <=) +#define timeval_cmp_neq(a, b) timeval_cmp((a), (b), !=) + +#define timeval_delta_ms(start, end) (((end).tv_sec-(start).tv_sec)*1000 + ((end).tv_usec-(start).tv_usec)/1000) +#define timeval_delta_us(start, end) (((end).tv_sec-(start).tv_sec)*1000*1000 + ((end).tv_usec-(start).tv_usec)) +#define timeval_to_ms(t) ((t).tv_sec*1000+(t).tv_usec/1000) + +#define SAFE_STRNCASECMP(s1, s1_len, s2, s2_len) ((s1_len) >= (s2_len) ? strncasecmp(s1, s2, s2_len) : -1) + +#define SIP_EXDATA_NAME "SIP_EXDATA" +#define SIP_REQUEST_TOPIC_NAME "SIP_REQUEST" +#define SIP_RESPONSE_TOPIC_NAME "SIP_RESPONSE" +#define SIP_TRANSACTION_TOPIC_NAME "SIP_TRANSACTION" +#define SIP_IDENTIFY_TIMES_MAX 128 + +#define SIP_REQUEST_LINE_PART_METHOD 0 +#define SIP_REQUEST_LINE_PART_URI 1 +#define SIP_REQUEST_LINE_PART_VERSION 2 +#define SIP_STATUS_LINE_PART_VERSION 0 +#define SIP_STATUS_LINE_PART_CODE 1 +#define SIP_STATUS_LINE_PART_REASON 2 +#define SIP_START_LINE_PART_NUM 3 +#define SIP_HEADER_FIELD_PART_NAME 0 +#define SIP_HEADER_FIELD_PART_VALUE 1 +#define SIP_HEADER_FIELD_PART_NUM 2 +#define SDP_MEDIA_PART_MEDIA 0 +#define SDP_MEDIA_PART_PORT 1 +#define SDP_MEDIA_PART_PROTO 2 +#define SDP_MEDIA_PART_FMT 3 +#define SDP_MEDIA_PART_NUM 4 +#define SDP_CONNECTION_PART_NETTYPE 0 +#define SDP_CONNECTION_PART_ADDRTYPE 1 +#define SDP_CONNECTION_PART_ADDRESS 2 +#define SDP_CONNECTION_PART_NUM 3 + +#define SIP_FROM_PART_ADDR 0 +#define SIP_FROM_PART_TAG 1 +#define SIP_FROM_PART_NUM 2 +#define SIP_TO_PART_ADDR 0 +#define SIP_TO_PART_TAG 1 +#define SIP_TO_PART_NUM 2 +#define SIP_CSEQ_PART_SEQ 0 +#define SIP_CSEQ_PART_METHOD 1 +#define SIP_CSEQ_PART_NUM 2 + +#define SIP_HEADER_FIELD_POOL_DEFAULT_SIZE 256 +#define SIP_STREAM_BUFFER_DEFAULT_SIZE 4096 +#define SIP_LINE_END "\r\n" +#define SIP_HEADER_END "\r\n\r\n" +#define SIP_STATUS_CODE_LEN 3 +#define SIP_PER_PAYLOAD_MESSAGE_MAX 8 + +enum sip_call_state { + SIP_CALL_STATE_OPENING, + SIP_CALL_STATE_WAITING, /* before seeing INVITE*/ + SIP_CALL_STATE_CALLING, /* after seeing INVITE */ + SIP_CALL_STATE_EARLY, /* provisional response (1xx status code) */ + SIP_CALL_STATE_CONNECTING, /* after seeing 200/OK response */ + SIP_CALL_STATE_CONFIRMED, /* after seeing ACK */ + SIP_CALL_STATE_DISCONNECTING, /* after seeing BYE */ + SIP_CALL_STATE_DISCONNECTED, /* call is disconnected */ + SIP_CALL_STATE_CLOSING, +}; + +enum sip_identify_state { + SIP_IDENTIFY_STATE_UNKNOWN, + SIP_IDENTIFY_STATE_HALF_TRUE, + SIP_IDENTIFY_STATE_TRUE, + SIP_IDENTIFY_STATE_FALSE, +}; + +enum sip_message_type { + SIP_MESSAGE_TYPE_UNKNOWN, + SIP_MESSAGE_TYPE_REQUEST, + SIP_MESSAGE_TYPE_RESPONSE, + SIP_MESSAGE_TYPE_MAX, +}; + +enum sip_dir { + SIP_DIR_UNKNOWN, + SIP_DIR_REQUEST, + SIP_DIR_RESPONSE, + SIP_DIR_DOUBLE, +}; + +enum sip_version { + SIP_VERSION_UNKNOWN, + SIP_VERSION_1_0, + SIP_VERSION_1_1, + SIP_VERSION_2_0, + + SIP_VERSION_NUM, +}; + +struct stream_buffer { + char *buf; + size_t buf_size; + size_t buf_off; +}; + +struct sip_header_field_pool { + struct sip_header_field *arr; + unsigned int used; + unsigned int size; +} __attribute__((aligned(64))); + +struct sip_transaction { + char *key; // use sip Call-ID string for uthash key + size_t key_len; + int seq; + enum sip_dir dir; + enum sip_call_state call_state; + long long call_duration_ms; + struct timeval last_update; + UT_hash_handle hh; +}; + +struct sip_message { + enum sip_message_type type; + enum sip_call_state call_state; + int transaction_seq; + + union { + struct sip_request_line request_line; + struct sip_status_line status_line; + }; + struct sip_header header; + struct sip_body body; + + struct sip_header_field_pool *header_field_pool; + struct session *sess_ref; +}; + +struct sip_exdata { + struct sip_decoder *decoder_ref; + struct session *sess_ref; + + int sess_ignored; + + enum sip_identify_state identify_state; + int identify_times; + + struct sip_transaction *transaction_table; // sip transaction uthash head (key: call_id) + int transaction_seq; + enum sip_dir dir; // request only/response only/ double + enum sip_call_state call_state; // sip call state + + struct stream_buffer streambuffer; // temporary buffer for incomplete sip message +}; + +struct sip_decoder { + int request_message_topic_id; + int response_message_topic_id; + int exdata_id; + + int transaction_limit_count; + int transaction_timeout_ms; + + int thread_num; + struct sip_header_field_pool **field_pools;// per thread field pool + struct module_manager *mod_mgr; +}; + +#ifdef __cplusplus +} +#endif |
