Allow gtalk and jingle to use TLS connections again.
authorJason Parker <jparker@digium.com>
Tue, 6 Nov 2007 18:44:19 +0000 (18:44 +0000)
committerJason Parker <jparker@digium.com>
Tue, 6 Nov 2007 18:44:19 +0000 (18:44 +0000)
Closes issue #9972

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89041 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_gtalk.c
channels/chan_jingle.c
include/asterisk/jabber.h
res/res_jabber.c

index f67cd6c..5666af9 100644 (file)
@@ -436,7 +436,7 @@ static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, in
        iks_insert_node(gtalk, transport);
        iks_insert_node(dcodecs, payload_telephone);
 
-       iks_send(client->connection->p, iq);
+       ast_aji_send(client->connection, iq);
        iks_delete(payload_telephone);
        iks_delete(transport);
        iks_delete(dcodecs);
@@ -473,7 +473,7 @@ static int gtalk_invite_response(struct gtalk_pvt *p, char *to , char *from, cha
        iks_insert_attrib(transport, "xmlns", "http://www.google.com/transport/p2p");
        iks_insert_node(iq,session);
        iks_insert_node(session,transport);
-       iks_send(p->parent->connection->p, iq);
+       ast_aji_send(p->parent->connection, iq);
        iks_delete(transport);
        iks_delete(session);
        iks_delete(iq);
@@ -570,7 +570,7 @@ static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const c
                                iks_insert_node(response, error);
                        }
                }
-               iks_send(client->connection->p, response);
+               ast_aji_send(client->connection, response);
                if (reason)
                        iks_delete(reason);
                if (error)
@@ -830,7 +830,7 @@ static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, ch
                        iks_insert_attrib(candidate, "type", "relay");
                iks_insert_attrib(candidate, "network", "0");
                iks_insert_attrib(candidate, "generation", "0");
-               iks_send(c->p, iq);
+               ast_aji_send(c, iq);
        }
        p->laststun = 0;
 
@@ -1036,7 +1036,7 @@ static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *a
                        iks_insert_attrib(session, "initiator", p->initiator ? p->us : p->them);
                        iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
                        iks_insert_node(request, session);
-                       iks_send(client->connection->p, request);
+                       ast_aji_send(client->connection, request);
                        iks_delete(session);
                        res = 0;
                }
@@ -1274,7 +1274,7 @@ static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
        iks_insert_attrib(receipt, "from", from);
        iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
        iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
-       iks_send(c->p, receipt);
+       ast_aji_send(c, receipt);
        iks_delete(receipt);
 
        return 1;
@@ -1447,7 +1447,7 @@ static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duratio
        } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END || duration != 0) {
                iks_insert_attrib(dtmf, "action", "button-up");
        }
-       iks_send(client->connection->p, iq);
+       ast_aji_send(client->connection, iq);
        iks_delete(iq);
        iks_delete(gtalk);
        iks_delete(dtmf);
index 1340ff8..e332159 100644 (file)
@@ -372,7 +372,7 @@ static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
                iks_insert_node(dcodecs, payload_audio);
                iks_insert_node(dcodecs, payload_cn);
 
-               iks_send(c->p, iq);
+               ast_aji_send(c, iq);
                iks_delete(payload_red);
                iks_delete(payload_audio);
                iks_delete(payload_cn);
@@ -473,7 +473,7 @@ static int jingle_response(struct jingle *client, ikspak *pak, const char *reaso
                                iks_insert_node(response, error);
                        }
                }
-               iks_send(client->connection->p, response);
+               ast_aji_send(client->connection, response);
                if (reason)
                        iks_delete(reason);
                if (error)
@@ -729,7 +729,7 @@ static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p,
                }
                iks_insert_attrib(candidate, "ufrag", tmp->ufrag);
 
-               iks_send(c->p, iq);
+               ast_aji_send(c, iq);
        }
        p->laststun = 0;
 
@@ -915,7 +915,7 @@ static int jingle_action(struct jingle *client, struct jingle_pvt *p, const char
 
                        iks_insert_node(iq, jingle);
 
-                       iks_send(client->connection->p, iq);
+                       ast_aji_send(client->connection, iq);
                        iks_delete(jingle);
                        res = 0;
                }
@@ -1124,7 +1124,7 @@ static int jingle_add_candidate(struct jingle *client, ikspak *pak)
        iks_insert_attrib(receipt, "from", c->jid->full);
        iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
        iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
-       iks_send(c->p, receipt);
+       ast_aji_send(c, receipt);
        iks_delete(receipt);
 
        return 1;
@@ -1287,7 +1287,7 @@ static int jingle_digit(struct ast_channel *ast, char digit, unsigned int durati
        } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END || duration != 0) {
                iks_insert_attrib(dtmf, "action", "button-up");
        }
