[asterisk-commits] oej: branch oej/codename-pineapple r45644 - in /team/oej/codename-pineapple/c...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 18 23:44:06 MST 2006


Author: oej
Date: Thu Oct 19 01:44:05 2006
New Revision: 45644

URL: http://svn.digium.com/view/asterisk?rev=45644&view=rev
Log:
Moving more functions out of the chan_sip3.c source code file

Modified:
    team/oej/codename-pineapple/channels/Makefile
    team/oej/codename-pineapple/channels/chan_sip3.c
    team/oej/codename-pineapple/channels/sip3/Makefile
    team/oej/codename-pineapple/channels/sip3/sip3.h
    team/oej/codename-pineapple/channels/sip3/sip3_auth.c
    team/oej/codename-pineapple/channels/sip3/sip3_sdprtp.c
    team/oej/codename-pineapple/channels/sip3/sip3core.h
    team/oej/codename-pineapple/channels/sip3/sip3funcs.h

Modified: team/oej/codename-pineapple/channels/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/Makefile?rev=45644&r1=45643&r2=45644&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/Makefile (original)
+++ team/oej/codename-pineapple/channels/Makefile Thu Oct 19 01:44:05 2006
@@ -14,7 +14,7 @@
 C_MODS:=$(filter-out $(MENUSELECT_CHANNELS),$(patsubst %.c,%,$(wildcard chan_*.c)))
 CC_MODS:=$(filter-out $(MENUSELECT_CHANNELS),$(patsubst %.cc,%,$(wildcard chan_*.cc)))
 SIP3_MODULES=chan_sip3.o sip3/sip3_network.o sip3/sip3_subscribe.o sip3/sip3_refer.o sip3/sip3_domain.o \
-	sip3/sip3_callerid.o sip3/sip3_auth.o sip3/sip3_sdprtp.c
+	sip3/sip3_callerid.o sip3/sip3_auth.o sip3/sip3_sdprtp.o sip3/sip3_config.o
 
 ifeq ($(OSARCH),OpenBSD)
   PTLIB=-lpt_OpenBSD_x86_r

Modified: team/oej/codename-pineapple/channels/chan_sip3.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/chan_sip3.c?rev=45644&r1=45643&r2=45644&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Thu Oct 19 01:44:05 2006
@@ -207,24 +207,13 @@
 
 
 /*! \brief various expiry times for registrations */
-static struct expiry_times expiry = {
+struct expiry_times expiry = {
 	.min_expiry = DEFAULT_MIN_EXPIRY,        /*!< Minimum accepted registration time */
 	.max_expiry = DEFAULT_MAX_EXPIRY,        /*!< Maximum accepted registration time */
 	.default_expiry = DEFAULT_DEFAULT_EXPIRY,
 	.expiry = DEFAULT_EXPIRY,		/*!< Is this ever used ??? */
 };
 
-/*! \brief Global jitterbuffer configuration - by default, jb is disabled */
-static struct ast_jb_conf default_jbconf =
-{
-        .flags = 0,
-	.max_size = -1,
-	.resync_threshold = -1,
-	.impl = ""
-};
-
-static const char config[] = "sip3.conf";
-static const char notify_config[] = "sip3_notify.conf";
 static int usecnt = 0;
 
 /* Default setttings are used as a channel setting and as a default when
@@ -233,7 +222,7 @@
 struct sip_globals global;
 
 /* Object counters */
-static struct channel_counters sipcounters = { 0, 0, 0, 0, 0, 0 };
+struct channel_counters sipcounters = { 0, 0, 0, 0, 0, 0 };
 
 /*! \brief Protect the SIP dialog list (of sip_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
@@ -261,31 +250,21 @@
 /* --- Linked lists of various objects --------*/
 
 /*! \brief List of concurrent SIP dialogs */
-static struct sip_pvt *iflist = NULL;
+static struct sip_pvt *dialoglist = NULL;
 
 /*! \brief The user list: Users and friends */
-static struct ast_user_list {
-	ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
-} userl;
+struct sip_user_list userl;
 
 /*! \brief The peer list: Peers and Friends */
-static struct ast_peer_list {
-	ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
-} peerl;
+struct sip_device_list peerl;
 
 /*! \brief  The register list: Other SIP proxys we register with and place calls to */
-static struct ast_register_list {
-	ASTOBJ_CONTAINER_COMPONENTS(struct sip_registry);
-	int recheck;
-} regl;
+struct sip_register_list regl;
 
 /*! \todo Move the sip_auth list to AST_LIST */
-static struct sip_auth *authl = NULL;		/*!< Authentication list for realm authentication */
-
-/* This structure needs to be encapsulated */
-extern struct sip_network sipnet;                      /*!< Sockets and networking */
-
-static struct ast_config *notify_types;		/*!< The list of manual NOTIFY types we know how to send */
+struct sip_auth *authl = NULL;		/*!< Authentication list for realm authentication */
+
+struct ast_config *notify_types;		/*!< The list of manual NOTIFY types we know how to send */
 
 /*---------------------------- Forward declarations of functions in chan_sip.c */
 /*! \note This is added to help splitting up chan_sip.c into several files
@@ -320,7 +299,6 @@
 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);
-static int transmit_reinvite_with_sdp(struct sip_pvt *p);
 static int transmit_info_with_digit(struct sip_pvt *p, const char digit);
 static int transmit_info_with_vidupdate(struct sip_pvt *p);
 static int transmit_message_with_text(struct sip_pvt *p, const char *text);
@@ -363,37 +341,21 @@
 
 /*--- Codec handling / SDP */
 static void try_suggested_sip_codec(struct sip_pvt *p);
-static int find_sdp(struct sip_request *req);
-static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
-			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-			     int debug);
-static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
-				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-				int debug);
-static int add_sdp(struct sip_request *resp, 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 build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
 static int clear_realm_authentication(struct sip_auth *authlist);	/* Clear realm authentication list (at reload) */
-static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno);	/* Add realm authentication in list */
 static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, const char *realm);	/* Find authentication for a specific realm */
 static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_request *req,
 					      int sipmethod, 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, char *uri, enum xmittype reliable, struct sockaddr_in *sin);
