Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

msg_translator.c File Reference

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "comp_defs.h"
#include "msg_translator.h"
#include "globals.h"
#include "error.h"
#include "mem/mem.h"
#include "dprint.h"
#include "config.h"
#include "md5utils.h"
#include "data_lump.h"
#include "data_lump_rpl.h"
#include "ip_addr.h"
#include "resolve.h"
#include "ut.h"
#include "pt.h"
#include "cfg/cfg.h"
#include "forward.h"

Go to the source code of this file.

Defines

#define append_str(_dest, _src, _len)
#define append_str_trans(_dest, _src, _len, _msg)   append_str( (_dest), (_src), (_len) );
#define str_print(string, string_len)
#define str_lenpair_print(string, string_len, string2, string2_len)
#define str_pair_print(string, string2, string2_len)   str_lenpair_print((string), strlen((string)), (string2), (string2_len))
#define str_int_print(string, intval)
#define str_su_print(sockaddr)
#define str_ipaddr_print(string, ipaddr_val)
#define get_ip_port_proto
#define RCVCOMP_LUMP_LEN
#define SENDCOMP_LUMP_LEN
#define SUBST_LUMP_LEN(subst_l)
#define RCVCOMP_PARAM_ADD
#define SENDCOMP_PARAM_ADD
#define SUBST_LUMP(subst_l)

Functions

void fix_global_req_flags (str *gname, str *name)
 cfg framework fixup
int check_via_address (struct ip_addr *ip, str *name, unsigned short port, int resolver)
int received_test (struct sip_msg *msg)
char * warning_builder (struct sip_msg *msg, unsigned int *returned_len)
char * received_builder (struct sip_msg *msg, unsigned int *received_len)
char * rport_builder (struct sip_msg *msg, unsigned int *rport_len)
char * id_builder (struct sip_msg *msg, unsigned int *id_len)
char * clen_builder (struct sip_msg *msg, int *clen_len, int diff, int body_only)
int lump_check_opt (enum lump_conditions cond, struct sip_msg *msg, struct dest_info *snd_i)
int lumps_len (struct sip_msg *msg, struct lump *lumps, struct dest_info *send_info)
void process_lumps (struct sip_msg *msg, struct lump *lumps, char *new_buf, unsigned int *new_buf_offs, unsigned int *orig_offs, struct dest_info *send_info)
int adjust_clen (struct sip_msg *msg, int body_delta, int proto)
char * build_req_buf_from_sip_req (struct sip_msg *msg, unsigned int *returned_len, struct dest_info *send_info)
 builds a request in memory from another sip request.
char * build_res_buf_from_sip_res (struct sip_msg *msg, unsigned int *returned_len)
char * build_res_buf_from_sip_req (unsigned int code, char *text, str *new_tag, struct sip_msg *msg, unsigned int *returned_len, struct bookmark *bmark)
int branch_builder (unsigned int hash_index, unsigned int label, char *char_v, int branch, char *branch_str, int *len)
char * via_builder (unsigned int *len, struct dest_info *send_info, str *branch, str *extra_params, struct hostport *hp)
char * create_via_hf (unsigned int *len, struct sip_msg *msg, struct dest_info *send_info, str *branch)
char * build_only_headers (struct sip_msg *msg, int skip_first_line, unsigned int *returned_len, int *error, struct dest_info *send_info)
char * build_body (struct sip_msg *msg, unsigned int *returned_len, int *error, struct dest_info *send_info)
char * build_all (struct sip_msg *msg, int touch_clen, unsigned int *returned_len, int *error, struct dest_info *send_info)

Variables

char version []
int version_len
unsigned int global_req_flags = 0


Define Documentation

#define append_str _dest,
_src,
_len   ) 
 

Value:

do{\
                memcpy( (_dest) , (_src) , (_len) );\
                (_dest) += (_len) ;\
        }while(0);

Definition at line 145 of file msg_translator.c.

#define append_str_trans _dest,
_src,
_len,
_msg   )     append_str( (_dest), (_src), (_len) );
 

Definition at line 151 of file msg_translator.c.

Referenced by build_res_buf_from_sip_req().

#define get_ip_port_proto
 

Value:

