[asterisk-commits] oej: branch oej/pinepacketrequest r217151 - /team/oej/pinepacketrequest/chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 8 14:23:49 CDT 2009


Author: oej
Date: Tue Sep  8 14:23:46 2009
New Revision: 217151

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=217151
Log:
Implementing a new string in each sip_message (old sip_request and sip_pkt) for the parsed data.

The benefits of this are
- we don't have to run copy_request and allocate temporary requests in a lot of places
- we still have the unparsed data available, which means that we can code very clever
  filters for SIP debug messages, since we can print them after we've matched them to a peer,
  or just every message in a dialog. Wow! But that part belongs in another patch
- codewise we have just one message structure for ALL sip messages - outbound and inbound

This is a rather massive patch, but a huge simplification.

Still need to fix the ->next and ->nextpacket uglyness, but this branch can actually be
operative. At least with two phones :-)

Modified:
    team/oej/pinepacketrequest/channels/chan_sip.c

Modified: team/oej/pinepacketrequest/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/oej/pinepacketrequest/channels/chan_sip.c?view=diff&rev=217151&r1=217150&r2=217151
==============================================================================
--- team/oej/pinepacketrequest/channels/chan_sip.c (original)
+++ team/oej/pinepacketrequest/channels/chan_sip.c Tue Sep  8 14:23:46 2009
@@ -1,3 +1,7 @@
+/* TESTING
+ 	- With TCP
+*/
+
 /*
  * Asterisk -- An open source telephony toolkit.
  *
@@ -147,16 +151,16 @@
  * \par Other bugs to fix ----
  * __set_address_from_contact(const char *fullcontact, struct sockaddr_in *sin, int tcp)
  *	- sets TLS port as default for all TCP connections, unless other port is given in contact.
- * parse_register_contact(struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req)
+ * parse_register_contact(struct sip_pvt *pvt, struct sip_peer *peer, struct sip_message *req)
  *	- assumes that the contact the UA registers is using the same transport as the REGISTER request, which is
  *	  a bad guess.
  *      - Does not save any information about TCP/TLS connected devices, which is a severe BUG, as discussed on the mailing list.
- * get_destination(struct sip_pvt *p, struct sip_request *oreq)
+ * get_destination(struct sip_pvt *p, struct sip_message *oreq)
  *	- Doesn't store the information that we got an incoming SIPS request in the channel, so that
  *	  we can require a secure signalling path OUT of Asterisk (on SIP or IAX2). Possibly, the call should
  *	  fail on in-secure signalling paths if there's no override in our configuration. At least, provide a
  *	  channel variable in the dialplan.
- * get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req)
+ * get_refer_info(struct sip_pvt *transferer, struct sip_message *outgoing_req)
  *	- As above, if we have a SIPS: uri in the refer-to header
  * 	- Does not check transport in refer_to uri.
  */
@@ -1307,7 +1311,7 @@
 	struct ast_tcptls_session_instance *tcptls_session;	/* If tcp or tls, a socket manager */
 };
 