-static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init);
-static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int digest_len);
 
 /*--- SIP realm authentication */
-static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno);
 static int clear_realm_authentication(struct sip_auth *authlist);
 static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, const char *realm);
 
 /*--- Misc functions */
 static int sip_do_reload(enum channelreloadreason reason);
-static int reload_config(enum channelreloadreason reason);
-static int expire_register(void *data);
 static int sip_sipredirect(struct sip_pvt *p, const char *dest);
 static void *do_monitor(void *data);
 static int restart_monitor(void);
@@ -411,7 +373,6 @@
 static int sip_poke_noanswer(void *data);
 static int sip_poke_peer(struct sip_peer *peer);
 static void sip_poke_all_peers(void);
-GNURK void sip_peer_hold(struct sip_pvt *p, int hold);
 
 /*--- Applications, functions, CLI and manager command helpers */
 static const char *sip_nat_mode(const struct sip_pvt *p);
@@ -427,7 +388,6 @@
 static void  print_group(int fd, ast_group_t group, int crlf);
 static const char *dtmfmode2str(int mode) attribute_const;
 static const char *insecure2str(int port, int invite) attribute_const;
-static void cleanup_stale_contexts(char *new, char *old);
 static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
 static int _sip_show_peer(int type, int fd, struct mansession *s, struct message *m, int argc, char *argv[]);
 static int manager_sip_show_peer( struct mansession *s, struct message *m);
@@ -473,44 +433,31 @@
 static void sip_dump_history(struct sip_pvt *dialog);	/* Dump history to LOG_DEBUG at end of dialog, before destroying data */
 static inline int sip_debug_test_addr(const struct sockaddr_in *addr);
 static inline int sip_debug_test_pvt(struct sip_pvt *p);
-static void append_history_full(struct sip_pvt *p, const char *fmt, ...);
 static void sip_dump_history(struct sip_pvt *dialog);
 
 /*--- Device object handling */
 static struct sip_peer *temp_peer(const char *name);
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
-static struct sip_peer *build_user(const char *name, struct ast_variable *v, int realtime);
 static int update_call_counter(struct sip_pvt *fup, int event);
-static void sip_destroy_device(struct sip_peer *peer);
 static int sip_poke_peer(struct sip_peer *peer);
-static void set_device_defaults(struct sip_peer *peer);
 static struct sip_peer *temp_peer(const char *name);
 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);
 static struct sip_peer *find_user(const char *name, int realtime);
 static int sip_poke_peer_s(void *data);
 static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req);
-static int expire_register(void *data);
-static void reg_source_db(struct sip_peer *peer);
-static void destroy_association(struct sip_peer *peer);
-static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v);
 
 /* Realtime device support */
 static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expirey);
-static struct sip_peer *realtime_user(const char *username);
 static void update_peer(struct sip_peer *p, int expiry);
-static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
 static int sip_prune_realtime(int fd, int argc, char *argv[]);
 
 /*--- Internal UA client handling (outbound registrations) */
 static int ast_sip_ouraddrfor(struct in_addr *them, struct in_addr *us);
 static void sip_registry_destroy(struct sip_registry *reg);
-static int sip_register(char *value, int lineno);
 static char *regstate2str(enum sipregistrystate regstate) attribute_const;
 static int sip_reregister(void *data);
 static int __sip_do_register(struct sip_registry *r);
 static int sip_reg_timeout(void *data);
