[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r260561 - in /team/eliel/data...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun May 2 01:45:58 CDT 2010


Author: eliel
Date: Sun May  2 01:45:53 2010
New Revision: 260561

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=260561
Log:
- Simplify the search engine.
- Add SIP data provider.


Modified:
    team/eliel/data_api_providers_gsoc2010/apps/app_queue.c
    team/eliel/data_api_providers_gsoc2010/apps/app_voicemail.c
    team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c
    team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
    team/eliel/data_api_providers_gsoc2010/main/data.c

Modified: team/eliel/data_api_providers_gsoc2010/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/apps/app_queue.c?view=diff&rev=260561&r1=260560&r2=260561
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/apps/app_queue.c (original)
+++ team/eliel/data_api_providers_gsoc2010/apps/app_queue.c Sun May  2 01:45:53 2010
@@ -7734,19 +7734,12 @@
 static void queues_data_provider_get_helper(const struct ast_data_search *search,
 	struct ast_data *data_root, struct call_queue *queue)
 {
-	int member_notmatch, caller_notmatch, caller_channel_notmatch;
 	struct ao2_iterator im;
 	struct member *member;
 	struct queue_ent *qe;
 	struct ast_data *data_queue, *data_members = NULL;
 	struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
 
-	/* compare the search pattern. */
-	if (ast_data_search_cmp_structure(search, call_queue, queue, "queue")) {
-		/* this doesn't match! continue! */
-		return;
-	}
-
 	data_queue = ast_data_add_node(data_root, "queue");
 	if (!data_queue) {
 		return;
@@ -7754,16 +7747,9 @@
 
 	ast_data_add_structure(call_queue, data_queue, queue);
 
-	member_notmatch = ast_data_search_has_condition(search, "queue/members/member");
 	/* add queue members */
 	im = ao2_iterator_init(queue->members, 0);
 	while ((member = ao2_iterator_next(&im))) {
-		/* compare the member structure. */
-		if (!ast_data_search_cmp_structure(search, member, member,
-					"queue/members/member")) {
-			member_notmatch = 0;
-		}
-
 		if (!data_members) {
 			data_members = ast_data_add_node(data_queue, "members");
 			if (!data_members) {
@@ -7783,28 +7769,9 @@
 		ao2_ref(member, -1);
 	}
 
-	if (member_notmatch) {
-		ast_data_remove_node(data_root, data_queue);
-		return;
-	}
-
-	caller_notmatch = ast_data_search_has_condition(search, "queue/callers/caller");
-	caller_channel_notmatch = ast_data_search_has_condition(search,
-		"queue/callers/caller/channel");
 	/* include the callers inside the result. */
 	if (queue->head) {
 		for (qe = queue->head; qe; qe = qe->next) {
-			/* compare the member structure. */
-			if (!ast_data_search_cmp_structure(search, queue_ent, qe,
-						"queue/callers/caller")) {
-				caller_notmatch = 0;
-			}
-
-			if (!ast_channel_data_cmp_structure(search, qe->chan,
-				"queue/callers/caller/channel")) {
-				caller_channel_notmatch = 0;
-			}
-
 			if (!data_callers) {
 				data_callers = ast_data_add_node(data_queue, "callers");
 				if (!data_callers) {
@@ -7830,7 +7797,7 @@
 	}
 
 	/* if this queue doesn't match remove the added queue. */
-	if (caller_notmatch || caller_channel_notmatch) {
+	if (!ast_data_search_match(search, data_queue)) {
 		ast_data_remove_node(data_root, data_queue);
 	}
 }

Modified: team/eliel/data_api_providers_gsoc2010/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/apps/app_voicemail.c?view=diff&rev=260561&r1=260560&r2=260561
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/apps/app_voicemail.c (original)
+++ team/eliel/data_api_providers_gsoc2010/apps/app_voicemail.c Sun May  2 01:45:53 2010
@@ -10864,11 +10864,6 @@
 #endif
 	struct vm_zone *zone = NULL;
 
-	/* check the search pattern to make sure it's valid to add it */
-	if (ast_data_search_cmp_structure(search, ast_vm_user, user, "user")) {
-		return;
-	}
-
 	data_user = ast_data_add_node(data_root, "user");
 	if (!data_user) {
 		return;
@@ -10890,16 +10885,6 @@
 
 	/* TODO: Should a user's vm state be accessible without compiling in
 	 *       IMAP support? */
-
-	if (
-#ifdef IMAP_STORAGE
-		!ast_data_search_cmp_structure(search, vm_state, state, "user/state") ||
-#endif
-		(zone && !ast_data_search_cmp_structure(search, vm_zone,
-							zone, "user/zone"))) {
-		ast_data_remove_node(data_root, data_user);
-		return;
-	}
 
 #ifdef IMAP_STORAGE
 	data_state = ast_data_add_node(data_user, "state");
@@ -10911,6 +10896,10 @@
 	if (zone) {
 		data_zone = ast_data_add_node(data_user, "zone");
 		ast_data_add_structure(vm_zone, data_zone, zone);
+	}
+
+	if (!ast_data_search_match(search, data_user)) {
+		ast_data_remove_node(data_root, data_user);
 	}
 
 	return;

Modified: team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c?view=diff&rev=260561&r1=260560&r2=260561
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c Sun May  2 01:45:53 2010
@@ -261,6 +261,7 @@
 #include "asterisk/event.h"
 #include "asterisk/stun.h"
 #include "asterisk/cel.h"
+#include "asterisk/data.h"
 #include "sip/include/sip.h"
 #include "sip/include/globals.h"
 #include "sip/include/config_parser.h"
@@ -27053,6 +27054,153 @@
 	sip_dialplan_function_unregister_tests();
 }
 
+#define DATA_EXPORT_SIP_PEER(MEMBER)				\
+	MEMBER(sip_peer, name, AST_DATA_STRING)			\
+	MEMBER(sip_peer, secret, AST_DATA_STRING)		\
+	MEMBER(sip_peer, md5secret, AST_DATA_STRING)		\
+	MEMBER(sip_peer, remotesecret, AST_DATA_STRING) 	\
+	MEMBER(sip_peer, context, AST_DATA_STRING)		\
+	MEMBER(sip_peer, subscribecontext, AST_DATA_STRING)	\
+	MEMBER(sip_peer, username, AST_DATA_STRING)		\
+	MEMBER(sip_peer, accountcode, AST_DATA_STRING)		\
+	MEMBER(sip_peer, tohost, AST_DATA_STRING)		\
+	MEMBER(sip_peer, regexten, AST_DATA_STRING)		\
+	MEMBER(sip_peer, fromuser, AST_DATA_STRING)		\
+	MEMBER(sip_peer, fromdomain, AST_DATA_STRING)		\
+	MEMBER(sip_peer, fullcontact, AST_DATA_STRING)		\
+	MEMBER(sip_peer, cid_num, AST_DATA_STRING)		\
+	MEMBER(sip_peer, cid_name, AST_DATA_STRING)		\
+	MEMBER(sip_peer, vmexten, AST_DATA_STRING)		\
+	MEMBER(sip_peer, language, AST_DATA_STRING)		\
+	MEMBER(sip_peer, mohinterpret, AST_DATA_STRING)		\
+	MEMBER(sip_peer, mohsuggest, AST_DATA_STRING)		\
+	MEMBER(sip_peer, parkinglot, AST_DATA_STRING)		\
+	MEMBER(sip_peer, useragent, AST_DATA_STRING)		\
+	MEMBER(sip_peer, mwi_from, AST_DATA_STRING)		\
+	MEMBER(sip_peer, engine, AST_DATA_STRING)		\
+	MEMBER(sip_peer, unsolicited_mailbox, AST_DATA_STRING)	\
+	MEMBER(sip_peer, transports, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, is_realtime, AST_DATA_BOOLEAN)		\
+	MEMBER(sip_peer, host_dynamic, AST_DATA_BOOLEAN)	\
+	MEMBER(sip_peer, autoframing, AST_DATA_BOOLEAN)		\
+	MEMBER(sip_peer, deprecated_username, AST_DATA_BOOLEAN)	\
+	MEMBER(sip_peer, amaflags, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, callingpres, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, inUse, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, inRinging, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, onHold, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, call_limit, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, t38_maxdatagram, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, allowtransfer, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, lastmsgssent, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, sipoptions, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, maxcallbitrate, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, expire, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, rtptimeout, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, rtpholdtimeout, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, rtpkeepalive, AST_DATA_INTEGER)	\
+	MEMBER(sip_peer, pokeexpire, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, lastms, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, maxms, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, qualifyfreq, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, timer_t1, AST_DATA_INTEGER)		\
+	MEMBER(sip_peer, timer_b, AST_DATA_INTEGER)
+
+AST_DATA_STRUCTURE(sip_peer, DATA_EXPORT_SIP_PEER);
+
+static int peers_data_provider_get(const struct ast_data_search *search,
+	struct ast_data *data_root)
+{
+	struct sip_peer *peer;
+	struct ao2_iterator i;
+	struct ast_data *data_peer, *data_peer_mailboxes = NULL, *data_peer_mailbox;
+	struct ast_data *data_peer_codecs, *data_peer_codec;
+	int total_mailboxes;
+	struct sip_mailbox *mailbox;
+	int x;
+	const struct ast_format_list *fmlist;
+	size_t fmlist_size;
+
+	i = ao2_iterator_init(peers, 0);
+	while ((peer = ao2_iterator_next(&i))) {
+		ao2_lock(peer);
+
+		data_peer = ast_data_add_node(data_root, "peer");
+		if (!data_peer) {
+			ao2_unlock(peer);
+			continue;
+		}
+
+		ast_data_add_structure(sip_peer, data_peer, peer);
+
+		/* peer type */
+		if ((peer->type & SIP_TYPE_USER) && (peer->type & SIP_TYPE_PEER)) {
+			ast_data_add_str(data_peer, "type", "friend");
+		} else if (peer->type & SIP_TYPE_PEER) {
+			ast_data_add_str(data_peer, "type", "peer");
+		} else if (peer->type & SIP_TYPE_USER) {
+			ast_data_add_str(data_peer, "type", "user");
+		}
+
+		/* mailboxes */
+		total_mailboxes = 0;
+		AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
+			if (!total_mailboxes) {
+				data_peer_mailboxes = ast_data_add_node(data_peer, "mailboxes");
+				if (!data_peer_mailboxes) {
+					break;
+				}
+				total_mailboxes++;
+			}
+
+			data_peer_mailbox = ast_data_add_node(data_peer_mailboxes, "mailbox");
+			if (!data_peer_mailbox) {
+				continue;
+			}
+			ast_data_add_str(data_peer_mailbox, "mailbox", mailbox->mailbox);
+			ast_data_add_str(data_peer_mailbox, "context", mailbox->context);
+		}
+
+		/* codecs */
+		data_peer_codecs = ast_data_add_node(data_peer, "codecs");
+		if (!data_peer_codecs) {
+			ao2_unlock(peer);
+			continue;
+		}
+		fmlist = ast_get_format_list(&fmlist_size);
+		for (x = 0; x < fmlist_size; x++) {
+			if (fmlist[x].bits & peer->capability) {
+				data_peer_codec = ast_data_add_node(data_peer_codecs, "codec");
+				if (!data_peer_codec) {
+					continue;
+				}
+				ast_data_add_str(data_peer_codec, "name", fmlist[x].name);
+				ast_data_add_int(data_peer_codec, "samplespersecond", fmlist[x].samplespersecond);
+				ast_data_add_str(data_peer_codec, "description", fmlist[x].desc);
+				ast_data_add_int(data_peer_codec, "frame_length", fmlist[x].fr_len);
+			}
+		}
+
+		if (!ast_data_search_match(search, data_peer)) {
+			ast_data_remove_node(data_root, data_peer);
+		}
+
+		ao2_unlock(peer);
+	}
+	ao2_iterator_destroy(&i);
+
+	return 0;
+}
+
+static const struct ast_data_handler peers_data_provider = {
+	.version = AST_DATA_HANDLER_VERSION,
+	.get = peers_data_provider_get
+};
+
+static const struct ast_data_entry sip_data_providers[] = {
+	AST_DATA_ENTRY("asterisk/channel/chan_sip/peers", &peers_data_provider),
+};
+
 /*! \brief PBX load module - initialization */
 static int load_module(void)
 {
@@ -27098,6 +27246,9 @@
 		sched_context_destroy(sched);
 		return AST_MODULE_LOAD_FAILURE;
 	}
+
+	/* Register AstData providers */
+	ast_data_register_multiple(sip_data_providers, ARRAY_LEN(sip_data_providers));
 
 	/* Register all CLI functions for SIP */
 	ast_cli_register_multiple(cli_sip, ARRAY_LEN(cli_sip));
@@ -27192,6 +27343,9 @@
 	ast_unregister_application(app_sipaddheader);
 	ast_unregister_application(app_sipremoveheader);
 
+	/* Unregister all the AstData providers */
+	ast_data_unregister(NULL);
+
 	/* Unregister CLI commands */
 	ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip));
 

Modified: team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h?view=diff&rev=260561&r1=260560&r2=260561
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h (original)
+++ team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h Sun May  2 01:45:53 2010
@@ -367,6 +367,11 @@
 #define ast_data_unregister(path) __ast_data_unregister(path, __FILE__)
 
 /*!
+ * \TODO Complete documentation.
+ */
+int ast_data_search_match(const struct ast_data_search *search, struct ast_data *data);
+
+/*!
  * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
  *        current string value.
  *        .search = "somename=somestring"

Modified: team/eliel/data_api_providers_gsoc2010/main/data.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/data.c?view=diff&rev=260561&r1=260560&r2=260561
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/data.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/data.c Sun May  2 01:45:53 2010
@@ -58,6 +58,8 @@
 	</manager>
  ***/
 
+static struct ast_data *data_result_find_child(struct ast_data *root, const char *name);
+
 #define NUM_DATA_NODE_BUCKETS	59
 #define NUM_DATA_RESULT_BUCKETS 59
 #define NUM_DATA_SEARCH_BUCKETS 59
@@ -979,6 +981,94 @@
 	}
 
 	return current;
+}
+
+int ast_data_search_match(const struct ast_data_search *search, struct ast_data *data)
+{
+	struct ao2_iterator i, ii;
+	struct ast_data_search *s, *s_child;
+	struct ast_data *d_child;
+	int notmatch = 1;
+
+	if (!search) {
+		return 1;
+	}
+
+	s_child = data_search_find(search->children, data->name);
+	if (!s_child) {
+		/* nothing to compare */
+		return 1;
+	}
+
+	i = ao2_iterator_init(s_child->children, 0);
+	while ((s = ao2_iterator_next(&i))) {
+		if (!ao2_container_count(s->children)) {
+			/* compare this search node with every data node */
+			d_child = data_result_find_child(data, s->name);
+			if (!d_child) {
+				ao2_ref(s, -1);
+				notmatch = 1;
+				continue;
+			}
+
+			switch (d_child->type) {
+			case AST_DATA_STRING:
+				notmatch = ast_data_search_cmp_string(s_child, d_child->name,
+					d_child->payload.str);
+				break;
+			case AST_DATA_INTEGER:
+				notmatch = ast_data_search_cmp_int(s_child, d_child->name,
+					d_child->payload.sint);
+				break;
+			case AST_DATA_BOOLEAN:
+				notmatch = ast_data_search_cmp_bool(s_child, d_child->name,
+					d_child->payload.boolean);
+				break;
+			case AST_DATA_UNSIGNED_INTEGER:
+				notmatch = ast_data_search_cmp_uint(s_child, d_child->name,
+					d_child->payload.uint);
+				break;
+			case AST_DATA_DOUBLE:
+				notmatch = ast_data_search_cmp_dbl(s_child, d_child->name,
+					d_child->payload.dbl);
+				break;
+			case AST_DATA_IPADDR:
+				notmatch = ast_data_search_cmp_ipaddr(s_child, d_child->name,
+					d_child->payload.ipaddr);
+				break;
+			case AST_DATA_POINTER:
+				notmatch = ast_data_search_cmp_ptr(s_child, d_child->name,
+					d_child->payload.ptr);
+				break;
+			case AST_DATA_CONTAINER:
+				break;
+			}
+			ao2_ref(d_child, -1);
+		} else {
+			ii = ao2_iterator_init(data->children, 0);
+			while ((d_child = ao2_iterator_next(&ii))) {
+				if (strcmp(d_child->name, s->name)) {
+					ao2_ref(d_child, -1);
+					continue;
+				}
+				if (!(notmatch = !ast_data_search_match(s_child, d_child))) {
+					/* do not continue if we have a match. */
+					ao2_ref(d_child, -1);
+					break;
+				}
+				ao2_ref(d_child, -1);
+			}
+			ao2_iterator_destroy(&ii);
+		}
+		ao2_ref(s, -1);
+		if (notmatch) {
+			/* do not continue if we don't have a match. */
+			break;
+		}
+	}
+	ao2_iterator_destroy(&i);
+
+	return !notmatch;
 }
 
 int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name,




More information about the asterisk-commits mailing list