-/*! \brief sip_request: The data grabbed from the UDP socket
+/*! \brief sip_message: An incoming or outbound SIP message (reply or request)
  *
  * \verbatim
  * Incoming messages: we first store the data from the socket in data[],
@@ -1330,61 +1334,68 @@
  * The \r\n at the end of the line are still there, so the get_header()
  * and similar functions don't work on these packets.
  * \endverbatim
- */
-struct sip_request {
-	ptrdiff_t rlPart1;         /*!< Offset of the SIP Method Name or "SIP/2.0" protocol version */
-	ptrdiff_t rlPart2;         /*!< Offset of the Request URI or Response Status */
-	int len;                /*!< bytes used in data[], excluding trailing null terminator. Rarely used. */
-	int headers;            /*!< # of SIP Headers */
-	int method;             /*!< Method of this request */
-	int lines;              /*!< Body Content */
-	unsigned int sdp_start; /*!< the line number where the SDP begins */
-	unsigned int sdp_end;   /*!< the line number where the SDP ends */
-	char debug;		/*!< print extra debugging if non zero */
-	char has_to_tag;	/*!< non-zero if packet has To: tag */
-	char ignore;		/*!< if non-zero This is a re-transmit, ignore it */
-	ptrdiff_t header[SIP_MAX_HEADERS]; /*!< Array of offsets into the request string of each SIP header*/
-	ptrdiff_t line[SIP_MAX_LINES]; /*!< Array of offsets into the request string of each SDP line*/
-	struct ast_str *data;	
-	/* XXX Do we need to unref socket.ser when the request goes away? */
-	struct sip_socket socket;	/*!< The socket used for this request */
-	AST_LIST_ENTRY(sip_request) next;
-	/* Fields copied from sip_pkt */
-	int retrans;		/*!< Retransmission number */
-	int seqno;		/*!< Sequence number */
-	unsigned int is_resp:1;			/*!< 1 if this is a response packet (e.g. 200 OK), 0 if it is a request */
-	unsigned int is_fatal:1;				/*!< non-zero if there is a fatal error */
-	unsigned int response_code;		/*!< If this is a response, the response code */
-	struct sip_pvt *owner;			/*!< Owner AST call */
-	int retransid;				/*!< Retransmission ID */
-	int timer_a;				/*!< SIP timer A, retransmission timer */
-	int timer_t1;				/*!< SIP Timer T1, estimated RTT or 500 ms */
-	int packetlen;				/*!< Length of packet */
-	struct sip_request *nextpacket;		/*!< STUPID STUPID STUPID */
-};
-
-/*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission
+ *
+ * THis structure is merged with the old sip_pk that was documented like this:
+ * sip packet - raw format for outbound packets that are sent or scheduled for transmission
  * Packets are linked in a list, whose head is in the struct sip_pvt they belong to.
  * Each packet holds a reference to the parent struct sip_pvt.
  * This structure is allocated in __sip_reliable_xmit() and only for packets that
  * require retransmissions.
  */
 
-
-/* \brief given a sip_request and an offset, return the char * that resides there
+struct sip_message {
+	/* For both incoming messages and outbound messages */
+	unsigned int outbound;		/*!< TRUE if this packet is outbound, FALSE if it's read from the wire */
+	int len;                	/*!< bytes used in data[], excluding trailing null terminator. Rarely used. */
+	int method;             /*!< Method of this request */
+	unsigned int is_resp:1;			/*!< 1 if this is a response packet (e.g. 200 OK), 0 if it is a request */
+	unsigned int is_parsed:1;			/*!< 1 if this is a response packet (e.g. 200 OK), 0 if it is a request */
+	unsigned int response_code;		/*!< If this is a response, the response code */
+	int seqno;				/*!< Our Sequence number */
+
+	/*------ For parsing */
+	ptrdiff_t rlPart1;         		/*!< Offset of the SIP Method Name or "SIP/2.0" protocol version */
+	ptrdiff_t rlPart2;      		/*!< Offset of the Request URI or Response Status */
+	int headers;            		/*!< # of SIP Headers */
+	int lines;              		/*!< Body Content */
+	unsigned int sdp_start;			/*!< the line number where the SDP begins */
+	unsigned int sdp_end;   		/*!< the line number where the SDP ends */
+	char debug;				/*!< print extra debugging if non zero */
+	unsigned int has_to_tag:1;		/*!< non-zero if packet has To: tag */
+	unsigned int ignore:1;			/*!< if non-zero This is a re-transmit, ignore it */
+	ptrdiff_t header[SIP_MAX_HEADERS]; 	/*!< Array of offsets into the request string of each SIP header*/
+	ptrdiff_t line[SIP_MAX_LINES]; 		/*!< Array of offsets into the request string of each SDP line*/
+	/* XXX Do we need to unref socket.ser when the request goes away? */
+	struct sip_socket socket;		/*!< The socket used for this request */
+	AST_LIST_ENTRY(sip_message) next;
+	/* ------------------------    Fields copied from sip_pkt */
+	/* Outbound messages only */
+	int retrans;				/*!< Retransmission number */
+	int retransid;				/*!< Retransmission ID (sched) */
+	unsigned int is_fatal:1;		/*!< non-zero if this message can cause a fatal error if we don't get a reply */
+	struct sip_pvt *owner;			/*!< Owner AST call */
+	int timer_a;				/*!< SIP timer A, retransmission timer */
+	int timer_t1;				/*!< SIP Timer T1, estimated RTT or 500 ms */
+	struct sip_message *nextpacket;		/*!< STUPID STUPID STUPID and well STUPID */
+	/* ----------------------- Data */
+	struct ast_str *data;			/*!< The actual raw data */
+	struct ast_str *parsedata;		/*!< The parsed data */
+};
+
+/* \brief given a sip_message and an offset, return the char * that resides there
  *
  * It used to be that rlPart1, rlPart2, and the header and line arrays were character
- * pointers. They are now offsets into the ast_str portion of the sip_request structure.
+ * pointers. They are now offsets into the ast_str portion of the sip_message structure.
  * To avoid adding a bunch of redundant pointer arithmetic to the code, this macro is
  * provided to retrieve the string at a particular offset within the request's buffer
  */