-static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod,  char *digest, int digest_len);
 static void sip_send_all_registers(void);
 
 /*--- Parsing SIP requests and responses */
@@ -518,11 +465,9 @@
 static int determine_firstline_parts(struct sip_request *req);
 static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
 static void parse_request(struct sip_request *req);
-static const char *get_header(const struct sip_request *req, const char *name);
 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_request *req, const char *name);
 static void extract_uri(struct sip_pvt *p, struct sip_request *req);
 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);
@@ -536,6 +481,7 @@
 static int get_msg_text(char *buf, int len, struct sip_request *req);
 static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
 static void free_old_route(struct sip_route *route);
+GNURK void parse_copy(struct sip_request *dst, const struct sip_request *src);
 
 /*--- Constructing requests and responses */
 static void initialize_initreq(struct sip_pvt *p, struct sip_request *req);
@@ -552,8 +498,6 @@
 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);
@@ -683,7 +627,7 @@
 }
 
 /*! \brief Test PVT for debugging output */
-static inline int sip_debug_test_pvt(struct sip_pvt *p) 
+inline int sip_debug_test_pvt(struct sip_pvt *p) 
 {
 	if (!sipdebug)
 		return 0;
@@ -739,11 +683,11 @@
 	return AST_SUCCESS;
 }
 
-static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
+GNURK void append_history_full(struct sip_pvt *p, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
 
 /*! \brief Append to SIP dialog history with arg list  */
-static void append_history_va(struct sip_pvt *p, const char *fmt, va_list ap)
+GNURK void append_history_va(struct sip_pvt *p, const char *fmt, va_list ap)
 {
 	char buf[80], *c = buf; /* max history length */
 	struct sip_history *hist;
@@ -763,7 +707,7 @@
 }
 
 /*! \brief Append to SIP dialog history with arg list  */
-static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
+GNURK void append_history_full(struct sip_pvt *p, const char *fmt, ...)
 {
 	va_list ap;
 
@@ -929,7 +873,7 @@
 }
 
 /*! \brief add a blank line if no body */
-void add_blank(struct sip_request *req)
+GNURK void add_blank(struct sip_request *req)
 {
 	if (!req->lines) {
 		/* Add extra empty return. add_header() reserves 4 bytes so cannot be truncated */
@@ -1088,7 +1032,7 @@
 }
 
 /*! \brief Destroy device object from memory */
-static void sip_destroy_device(struct sip_peer *device)
+GNURK void sip_destroy_device(struct sip_peer *device)
 {
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "Destroying SIP %s %s\n", device->type & SIP_USER ? "user" : "peer", device->name);
@@ -1142,74 +1086,6 @@
 	}
 }
 