-       iks_send(client->connection->p, iq);
+       ast_aji_send(client->connection, iq);
        iks_delete(iq);
        iks_delete(jingle);
        iks_delete(dtmf);
@@ -1354,7 +1354,7 @@ static int jingle_transmit_invite(struct jingle_pvt *p)
        iks_insert_node(jingle, content);
        iks_insert_node(iq, jingle);
 
-       iks_send(client->p, iq);
+       ast_aji_send(client, iq);
 
        iks_delete(iq);
        iks_delete(jingle);
index 504bcdd..4bb8b91 100644 (file)
@@ -181,8 +181,10 @@ struct aji_client_container{
        ASTOBJ_CONTAINER_COMPONENTS(struct aji_client);
 };
 
-/*! Send jabber message from connected client to jabber URI */
-int ast_aji_send(struct aji_client *client, const char *address, const char *message);
+/* !Send XML stanza over the established XMPP connection */
+int ast_aji_send(struct aji_client *client, iks *x);
+/*! Send jabber chat message from connected client to jabber URI */
+int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message);
 /*! Disconnect jabber client */
 int ast_aji_disconnect(struct aji_client *client);
 int ast_aji_check_roster(void);
index 8e21e16..7bd9601 100644 (file)
@@ -80,7 +80,6 @@ static int aji_tls_handshake(struct aji_client *client);
 static int aji_io_recv(struct aji_client *client, char *buffer, size_t buf_len, int timeout);
 static int aji_recv(struct aji_client *client, int timeout);
 static int aji_send_header(struct aji_client *client, const char *to);
-static int aji_send(struct aji_client *client, iks *x);
 static int aji_send_raw(struct aji_client *client, const char *xmlstr);
 static void aji_log_hook(void *data, const char *xmpp, size_t size, int is_incoming);
 static int aji_start_sasl(struct aji_client *client, enum ikssasltype type, char *username, char *pass);
@@ -502,7 +501,7 @@ static int aji_send_exec(struct ast_channel *chan, void *data)
                return -1;
        }
        if (strchr(args.recipient, '@') && !ast_strlen_zero(args.message))
-               ast_aji_send(client, args.recipient, args.message);
+               ast_aji_send_chat(client, args.recipient, args.message);
        return 0;
 }
 
@@ -714,7 +713,7 @@ static int aji_send_header(struct aji_client *client, const char *to)
  * \param x the XMPP packet to send
  * \return IKS_OK on success, any other value on failure
  */
-static int aji_send(struct aji_client *client, iks *x)
+int ast_aji_send(struct aji_client *client, iks *x)
 {
        return aji_send_raw(client, iks_string(iks_stack(x), x));
 }
@@ -818,7 +817,7 @@ static int aji_start_sasl(struct aji_client *client, enum ikssasltype type, char
        snprintf(s, len, "%c%s%c%s", 0, username, 0, pass);
        ast_base64encode(base64, (const unsigned char *) s, len, (len + 2) * 4 / 3);
        iks_insert_cdata(x, base64, 0);
-       aji_send(client, x);
+       ast_aji_send(client, x);
        iks_delete(x);
 
        return IKS_OK;
@@ -870,7 +869,7 @@ static int aji_act_hook(void *data, int type, iks *node)
                                        iks_insert_attrib(auth, "id", client->mid);
                                        iks_insert_attrib(auth, "to", client->jid->server);
                                        ast_aji_increment_mid(client->mid);
-                                       aji_send(client, auth);
+                                       ast_aji_send(client, auth);
                                        iks_delete(auth);
                                } else
                                        ast_log(LOG_ERROR, "Out of memory.\n");