-#define REQ_OFFSET_TO_STR(req,offset) (ast_str_buffer((req)->data) + ((req)->offset))
+#define REQ_OFFSET_TO_STR(req,offset) (ast_str_buffer((req)->parsedata) + ((req)->offset))
 
 /*! \brief structure used in transfers */
 struct sip_dual {
 	struct ast_channel *chan1;	/*!< First channel involved */
 	struct ast_channel *chan2;	/*!< Second channel involved */
-	struct sip_request req;		/*!< Request that caused the transfer (REFER) */
+	struct sip_message req;		/*!< Request that caused the transfer (REFER) */
 	int seqno;			/*!< Sequence number */
 };
 
@@ -1816,7 +1827,7 @@
 	int glareinvite;			/*!< A invite received while a pending invite is already present is stored here.  Its seqno is the
 						value. Since this glare invite's seqno is not the same as the pending invite's, it must be
 						held in order to properly process acknowledgements for our 491 response. */
-	struct sip_request initreq;		/*!< Latest request that opened a new transaction
+	struct sip_message initreq;		/*!< Latest request that opened a new transaction
 							within this dialog.
 							NOT the request that opened the dialog */
 
@@ -1838,11 +1849,11 @@
 	struct ast_rtp_instance *rtp;		/*!< RTP Session */
 	struct ast_rtp_instance *vrtp;		/*!< Video RTP session */
 	struct ast_rtp_instance *trtp;		/*!< Text RTP session */
-	struct sip_request *packets;		/*!< Packets scheduled for re-transmission */
+	struct sip_message *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	size_t history_entries;			/*!< Number of entires in the history */
 	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
-	AST_LIST_HEAD_NOLOCK(request_queue, sip_request) request_queue; /*!< Requests that arrived but could not be processed immediately */
+	AST_LIST_HEAD_NOLOCK(request_queue, sip_message) request_queue; /*!< Requests that arrived but could not be processed immediately */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
 	struct sip_st_dlg *stimer;		/*!< SIP Session-Timers */
 
@@ -2381,7 +2392,7 @@
 static int sip_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
 static const char *sip_get_callid(struct ast_channel *chan);
 
-static int handle_request_do(struct sip_request *req, struct sockaddr_in *sin);
+static int handle_request_do(struct sip_message *req, struct sockaddr_in *sin);
 static int sip_standard_port(enum sip_transport type, int port);
 static int sip_prepare_socket(struct sip_pvt *p);
 static int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport);
@@ -2390,18 +2401,18 @@
 static int sipsock_read(int *id, int fd, short events, void *ignore);
 static int __sip_xmit(struct sip_pvt *p, struct ast_str *data, int len);
 static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod);
-static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
+static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_message *req, enum xmittype reliable);
 static int retrans_pkt(const void *data);