if ((snd_i==0) || (snd_i->send_sock==0)){ \
                                LOG(L_CRIT, "ERROR: lump_check_opt: null send socket\n"); \
                                return 1; /* we presume they are different :-) */ \
                        } \
                        if (msg->rcv.bind_address){ \
                                ip=&msg->rcv.bind_address->address; \
                                port=msg->rcv.bind_address->port_no; \
                                proto=msg->rcv.bind_address->proto; \
                        }else{ \
                                ip=&msg->rcv.dst_ip; \
                                port=msg->rcv.dst_port; \
                                proto=msg->rcv.proto; \
                        } \

#define RCVCOMP_LUMP_LEN
 

#define RCVCOMP_PARAM_ADD
 

#define SENDCOMP_LUMP_LEN
 

#define SENDCOMP_PARAM_ADD
 

#define str_int_print string,
intval   ) 
 

Value:

do{\
                        t=int2str((intval), &print_len); \
                        str_pair_print(string, t, print_len);\
                } while(0)

Referenced by warning_builder().

#define str_ipaddr_print string,
ipaddr_val   ) 
 

Value:

do{\
                        t=ip_addr2a((ipaddr_val)); \
                        print_len=strlen(t); \
                        str_pair_print(string, t, print_len);\
                } while(0)

Referenced by warning_builder().

#define str_lenpair_print string,
string_len,
string2,
string2_len   ) 
 

Value:

do{ \
                        str_print(string, string_len); \
                        str_print(string2, string2_len);\
                }while(0)

#define str_pair_print string,
string2,
string2_len   )     str_lenpair_print((string), strlen((string)), (string2), (string2_len))
 

Referenced by warning_builder().

#define str_print string,
string_len   ) 
 

Value:

do{ \
                        l=(string_len); \
                        if ((clen+l)>MAX_WARNING_LEN) \
                                goto error_overflow; \
                        memcpy(buf+clen, (string), l); \
                        clen+=l; \
                }while(0)

Referenced by warning_builder().

#define str_su_print sockaddr   ) 
 

Value:

do{\
                        t=su2a(&sockaddr, sizeof(sockaddr)); \
                        print_len=strlen(t); \
                        str_print(t, print_len); \
                } while(0)

Referenced by warning_builder().

#define SUBST_LUMP subst_l   ) 
 

Referenced by process_lumps().

#define SUBST_LUMP_LEN subst_l   ) 
 

Referenced by lumps_len().


Function Documentation

int adjust_clen struct sip_msg msg,
int  body_delta,
int  proto
[inline, static]
 

Definition at line 1356 of file msg_translator.c.

References anchor_lump(), hdr_field::body, sip_msg::buf, clen_builder(), sip_msg::content_length, del_lump(), get_body(), HDR_CONTENTLENGTH_F, HDR_CONTENTLENGTH_T, insert_new_lump_after(), L_ERR, _str::len, sip_msg::len, LOG, parse_headers(), hdr_field::parsed, pkg_free, PROTO_TCP, PROTO_TLS, _str::s, ser_error, unlikely, and sip_msg::unparsed.

Referenced by build_all(), build_req_buf_from_sip_req(), and build_res_buf_from_sip_res().

int branch_builder unsigned int  hash_index,
unsigned int  label,
char *  char_v,
int  branch,
char *  branch_str,
int len
 

Definition at line 2126 of file msg_translator.c.

References int2reverse_hex(), len, MAX_BRANCH_PARAM_LEN, MCOOKIE, MCOOKIE_LEN, MD5_LEN, and size.

Referenced by forward_request(), and t_calc_branch().

char* build_all struct sip_msg msg,
int  touch_clen,
unsigned int returned_len,
int error,
struct dest_info send_info
 

Definition at line 2479 of file msg_translator.c.

References sip_msg::add_rm, adjust_clen(), sip_msg::body_lumps, buf, sip_msg::buf, L_ERR, len, sip_msg::len, LOG, lumps_len(), pkg_malloc, process_lumps(), and dest_info::proto.

char* build_body struct sip_msg msg,
unsigned int returned_len,
int error,
struct dest_info send_info
 

Definition at line 2428 of file msg_translator.c.

References sip_msg::body_lumps, buf, sip_msg::buf, get_body(), L_ERR, len, sip_msg::len, LOG, lumps_len(), pkg_malloc, and process_lumps().