@@ -896,7 +895,7 @@ static int aji_act_hook(void *data, int type, iks *node)
                                                        if (auth) {
                                                                iks_insert_attrib(auth, "id", client->mid);
                                                                ast_aji_increment_mid(client->mid);
-                                                               aji_send(client, auth);
+                                                               ast_aji_send(client, auth);
                                                                iks_delete(auth);
                                                        } else {
                                                                ast_log(LOG_ERROR, "Out of memory.\n");
@@ -909,7 +908,7 @@ static int aji_act_hook(void *data, int type, iks *node)
                                                        if (auth) {
                                                                iks_insert_attrib(auth, "id", "auth");
                                                                ast_aji_increment_mid(client->mid);
-                                                               aji_send(client, auth);
+                                                               ast_aji_send(client, auth);
                                                                iks_delete(auth);
                                                        } else {
                                                                ast_log(LOG_ERROR, "Out of memory.\n");
@@ -1040,7 +1039,7 @@ static int aji_register_approve_handler(void *data, ikspak *pak)
                        iks_insert_attrib(iq, "to", pak->from->full);
                        iks_insert_attrib(iq, "id", pak->id);
                        iks_insert_attrib(iq, "type", "result");
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
 
                        iks_insert_attrib(presence, "from", client->jid->full);
                        iks_insert_attrib(presence, "to", pak->from->partial);
@@ -1049,7 +1048,7 @@ static int aji_register_approve_handler(void *data, ikspak *pak)
                        iks_insert_attrib(presence, "type", "subscribe");
                        iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
                        iks_insert_node(presence, x);
-                       aji_send(client, presence); 
+                       ast_aji_send(client, presence); 
                }
        } else {
                ast_log(LOG_ERROR, "Out of memory.\n");
@@ -1099,7 +1098,7 @@ static int aji_register_query_handler(void *data, ikspak *pak)
                        iks_insert_node(iq, query);
                        iks_insert_node(iq, error);
                        iks_insert_node(error, notacceptable);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1126,7 +1125,7 @@ static int aji_register_query_handler(void *data, ikspak *pak)
                        iks_insert_cdata(instructions, explain, 0);
                        iks_insert_node(iq, query);
                        iks_insert_node(query, instructions);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1170,7 +1169,7 @@ static int aji_ditems_handler(void *data, ikspak *pak)
 
                        iks_insert_node(iq, query);
                        iks_insert_node(query, item);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1199,7 +1198,7 @@ static int aji_ditems_handler(void *data, ikspak *pak)
 
                        iks_insert_node(iq, query);
                        iks_insert_node(query, confirm);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1226,7 +1225,7 @@ static int aji_ditems_handler(void *data, ikspak *pak)
                        iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
                        iks_insert_node(iq, query);
                        iks_insert_node(query, feature);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1287,7 +1286,7 @@ static int aji_client_info_handler(void *data, ikspak *pak)
                        iks_insert_node(query, ident);
                        iks_insert_node(query, google);
                        iks_insert_node(query, disco);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else
                        ast_log(LOG_ERROR, "Out of Memory.\n");
                if (iq)
@@ -1374,7 +1373,7 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                        iks_insert_node(query, version);
                        iks_insert_node(query, vcard);
                        iks_insert_node(query, search);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1418,7 +1417,7 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                        iks_insert_attrib(confirm, "jid", client->user);
                        iks_insert_node(iq, query);
                        iks_insert_node(query, confirm);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1445,7 +1444,7 @@ static int aji_dinfo_handler(void *data, ikspak *pak)
                        iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
                        iks_insert_node(iq, query);
                        iks_insert_node(query, feature);
-                       aji_send(client, iq);
+                       ast_aji_send(client, iq);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1686,7 +1685,7 @@ static void aji_handle_presence(struct aji_client *client, ikspak *pak)
                                ast_aji_increment_mid(client->mid);
                                iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
                                iks_insert_node(iq, query);
-                               aji_send(client, iq);
+                               ast_aji_send(client, iq);
                                
                        } else
                                ast_log(LOG_ERROR, "Out of memory.\n");
@@ -1750,7 +1749,7 @@ static void aji_handle_subscribe(struct aji_client *client, ikspak *pak)
                                iks_insert_attrib(presence, "id", pak->id);
                        iks_insert_cdata(status, "Asterisk has approved subscription", 0);
                        iks_insert_node(presence, status);
-                       aji_send(client, presence);
+                       ast_aji_send(client, presence);
                } else
                        ast_log(LOG_ERROR, "Unable to allocate nodes\n");
                if (presence)
@@ -1787,7 +1786,7 @@ static void aji_handle_subscribe(struct aji_client *client, ikspak *pak)
  * \param message
  * \return 1.
  */