-static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg);
-static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req);
-static int transmit_response_reliable(struct sip_pvt *p, const char *msg, const struct sip_request *req);
-static int transmit_response_with_date(struct sip_pvt *p, const char *msg, const struct sip_request *req);
-static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid);
-static int transmit_response_with_unsupported(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported);
-static int transmit_response_with_auth(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *rand, enum xmittype reliable, const char *header, int stale);
-static int transmit_provisional_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp);
-static int transmit_response_with_allow(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
-static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable);
+static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_message *req, const char *msg);
+static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_message *req);
+static int transmit_response_reliable(struct sip_pvt *p, const char *msg, const struct sip_message *req);
+static int transmit_response_with_date(struct sip_pvt *p, const char *msg, const struct sip_message *req);
+static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_message *req, enum xmittype reliable, int oldsdp, int rpid);
+static int transmit_response_with_unsupported(struct sip_pvt *p, const char *msg, const struct sip_message *req, const char *unsupported);
+static int transmit_response_with_auth(struct sip_pvt *p, const char *msg, const struct sip_message *req, const char *rand, enum xmittype reliable, const char *header, int stale);
+static int transmit_provisional_response(struct sip_pvt *p, const char *msg, const struct sip_message *req, int with_sdp);
+static int transmit_response_with_allow(struct sip_pvt *p, const char *msg, const struct sip_message *req, enum xmittype reliable);
+static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_message *req, enum xmittype reliable);
 static int transmit_request(struct sip_pvt *p, int sipmethod, int inc, enum xmittype reliable, int newbranch);
 static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
 static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init);
@@ -2414,16 +2425,16 @@
 static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);
 static int transmit_notify_custom(struct sip_pvt *p, struct ast_variable *vars);
 static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
-static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
-static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
-static void copy_request(struct sip_request *dst, const struct sip_request *src);
-static void receive_message(struct sip_pvt *p, struct sip_request *req);
-static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward);
+static int send_response(struct sip_pvt *p, struct sip_message *req, enum xmittype reliable, int seqno);
+static int send_request(struct sip_pvt *p, struct sip_message *req, enum xmittype reliable, int seqno);
+static void copy_request(struct sip_message *dst, const struct sip_message *src);
+static void receive_message(struct sip_pvt *p, struct sip_message *req);
+static void parse_moved_contact(struct sip_pvt *p, struct sip_message *req, char **name, char **number, int set_call_forward);
 static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only);
 
 /*--- Dialog management */
 static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
-				 int useglobal_nat, const int intended_method, struct sip_request *req);
+				 int useglobal_nat, const int intended_method, struct sip_message *req);
 static int __sip_autodestruct(const void *data);
 static void sip_scheddestroy(struct sip_pvt *p, int ms);
 static int sip_cancel_destroy(struct sip_pvt *p);
@@ -2438,45 +2449,45 @@
 static int update_call_counter(struct sip_pvt *fup, int event);
 static int hangup_sip2cause(int cause);
 static const char *hangup_cause2sip(int cause);
-static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method);
+static struct sip_pvt *find_call(struct sip_message *req, struct sockaddr_in *sin, const int intended_method);
 static void free_old_route(struct sip_route *route);
 static void list_route(struct sip_route *route);
-static void build_route(struct sip_pvt *p, struct sip_request *req, int backwards);
+static void build_route(struct sip_pvt *p, struct sip_message *req, int backwards);
 static enum check_auth_result register_verify(struct sip_pvt *p, struct sockaddr_in *sin,
-					      struct sip_request *req, const char *uri);
+					      struct sip_message *req, const char *uri);
 static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *totag, const char *fromtag);
 static void check_pendings(struct sip_pvt *p);
 static void *sip_park_thread(void *stuff);
-static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno);
+static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_message *req, int seqno);
 static int sip_sipredirect(struct sip_pvt *p, const char *dest);
 static int is_method_allowed(unsigned int *allowed_methods, enum sipmethod method);
 
 /*--- Codec handling / SDP */
 static void try_suggested_sip_codec(struct sip_pvt *p);