Referenced by out_msgbody_proc().

char* build_only_headers struct sip_msg msg,
int  skip_first_line,
unsigned int returned_len,
int error,
struct dest_info send_info
 

Definition at line 2376 of file msg_translator.c.

References sip_msg::add_rm, buf, sip_msg::buf, sip_msg::headers, L_ERR, len, LOG, lumps_len(), hdr_field::name, pkg_malloc, process_lumps(), _str::s, and sip_msg::unparsed.

Referenced by out_contacthdr_proc().

char* build_req_buf_from_sip_req struct sip_msg msg,
unsigned int returned_len,
struct dest_info send_info
 

builds a request in memory from another sip request.

Side-effects: - it adds lumps to the msg which are _not_ cleaned. All the added lumps are HDR_VIA_T.

  • it might change send_info->proto and send_info->send_socket if proto fallback is enabled (see below).

Uses also global_req_flags ( OR'ed with msg->msg_flags, see send_info below).

Parameters:
msg - sip message structure, complete with lumps
returned_len - result length (filled in)
send_info - dest_info structure (value/result), contains where the packet will be sent to (it's needed for building a correct via, fill RR lumps a.s.o.). If MTU based protocol fall-back is enabled (see flags below), send_info->proto might be updated with the new protocol. msg->msg_flags used:
  • FL_TCP_MTU_FB, FL_TLS_MTU_FB and FL_SCTP_MTU_FB - fallback to the corresp. proto if the built message > mtu and send_info->proto==PROTO_UDP. It will also update send_info->proto.
  • FL_FORCE_RPORT: add rport to via
Returns:
pointer to the new request (pkg_malloc'ed, needs freeing when done) and sets returned_len or 0 on error.

Definition at line 1512 of file msg_translator.c.

References sip_msg::add_rm, sip_msg::add_to_branch_len, sip_msg::add_to_branch_s, adjust_clen(), anchor_lump(), sip_msg::body_lumps, buf, sip_msg::buf, cfg_get, core_cfg, create_via_hf(), del_lump(), sip_msg::first_line, FL_MTU_FB_MASK, flags, get_send_socket(), via_body::hdr, HDR_VIA_T, via_body::host, insert_new_lump_after(), insert_new_lump_before(), L_ERR, len, sip_msg::len, _str::len, LOG, lumps_len(), sip_msg::msg_flags, sip_msg::new_uri, via_body::params, pkg_free, pkg_malloc, via_body::port, via_body::port_str, process_lumps(), dest_info::proto, PROTO_SCTP, PROTO_TCP, PROTO_TLS, PROTO_UDP, via_body::received, received_builder(), received_test(), msg_start::request, via_body::rport, rport_builder(), _str::s, dest_info::send_sock, ser_error, size, via_param::size, via_param::start, str, dest_info::to, msg_start::u, unlikely, msg_start::uri, sip_msg::via1, and via_len.

Referenced by forward_request(), and print_uac_request().

char* build_res_buf_from_sip_req unsigned int  code,
char *  text,
str new_tag,
struct sip_msg msg,
unsigned int returned_len,
struct bookmark bmark
 

Definition at line 1823 of file msg_translator.c.

References append_str, append_str_trans, hdr_field::body, buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN, CRLF, CRLF_LEN, sip_msg::first_line, lump_rpl::flags, get_to, sip_msg::h_via1, HDR_CALLID_T, HDR_CSEQ_T, HDR_EOH_F, HDR_FROM_T, HDR_RECORDROUTE_T, HDR_TO_T, HDR_VIA_T, sip_msg::headers, int2str(), L_CRIT, L_ERR, L_WARN, _str::len, len, hdr_field::len, LOG, sip_msg::msg_flags, hdr_field::name, hdr_field::next, lump_rpl::next, parse_headers(), hdr_field::parsed, pkg_free, pkg_malloc, received_builder(), received_test(), sip_msg::reply_lump, msg_start::request, via_body::rport, rport_builder(), _str::s, SERVER_HDR, SERVER_HDR_LEN, via_param::size, via_param::start, str, lump_rpl::text, bookmark::to_tag_val, TOTAG_TOKEN, TOTAG_TOKEN_LEN, hdr_field::type, msg_start::u, msg_start::version, sip_msg::via1, and warning_builder().

Referenced by _reply(), relay_reply(), reply_aggregate_auth(), sl_send_reply(), and t_reply_with_body().

char* build_res_buf_from_sip_res struct sip_msg msg,
unsigned int returned_len
 

Definition at line 1753 of file msg_translator.c.

References sip_msg::add_rm, adjust_clen(), hdr_field::body, sip_msg::body_lumps, via_body::bsize, buf, sip_msg::buf, DBG, del_lump(), sip_msg::h_via1, HDR_VIA_T, L_ERR, len, sip_msg::len, hdr_field::len, LOG, lumps_len(), hdr_field::name, via_body::next, pkg_malloc, process_lumps(), via_body::proto, PROTO_UDP, _str::s, sip_msg::via1, sip_msg::via2, and via_len.

Referenced by forward_reply(), and relay_reply().

int check_via_address struct ip_addr ip,
str name,
unsigned short  port,
int  resolver
[static]
 

Definition at line 193 of file msg_translator.c.

References ip_addr::addr, ip_addr::af, DBG, ip_addr2a(), L_CRIT, ip_addr::len, len, _str::len, LOG, rev_resolvehost, _str::s, s, sip_resolvehost, str, and ip_addr::u.

Referenced by received_test().

char* clen_builder struct sip_msg msg,
int clen_len,
int  diff,
int  body_only
 

Definition at line 438 of file msg_translator.c.

References buf, sip_msg::buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN, CRLF, CRLF_LEN, DBG, get_body(), int2str(), L_ERR, len, sip_msg::len, LOG, pkg_malloc, and ser_error.

Referenced by adjust_clen().

char* create_via_hf unsigned int len,
struct sip_msg msg,
struct dest_info send_info,
str branch
 

Definition at line 2312 of file msg_translator.c.

References DBG, id_builder(), L_ERR, _str::len, len, LOG, pkg_free, receive_info::proto, sip_msg::rcv, _str::s, set_hostport, str, and via_builder().

Referenced by build_req_buf_from_sip_req().

void fix_global_req_flags str gname,
str name
 

cfg framework fixup

It should be called from the configuration framework.

Definition at line 165 of file msg_translator.c.

References cfg_get, core_cfg, global_req_flags, PROTO_NONE, PROTO_SCTP, PROTO_TCP, PROTO_TLS, PROTO_UDP, and str.

char* id_builder struct sip_msg msg,
unsigned int id_len
 

Definition at line 407 of file msg_translator.c.

References buf, ID_PARAM, ID_PARAM_LEN, int2reverse_hex(), L_CRIT, L_ERR, len, LOG, pkg_malloc, receive_info::proto_reserved1, sip_msg::rcv, ser_error, and size.

Referenced by build_local(), and create_via_hf().

int lump_check_opt enum lump_conditions  cond,
struct sip_msg msg,
struct dest_info snd_i
[inline, static]
 

Definition at line 489 of file msg_translator.c.

References socket_info::address, ip_addr::af, COND_FALSE, COND_IF_DIFF_AF, COND_IF_DIFF_IP, COND_IF_DIFF_PORT, COND_IF_DIFF_PROTO, COND_IF_DIFF_REALMS, COND_IF_RAND, COND_TRUE, ip_addr_cmp, L_CRIT, LOG, socket_info::port_no, socket_info::proto, rand, sip_msg::rcv, and dest_info::send_sock.

Referenced by lumps_len(), and process_lumps().

int lumps_len struct sip_msg msg,
struct lump lumps,
struct dest_info send_info
[inline, static]
 

Definition at line 558 of file msg_translator.c.

References socket_info::address_str, lump::after, lump::before, L_CRIT, lump::len, _str::len, LOG, LUMP_ADD, LUMP_ADD_OPT, LUMP_ADD_SUBST, lump_check_opt(), LUMP_DEL, LUMP_NOP, lump::next, lump::offset, socket_info::port_no_str, dest_info::send_sock, sip_msg::set_global_address, sip_msg::set_global_port, str, SUBST_LUMP_LEN, and lump::u.

Referenced by build_all(), build_body(), build_only_headers(), build_req_buf_from_sip_req(), and build_res_buf_from_sip_res().

void process_lumps struct sip_msg msg,
struct lump lumps,
char *  new_buf,
unsigned int new_buf_offs,
unsigned int orig_offs,
struct dest_info send_info
[inline, static]
 

Definition at line 871 of file msg_translator.c.

References socket_info::address_str, lump::after, lump::before, sip_msg::buf, DBG, L_CRIT, lump::len, _str::len, LOG, LUMP_ADD, LUMP_ADD_OPT, LUMP_ADD_SUBST, lump_check_opt(), LUMP_DEL, LUMP_NOP, lump::next, lump::offset, socket_info::port_no_str, dest_info::send_sock, sip_msg::set_global_address, sip_msg::set_global_port, size, str, SUBST_LUMP, lump::u, and lump::value.

Referenced by build_all(), build_body(), build_only_headers(), build_req_buf_from_sip_req(), and build_res_buf_from_sip_res().

char* received_builder struct sip_msg msg,
unsigned int received_len
 

Definition at line 350 of file msg_translator.c.

References buf, ip_addr2a(), L_ERR, len, LOG, MAX_RECEIVED_SIZE, pkg_malloc, sip_msg::rcv, RECEIVED, RECEIVED_LEN, ser_error, and receive_info::src_ip.

Referenced by build_req_buf_from_sip_req(), and build_res_buf_from_sip_req().

int received_test struct sip_msg msg  ) 
 

Definition at line 257 of file msg_translator.c.

References check_via_address(), via_body::host, via_body::port, sip_msg::rcv, via_body::received, received_dns, receive_info::src_ip, and sip_msg::via1.

Referenced by build_req_buf_from_sip_req(), build_res_buf_from_sip_req(), nat_uac_test_f(), and testSourceAddress().

char* rport_builder struct sip_msg msg,
unsigned int rport_len
 

Definition at line 381 of file msg_translator.c.

References buf, int2str(), L_ERR, len, LOG, pkg_malloc, sip_msg::rcv, RPORT, RPORT_LEN, ser_error, and receive_info::src_port.

Referenced by build_req_buf_from_sip_req(), and build_res_buf_from_sip_req().

char* via_builder unsigned int len,
struct dest_info send_info,
str branch,
str extra_params,
struct hostport hp
 

Definition at line 2180 of file msg_translator.c.

References socket_info::address, socket_info::address_str, ip_addr::af, COMP_PARAM, COMP_PARAM_LEN, CRLF, CRLF_LEN, hostport::host, L_CRIT, L_ERR, _str::len, len, LOG, MY_BRANCH, MY_BRANCH_LEN, MY_VIA, MY_VIA_LEN, pkg_malloc, hostport::port, socket_info::port_no, socket_info::port_no_str, dest_info::proto, _str::s, dest_info::send_sock, ser_error, str, and via_len.

Referenced by assemble_via(), build_dlg_ack(), build_local(), create_via(), create_via_hf(), http_xmlrpc2sip(), and sip_ping_builder().

char* warning_builder struct sip_msg msg,
unsigned int returned_len
[static]
 

Definition at line 268 of file msg_translator.c.

References receive_info::bind_address, buf, sip_msg::first_line, HDR_EOH_F, L_NOTICE, _str::len, LOG, my_pid(), sip_msg::new_uri, sip_msg::parsed_flag, sip_msg::rcv, msg_start::request, _str::s, receive_info::src_ip, receive_info::src_port, str, str_int_print, str_ipaddr_print, str_pair_print, str_print, str_su_print, socket_info::su, msg_start::u, msg_start::uri, via_cnt, WARNING, WARNING_LEN, WARNING_PHRASE, and WARNING_PHRASE_LEN.

Referenced by build_res_buf_from_sip_req().


Variable Documentation

unsigned int global_req_flags = 0 [static]
 

Definition at line 158 of file msg_translator.c.

Referenced by fix_global_req_flags().

char version[]
 

Referenced by check_ruri_sip_version(), ld_con_connect(), main(), sel_cert_version(), sel_version(), and sercmd_ver().

int version_len
 


Generated on Thu Jul 29 04:16:05 2010 for SIPExpressRouter by  doxygen 1.3.9.1