msg_parser.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef MSG_PARSER_H
00047 #define MSG_PARSER_H
00048
00049 #include "../str.h"
00050 #include "../lump_struct.h"
00051 #include "../flags.h"
00052 #include "../ip_addr.h"
00053 #include "../md5utils.h"
00054 #include "../config.h"
00055 #include "parse_def.h"
00056 #include "parse_cseq.h"
00057 #include "parse_via.h"
00058 #include "parse_fline.h"
00059 #include "hf.h"
00060 #include "sdp/sdp.h"
00061
00062
00063
00064 #define REQ_LINE(_msg) ((_msg)->first_line.u.request)
00065 #define REQ_METHOD first_line.u.request.method_value
00066 #define REPLY_STATUS first_line.u.reply.statuscode
00067 #define REPLY_CLASS(_reply) ((_reply)->REPLY_STATUS/100)
00068
00069
00070 enum request_method {
00071 METHOD_UNDEF=0,
00072 METHOD_INVITE=1,
00073 METHOD_CANCEL=2,
00074 METHOD_ACK=4,
00075 METHOD_BYE=8,
00076 METHOD_INFO=16,
00077 METHOD_OPTIONS=32,
00078 METHOD_UPDATE=64,
00079 METHOD_REGISTER=128,
00080 METHOD_MESSAGE=256,
00081 METHOD_SUBSCRIBE=512,
00082 METHOD_NOTIFY=1024,
00083 METHOD_PRACK=2048,
00084 METHOD_REFER=4096,
00085 METHOD_PUBLISH=8192,
00086 METHOD_OTHER=16384
00087 };
00088
00089 #define FL_FORCE_RPORT (1<<0)
00090 #define FL_FORCE_ACTIVE (1<<1)
00091 #define FL_FORCE_LOCAL_RPORT (1<<2)
00092 #define FL_SDP_IP_AFS (1<<3)
00093 #define FL_SDP_PORT_AFS (1<<4)
00094 #define FL_SHM_CLONE (1<<5)
00095 #define FL_USE_UAC_FROM (1<<6)
00096 #define FL_USE_UAC_TO (1<<7)
00097 #define FL_USE_UAC_CSEQ (1<<8)
00098 #define FL_REQ_UPSTREAM (1<<9)
00099 #define FL_DO_KEEPALIVE (1<<10)
00100
00101 #define FL_USE_MEDIA_PROXY (1<<11)
00102
00103
00104 #define IFISMETHOD(methodname,firstchar) \
00105 if ( (*tmp==(firstchar) || *tmp==((firstchar) | 32)) && \
00106 strncasecmp( tmp+1, #methodname +1, methodname##_LEN-1)==0 && \
00107 *(tmp+methodname##_LEN)==' ') { \
00108 fl->type=SIP_REQUEST; \
00109 fl->u.request.method.len=methodname##_LEN; \
00110 fl->u.request.method_value=METHOD_##methodname; \
00111 tmp=buffer+methodname##_LEN; \
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 #define GET_NEXT_HOP(m) \
00123 (((m)->dst_uri.s && (m)->dst_uri.len) ? (&(m)->dst_uri) : \
00124 (((m)->new_uri.s && (m)->new_uri.len) ? (&(m)->new_uri) : (&(m)->first_line.u.request.uri)))
00125
00126
00127
00128
00129
00130
00131
00132
00133 #define GET_RURI(m) \
00134 (((m)->new_uri.s && (m)->new_uri.len) ? (&(m)->new_uri) : (&(m)->first_line.u.request.uri))
00135
00136
00137 enum _uri_type{ERROR_URI_T=0, SIP_URI_T, SIPS_URI_T, TEL_URI_T, TELS_URI_T};
00138 typedef enum _uri_type uri_type;
00139
00140 struct sip_uri {
00141 str user;
00142 str passwd;
00143 str host;
00144 str port;
00145 str params;
00146 str headers;
00147 unsigned short port_no;
00148 unsigned short proto;
00149 uri_type type;
00150
00151 str transport;
00152 str ttl;
00153 str user_param;
00154 str maddr;
00155 str method;
00156 str lr;
00157 str r2;
00158
00159 str transport_val;
00160 str ttl_val;
00161 str user_param_val;
00162 str maddr_val;
00163 str method_val;
00164 str lr_val;
00165 str r2_val;
00166 };
00167
00168
00169 #include "parse_to.h"
00170
00171 struct sip_msg {
00172 unsigned int id;
00173 struct msg_start first_line;
00174 struct via_body* via1;
00175 struct via_body* via2;
00176 struct hdr_field* headers;
00177 struct hdr_field* last_header;
00178 hdr_flags_t parsed_flag;
00179
00180
00181
00182
00183
00184
00185 struct hdr_field* h_via1;
00186 struct hdr_field* h_via2;
00187 struct hdr_field* callid;
00188 struct hdr_field* to;
00189 struct hdr_field* cseq;
00190 struct hdr_field* from;
00191 struct hdr_field* contact;
00192 struct hdr_field* maxforwards;
00193 struct hdr_field* route;
00194 struct hdr_field* record_route;
00195 struct hdr_field* path;
00196 struct hdr_field* content_type;
00197 struct hdr_field* content_length;
00198 struct hdr_field* authorization;
00199 struct hdr_field* expires;
00200 struct hdr_field* proxy_auth;
00201 struct hdr_field* supported;
00202 struct hdr_field* proxy_require;
00203 struct hdr_field* unsupported;
00204 struct hdr_field* allow;
00205 struct hdr_field* event;
00206 struct hdr_field* accept;
00207 struct hdr_field* accept_language;
00208 struct hdr_field* organization;
00209 struct hdr_field* priority;
00210 struct hdr_field* subject;
00211 struct hdr_field* user_agent;
00212 struct hdr_field* content_disposition;
00213 struct hdr_field* accept_disposition;
00214 struct hdr_field* diversion;
00215 struct hdr_field* rpid;
00216 struct hdr_field* refer_to;
00217 struct hdr_field* session_expires;
00218 struct hdr_field* min_se;
00219 struct hdr_field* ppi;
00220 struct hdr_field* pai;
00221 struct hdr_field* privacy;
00222
00223 struct sdp_info* sdp;
00224
00225 char* eoh;
00226 char* unparsed;
00227
00228 struct receive_info rcv;
00229
00230 char* buf;
00231
00232 unsigned int len;
00233
00234
00235
00236 str new_uri;
00237
00238
00239 str dst_uri;
00240
00241
00242 int parsed_uri_ok;
00243
00244 struct sip_uri parsed_uri;
00245
00246
00247 int parsed_orig_ruri_ok;
00248 struct sip_uri parsed_orig_ruri;
00249
00250 struct lump* add_rm;
00251 struct lump* body_lumps;
00252 struct lump_rpl *reply_lump;
00253
00254
00255 char add_to_branch_s[MAX_BRANCH_PARAM_LEN];
00256 int add_to_branch_len;
00257
00258
00259
00260 unsigned int hash_index;
00261 int branch_index;
00262
00263
00264 flag_t flags;
00265
00266
00267
00268
00269 unsigned int msg_flags;
00270
00271 str set_global_address;
00272 str set_global_port;
00273
00274
00275 struct socket_info* force_send_socket;
00276
00277
00278 str path_vec;
00279 };
00280
00281
00282
00283
00284
00285
00286 #define FAKED_REPLY ((struct sip_msg *) -1)
00287
00288 extern int via_cnt;
00289
00290 int parse_msg(char* buf, unsigned int len, struct sip_msg* msg);
00291
00292 int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next);
00293
00294 char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr);
00295
00296 void free_sip_msg(struct sip_msg* msg);
00297
00298
00299
00300
00301
00302 int check_transaction_quadruple( struct sip_msg* msg );
00303
00304
00305
00306
00307
00308 inline static int char_msg_val( struct sip_msg *msg, char *cv )
00309 {
00310 str src[8];
00311
00312 if (!check_transaction_quadruple(msg)) {
00313 LM_ERR("can't calculate char_value due to a parsing error\n");
00314 memset( cv, '0', MD5_LEN );
00315 return 0;
00316 }
00317
00318 src[0]= msg->from->body;
00319 src[1]= msg->to->body;
00320 src[2]= msg->callid->body;
00321 src[3]= msg->first_line.u.request.uri;
00322 src[4]= get_cseq( msg )->number;
00323
00324
00325 src[5]= msg->via1->host;
00326 src[6]= msg->via1->port_str;
00327 if (msg->via1->branch) {
00328 src[7]= msg->via1->branch->value;
00329 MD5StringArray ( cv, src, 8 );
00330 } else {
00331 MD5StringArray( cv, src, 7 );
00332 }
00333 return 1;
00334 }
00335
00336
00337
00338
00339 inline static char* get_body(struct sip_msg *msg)
00340 {
00341 int offset;
00342 unsigned int len;
00343
00344 if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
00345 return 0;
00346
00347 if (msg->unparsed){
00348 len=(unsigned int)(msg->unparsed-msg->buf);
00349 }else return 0;
00350 if ((len+2<=msg->len) && (strncmp(CRLF,msg->unparsed,CRLF_LEN)==0) )
00351 offset = CRLF_LEN;
00352 else if ( (len+1<=msg->len) &&
00353 (*(msg->unparsed)=='\n' || *(msg->unparsed)=='\r' ) )
00354 offset = 1;
00355 else
00356 return 0;
00357
00358 return msg->unparsed + offset;
00359 }
00360
00361
00362
00363
00364
00365 int set_dst_uri(struct sip_msg* msg, str* uri);
00366
00367
00368
00369
00370 int set_path_vector(struct sip_msg* msg, str* path);
00371
00372
00373 #endif