-static const char* get_sdp_iterate(int* start, struct sip_request *req, const char *name);
-static const char *get_sdp(struct sip_request *req, const char *name);
-static int find_sdp(struct sip_request *req);
-static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action);
+static const char* get_sdp_iterate(int* start, struct sip_message *req, const char *name);
+static const char *get_sdp(struct sip_message *req, const char *name);
+static int find_sdp(struct sip_message *req);
+static int process_sdp(struct sip_pvt *p, struct sip_message *req, int t38action);
 static void add_codec_to_sdp(const struct sip_pvt *p, int codec,
 			     struct ast_str **m_buf, struct ast_str **a_buf,
 			     int debug, int *min_packet_size);
 static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
 				struct ast_str **m_buf, struct ast_str **a_buf,
 				int debug);
-static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38);
+static enum sip_result add_sdp(struct sip_message *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38);
 static void do_setnat(struct sip_pvt *p);
 static void stop_media_flows(struct sip_pvt *p);
 
 /*--- Authentication stuff */
-static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len);
+static int reply_digest(struct sip_pvt *p, struct sip_message *req, char *header, int sipmethod, char *digest, int digest_len);
 static int build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
-static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
+static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_message *req, const char *username,
 					 const char *secret, const char *md5secret, int sipmethod,
 					 const char *uri, enum xmittype reliable, int ignore);
-static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_request *req,
+static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_message *req,
 					      int sipmethod, const char *uri, enum xmittype reliable,
 					      struct sockaddr_in *sin, struct sip_peer **authpeer);
-static int check_user(struct sip_pvt *p, struct sip_request *req, int sipmethod, const char *uri, enum xmittype reliable, struct sockaddr_in *sin);
+static int check_user(struct sip_pvt *p, struct sip_message *req, int sipmethod, const char *uri, enum xmittype reliable, struct sockaddr_in *sin);
 
 /*--- Domain handling */
 static int check_sip_domain(const char *domain, char *context, size_t len); /* Check if domain is one of our local domains */
@@ -2581,7 +2592,7 @@
 static void register_peer_exten(struct sip_peer *peer, int onoff);
 static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime, int forcenamematch, int devstate_only, int transport);
 static int sip_poke_peer_s(const void *data);
-static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req);
+static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_message *req);
 static void reg_source_db(struct sip_peer *peer);
 static void destroy_association(struct sip_peer *peer);
 static void set_insecure_flags(struct ast_flags *flags, const char *value, int lineno);
@@ -2608,54 +2619,53 @@
 static int sip_reinvite_retry(const void *data);
 
 /*--- Parsing SIP requests and responses */
-static void append_date(struct sip_request *req);	/* Append date to SIP packet */
-static int determine_firstline_parts(struct sip_request *req);
+static void append_date(struct sip_message *req);	/* Append date to SIP packet */
+static int determine_firstline_parts(struct sip_message *req);
 static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
-static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
+static const char *gettag(const struct sip_message *req, const char *header, char *tagbuf, int tagbufsize);
 static int find_sip_method(const char *msg);
 static unsigned int parse_sip_options(struct sip_pvt *pvt, const char *supported);
-static unsigned int parse_allowed_methods(struct sip_request *req);
-static unsigned int set_pvt_allowed_methods(struct sip_pvt *pvt, struct sip_request *req);
-static int parse_request(struct sip_request *req);
-static const char *get_header(const struct sip_request *req, const char *name);
+static unsigned int parse_allowed_methods(struct sip_message *req);
+static unsigned int set_pvt_allowed_methods(struct sip_pvt *pvt, struct sip_message *req);
+static int parse_request(struct sip_message *req);
+static const char *get_header(const struct sip_message *req, const char *name);
 static const char *referstatus2str(enum referstatus rstatus) attribute_pure;
 static int method_match(enum sipmethod id, const char *name);
-static void parse_copy(struct sip_request *dst, const struct sip_request *src);
 static char *get_in_brackets(char *tmp);
 static const char *find_alias(const char *name, const char *_default);
-static const char *__get_header(const struct sip_request *req, const char *name, int *start);
+static const char *__get_header(const struct sip_message *req, const char *name, int *start);
 static int lws2sws(char *msgbuf, int len);
-static void extract_uri(struct sip_pvt *p, struct sip_request *req);
+static void extract_uri(struct sip_pvt *p, struct sip_message *req);
 static char *remove_uri_parameters(char *uri);