-int ast_aji_send(struct aji_client *client, const char *address, const char *message)
+int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message)
 {
        int res = 0;
        iks *message_packet = NULL;
@@ -1795,7 +1794,7 @@ int ast_aji_send(struct aji_client *client, const char *address, const char *mes
                message_packet = iks_make_msg(IKS_TYPE_CHAT, address, message);
                if (message_packet) {
                        iks_insert_attrib(message_packet, "from", client->jid->full);
-                       res = aji_send(client, message_packet);
+                       res = ast_aji_send(client, message_packet);
                } else {
                        ast_log(LOG_ERROR, "Out of memory.\n");
                }
@@ -1824,7 +1823,7 @@ int ast_aji_create_chat(struct aji_client *client, char *room, char *server, cha
                iks_insert_attrib(iq, "to", server);
                iks_insert_attrib(iq, "id", client->mid);
                ast_aji_increment_mid(client->mid);
-               aji_send(client, iq);
+               ast_aji_send(client, iq);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
        return res;
@@ -1846,10 +1845,10 @@ int ast_aji_join_chat(struct aji_client *client, char *room)
                iks_insert_cdata(priority, "0", 1);
                iks_insert_attrib(presence, "to", room);
                iks_insert_node(presence, priority);
-               res = aji_send(client, presence);
+               res = ast_aji_send(client, presence);
                iks_insert_cdata(priority, "5", 1);
                iks_insert_attrib(presence, "to", room);
-               res = aji_send(client, presence);
+               res = ast_aji_send(client, presence);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
        if (presence)
@@ -1884,7 +1883,7 @@ int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char
                iks_insert_attrib(namespace, "jid", room);
                iks_insert_node(invite, body);
                iks_insert_node(invite, namespace);
-               res = aji_send(client, invite);
+               res = ast_aji_send(client, invite);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
        if (body)
@@ -1997,7 +1996,7 @@ static int aji_register_transport(void *data, ikspak *pak)
                iks_insert_attrib(send, "id", client->mid);
                ast_aji_increment_mid(client->mid);
                iks_insert_attrib(send, "from", client->user);
-               res = aji_send(client, send);
+               res = ast_aji_send(client, send);
        } else 
                ast_log(LOG_ERROR, "Out of memory.\n");
 
@@ -2042,7 +2041,7 @@ static int aji_register_transport2(void *data, ikspak *pak)
                iks_insert_node(regiq, regquery);
                iks_insert_node(regquery, reguser);
                iks_insert_node(regquery, regpass);
-               res = aji_send(client, regiq);
+               res = ast_aji_send(client, regiq);
        } else
                ast_log(LOG_ERROR, "Out of memory.\n");
        if (regiq)
@@ -2079,10 +2078,10 @@ static void aji_pruneregister(struct aji_client *client)
                        /* For an aji_buddy, both AUTOPRUNE and AUTOREGISTER will never
                         * be called at the same time */
                        if (ast_test_flag(iterator, AJI_AUTOPRUNE)) {
-                               res = aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBE, iterator->name,
+                               res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBE, iterator->name,
                                                "GoodBye your status is no longer needed by Asterisk the Open Source PBX"
                                                " so I am no longer subscribing to your presence.\n"));
-                               res = aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBED, iterator->name,
+                               res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBED, iterator->name,
                                                "GoodBye you are no longer in the asterisk config file so I am removing"
                                                " your access to my presence.\n"));
                                iks_insert_attrib(removeiq, "from", client->jid->full); 
@@ -2090,9 +2089,9 @@ static void aji_pruneregister(struct aji_client *client)
                                iks_insert_attrib(removequery, "xmlns", "jabber:iq:roster");
                                iks_insert_attrib(removeitem, "jid", iterator->name);
                                iks_insert_attrib(removeitem, "subscription", "remove");
-                               res = aji_send(client, removeiq);
+                               res = ast_aji_send(client, removeiq);
                        } else if (ast_test_flag(iterator, AJI_AUTOREGISTER)) {
-                               res = aji_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, iterator->name, 
+                               res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, iterator->name, 
                                                "Greetings I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
                                ast_clear_flag(iterator, AJI_AUTOREGISTER);
                        }
@@ -2220,7 +2219,7 @@ static int aji_get_roster(struct aji_client *client)
        if(roster) {
                iks_insert_attrib(roster, "id", "roster");
                aji_set_presence(client, NULL, client->jid->full, client->status, client->statusmessage);
-               aji_send(client, roster);
+               ast_aji_send(client, roster);
        }
        if (roster)
                iks_delete(roster);
@@ -2329,7 +2328,7 @@ static void aji_set_presence(struct aji_client *client, char *to, char *from, in
                iks_insert_attrib(cnode, "ext", "voice-v1");
                iks_insert_attrib(cnode, "xmlns", "http://jabber.org/protocol/caps");
                iks_insert_node(presence, cnode);
-               res = aji_send(client, presence);
+               res = ast_aji_send(client, presence);
        } else
                ast_log(LOG_ERROR, "Out of memory.\n");
        if (cnode)
@@ -2540,7 +2539,7 @@ static char *aji_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
        }
 
        /* XXX Does Matt really want everyone to use his personal address for tests? */ /* XXX yes he does */
-       ast_aji_send(client, "mogorman@astjab.org", "blahblah");
+       ast_aji_send_chat(client, "mogorman@astjab.org", "blahblah");
        ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
                ASTOBJ_RDLOCK(iterator);
                ast_verbose("User: %s\n", iterator->name);
@@ -2932,7 +2931,7 @@ static int manager_jabber_send(struct mansession *s, const struct message *m)
                return 0;
        }       
        if (strchr(screenname, '@') && message){
-               ast_aji_send(client, screenname, message);      
+               ast_aji_send_chat(client, screenname, message); 
                if (!ast_strlen_zero(id))
                        astman_append(s, "ActionID: %s\r\n",id);
                astman_append(s, "Response: Success\r\n");