-
-/*! \brief  realtime_peer: Get peer from realtime storage
- * Checks the "sippeers" realtime family from extconfig.conf 
- * \todo Consider adding check of port address when matching here to follow the same
- * 	algorithm as for static peers. Will we break anything by adding that?
-*/
-static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_in *sin)
-{
-	struct sip_peer *peer;
-	struct ast_variable *var = NULL;
-	struct ast_variable *tmp;
-	char ipaddr[INET_ADDRSTRLEN];
-
-	/* First check on peer name */
-	if (newpeername) 
-		var = ast_load_realtime("sippeers", "name", newpeername, NULL);
-	else if (sin) {	/* Then check on IP address for dynamic peers */
-		ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr));
-		var = ast_load_realtime("sippeers", "host", ipaddr, NULL);	/* First check for fixed IP hosts */
-		if (!var)
-			var = ast_load_realtime("sippeers", "ipaddr", ipaddr, NULL);	/* Then check for registred hosts */
-	}
-
-	if (!var)
-		return NULL;
-
-	for (tmp = var; tmp; tmp = tmp->next) {
-		/* If this is type=user, then skip this object. */
-		if (!strcasecmp(tmp->name, "type") &&
-		    !strcasecmp(tmp->value, "user")) {
-			ast_variables_destroy(var);
-			return NULL;
-		} else if (!newpeername && !strcasecmp(tmp->name, "name")) {
-			newpeername = tmp->value;
-		}
-	}
-	
-	if (!newpeername) {	/* Did not find peer in realtime */
-		ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", ipaddr);
-		ast_variables_destroy(var);
-		return NULL;
-	}
-
-	/* Peer found in realtime, now build it in memory */
-	peer = build_peer(newpeername, var, NULL, !ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS));
-	if (!peer) {
-		ast_variables_destroy(var);
-		return NULL;
-	}
-
-	if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-		/* Cache peer */
-		ast_copy_flags(&peer->flags[1],&global.flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
-		if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
-			if (peer->expire > -1) {
-				ast_sched_del(sched, peer->expire);
-			}
-			peer->expire = ast_sched_add(sched, (global.rtautoclear) * 1000, expire_register, (void *)peer);
-		}
-		ASTOBJ_CONTAINER_LINK(&peerl,peer);
-	} else {
-		ast_set_flag(&peer->flags[0], SIP_REALTIME);
-	}
-	ast_variables_destroy(var);
-
-	return peer;
-}
-
 /*! \brief Support routine for find_peer */
 static int sip_addrcmp(char *name, struct sockaddr_in *sin)
 {
@@ -1236,48 +1112,6 @@
 		p = realtime_peer(peer, sin);
 
 	return p;
-}
-
-/*! \brief Load user from realtime storage
- * Loads user from "sipusers" category in realtime (extconfig.conf)
- * Users are matched on From: user name (the domain in skipped) */
-static struct sip_peer *realtime_user(const char *username)
-{
-	struct ast_variable *var;
-	struct ast_variable *tmp;
-	struct sip_peer *user = NULL;
-
-	var = ast_load_realtime("sipusers", "name", username, NULL);
-
-	if (!var)
-		return NULL;
-
-	for (tmp = var; tmp; tmp = tmp->next) {
-		if (!strcasecmp(tmp->name, "type") &&
-			!strcasecmp(tmp->value, "peer")) {
-			ast_variables_destroy(var);
-			return NULL;
-		}
-	}
-
-	user = build_user(username, var, !ast_test_flag((&global.flags[1]), SIP_PAGE2_RTCACHEFRIENDS)); 
-	if (!user) {	/* No user found */
-		ast_variables_destroy(var);
-		return NULL;
-	}
-
-	if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-		ast_set_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
-		sipcounters.static_users++;
-		ASTOBJ_CONTAINER_LINK(&userl,user);
-	} else {
-		/* Move counter from s to r... */
-		sipcounters.static_users--;
-		sipcounters.realtime_users++;
-		ast_set_flag(&user->flags[0], SIP_REALTIME);
-	}
-	ast_variables_destroy(var);
-	return user;
 }
 
 /*! \brief Locate user by name 
@@ -1669,9 +1503,9 @@
 		p->history = NULL;
 	}
 
-	for (prev = NULL, cur = iflist; cur; prev = cur, cur = cur->next) {
+	for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) {
 		if (cur == p) {
-			UNLINK(cur, iflist, prev);
+			UNLINK(cur, dialoglist, prev);
 			break;
 		}
 	}
@@ -2658,7 +2492,7 @@
 }
 
 /*! \brief Get header from SIP request */
-static const char *get_header(const struct sip_request *req, const char *name)
+GNURK const char *get_header(const struct sip_request *req, const char *name)
 {
 	int start = 0;
 	return __get_header(req, name, &start);
@@ -2913,8 +2747,8 @@
 
 	/* Add to active dialog list */
 	ast_mutex_lock(&iflock);
-	p->next = iflist;
-	iflist = p;
+	p->next = dialoglist;
+	dialoglist = p;
 	ast_mutex_unlock(&iflock);
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_method2txt(intended_method), p->rtp ? "With RTP" : "No RTP");
@@ -2951,7 +2785,7 @@
 		ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
 
 	ast_mutex_lock(&iflock);