-static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req);
-static int get_also_info(struct sip_pvt *p, struct sip_request *oreq);
-static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req);
+static int get_refer_info(struct sip_pvt *transferer, struct sip_message *outgoing_req);
+static int get_also_info(struct sip_pvt *p, struct sip_message *oreq);
+static int parse_ok_contact(struct sip_pvt *pvt, struct sip_message *req);
 static int set_address_from_contact(struct sip_pvt *pvt);
-static void check_via(struct sip_pvt *p, struct sip_request *req);
+static void check_via(struct sip_pvt *p, struct sip_message *req);
 static char *get_calleridname(const char *input, char *output, size_t outputsize);
-static int get_rpid(struct sip_pvt *p, struct sip_request *oreq);
-static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason);
-static int get_destination(struct sip_pvt *p, struct sip_request *oreq);
-static int get_msg_text(char *buf, int len, struct sip_request *req, int addnewline);
+static int get_rpid(struct sip_pvt *p, struct sip_message *oreq);
+static int get_rdnis(struct sip_pvt *p, struct sip_message *oreq, char **name, char **number, int *reason);
+static int get_destination(struct sip_pvt *p, struct sip_message *oreq);
+static int get_msg_text(char *buf, int len, struct sip_message *req, int addnewline);
 static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout);
 static void update_connectedline(struct sip_pvt *p, const void *data, size_t datalen);
 static void update_redirecting(struct sip_pvt *p, const void *data, size_t datalen);
-static void change_redirecting_information(struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, int set_call_forward);
+static void change_redirecting_information(struct sip_pvt *p, struct sip_message *req, struct ast_party_redirecting *redirecting, int set_call_forward);
 static int get_domain(const char *str, char *domain, int len);
-static void get_realm(struct sip_pvt *p, const struct sip_request *req);
+static void get_realm(struct sip_pvt *p, const struct sip_message *req);
 
 /*-- TCP connection handling ---*/
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session);
 static void *sip_tcp_worker_fn(void *);
 
 /*--- Constructing requests and responses */
-static void initialize_initreq(struct sip_pvt *p, struct sip_request *req);
-static int init_req(struct sip_request *req, int sipmethod, const char *recip);
-static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch);
-static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod);
-static int init_resp(struct sip_request *resp, const char *msg);
+static void initialize_initreq(struct sip_pvt *p, struct sip_message *req);
+static int init_req(struct sip_message *req, int sipmethod, const char *recip);
+static int reqprep(struct sip_message *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch);
+static void initreqprep(struct sip_message *req, struct sip_pvt *p, int sipmethod);
+static int init_resp(struct sip_message *resp, const char *msg);
 static inline int resp_needs_contact(const char *msg, enum sipmethod method);
-static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req);
+static int respprep(struct sip_message *resp, struct sip_pvt *p, const char *msg, const struct sip_message *req);
 static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
 static void build_via(struct sip_pvt *p);
 static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
@@ -2664,53 +2674,53 @@
 static void build_callid_pvt(struct sip_pvt *pvt);
 static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
 static void make_our_tag(char *tagbuf, size_t len);
-static int add_header(struct sip_request *req, const char *var, const char *value);
-static int add_header_contentLength(struct sip_request *req, int len);
-static int add_line(struct sip_request *req, const char *line);
-static int add_text(struct sip_request *req, const char *text);
-static int add_digit(struct sip_request *req, char digit, unsigned int duration, int mode);
-static int add_rpid(struct sip_request *req, struct sip_pvt *p);
-static int add_vidupdate(struct sip_request *req);
-static void add_route(struct sip_request *req, struct sip_route *route);
-static int copy_header(struct sip_request *req, const struct sip_request *orig, const char *field);
-static int copy_all_header(struct sip_request *req, const struct sip_request *orig, const char *field);
-static int copy_via_headers(struct sip_pvt *p, struct sip_request *req, const struct sip_request *orig, const char *field);
+static int add_header(struct sip_message *req, const char *var, const char *value);
+static int add_header_contentLength(struct sip_message *req, int len);
+static int add_line(struct sip_message *req, const char *line);
+static int add_text(struct sip_message *req, const char *text);
+static int add_digit(struct sip_message *req, char digit, unsigned int duration, int mode);
+static int add_rpid(struct sip_message *req, struct sip_pvt *p);
+static int add_vidupdate(struct sip_message *req);
+static void add_route(struct sip_message *req, struct sip_route *route);
+static int copy_header(struct sip_message *req, const struct sip_message *orig, const char *field);
+static int copy_all_header(struct sip_message *req, const struct sip_message *orig, const char *field);
+static int copy_via_headers(struct sip_pvt *p, struct sip_message *req, const struct sip_message *orig, const char *field);
 static void set_destination(struct sip_pvt *p, char *uri);
