[asterisk-commits] rizzo: branch rizzo/astobj2 r47340 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 8 15:14:32 MST 2006


Author: rizzo
Date: Wed Nov  8 16:14:31 2006
New Revision: 47340

URL: http://svn.digium.com/view/asterisk?rev=47340&view=rev
Log:
commit some simplifications i forgot


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?rev=47340&r1=47339&r2=47340&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Wed Nov  8 16:14:31 2006
@@ -993,7 +993,7 @@
 							you know more) */
 };
 
-//#define	USE_AO2
+// #define	USE_AO2
 #ifdef	USE_AO2	/* astobj2 implementation */
 #include "asterisk/astobj2.h"
 ao2_container *dialoglist;
@@ -3107,11 +3107,13 @@
 		ast_variables_destroy(p->chanvars);
 		p->chanvars = NULL;
 	}
+
+	ast_string_field_free_pools(p);
+
+#ifndef USE_AO2
 	ast_mutex_destroy(&p->pvt_lock);
-
-	ast_string_field_free_pools(p);
-
 	free(p);
+#endif
 }
 
 /*! \brief  update_call_counter: Handle call_limit for SIP users 
@@ -4286,12 +4288,28 @@
 	snprintf(tagbuf, len, "as%08lx", ast_random());
 }
 
+#ifdef USE_AO2
+static void pvt_destructor(void *p)
+{
+	__sip_destroy(p);
+}
+#endif
+
 /*! \brief Allocate SIP_PVT structure and set defaults */
 static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
 				 int useglobal_nat, const int intended_method)
 {
 	struct sip_pvt *p;
 
+#ifdef USE_AO2
+	p = ao2_alloc(sizeof(*p), pvt_destructor);
+	if (!p)
+		return NULL;
+	if (ast_string_field_init(p, 512)) {
+		ao2_ref(p, -1);
+		return NULL;
+	}
+#else
 	if (!(p = ast_calloc(1, sizeof(*p))))
 		return NULL;
 
@@ -4301,6 +4319,7 @@
 	}
 
 	ast_mutex_init(&p->pvt_lock);
+#endif
 
 	p->method = intended_method;
 	p->initid = -1;
@@ -8451,34 +8470,36 @@
 	return res;
 }
 
+struct _redir_map {
+	const char *reason;
+	const char *cause;
+};
+
+
 /*! \brief Translate referring cause */
-static void sip_set_redirstr(struct sip_pvt *p, char *reason) {
-
-	if (strcmp(reason, "unknown")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "user-busy")==0) {
-		ast_string_field_set(p, redircause, "BUSY");
-	} else if (strcmp(reason, "no-answer")==0) {
-		ast_string_field_set(p, redircause, "NOANSWER");
-	} else if (strcmp(reason, "unavailable")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else if (strcmp(reason, "unconditional")==0) {
-		ast_string_field_set(p, redircause, "UNCONDITIONAL");
-	} else if (strcmp(reason, "time-of-day")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "do-not-disturb")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "deflection")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "follow-me")==0) {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	} else if (strcmp(reason, "out-of-service")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else if (strcmp(reason, "away")==0) {
-		ast_string_field_set(p, redircause, "UNREACHABLE");
-	} else {
-		ast_string_field_set(p, redircause, "UNKNOWN");
-	}
+static void sip_set_redirstr(struct sip_pvt *p, char *reason)
+{
+	struct _redir_map *x;
+	static struct _redir_map m[] = {
+		{ "user-busy",		"BUSY"		},
+		{ "no-answer",		"NOANSWER"	},
+		{ "unavailable",	"UNREACHABLE"	},
+		{ "unconditional",	"UNCONDITIONAL"	},
+		{ "out-of-service",	"UNREACHABLE"	},
+		{ "away",		"UNREACHABLE"	},
+#if 0	/* same as the default, so don't bother checking */
+		{ "unknown",		"UNKNOWN"	},
+		{ "time-of-day",	"UNKNOWN"	},
+		{ "do-not-disturb",	"UNKNOWN"	},
+		{ "follow-me",		"UNKNOWN"	},
+#endif
+		{ NULL,			"UNKNOWN"	}
+	};
+	for (x = m; x->reason; x++) {
+		if (!strcmp(reason, x->reason))
+			break;
+	}
+	ast_string_field_set(p, redircause, x->cause);
 }
 
 /*! \brief Get referring dnis */



More information about the asterisk-commits mailing list