-	for (p = iflist; p; p = p->next) {
+	for (p = dialoglist; p; p = p->next) {
 		/* we do not want packets with bad syntax to be connected to a PVT */
 		int found = FALSE;
 		if (req->method == SIP_REGISTER)
@@ -2993,7 +2827,7 @@
 }
 
 /*! \brief Parse register=> line in sip.conf and add to registry */
-static int sip_register(char *value, int lineno)
+GNURK int sip_register(char *value, int lineno)
 {
 	struct sip_registry *reg;
 	char copy[256];
@@ -3160,72 +2994,8 @@
 	determine_firstline_parts(req);
 }
 
-
-/*!
-  \brief Determine whether a SIP message contains an SDP in its body
-  \param req the SIP request to process
-  \return 1 if SDP found, 0 if not found
-
-  Also updates req->sdp_start and req->sdp_end to indicate where the SDP
-  lives in the message body.
-*/
-static int find_sdp(struct sip_request *req)
-{
-	const char *content_type;
-	const char *search;
-	char *boundary;
-	unsigned int x;
-
-	content_type = get_header(req, "Content-Type");
-
-	/* if the body contains only SDP, this is easy */
-	if (!strcasecmp(content_type, "application/sdp")) {
-		req->sdp_start = 0;
-		req->sdp_end = req->lines;
-		return 1;
-	}
-
-	/* if it's not multipart/mixed, there cannot be an SDP */
-	if (strncasecmp(content_type, "multipart/mixed", 15))
-		return 0;
-
-	/* if there is no boundary marker, it's invalid */
-	if (!(search = strcasestr(content_type, ";boundary=")))
-		return 0;
-
-	search += 10;
-
-	if (ast_strlen_zero(search))
-		return 0;
-
-	/* make a duplicate of the string, with two extra characters
-	   at the beginning */
-	boundary = ast_strdupa(search - 2);
-	boundary[0] = boundary[1] = '-';
-
-	/* search for the boundary marker, but stop when there are not enough
-	   lines left for it, the Content-Type header and at least one line of
-	   body */
-	for (x = 0; x < (req->lines - 2); x++) {
-		if (!strncasecmp(req->line[x], boundary, strlen(boundary)) &&
-		    !strcasecmp(req->line[x + 1], "Content-Type: application/sdp")) {
-			req->sdp_start = x + 2;
-			/* search for the end of the body part */
-			for ( ; x < req->lines; x++) {
-				if (!strncasecmp(req->line[x], boundary, strlen(boundary)))
-					break;
-			}
-			req->sdp_end = x;
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
-
 /*! \brief Add header to SIP message */
-static int add_header(struct sip_request *req, const char *var, const char *value)
+GNURK int add_header(struct sip_request *req, const char *var, const char *value)
 {
 	int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */
 
@@ -3261,7 +3031,7 @@
 }
 
 /*! \brief Add 'Content-Length' header to SIP message */
-static int add_header_contentLength(struct sip_request *req, int len)
+GNURK int add_header_contentLength(struct sip_request *req, int len)
 {
 	char clen[10];
 
@@ -3308,14 +3078,20 @@
 {
 	int start = 0;
 	int copied = 0;
+	int res;
+
 	for (;;) {
 		const char *tmp = __get_header(orig, field, &start);
 
 		if (ast_strlen_zero(tmp))
 			break;
 		/* Add what we're responding to */
-		add_header(req, field, tmp);
-		copied++;
+		res = add_header(req, field, tmp);
+		if (res != -1)
+			copied++;
+		else
+			return -1;
+		
 	}
 	return copied ? 0 : -1;
 }
@@ -3793,43 +3569,6 @@
 	add_header_contentLength(req, strlen(xml_is_a_huge_waste_of_space));
 	add_line(req, xml_is_a_huge_waste_of_space);
 	return 0;
-}
-
-/*! \brief Add codec offer to SDP offer/answer body in INVITE or 200 OK */
-static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
-			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-			     int debug)
-{
-	int rtp_code;
-	struct ast_format_list fmt;
-
-
-	if (debug)
-		ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
-	if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1)
-		return;
-
-	if (p->rtp) {
-		struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
-		fmt = ast_codec_pref_getsize(pref, codec);
-	} else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
-		return;
-	ast_build_string(m_buf, m_size, " %d", rtp_code);
-	ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-			 ast_rtp_lookup_mime_subtype(1, codec,
-						     ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0),
-			 sample_rate);
-	if (codec == AST_FORMAT_G729A) {
-		/* Indicate that we don't support VAD (G.729 annex B) */
-		ast_build_string(a_buf, a_size, "a=fmtp:%d annexb=no\r\n", rtp_code);
-	} else if (codec == AST_FORMAT_ILBC) {
-		/* Add information about us using only 20/30 ms packetization */
-		ast_build_string(a_buf, a_size, "a=fmtp:%d mode=%d\r\n", rtp_code, fmt.cur_ms);
-	}
-
-	if (codec != AST_FORMAT_ILBC) {
-		ast_build_string(a_buf, a_size, "a=ptime:%d\r\n", fmt.cur_ms);
-	}
 }
 
 /*! \brief Get Max T.38 Transmission rate from T38 capabilities */
@@ -3966,297 +3705,6 @@
 }
 
 
