[Freeswitch-branches] [commit] r3315 - in freeswitch/branches/knhor/trunk: . src src/include src/mod/event_handlers/mod_event_multicast src/mod/event_handlers/mod_event_socket src/mod/event_handlers/mod_event_test src/mod/event_handlers/mod_xmpp_event src/mod/languages/mod_spidermonkey

Freeswitch SVN knhor at freeswitch.org
Sat Nov 11 14:39:22 EST 2006


Author: knhor
Date: Sat Nov 11 14:39:20 2006
New Revision: 3315

Modified:
   freeswitch/branches/knhor/trunk/   (props changed)
   freeswitch/branches/knhor/trunk/src/include/switch_core.h
   freeswitch/branches/knhor/trunk/src/include/switch_event.h
   freeswitch/branches/knhor/trunk/src/include/switch_ivr.h
   freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
   freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c
   freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c
   freeswitch/branches/knhor/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/knhor/trunk/src/switch_core.c
   freeswitch/branches/knhor/trunk/src/switch_event.c

Log:
Merged revisions 3312-3314 via svnmerge from trunk


Modified: freeswitch/branches/knhor/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/knhor/trunk/src/include/switch_core.h	(original)
+++ freeswitch/branches/knhor/trunk/src/include/switch_core.h	Sat Nov 11 14:39:20 2006
@@ -130,7 +130,7 @@
 														  switch_media_bug_t **new_bug);
 /*!
   \brief Obtain private data from a media bug
-  \param session the session to obtain the private data from
+  \param bug the bug to get the data from
   \return the private data
 */
 SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *bug);
@@ -1205,6 +1205,7 @@
 /*!
   \brief Unload a grammar from an asr handle
   \param ah the handle to unload the grammar from
+  \param grammar the grammar to unload
   \return SWITCH_STATUS_SUCCESS
 */
 SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle_t *ah, char *grammar);

Modified: freeswitch/branches/knhor/trunk/src/include/switch_event.h
==============================================================================
--- freeswitch/branches/knhor/trunk/src/include/switch_event.h	(original)
+++ freeswitch/branches/knhor/trunk/src/include/switch_event.h	Sat Nov 11 14:39:20 2006
@@ -238,13 +238,11 @@
 /*!
   \brief Render a string representation of an event sutable for printing or network transport 
   \param event the event to render
-  \param buf a string buffer to write the data to
-  \param buflen the size in bytes of the buffer
-  \param fmt optional body of the event (varargs see standard sprintf family)
+  \param str a string pointer to point at the allocated data
   \return SWITCH_STATUS_SUCCESS if the operation was successful
-  \note the body supplied by this function will supersede an existing body the event may have
+  \note you must free the resulting string when you are finished with it
 */
-SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char *buf, switch_size_t buflen, char *fmt, ...);
+SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str);
 
 /*!
   \brief Render a XML representation of an event sutable for printing or network transport

Modified: freeswitch/branches/knhor/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/knhor/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/branches/knhor/trunk/src/include/switch_ivr.h	Sat Nov 11 14:39:20 2006
@@ -229,8 +229,9 @@
   \param bad_input_audio_file file to play if the input from the user was invalid
   \param digit_buffer variable digits captured will be put back into (empty if capture failed)
   \param digit_buffer_length length of the buffer for digits (should be the same or larger than max_digits)
+  \param digits_regex the qualifying regex
   \return switch status, used to note status of channel (will still return success if digit capture failed)
-  \note to test for digit capture failure look for \0 in the first position of the buffer
+  \note to test for digit capture failure look for \\0 in the first position of the buffer
 */
 SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
                                                            unsigned int min_digits,