-static void append_date(struct sip_request *req);
+static void append_date(struct sip_message *req);
 static void build_contact(struct sip_pvt *p);
 
 /*------Request handling functions */
-static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock);
-static int handle_request_update(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, const char *e, int *nounlock);
-static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, int *nounlock);
-static int handle_request_bye(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_register(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, const char *e);
-static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_message(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e);
-static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_options(struct sip_pvt *p, struct sip_request *req);
-static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin);
-static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e);
-static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno);
+static int handle_incoming(struct sip_pvt *p, struct sip_message *req, struct sockaddr_in *sin, int *recount, int *nounlock);
+static int handle_request_update(struct sip_pvt *p, struct sip_message *req);
+static int handle_request_invite(struct sip_pvt *p, struct sip_message *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, const char *e, int *nounlock);
+static int handle_request_refer(struct sip_pvt *p, struct sip_message *req, int debug, int seqno, int *nounlock);
+static int handle_request_bye(struct sip_pvt *p, struct sip_message *req);
+static int handle_request_register(struct sip_pvt *p, struct sip_message *req, struct sockaddr_in *sin, const char *e);
+static int handle_request_cancel(struct sip_pvt *p, struct sip_message *req);
+static int handle_request_message(struct sip_pvt *p, struct sip_message *req);
+static int handle_request_subscribe(struct sip_pvt *p, struct sip_message *req, struct sockaddr_in *sin, int seqno, const char *e);
+static void handle_request_info(struct sip_pvt *p, struct sip_message *req);
+static int handle_request_options(struct sip_pvt *p, struct sip_message *req);
+static int handle_invite_replaces(struct sip_pvt *p, struct sip_message *req, int debug, int seqno, struct sockaddr_in *sin);
+static int handle_request_notify(struct sip_pvt *p, struct sip_message *req, struct sockaddr_in *sin, int seqno, const char *e);
+static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_message *req, int seqno);
 
 /*------Response handling functions */
-static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
-static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
-static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
-static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
-static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
-static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
+static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
+static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
+static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
+static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
+static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
+static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_message *req, int seqno);
 
 /*------ T38 Support --------- */
-static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans);
+static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_message *req, int retrans);
 static struct ast_udptl *sip_get_udptl_peer(struct ast_channel *chan);
 static int sip_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
 static void change_t38_state(struct sip_pvt *p, int state);
 
 /*------ Session-Timers functions --------- */
-static void proc_422_rsp(struct sip_pvt *p, struct sip_request *rsp);
+static void proc_422_rsp(struct sip_pvt *p, struct sip_message *rsp);
 static int  proc_session_timer(const void *vp);
 static void stop_session_timer(struct sip_pvt *p);
 static void start_session_timer(struct sip_pvt *p);
