[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r260564 - in /team/eliel/data...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 3 08:24:12 CDT 2010
Author: eliel
Date: Mon May 3 08:24:08 2010
New Revision: 260564
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=260564
Log:
- chan_iax2 data providers (peers & users).
- complete documentation.
- simplification to the chan_sip data provider.
Modified:
team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.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/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c?view=diff&rev=260564&r1=260563&r2=260564
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c Mon May 3 08:24:08 2010
@@ -90,6 +90,7 @@
#include "asterisk/astobj2.h"
#include "asterisk/timing.h"
#include "asterisk/taskprocessor.h"
+#include "asterisk/data.h"
#include "iax2.h"
#include "iax2-parser.h"
@@ -13837,6 +13838,7 @@
ast_manager_unregister( "IAXnetstats" );
ast_manager_unregister( "IAXregistry" );
ast_unregister_application(papp);
+ ast_data_unregister(NULL);
ast_cli_unregister_multiple(cli_iax2, ARRAY_LEN(cli_iax2));
ast_unregister_switch(&iax2_switch);
ast_channel_unregister(&iax2_tech);
@@ -13980,6 +13982,172 @@
return AST_MODULE_LOAD_FAILURE;
}
+#define DATA_EXPORT_IAX2_PEER(MEMBER) \
+ MEMBER(iax2_peer, name, AST_DATA_STRING) \
+ MEMBER(iax2_peer, username, AST_DATA_STRING) \
+ MEMBER(iax2_peer, secret, AST_DATA_STRING) \
+ MEMBER(iax2_peer, dbsecret, AST_DATA_STRING) \
+ MEMBER(iax2_peer, outkey, AST_DATA_STRING) \
+ MEMBER(iax2_peer, regexten, AST_DATA_STRING) \
+ MEMBER(iax2_peer, context, AST_DATA_STRING) \
+ MEMBER(iax2_peer, peercontext, AST_DATA_STRING) \
+ MEMBER(iax2_peer, mailbox, AST_DATA_STRING) \
+ MEMBER(iax2_peer, mohinterpret, AST_DATA_STRING) \
+ MEMBER(iax2_peer, mohsuggest, AST_DATA_STRING) \
+ MEMBER(iax2_peer, inkeys, AST_DATA_STRING) \
+ MEMBER(iax2_peer, cid_num, AST_DATA_STRING) \
+ MEMBER(iax2_peer, cid_name, AST_DATA_STRING) \
+ MEMBER(iax2_peer, zonetag, AST_DATA_STRING) \
+ MEMBER(iax2_peer, parkinglot, AST_DATA_STRING) \
+ MEMBER(iax2_peer, expire, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, expiry, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, callno, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, pokeexpire, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, lastms, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, maxms, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, pokefreqok, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, pokefreqnotok, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, historicms, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, smoothing, AST_DATA_INTEGER) \
+ MEMBER(iax2_peer, maxcallno, AST_DATA_INTEGER)
+
+AST_DATA_STRUCTURE(iax2_peer, DATA_EXPORT_IAX2_PEER);
+
+static int peers_data_provider_get(const struct ast_data_search *search,
+ struct ast_data *data_root)
+{
+ struct ast_data *data_peer;
+ struct iax2_peer *peer;
+ struct ao2_iterator i;
+ char status[20];
+ struct ast_str *encmethods = ast_str_alloca(256);
+
+ i = ao2_iterator_init(peers, 0);
+ while ((peer = ao2_iterator_next(&i))) {
+ data_peer = ast_data_add_node(data_root, "peer");
+ if (!data_peer) {
+ peer_unref(peer);
+ continue;
+ }
+
+ ast_data_add_structure(iax2_peer, data_peer, peer);
+
+ ast_data_add_codecs(data_peer, "codecs", peer->capability);
+
+ peer_status(peer, status, sizeof(status));
+ ast_data_add_str(data_peer, "status", status);
+
+ ast_data_add_str(data_peer, "host", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "");
+
+ ast_data_add_str(data_peer, "mask", ast_inet_ntoa(peer->mask));
+
+ ast_data_add_int(data_peer, "port", ntohs(peer->addr.sin_port));
+
+ ast_data_add_bool(data_peer, "trunk", ast_test_flag64(peer, IAX_TRUNK));
+
+ ast_data_add_bool(data_peer, "dynamic", ast_test_flag64(peer, IAX_DYNAMIC));
+
+ encmethods_to_str(peer->encmethods, encmethods);
+ ast_data_add_str(data_peer, "encryption", peer->encmethods ? ast_str_buffer(encmethods) : "no");
+
+ peer_unref(peer);
+
+ if (!ast_data_search_match(search, data_peer)) {
+ ast_data_remove_node(data_root, data_peer);
+ }
+ }
+ ao2_iterator_destroy(&i);
+
+ return 0;
+}
+
+#define DATA_EXPORT_IAX2_USER(MEMBER) \
+ MEMBER(iax2_user, name, AST_DATA_STRING) \
+ MEMBER(iax2_user, dbsecret, AST_DATA_STRING) \
+ MEMBER(iax2_user, accountcode, AST_DATA_STRING) \
+ MEMBER(iax2_user, mohinterpret, AST_DATA_STRING) \
+ MEMBER(iax2_user, mohsuggest, AST_DATA_STRING) \
+ MEMBER(iax2_user, inkeys, AST_DATA_STRING) \
+ MEMBER(iax2_user, language, AST_DATA_STRING) \
+ MEMBER(iax2_user, cid_num, AST_DATA_STRING) \
+ MEMBER(iax2_user, cid_name, AST_DATA_STRING) \
+ MEMBER(iax2_user, parkinglot, AST_DATA_STRING) \
+ MEMBER(iax2_user, amaflags, AST_DATA_INTEGER) \
+ MEMBER(iax2_user, maxauthreq, AST_DATA_INTEGER) \
+ MEMBER(iax2_user, curauthreq, AST_DATA_INTEGER) \
+ MEMBER(iax2_user, authmethods, AST_DATA_INTEGER)
+
+AST_DATA_STRUCTURE(iax2_user, DATA_EXPORT_IAX2_USER);
+
+static int users_data_provider_get(const struct ast_data_search *search,
+ struct ast_data *data_root)
+{
+ struct ast_data *data_user;
+ struct iax2_user *user;
+ struct ao2_iterator i;
+ char auth[90];
+ char *pstr = "";
+
+ i = ao2_iterator_init(users, 0);
+ while ((user = ao2_iterator_next(&i))) {
+ data_user = ast_data_add_node(data_root, "user");
+ if (!data_user) {
+ user_unref(user);
+ continue;
+ }
+
+ ast_data_add_structure(iax2_user, data_user, user);
+
+ ast_data_add_codecs(data_user, "codecs", user->capability);
+
+ if (!ast_strlen_zero(user->secret)) {
+ ast_copy_string(auth, user->secret, sizeof(auth));
+ } else if (!ast_strlen_zero(user->inkeys)) {
+ snprintf(auth, sizeof(auth), "Key: %s", user->inkeys);
+ } else {
+ ast_copy_string(auth, "no secret", sizeof(auth));
+ }
+ ast_data_add_str(data_user, "secret", auth);
+
+ ast_data_add_str(data_user, "context", user->contexts ? user->contexts->context : DEFAULT_CONTEXT);
+
+ ast_data_add_bool(data_user, "access-control", user->ha ? 1 : 0);
+
+ if (ast_test_flag64(user, IAX_CODEC_NOCAP)) {
+ pstr = "REQ only";
+ } else if (ast_test_flag64(user, IAX_CODEC_NOPREFS)) {
+ pstr = "disabled";
+ } else {
+ pstr = ast_test_flag64(user, IAX_CODEC_USER_FIRST) ? "caller" : "host";
+ }
+ ast_data_add_str(data_user, "codec-preferences", pstr);
+
+ user_unref(user);
+
+ if (!ast_data_search_match(search, data_user)) {
+ ast_data_remove_node(data_root, data_user);
+ }
+ }
+ 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_handler users_data_provider = {
+ .version = AST_DATA_HANDLER_VERSION,
+ .get = users_data_provider_get
+};
+
+static const struct ast_data_entry iax2_data_providers[] = {
+ AST_DATA_ENTRY("asterisk/channel/chan_iax2/peers", &peers_data_provider),
+ AST_DATA_ENTRY("asterisk/channel/chan_iax2/users", &users_data_provider),
+};
+
/*! \brief Load IAX2 module, load configuraiton ---*/
static int load_module(void)
{
@@ -14033,6 +14201,9 @@
}
ast_netsock_init(outsock);
+ /* Register AstData providers */
+ ast_data_register_multiple(iax2_data_providers, ARRAY_LEN(iax2_data_providers));
+
ast_cli_register_multiple(cli_iax2, ARRAY_LEN(cli_iax2));
ast_register_application_xml(papp, iax2_prov_app);
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=260564&r1=260563&r2=260564
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c Mon May 3 08:24:08 2010
@@ -27113,12 +27113,8 @@
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))) {
@@ -27164,24 +27160,7 @@
}
/* 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);
- }
- }
+ ast_data_add_codecs(data_peer, "codecs", peer->capability);
if (!ast_data_search_match(search, data_peer)) {
ast_data_remove_node(data_root, data_peer);
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=260564&r1=260563&r2=260564
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h (original)
+++ team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h Mon May 3 08:24:08 2010
@@ -24,6 +24,8 @@
#ifndef ASTERISK_DATA_H
#define ASTERISK_DATA_H
+
+#include "asterisk/frame.h"
/*!
* \page AstDataRetrieval The Asterisk DATA retrieval API.
@@ -367,7 +369,13 @@
#define ast_data_unregister(path) __ast_data_unregister(path, __FILE__)
/*!
- * \TODO Complete documentation.
+ * \brief Check the current generated node to know if it matches the search
+ * condition.
+ * \param[in] search The search condition.
+ * \param[in] data The AstData node generated.
+ * \return 1 If the "data" node matches the search condition.
+ * \return 0 If the "data" node does not matches the search condition.
+ * \see ast_data_remove_node
*/
int ast_data_search_match(const struct ast_data_search *search, struct ast_data *data);
@@ -681,6 +689,17 @@
return ret.value.AST_DATA_IPADDR;
}
+/*!
+ * \brief Add the list of codecs in the root node based on the capability parameter.
+ * \param[in] root The astdata root node where to add the codecs node.
+ * \param[in] node_name The name of the node where we are going to add the list of
+ * codecs.
+ * \param[in] capability The codecs allowed.
+ * \return < 0 on error.
+ * \return 0 on success.
+ */
+int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
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=260564&r1=260563&r2=260564
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/data.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/data.c Mon May 3 08:24:08 2010
@@ -40,6 +40,7 @@
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/test.h"
+#include "asterisk/frame.h"
/*** DOCUMENTATION
<manager name="DataGet" language="en_US">
@@ -2872,6 +2873,34 @@
return RESULT_SUCCESS;
}
+int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability)
+{
+ struct ast_data *codecs, *codec;
+ size_t fmlist_size;
+ const struct ast_format_list *fmlist;
+ int x;
+
+ codecs = ast_data_add_node(root, node_name);
+ if (!codecs) {
+ return -1;
+ }
+ fmlist = ast_get_format_list(&fmlist_size);
+ for (x = 0; x < fmlist_size; x++) {
+ if (fmlist[x].bits & capability) {
+ codec = ast_data_add_node(codecs, "codec");
+ if (!codec) {
+ return -1;
+ }
+ ast_data_add_str(codec, "name", fmlist[x].name);
+ ast_data_add_int(codec, "samplespersecond", fmlist[x].samplespersecond);
+ ast_data_add_str(codec, "description", fmlist[x].desc);
+ ast_data_add_int(codec, "frame_length", fmlist[x].fr_len);
+ }
+ }
+
+ return 0;
+}
+
#ifdef TEST_FRAMEWORK
/*!
More information about the asterisk-commits
mailing list