-/*! \brief Add RFC 2833 DTMF offer to SDP */
-static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
-				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-				int debug)
-{
-	int rtp_code;
-
-	if (debug)
-		ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format, 0));
-	if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1)
-		return;
-
-	ast_build_string(m_buf, m_size, " %d", rtp_code);
-	ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-			 ast_rtp_lookup_mime_subtype(0, format, 0),
-			 sample_rate);
-	if (format == AST_RTP_DTMF)
-		/* Indicate we support DTMF and FLASH... */
-		ast_build_string(a_buf, a_size, "a=fmtp:%d 0-16\r\n", rtp_code);
-}
-
-/*! \brief Add Session Description Protocol message */
-static int add_sdp(struct sip_request *resp, struct sip_pvt *p)
-{
-	int len = 0;
-	int alreadysent = 0;
-
-	struct sockaddr_in sin;
-	struct sockaddr_in vsin;
-	struct sockaddr_in dest;
-	struct sockaddr_in vdest = { 0, };
-
-	/* SDP fields */
-	char *version = 	"v=0\r\n";		/* Protocol version */
-	char *subject = 	"s=session\r\n";	/* Subject of the session */
-	char owner[256];				/* Session owner/creator */
-	char connection[256];				/* Connection data */
-	char *stime = "t=0 0\r\n"; 			/* Time the session is active */
-	char bandwidth[256] = "";			/* Max bitrate */
-	char *hold;
-	char m_audio[256];				/* Media declaration line for audio */
-	char m_video[256];				/* Media declaration line for video */
-	char a_audio[1024];				/* Attributes for audio */
-	char a_video[1024];				/* Attributes for video */
-	char *m_audio_next = m_audio;
-	char *m_video_next = m_video;
-	size_t m_audio_left = sizeof(m_audio);
-	size_t m_video_left = sizeof(m_video);
-	char *a_audio_next = a_audio;
-	char *a_video_next = a_video;
-	size_t a_audio_left = sizeof(a_audio);
-	size_t a_video_left = sizeof(a_video);
-
-	int x;
-	int capability;
-	int needvideo = FALSE;
-	int debug = sip_debug_test_pvt(p);
-
-	m_video[0] = '\0';	/* Reset the video media string if it's not needed */
-
-	if (!p->rtp) {
-		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
-		return -1;
-	}
-
-	/* Set RTP Session ID and version */
-	if (!p->sessionid) {
-		p->sessionid = getpid();
-		p->sessionversion = p->sessionid;
-	} else
-		p->sessionversion++;
-
-	/* Get our addresses */
-	ast_rtp_get_us(p->rtp, &sin);
-	if (p->vrtp)
-		ast_rtp_get_us(p->vrtp, &vsin);
-
-	/* Is this a re-invite to move the media out, then use the original offer from caller  */
-	if (p->redirip.sin_addr.s_addr) {
-		dest.sin_port = p->redirip.sin_port;
-		dest.sin_addr = p->redirip.sin_addr;
-		if (p->redircodecs)
-			capability = p->redircodecs;
-	} else {
-		dest.sin_addr = p->ourip;
-		dest.sin_port = sin.sin_port;
-	}
-
-	/* Ok, let's start working with codec selection here */
-	capability = p->jointcapability;
-
-	if (option_debug > 1) {
-		char codecbuf[BUFSIZ];
-		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
-		ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
-	}
-	
-	if ((ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_RTP))) {
-		ast_build_string(&m_audio_next, &m_audio_left, " %d", 191);
-		ast_build_string(&a_audio_next, &a_audio_left, "a=rtpmap:%d %s/%d\r\n", 191, "t38", 8000);
-	}
-
-	/* Check if we need video in this call */
-	if((capability & AST_FORMAT_VIDEO_MASK) && !ast_test_flag(&p->flags[0], SIP_NOVIDEO)) {
-		if (p->vrtp) {
-			needvideo = TRUE;
-			if (option_debug > 1)
-				ast_log(LOG_DEBUG, "This call needs video offers! \n");
-		} else if (option_debug > 1)
-			ast_log(LOG_DEBUG, "This call needs video offers, but there's no video support enabled ! \n");
-	}
-		
-
-	/* Ok, we need video. Let's add what we need for video and set codecs.
-	   Video is handled differently than audio since we can not transcode. */
-	if (needvideo) {
-
-		/* Determine video destination */
-		if (p->vredirip.sin_addr.s_addr) {
-			vdest.sin_addr = p->vredirip.sin_addr;
-			vdest.sin_port = p->vredirip.sin_port;
-		} else {
-			vdest.sin_addr = p->ourip;
-			vdest.sin_port = vsin.sin_port;
-		}
-		ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port));
-
-		/* Build max bitrate string */
-		if (p->maxcallbitrate)
-			snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate);
-		if (debug) 
-			ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(vsin.sin_port));	
-
-		/* For video, we can't negotiate video offers. Let's compare the incoming call with what we got. */
-		if (p->prefcodec) {
-			int videocapability = (capability & p->prefcodec) & AST_FORMAT_VIDEO_MASK; /* Outbound call */
-		
-			/*! \todo XXX We need to select one codec, not many, since there's no transcoding */
-
-			/* Now, merge this video capability into capability while removing unsupported codecs */
-			if (!videocapability) {
-				needvideo = FALSE;
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "** No compatible video codecs... Disabling video.\n");
-			} 
-
-			/* Replace video capabilities with the new videocapability */
-			capability = (capability & AST_FORMAT_AUDIO_MASK) | videocapability;
-
-			if (option_debug > 4) {
-				char codecbuf[BUFSIZ];
-				if (videocapability)
-					ast_log(LOG_DEBUG, "** Our video codec selection is: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), videocapability));
-				ast_log(LOG_DEBUG, "** Capability now set to : %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability));
-			}
-		}
-	}
-	if (debug) 
-		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port));	
-
-	/* Start building generic SDP headers */
-
-	/* We break with the "recommendation" and send our IP, in order that our
-	   peer doesn't have to ast_gethostbyname() us */
-
-	snprintf(owner, sizeof(owner), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(dest.sin_addr));
-	snprintf(connection, sizeof(connection), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr));
-	ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port));
-
-	if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD_ONEDIR))
-		hold = "a=recvonly\r\n";
-	else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD_INACTIVE))
-		hold = "a=inactive\r\n";
-	else
-		hold = "a=sendrecv\r\n";
-
-	/* Now, start adding audio codecs. These are added in this order:
-		- First what was requested by the calling channel
-		- Then preferences in order from sip.conf device config for this peer/user
-		- Then other codecs in capabilities, including video
-	*/
-
-	/* Prefer the audio codec we were requested to use, first, no matter what 
-		Note that p->prefcodec can include video codecs, so mask them out
-	 */
-	if (capability & p->prefcodec) {
-		add_codec_to_sdp(p, p->prefcodec & AST_FORMAT_AUDIO_MASK, 8000,
-				 &m_audio_next, &m_audio_left,
-				 &a_audio_next, &a_audio_left,
-				 debug);
-		alreadysent |= p->prefcodec & AST_FORMAT_AUDIO_MASK;
-	}
-
-
-	/* Start by sending our preferred audio codecs */
-	for (x = 0; x < 32; x++) {
-		int pref_codec;
-
-		if (!(pref_codec = ast_codec_pref_index(&p->prefs, x)))
-			break; 
-
-		if (!(capability & pref_codec))
-			continue;
-
-		if (alreadysent & pref_codec)
-			continue;
-
-		add_codec_to_sdp(p, pref_codec, 8000,
-				 &m_audio_next, &m_audio_left,
-				 &a_audio_next, &a_audio_left,
-				 debug);
-		alreadysent |= pref_codec;
-	}
-
-	/* Now send any other common audio and video codecs, and non-codec formats: */
-	for (x = 1; x <= (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) {
-		if (!(capability & x))	/* Codec not requested */
-			continue;
-
-		if (alreadysent & x)	/* Already added to SDP */
-			continue;
-
-		if (x <= AST_FORMAT_MAX_AUDIO)
-			add_codec_to_sdp(p, x, 8000,
-					 &m_audio_next, &m_audio_left,
-					 &a_audio_next, &a_audio_left,
-					 debug);
-		else 
-			add_codec_to_sdp(p, x, 90000,
-					 &m_video_next, &m_video_left,
-					 &a_video_next, &a_video_left,
-					 debug);
-	}
-
-	/* Now add DTMF RFC2833 telephony-event as a codec */
-	for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
-		if (!(p->noncodeccapability & x))
-			continue;
-
-		add_noncodec_to_sdp(p, x, 8000,
-				    &m_audio_next, &m_audio_left,
-				    &a_audio_next, &a_audio_left,
-				    debug);
-	}
-
-	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "-- Done with adding codecs to SDP\n");
-
-	if(!p->owner || !ast_internal_timing_enabled(p->owner))
-		ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n");
-
-	if ((m_audio_left < 2) || (m_video_left < 2) || (a_audio_left == 0) || (a_video_left == 0))
-		ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
-
-	ast_build_string(&m_audio_next, &m_audio_left, "\r\n");
-	if (needvideo)
-		ast_build_string(&m_video_next, &m_video_left, "\r\n");
-
-	len = strlen(version) + strlen(subject) + strlen(owner) + strlen(connection) + strlen(stime) + strlen(m_audio) + strlen(a_audio) + strlen(hold);
-	if (needvideo) /* only if video response is appropriate */
-		len += strlen(m_video) + strlen(a_video) + strlen(bandwidth) + strlen(hold);
-
-	add_header(resp, "Content-Type", "application/sdp");
-	add_header_contentLength(resp, len);
-	add_line(resp, version);
-	add_line(resp, owner);
-	add_line(resp, subject);
-	add_line(resp, connection);
-	if (needvideo)	 	/* only if video response is appropriate */
-		add_line(resp, bandwidth);
-	add_line(resp, stime);
-	add_line(resp, m_audio);
-	add_line(resp, a_audio);
-	add_line(resp, hold);
-	if (needvideo) { /* only if video response is appropriate */
-		add_line(resp, m_video);
-		add_line(resp, a_video);
-		add_line(resp, hold);	/* Repeat hold for the video stream */
-	}
-
-	/* Update lastrtprx when we send our SDP */
-	p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
-
-	if (option_debug > 2) {
-		char buf[BUFSIZ];
-		ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
-	}
-
-	return 0;
-}
-
 /*! \brief Used for 200 OK and 183 early media */
 static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
 {
@@ -4365,7 +3813,7 @@
 	We reinvite so that the audio stream (RTP) go directly between
 	the SIP UAs. SIP Signalling stays with * in the path.
 */
-static int transmit_reinvite_with_sdp(struct sip_pvt *p)
+GNURK int transmit_reinvite_with_sdp(struct sip_pvt *p)
 {
 	struct sip_request req;
 
@@ -5399,7 +4847,7 @@
 }
 
 /*! \brief Remove registration data from realtime database or AST/DB when registration expires */
-static void destroy_association(struct sip_peer *peer)
+GNURK void destroy_association(struct sip_peer *peer)
 {
 	if (!ast_test_flag(&global.flags[1], SIP_PAGE2_IGNOREREGEXPIRE)) {
 		if (ast_test_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT))
@@ -5410,7 +4858,7 @@
 }
 
 /*! \brief Expire registration of SIP peer */
-static int expire_register(void *data)
+GNURK int expire_register(void *data)
 {
 	struct sip_peer *peer = data;
 	
@@ -5449,7 +4897,7 @@
 }
 
 /*! \brief Get registration details from Asterisk DB */
-static void reg_source_db(struct sip_peer *peer)
+GNURK void reg_source_db(struct sip_peer *peer)
 {
 	char data[256];
 	struct in_addr in;
@@ -6310,7 +5758,7 @@
 		ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
 
 	/* Search interfaces and find the match */
-	for (sip_pvt_ptr = iflist; sip_pvt_ptr; sip_pvt_ptr = sip_pvt_ptr->next) {
+	for (sip_pvt_ptr = dialoglist; sip_pvt_ptr; sip_pvt_ptr = sip_pvt_ptr->next) {
 		if (!strcmp(sip_pvt_ptr->callid, callid)) {
 			int match = 1;
 			char *ourtag = sip_pvt_ptr->tag;
@@ -7378,32 +6826,6 @@
 		return "invite";
 	else
 		return "no";
-}
-
-/*! \brief Destroy disused contexts between reloads
-	Only used in reload_config so the code for regcontext doesn't get ugly
-*/
-static void cleanup_stale_contexts(char *new, char *old)
-{
-	char *oldcontext, *newcontext, *stalecontext, *stringp, newlist[AST_MAX_CONTEXT];
-
-	while ((oldcontext = strsep(&old, "&"))) {
-		stalecontext = '\0';
-		ast_copy_string(newlist, new, sizeof(newlist));
-		stringp = newlist;
-		while ((newcontext = strsep(&stringp, "&"))) {
-			if (strcmp(newcontext, oldcontext) == 0) {
-				/* This is not the context you're looking for */
-				stalecontext = '\0';
-				break;
-			} else if (strcmp(newcontext, oldcontext)) {
-				stalecontext = oldcontext;
-			}
-			
-		}
-		if (stalecontext)
-			ast_context_destroy(ast_context_find(stalecontext), "SIP");
-	}
 }
 
 /*! \brief Remove temporary realtime objects from memory (CLI) */
@@ -8020,7 +7442,7 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	ast_mutex_lock(&iflock);
-	cur = iflist;
+	cur = dialoglist;
 	if (!subscriptions)
 		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
 	else 
@@ -8076,7 +7498,7 @@
 	int wordlen = strlen(word);
 
 	ast_mutex_lock(&iflock);
-	for (cur = iflist; cur; cur = cur->next) {
+	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) {
 			c = ast_strdup(cur->callid);
 			break;
@@ -8208,7 +7630,7 @@
 		return RESULT_SHOWUSAGE;
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	for (cur = iflist; cur; cur = cur->next) {
+	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			char formatbuf[BUFSIZ/2];
 			ast_cli(fd,"\n");
@@ -8274,7 +7696,7 @@
 		ast_cli(fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	for (cur = iflist; cur; cur = cur->next) {
+	for (cur = dialoglist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			struct sip_history *hist;
 			int x = 0;
@@ -8578,198 +8000,6 @@
 	return RESULT_SUCCESS;
 }
 
-/*! \brief Authenticate for outbound registration */
-static int do_register_auth(struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code)
-{
-	char *header, *respheader;
-	char digest[1024];
-
-	p->authtries++;
-	auth_headers(code, &header, &respheader);
-	memset(digest,0,sizeof(digest));
-	if (reply_digest(p, req, header, SIP_REGISTER, digest, sizeof(digest))) {
-		/* There's nothing to use for authentication */
- 		/* No digest challenge in request */
- 		if (sip_debug_test_pvt(p) && p->registry)
- 			ast_verbose("No authentication challenge, sending blank registration to domain/host name %s\n", p->registry->hostname);
- 			/* No old challenge */
-		return -1;
-	}
-	if (global.recordhistory)
-		append_history(p, "RegistryAuth", "Try: %d", p->authtries);
- 	if (sip_debug_test_pvt(p) && p->registry)
- 		ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname);
-	return transmit_register(p->registry, SIP_REGISTER, digest, respheader); 
-}
-

[... 2127 lines stripped ...]


More information about the asterisk-commits mailing list