@@ -2894,7 +2904,7 @@
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session)
 {
 	int res, cl;
-	struct sip_request req = { 0, } , reqcpy = { 0, };
+	struct sip_message req = { 0, };
 	struct sip_threadinfo *me;
 	char buf[1024] = "";
 
@@ -2918,8 +2928,6 @@
 
 	if (!(req.data = ast_str_create(SIP_MIN_PACKET)))
 		goto cleanup;
-	if (!(reqcpy.data = ast_str_create(SIP_MIN_PACKET)))
-		goto cleanup;
 
 	for (;;) {
 		struct ast_str *str_save;
@@ -2928,11 +2936,6 @@
 		memset(&req, 0, sizeof(req));
 		req.data = str_save;
 		ast_str_reset(req.data);
-
-		str_save = reqcpy.data;
-		memset(&reqcpy, 0, sizeof(reqcpy));
-		reqcpy.data = str_save;
-		ast_str_reset(reqcpy.data);
 
 		memset(buf, 0, sizeof(buf));
 
@@ -2963,10 +2966,9 @@
 			ast_str_append(&req.data, 0, "%s", buf);
 			req.len = req.data->used;
 		}
-		copy_request(&reqcpy, &req);
-		parse_request(&reqcpy);
+		parse_request(&req);
 		/* In order to know how much to read, we need the content-length header */
-		if (sscanf(get_header(&reqcpy, "Content-Length"), "%30d", &cl)) {
+		if (sscanf(get_header(&req, "Content-Length"), "%30d", &cl)) {
 			while (cl > 0) {
 				ast_mutex_lock(&tcptls_session->lock);
 				if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, tcptls_session->f)) {
@@ -2997,9 +2999,6 @@
 	fclose(tcptls_session->f);
 	tcptls_session->f = NULL;
 	tcptls_session->fd = -1;
-	if (reqcpy.data) {
-		ast_free(reqcpy.data);
-	}
 
 	if (req.data) {
 		ast_free(req.data);
@@ -3068,7 +3067,7 @@
  */
 static void *dialog_unlink_all(struct sip_pvt *dialog, int lockowner, int lockdialoglist)
 {
-	struct sip_request *cp;
+	struct sip_message *cp;
 
 	dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
 
@@ -3171,7 +3170,7 @@
 /*! \brief Initialize the initital request packet in the pvt structure.
  	This packet is used for creating replies and future requests in
 	a dialog */
-static void initialize_initreq(struct sip_pvt *p, struct sip_request *req)
+static void initialize_initreq(struct sip_pvt *p, struct sip_message *req)
 {
 	if (p->initreq.headers)
 		ast_debug(1, "Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->callid);
@@ -3645,7 +3644,7 @@
 /*! \brief Retransmit SIP message if no answer (Called from scheduler) */
 static int retrans_pkt(const void *data)
 {
-	struct sip_request *pkt = (struct sip_request *)data, *prev, *cur = NULL;
+	struct sip_message *pkt = (struct sip_message *)data, *prev, *cur = NULL;
 	int reschedule = DEFAULT_RETRANS;
 	int xmitres = 0;
 	
@@ -3686,7 +3685,7 @@
 		}
 
 		append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data->str);
-		xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
+		xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->len);
 		sip_pvt_unlock(pkt->owner);
 		if (xmitres == XMIT_ERROR)
 			ast_log(LOG_WARNING, "Network error on retransmit in dialog %s\n", pkt->owner->callid);
@@ -3771,7 +3770,7 @@
 */
 static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod)
 {
-	struct sip_request *pkt = NULL;
+	struct sip_message *pkt = NULL;
 	int siptimer_a = DEFAULT_RETRANS;
 	int xmitres = 0;
 	int respid;
@@ -3802,7 +3801,7 @@
 		return AST_FAILURE;
 	}
 	ast_str_set(&pkt->data, 0, "%s%s", data->str, "\0");
-	pkt->packetlen = len;
+	pkt->len = len;
 	/* copy other parameters from the caller */
 	pkt->method = sipmethod;
 	pkt->seqno = seqno;
@@ -3827,7 +3826,7 @@
 	if (sipdebug)
 		ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id  #%d\n", pkt->retransid);
 
-	xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen);	/* Send packet */
+	xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->len);	/* Send packet */
 
 	if (xmitres == XMIT_ERROR) {	/* Serious network trouble, no need to try again */
 		append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
@@ -3954,7 +3953,7 @@
  * called with p locked*/
 static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
 {
-	struct sip_request *cur, *prev = NULL;
+	struct sip_message *cur, *prev = NULL;
 	const char *msg = "Not Found";	/* used only for debugging */

[... 1486 lines stripped ...]



More information about the asterisk-commits mailing list