@@ -378,7 +379,7 @@
 
 /*!
   \brief Signal the session with a protocol specific unhold message.
-  \param uuid the uuid of the session to unhold
+  \param session the session to unhold
   \return SWITCH_STATUS_SUCCESS if all is well
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session);

Modified: freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c	Sat Nov 11 14:39:20 2006
@@ -158,17 +158,20 @@
 
 	if (send) {
 		char *packet;
-		memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
-		packet = buf + sizeof(globals.host_hash);
-		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", globals.hostname);
+		
 		switch (event->event_id) {
 		case SWITCH_EVENT_LOG:
 			return;
 		default:
-			switch_event_serialize(event, packet, sizeof(buf) - sizeof(globals.host_hash), NULL);
-			len = strlen(packet) + sizeof(globals.host_hash);;
-			//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf);
-			switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", globals.hostname);
+			if (switch_event_serialize(event, &packet) == SWITCH_STATUS_SUCCESS) {
+				memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
+				switch_copy_string(buf + sizeof(globals.host_hash), packet, sizeof(buf) - sizeof(globals.host_hash));
+				len = strlen(packet) + sizeof(globals.host_hash);;
+				//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf);
+				switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
+				switch_safe_free(packet);
+			}
 			break;
 		}
 	}

Modified: freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Sat Nov 11 14:39:20 2006
@@ -345,24 +345,18 @@
 				if (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 					char hbuf[512];
 					switch_event_t *event = (switch_event_t *) pop;
-					char *etype, *packet, *xmlstr = NULL;
+					char *etype;
 
-					if (!listener->ebuf) {
-						listener->ebuf = switch_core_alloc(listener->pool, CMD_BUFLEN);
-					}
-
 					do_sleep = 0;
 					if (listener->format == EVENT_FORMAT_PLAIN) {
 						etype = "plain";
-						switch_event_serialize(event, listener->ebuf, CMD_BUFLEN, NULL);
-						packet = listener->ebuf;
+						switch_event_serialize(event, &listener->ebuf);
 					} else {
 						switch_xml_t xml;
 						etype = "xml";
 
 						if ((xml = switch_event_xmlize(event, NULL))) {
-							xmlstr = switch_xml_toxml(xml);
-							packet = xmlstr;
+							listener->ebuf = switch_xml_toxml(xml);
 							switch_xml_free(xml);
 						} else {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XML ERROR!\n");
@@ -370,7 +364,7 @@
 						}
 					}
 			
-					len = strlen(packet);
+					len = strlen(listener->ebuf);
 
 					snprintf(hbuf, sizeof(hbuf), "Content-Length: %"APR_SSIZE_T_FMT"\n" 
 							 "Content-Type: text/event-%s\n"
@@ -379,12 +373,10 @@
 					len = strlen(hbuf);
 					switch_socket_send(listener->sock, hbuf, &len);
 
-					len = strlen(packet);
-					switch_socket_send(listener->sock, packet, &len);
+					len = strlen(listener->ebuf);
+					switch_socket_send(listener->sock, listener->ebuf, &len);
 
-					if (xmlstr) {
-						free(xmlstr);
-					}
+					switch_safe_free(listener->ebuf);
 				}
 			}
 		}
@@ -392,7 +384,9 @@
 			switch_yield(1000);
 		}
 	}
-	
+
+
+
 	return status;
 
 }

Modified: freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c	Sat Nov 11 14:39:20 2006
@@ -38,7 +38,7 @@
 
 static void event_handler(switch_event_t *event)
 {
-	char buf[1024];
+	char *buf;
 	switch_xml_t xml;
 	char *xmlstr = "N/A";
 	uint8_t dofree = 0;
@@ -47,7 +47,7 @@
 	case SWITCH_EVENT_LOG:
 		return;
 	default:
-		switch_event_serialize(event, buf, sizeof(buf), NULL);
+		switch_event_serialize(event, &buf);
 		if ((xml = switch_event_xmlize(event, NULL))) {
 			xmlstr = switch_xml_toxml(xml);
 			dofree++;
@@ -58,6 +58,8 @@
 		break;
 	}
 
+	switch_safe_free(buf);
+	
 	if (dofree) {
 		if (xml) {
 			switch_xml_free(xml);

Modified: freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c	Sat Nov 11 14:39:20 2006
@@ -60,7 +60,7 @@
 
 static void event_handler(switch_event_t *event)
 {
-	char buf[1024];
+	char *buf;
 	iks *msg;
 	int loops = 0;
 
@@ -78,12 +78,13 @@
 
 	switch (event->event_id) {
 	default:
-		switch_event_serialize(event, buf, sizeof(buf), NULL);
+		switch_event_serialize(event, &buf);
 		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf);
 		msg = iks_make_msg(IKS_TYPE_NONE, globals.target_jid, buf);
 		iks_insert_attrib(msg, "subject", "Event");
 		iks_send(globals.session.parser, msg);
 		iks_delete(msg);
+		switch_safe_free(buf);
 		break;
 	}
 }

Modified: freeswitch/branches/knhor/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Sat Nov 11 14:39:20 2006
@@ -264,7 +264,7 @@
 static JSBool event_serialize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
 	struct event_obj *eo = JS_GetPrivate(cx, obj);
-	char buf[1024];
+	char *buf;
 	uint8_t isxml = 0;
 
 	if (!eo) {
@@ -291,8 +291,10 @@
 			*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
 		}
 	} else {
-		switch_event_serialize(eo->event, buf, sizeof(buf), NULL);
-		*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, buf));
+		if (switch_event_serialize(eo->event, &buf) == SWITCH_STATUS_SUCCESS) {
+			*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, buf));
+			switch_safe_free(buf);
+		}
 	}
 
 	return JS_TRUE;

Modified: freeswitch/branches/knhor/trunk/src/switch_core.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/switch_core.c	(original)
+++ freeswitch/branches/knhor/trunk/src/switch_core.c	Sat Nov 11 14:39:20 2006
@@ -3695,9 +3695,6 @@
 									 );
 		break;
 	default:
-		//buf[0] = '\0';
-		//switch_event_serialize(event, buf, sizeof(buf), NULL);
-		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
 		break;
 	}
 

Modified: freeswitch/branches/knhor/trunk/src/switch_event.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/switch_event.c	(original)
+++ freeswitch/branches/knhor/trunk/src/switch_event.c	Sat Nov 11 14:39:20 2006
@@ -596,55 +596,59 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char *buf, switch_size_t buflen, char *fmt, ...)
+SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str)
 {
 	switch_size_t len = 0;
 	switch_event_header_t *hp;
-	char *data = NULL, *body = NULL;
-	int ret = 0;
-	va_list ap;
+	switch_size_t llen = 0, dlen = 0, blocksize = 512;
+	char *buf;
+	
+	*str = NULL;
 
-	if (fmt) {
-		va_start(ap, fmt);
-#ifdef HAVE_VASPRINTF
-		ret = vasprintf(&data, fmt, ap);
-#else
-		data = (char *) malloc(2048);
-		ret = vsnprintf(data, 2048, fmt, ap);
-#endif
-		va_end(ap);
-		if (ret == -1) {
-			return SWITCH_STATUS_MEMERR;
-		}
+	if (!(buf = malloc(blocksize))) {
+		return SWITCH_STATUS_MEMERR;
 	}
 
+	dlen = blocksize;
+
 	for (hp = event->headers; hp; hp = hp->next) {
-		snprintf(buf + len, buflen - len, "%s: %s\n", hp->name, hp->value);
-		len = strlen(buf);
+		llen = strlen(hp->name) + strlen(hp->value) + 2;
+		
+		if ((len + llen) > dlen) {
+			dlen += (blocksize + (len + llen));
+			buf = realloc(buf, dlen);
+		}
 
+		snprintf(buf + len, dlen - len, "%s: %s\n", hp->name, hp->value);
+		len = strlen(buf);
 	}
 
-	if (data) {
-		body = data;
-	} else if (event->body) {
-		body = event->body;
-	}
+	if (event->body) {
+		int blen = (int) strlen(event->body);
+		llen = blen;
 
-	if (body) {
-		int blen = (int) strlen(body);
 		if (blen) {
-			snprintf(buf + len, buflen - len, "Content-Length: %d\n\n%s", blen, body);
+			llen += 25;
 		} else {
-			snprintf(buf + len, buflen - len, "\n");
+			llen += 5;
 		}
+		
+		if ((len + llen) > dlen) {
+			dlen += (blocksize + (len + llen));
+			buf = realloc(buf, dlen);
+		}
+
+		if (blen) {
+			snprintf(buf + len, dlen - len, "Content-Length: %d\n\n%s", blen, event->body);
+		} else {
+			snprintf(buf + len, dlen - len, "\n");
+		}
 	} else {
-		snprintf(buf + len, buflen - len, "\n");
+		snprintf(buf + len, dlen - len, "\n");
 	}
 
-	if (data) {
-		free(data);
-	}
-
+	*str = buf;
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 



More information about the Freeswitch-branches mailing list