#ifndef _SIP_PROTOCOL_H
#define _SIP_PROTOCOL_H
#include "common/sip_common.h"
/* SIP方法定义 */
typedef enum sip_method {
SIP_METHOD_INVITE = 0,
SIP_METHOD_ACK,
SIP_METHOD_BYE,
SIP_METHOD_CANCEL,
SIP_METHOD_REGISTER,
SIP_METHOD_OPTIONS,
SIP_METHOD_MAX
}sip_method;
/* SIP响应状态码 */
/* SIP响应状态码枚举 (RFC 3261及相关扩展) */
typedef enum sip_status_code {
/* 1xx 临时响应 */
SIP_100_TRYING = 100,
SIP_180_RINGING = 180,
SIP_181_CALL_IS_BEING_FORWARDED = 181,
SIP_182_QUEUED = 182,
SIP_183_SESSION_PROGRESS = 183,
/* 2xx 成功响应 */
SIP_200_OK = 200,
SIP_202_ACCEPTED = 202, // RFC3265
/* 3xx 重定向响应 */
SIP_300_MULTIPLE_CHOICES = 300,
SIP_301_MOVED_PERMANENTLY = 301,
SIP_302_MOVED_TEMPORARILY = 302,
SIP_305_USE_PROXY = 305,
SIP_380_ALTERNATIVE_SERVICE = 380,
/* 4xx 客户端错误 */
SIP_400_BAD_REQUEST = 400,
SIP_401_UNAUTHORIZED = 401,
SIP_402_PAYMENT_REQUIRED = 402,
SIP_403_FORBIDDEN = 403,
SIP_404_NOT_FOUND = 404,
SIP_405_METHOD_NOT_ALLOWED = 405,
SIP_406_NOT_ACCEPTABLE = 406,
SIP_407_PROXY_AUTHENTICATION_REQUIRED = 407,
SIP_408_REQUEST_TIMEOUT = 408,
SIP_410_GONE = 410,
SIP_413_REQUEST_ENTITY_TOO_LARGE = 413,
SIP_414_REQUEST_URI_TOO_LONG = 414,
SIP_415_UNSUPPORTED_MEDIA_TYPE = 415,
SIP_416_UNSUPPORTED_URI_SCHEME = 416,
SIP_420_BAD_EXTENSION = 420,
SIP_421_EXTENSION_REQUIRED = 421,
SIP_423_INTERVAL_TOO_BRIEF = 423,
SIP_480_TEMPORARILY_UNAVAILABLE = 480,
SIP_481_CALL_TRANSACTION_DOES_NOT_EXIST = 481,
SIP_482_LOOP_DETECTED = 482,
SIP_483_TOO_MANY_HOPS = 483,
SIP_484_ADDRESS_INCOMPLETE = 484,
SIP_485_AMBIGUOUS = 485,
SIP_486_BUSY_HERE = 486,
SIP_487_REQUEST_TERMINATED = 487,
SIP_488_NOT_ACCEPTABLE_HERE = 488,
SIP_489_BAD_EVENT = 489, // RFC3265
SIP_491_REQUEST_PENDING = 491,
SIP_493_UNDECIPHERABLE = 493,
/* 5xx 服务器错误 */
SIP_500_SERVER_INTERNAL_ERROR = 500,
SIP_501_NOT_IMPLEMENTED = 501,
SIP_502_BAD_GATEWAY = 502,
SIP_503_SERVICE_UNAVAILABLE = 503,
SIP_504_SERVER_TIME_OUT = 504,
SIP_505_VERSION_NOT_SUPPORTED = 505,
SIP_513_MESSAGE_TOO_LARGE = 513,
/* 6xx 全局错误 */
SIP_600_BUSY_EVERYWHERE = 600,
SIP_603_DECLINE = 603,
SIP_604_DOES_NOT_EXIST_ANYWHERE = 604,
SIP_606_NOT_ACCEPTABLE = 606
} sip_status_code;
/* SIP URI结构 */
typedef struct sip_uri {
char scheme[8]; /* "sip" or "sips" */
char user[32]; /* username */
char host[32]; /* domain or IP */
U16 port; /* port number */
char parameters[32]; /* URI parameters */
}sip_uri;
/* SIP Via头结构 */
typedef struct sip_via {
char protocol[16]; /* "SIP/2.0" */
char transport[8]; /* "UDP", "TCP" */
char host[64]; /* sent-by host */
U16 port; /* sent-by port */
char branch[32]; /* branch parameter */
char received[32]; /* received parameter */
U16 rport; /* rport parameter */
}sip_via;
/* 认证信息结构体 */
typedef struct auth_info_t{
char realm[128];
char nonce[128];
char algorithm[32];
char qop[32];
char opaque[128];
int stale;
char response[33];
} auth_info_t;
/* SIP消息头结构 */
typedef struct sip_headers {
struct sip_uri from; /* From header */
struct sip_uri to; /* To header */
struct sip_uri request_uri; /* Request-URI */
struct sip_via via; /* Via header */
char call_id[64]; /* Call-ID header */
U32 cseq; /* CSeq number */
enum sip_method cseq_method;/* CSeq method */
U8 max_forwards; /* Max-Forwards header */
char content_type[64]; /* Content-Type header */
char contact[64];
U32 content_length; /* Content-Length header */
U32 Expires;
char user_agent[64]; /* User-Agent header */
auth_info_t auth;
}sip_headers;
/* SIP消息体结构 */
typedef struct sip_body {
char *content; /* Message body content */
U32 length; /* Message body length */
char type[32]; /* Content type */
}sip_body;
/* SIP消息结构 */
typedef struct sip_message {
U8 type; /* 0: request, 1: response */
enum sip_method method;/* Method (for requests) */
U16 status_code; /* Status code (for responses) */
char reason_phrase[32];/* Reason phrase (for responses) */
struct sip_headers headers; /* SIP headers */
struct sip_body body; /* Message body */
char *raw_data; /* Raw message data */
U32 raw_length; /* Raw message length */
struct sockaddr_in source; /* Message source */
struct list_head list; /* List head for message queue */
}sip_message;
/* SIP事务信息 */
typedef struct sip_transaction {
char branch[32]; /* Transaction branch */
enum sip_method method; /* Transaction method */
U32 timeout; /* Transaction timeout */
unsigned long start_time; /* Start time in jiffies */
struct sip_message request; /* Original request */
struct sip_message last_response; /* Last response */
void *user_data; /* User-specific data */
U8 state; /*0,off,1 on*/
}sip_transaction;
/* 协议栈配置 */
typedef struct sip_protocol_config {
char user_agent[32];
U8 max_forwards;
U32 t1_timeout; /* T1 timer (RTT estimate) */
U32 t2_timeout; /* T2 timer (64*T1) */
U32 t4_timeout; /* T4 timer (5000ms) */
}sip_protocol_config;
/* SIP协议栈接口 */
int sip_message_parse(sip_message *msg, const char *data, U32 length);
int sip_message_build(sip_message *msg, char *buffer, U32 size);
void sip_message_free(sip_message *msg);
// int sip_send_message(S32 sip_socket, struct sip_message *msg,const char *dest_addr, U16 dest_port);
int sip_uri_parse(struct sip_uri *uri, const char *uri_str);
int sip_uri_build(struct sip_uri *uri, char *buffer, U32 size);
struct sip_transaction *sip_transaction_create(struct sip_message *ori_req);
void sip_transaction_free(struct sip_transaction *trans);
const char *sip_method_to_string(enum sip_method method);
sip_method sip_string_to_method(const char *method_str);
const char *sip_status_to_reason(U16 status_code);
void sip_generate_branch(char *branch, U32 size);
void sip_generate_tag(char *tag, U32 size);
void sip_generate_call_id(char *buf, int len);
#endif /* _SIP_PROTOCOL_H */
为这段程序所有字符数组最大长度改为宏定义的最大长度