[svn-commits] file: branch file/res_xmpp r367975 - in /team/file/res_xmpp: include/asterisk...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed May 30 11:39:19 CDT 2012
Author: file
Date: Wed May 30 11:39:15 2012
New Revision: 367975
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367975
Log:
Add some locking to protect the message ID, which can be used from multiple threads, and support the buddy configuration option.
Modified:
team/file/res_xmpp/include/asterisk/xmpp.h
team/file/res_xmpp/res/res_xmpp.c
Modified: team/file/res_xmpp/include/asterisk/xmpp.h
URL: http://svnview.digium.com/svn/asterisk/team/file/res_xmpp/include/asterisk/xmpp.h?view=diff&rev=367975&r1=367974&r2=367975
==============================================================================
--- team/file/res_xmpp/include/asterisk/xmpp.h (original)
+++ team/file/res_xmpp/include/asterisk/xmpp.h Wed May 30 11:39:15 2012
@@ -177,6 +177,20 @@
void ast_xmpp_client_unref(struct ast_xmpp_client *client);
/*!
+ * \brief Lock an XMPP client connection
+ *
+ * \param client Pointer to the client
+ */
+void ast_xmpp_client_lock(struct ast_xmpp_client *client);
+
+/*!
+ * \brief Unlock an XMPP client connection
+ *
+ * \param client Pointer to the client
+ */
+void ast_xmpp_client_unlock(struct ast_xmpp_client *client);
+
+/*!
* \brief Send an XML stanza out using an established XMPP client connection
*
* \param client Pointer to the client
Modified: team/file/res_xmpp/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/res_xmpp/res/res_xmpp.c?view=diff&rev=367975&r1=367974&r2=367975
==============================================================================
--- team/file/res_xmpp/res/res_xmpp.c (original)
+++ team/file/res_xmpp/res/res_xmpp.c Wed May 30 11:39:15 2012
@@ -504,6 +504,16 @@
ao2_ref(client, -1);
}
+void ast_xmpp_client_lock(struct ast_xmpp_client *client)
+{
+ ao2_lock(client);
+}
+
+void ast_xmpp_client_unlock(struct ast_xmpp_client *client)
+{
+ ao2_unlock(client);
+}
+
/*! \brief Internal function used to send a message to a user or chatroom */
static int xmpp_client_send_message(struct ast_xmpp_client *client, int group, const char *nick, const char *address, const char *message)
{
@@ -546,8 +556,10 @@
}
iks_insert_attrib(invite, "to", user);
+ ast_xmpp_client_lock(client);
iks_insert_attrib(invite, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
iks_insert_cdata(body, message, 0);
iks_insert_node(invite, body);
iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
@@ -644,8 +656,10 @@
iks_insert_attrib(request, "to", client->pubsubnode);
iks_insert_attrib(request, "from", client->jid->full);
iks_insert_attrib(request, "type", type);
+ ast_xmpp_client_lock(client);
ast_xmpp_increment_mid(client->mid);
iks_insert_attrib(request, "id", client->mid);
+ ast_xmpp_client_unlock(client);
return request;
}
@@ -1752,7 +1766,7 @@
ast_copy_string(buddy->id, id, sizeof(buddy->id));
- /* Assume we need to get subscribe to get their presence until proven otherwise */
+ /* Assume we need to subscribe to get their presence until proven otherwise */
buddy->subscribe = 1;
ao2_link(client->buddies, buddy);
@@ -2202,15 +2216,17 @@
ast_sha1_hash(buf, sidpass);
iks_insert_cdata(iks_insert(query, "digest"), buf, 0);
+ ast_xmpp_client_lock(client);
+ iks_filter_add_rule(client->filter, xmpp_connect_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid, IKS_RULE_DONE);
iks_insert_attrib(iq, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
+
iks_insert_attrib(iq, "to", client->jid->server);
ast_xmpp_client_send(client, iq);
iks_delete(iq);
-
- iks_filter_add_rule(client->filter, xmpp_connect_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid, IKS_RULE_DONE);
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATING);
@@ -2303,8 +2319,10 @@
return -1;
}
+ ast_xmpp_client_lock(client);
iks_insert_attrib(auth, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
ast_xmpp_client_send(client, auth);
iks_delete(auth);
@@ -2321,7 +2339,9 @@
}
iks_insert_attrib(auth, "id", "auth");
+ ast_xmpp_client_lock(client);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
ast_xmpp_client_send(client, auth);
iks_delete(auth);
@@ -2519,8 +2539,10 @@
iks_insert_attrib(presence, "from", client->jid->full);
iks_insert_attrib(presence, "to", pak->from->partial);
+ ast_xmpp_client_lock(client);
iks_insert_attrib(presence, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
iks_insert_attrib(presence, "type", "subscribe");
iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
@@ -2637,10 +2659,14 @@
if ((msg = ast_msg_alloc())) {
int res;
+ ast_xmpp_client_lock(client);
+
res = ast_msg_set_to(msg, "xmpp:%s", client->user);
res |= ast_msg_set_from(msg, "xmpp:%s", message->from);
res |= ast_msg_set_body(msg, "%s", message->message);
res |= ast_msg_set_context(msg, "%s", client->context);
+
+ ast_xmpp_client_unlock(client);
if (res) {
ast_msg_destroy(msg);
@@ -2680,8 +2706,10 @@
iks_insert_attrib(iq, "type", "get");
iks_insert_attrib(iq, "to", to);
iks_insert_attrib(iq, "from", from);
+ ast_xmpp_client_lock(client);
iks_insert_attrib(iq, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
+ ast_xmpp_client_unlock(client);
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
iks_insert_node(iq, query);
@@ -3189,6 +3217,26 @@
}
}
+/*! \brief Helper function which interpets a buddy configuration value and stores it on a client */
+static void store_config_buddy(struct ast_xmpp_client *client, const char *value)
+{
+ struct ast_xmpp_buddy *buddy;
+
+ ao2_lock(client->buddies);
+
+ /* If the buddy already exists in the roster don't bother adding it */
+ if ((buddy = ao2_find(client->buddies, value, OBJ_KEY | OBJ_NOLOCK))) {
+ ao2_unlock(client->buddies);
+ return;
+ }
+
+ if ((buddy = xmpp_client_create_buddy(client, value))) {
+ ao2_ref(buddy, -1);
+ }
+
+ ao2_unlock(client->buddies);
+}
+
/*! \brief Internal function used to store client configuration information */
static void store_config_client(struct ast_config *cfg, const char *category)
{
@@ -3276,8 +3324,7 @@
CV_STR("context", client->context);
CV_F("sendtodialplan", ast_set2_flag(&client->flags, ast_true(__val), XMPP_SEND_TO_DIALPLAN));
CV_F("status", store_config_status(client, __val));
-
- /* Items to do: buddy */
+ CV_F("buddy", store_config_buddy(client, __val));
CV_END;
}
More information about the svn-commits
mailing list