[asterisk-commits] branch mogorman/asterisk-xmpp r21275 - in
/team/mogorman/asterisk-xmpp: ./ ch...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Apr 18 17:15:36 MST 2006
Author: mogorman
Date: Tue Apr 18 19:15:35 2006
New Revision: 21275
URL: http://svn.digium.com/view/asterisk?rev=21275&view=rev
Log:
Im not tired.
Modified:
team/mogorman/asterisk-xmpp/ (props changed)
team/mogorman/asterisk-xmpp/channels/chan_jingle.c
team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
team/mogorman/asterisk-xmpp/res/res_jabber.c
Propchange: team/mogorman/asterisk-xmpp/
------------------------------------------------------------------------------
automerge = *
Modified: team/mogorman/asterisk-xmpp/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_jingle.c?rev=21275&r1=21274&r2=21275&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Tue Apr 18 19:15:35 2006
@@ -143,6 +143,16 @@
struct jingle_container jingles;
static int flipflop = 0;
+
+
+struct jingle *find_jingle(char *name)
+{
+ struct jingle *jingle = NULL;
+ jingle = ASTOBJ_CONTAINER_FIND(&jingles,name);
+ if(!jingle && strchr(name, '@'))
+ jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingles,name,user,,,strcasecmp);
+ return jingle;
+}
static int jingle_queue_frame(struct jingle_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
@@ -1223,17 +1233,38 @@
/*! \brief Part of PBX interface */
static struct ast_channel *jingle_request(const char *type, int format, void *data, int *cause)
{
-#if 0
- struct jingle_pvt *p;
+ ast_verbose("hello im stupid, %s and %s\n", type, data);
+ struct jingle_pvt *p = NULL;
+ struct jingle *client = NULL;
+ char *sender = NULL, *to = NULL, *s = NULL;
+
struct ast_channel *chan = NULL;
-
- p = jingle_alloc(data, format);
+ if(data) {
+ s = ast_strdupa((char *)data);
+ if (s) {
+ sender = strsep(&s,"/");
+ if(sender && (sender[0]!='\0'))
+ to = strsep(&s, "/");
+ if (!to) {
+ ast_log(LOG_ERROR, "Bad arguments\n");
+ if(s)
+ free(s);
+ return NULL;
+ }
+ }
+ }
+ ast_verbose("to : %s\n from :%s\n",to,sender);
+ client = find_jingle(to);
+ if(!client) {
+ ast_log(LOG_WARNING, "Could not find Sender.\n");
+ if(s)
+ free(s);
+ return NULL;
+ }
+ p = jingle_alloc(client, to, NULL);
if (p)
- chan = jingle_new(p, AST_STATE_DOWN);
+ chan = jingle_new(client->connection, p, AST_STATE_DOWN, to);
return chan;
-#endif
-
- return NULL;
}
#if 0
@@ -1354,6 +1385,7 @@
struct aji_client *client;
if(!member)
ast_log(LOG_WARNING, "Out of memory.\n");
+
ast_copy_string(member->name, label, sizeof(member->name));
ast_copy_string(member->user, label, sizeof(member->user));
ast_copy_string(member->context, context, sizeof(member->context));
@@ -1387,6 +1419,7 @@
}
var = var->next;
}
+ ast_verbose("LABEL: %s\n member->name %s\n member->user %s\n",label,member->name,member->user);
return 1;
}
Modified: team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/jabber.h?rev=21275&r1=21274&r2=21275&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jabber.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jabber.h Tue Apr 18 19:15:35 2006
@@ -46,6 +46,15 @@
AJI_CLIENT=1,
};
+struct aji_resource {
+ int status;
+ int jinglecapable;
+ char resource[80];
+ char description[1000];
+ int priority;
+ struct aji_resource *next;
+};
+
struct aji_buddy {
ASTOBJ_COMPONENTS(struct aji_buddy);
char user[160];
@@ -53,9 +62,9 @@
char pass[160]; /*For Transports*/
char server[160]; /*For Transports */
char channel[160];
+ struct aji_resource *resources;
enum aji_btype btype;
enum aji_prune_register on_roster;
- int status;
};
struct aji_buddy_container {
Modified: team/mogorman/asterisk-xmpp/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_jabber.c?rev=21275&r1=21274&r2=21275&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_jabber.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_jabber.c Tue Apr 18 19:15:35 2006
@@ -58,6 +58,7 @@
static void aji_log_hook(void *udata, const char *data, size_t size,int is_incoming);
static int aji_act_hook(void *udata, int type, iks * node);
static void aji_handle_iq(struct aji_client *client, iks *node);
+static void aji_handle_presence(struct aji_client *client, ikspak *pak);
static void aji_handle_subscribe(struct aji_client *client, ikspak *pak);
static void *aji_recv_loop(void *data);
static int aji_component_initialize(struct aji_client *client);
@@ -176,9 +177,9 @@
static int aji_status_exec(struct ast_channel *chan, void *data)
{
struct aji_client *client=NULL;
- struct aji_buddy *buddy=NULL;
- char *s=NULL,*sender=NULL,*screenname=NULL,*variable=NULL;
- int stat=7;
+ struct aji_resource *r=NULL;
+ char *s=NULL,*sender=NULL,*screenname=NULL, *resource = NULL,*variable=NULL;
+ int stat=7, found = 0;
char status[2];
if (data) {
s = ast_strdupa((char *)data);
@@ -198,28 +199,46 @@
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
+
+ resource = strsep(&screenname,"/");
+
client = ast_aji_get_client(sender);
if(!client) {
- ast_log(LOG_WARNING, "Could not find Sender.\n");
+ ast_log(LOG_WARNING, "Could not find Connection.\n");
return -1;
}
- if(strchr(screenname,'@')) { /*real jabber id */
- ASTOBJ_CONTAINER_TRAVERSE2(&client->buddies,1,1,{
- ASTOBJ_RDLOCK(iterator1);
- {
- if(!strcasecmp(iterator1->user,screenname)) {
- stat=iterator1->status;
+
+ ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1,{
+ ASTOBJ_RDLOCK(iterator);
+ {
+ if(!strcasecmp(iterator->user,screenname)) {
+ found=1;
+ r = iterator->resources;
+ if(!r){ /* client hasnt signed on */
+ break;
+ } else {
+ if(resource) {
+ while(r) {
+ if(!strcasecmp(r->resource,resource)) {
+ stat=r->status;
+ break;
+ }
+ r=r->next;
+ }
+ ast_log(LOG_WARNING, "Resource not found %s\n",resource);
+ } else {
+ stat=r->status;
+ break;
+ }
}
}
- ASTOBJ_UNLOCK(iterator1);
- });
- } else { /* just a label*/
- buddy=ASTOBJ_CONTAINER_FIND(&client->buddies,screenname);
- if(!buddy) {
- ast_log(LOG_WARNING, "Could not find Buddy.\n");
- return -1;
- }
- stat=buddy->status;
+ }
+ ASTOBJ_UNLOCK(iterator);
+ });
+
+ if(!found) { /* just a label*/
+ ast_log(LOG_WARNING, "Could not find Buddy in list.\n");
+ return -1;
}
sprintf(status,"%d",stat);
pbx_builtin_setvar_helper(chan, variable,status);
@@ -457,7 +476,7 @@
}
}
}
-
+
switch(pak->type) {
case IKS_PAK_NONE:
if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you NONE\n");
@@ -466,6 +485,7 @@
if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you MESSAGE\n");
break;
case IKS_PAK_PRESENCE:
+ aji_handle_presence(client,pak);
if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Do know how to handle presence!!\n");
break;
case IKS_PAK_S10N:
@@ -491,22 +511,35 @@
static int aji_register_approve_handler(void *udata,ikspak *pak)
{
struct aji_client *client = NULL;
- iks *iq = NULL, *query = NULL;
+ iks *iq = NULL, *query = NULL, *item = NULL;
client = (struct aji_client *) udata;
iq = iks_new("iq");
query = iks_new("query");
-
- if(client && iq && query) {
- iks_insert_attrib(iq, "from", client->user);
- iks_insert_attrib(iq, "to", pak->from->full);
- iks_insert_attrib(iq, "id", pak->id);
- iks_insert_attrib(iq, "type", "result");
- iks_insert_attrib(query, "xmlns", "jabber:iq:register");
-
- iks_insert_node(iq,query);
- iks_send(client->p,iq);
+ item = iks_new("item");
+
+ if(client && iq && query && item) {
+ if(!iks_find(pak->query, "remove")) {
+ iks_insert_attrib(iq, "from", client->jid->full);
+ iks_insert_attrib(iq, "to", pak->from->full);
+ iks_insert_attrib(iq, "id", pak->id);
+ iks_insert_attrib(iq, "type", "result");
+ iks_insert_attrib(query, "xmlns", "jabber:iq:register");
+
+ iks_insert_node(iq,query);
+ iks_send(client->p,iq);
+ iks_insert_attrib(iq, "from", pak->from->full);
+ iks_insert_attrib(iq, "to", pak->from->full);
+ iks_insert_attrib(iq, "id", client->mid);
+ ast_aji_increment_mid(client->mid);
+ iks_insert_attrib(iq, "type", "set");
+ iks_insert_attrib(query, "xmlns", "jabber:iq:roster");
+ iks_insert_attrib(item, "subscription" , "none");
+ iks_insert_attrib(item, "jid", client->jid->full);
+ iks_insert_node(query,item);
+ iks_send(client->p,iq);
+ }
} else {
ast_log(LOG_ERROR, "Out of memory.\n");
}
@@ -514,6 +547,9 @@
iks_delete(iq);
if(query)
iks_delete(query);
+ if(item)
+ iks_delete(item);
+
return IKS_FILTER_EAT;
}
@@ -555,7 +591,6 @@
static int aji_ditems_handler(void *udata,ikspak *pak)
{
- int res=0;
struct aji_client *client = NULL;
char *node = NULL;
@@ -590,7 +625,7 @@
iks_delete(item);
} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
- iks *iq, *query, *confirm, *emaillookup, *formatscreenname, *connectusers, *confirmaccount, *aimuritranslate, *changepassword, *stats, *updatemyvcard, *changeemail;
+ iks *iq, *query, *confirm;
iq = iks_new("iq");
query = iks_new("query");
confirm = iks_new("item");
@@ -652,7 +687,6 @@
static int aji_dinfo_handler(void *udata,ikspak *pak)
{
- int res=0;
struct aji_client *client = NULL;
char *node = NULL;
@@ -724,7 +758,7 @@
iks_delete(search);
} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
- iks *iq = NULL, *query = NULL, *confirm = NULL, *emaillookup = NULL, *formatscreenname = NULL, *connectusers = NULL, *confirmaccount = NULL, *aimuritranslate = NULL, *changepassword = NULL, *stats = NULL, *updatemyvcard = NULL, *changeemail = NULL;
+ iks *iq = NULL, *query = NULL, *confirm = NULL;
iq = iks_new("iq");
query = iks_new("query");
confirm = iks_new("item");
@@ -791,7 +825,148 @@
if(option_verbose > 77) ast_verbose("MWAHHAHAHA NOTHING TO SEE HERE!\n");
}
-
+/*!
+ * \brief Handles presence packets.
+ * \param client structure and the node.
+ * \return void.
+ */
+static void aji_handle_presence(struct aji_client *client, ikspak *pak)
+{
+ int status, priority;
+ struct aji_buddy *buddy = NULL;
+ struct aji_resource *tmp = NULL, *last= NULL, *found = NULL;
+
+ buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,pak->from->partial);
+ if(!buddy)
+ {
+ ast_log(LOG_WARNING, "Got presence packet from %s, somone not in our roster!!!!\n",pak->from->partial);
+ return;
+ }
+ status=(pak->show)?pak->show:6;
+ priority=atoi((iks_find_cdata(pak->x,"priority"))?iks_find_cdata(pak->x,"priority"):"0");
+ tmp=buddy->resources;
+
+ while(tmp) {
+ if(!strcasecmp(tmp->resource,pak->from->resource)) {
+ tmp->status=status;
+ if(status == 6) { /* Sign off Destroy resource */
+ ast_verbose("KILL THE SIGN OFF!\n");
+ found = tmp;
+ if (last && found->next) {
+ last->next = found->next;
+ } else if(!last) {
+ if(found->next)
+ buddy->resources = found->next;
+ else
+ buddy->resources = NULL;
+ } else if(!found->next) {
+ if(last)
+ last->next = NULL;
+ else
+ buddy->resources = NULL;
+ }
+ free(found);
+ found = NULL;
+ break;
+ }
+ if(tmp->priority!=priority) {
+ found=tmp;
+ found->priority= priority;
+ if(!last && !found->next)
+ break;
+ if(last)
+ last->next=found->next;
+ else
+ buddy->resources=found->next;
+ last=NULL;
+ tmp=buddy->resources;
+ while(tmp) {
+ if(found->priority > tmp->priority) {
+ if(last) last->next = found;
+ found->next = tmp;
+ if(!last) buddy->resources = found;
+ break;
+ }
+ if(!tmp->next) {
+ tmp->next = found;
+ break;
+ }
+ last=tmp;
+ tmp=tmp->next;
+ }
+ if (!tmp)
+ buddy->resources = found;
+ }
+ break;
+ }
+ last=tmp;
+ tmp=tmp->next;
+ }
+
+ if(!found && status !=6) {
+ found = (struct aji_resource *)malloc(sizeof(struct aji_resource));
+ if(!found) {
+ ast_log(LOG_ERROR, "Out of memory!\n");
+ return;
+ }
+ ast_copy_string(found->resource, pak->from->resource, sizeof(found->resource));
+ found->status = status;
+ found->priority = priority;
+ found->next = NULL;
+ last = NULL;
+ tmp = buddy->resources;
+ while(tmp) {
+ if(found->priority > tmp->priority) {
+ if(last) last->next = found;
+ found->next = tmp;
+ if(!last) buddy->resources = found;
+ break;
+ }
+ if(!tmp->next) {
+ tmp->next = found;
+ break;
+ }
+ last=tmp;
+ tmp=tmp->next;
+ }
+ if (!tmp)
+ buddy->resources = found;
+ }
+
+ switch(pak->subtype) {
+ case IKS_TYPE_AVAILABLE:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: I am available ^_* %i\n",pak->subtype );
+ break;
+ case IKS_TYPE_UNAVAILABLE:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: I am unavailable ^_* %i\n",pak->subtype );
+ break;
+ default:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: Ohh sexy and the wrong type%i\n",pak->subtype );
+ }
+ switch(pak->show)
+ {
+ case IKS_SHOW_UNAVAILABLE:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type: %i subtype %i\n",pak->subtype,pak->show);
+ break;
+ case IKS_SHOW_AVAILABLE:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type is available\n");
+ break;
+ case IKS_SHOW_CHAT:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type: %i subtype %i\n",pak->subtype,pak->show);
+ break;
+ case IKS_SHOW_AWAY:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type is away\n");
+ break;
+ case IKS_SHOW_XA:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type: %i subtype %i\n",pak->subtype,pak->show);
+ break;
+ case IKS_SHOW_DND:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: type: %i subtype %i\n",pak->subtype,pak->show);
+ break;
+ default:
+ ast_verbose(VERBOSE_PREFIX_3 "JABBER: Kinky! how did that happen %i\n",pak->show);
+ }
+}
/*!
* \brief handles subscription requests.
@@ -1466,6 +1641,7 @@
static int aji_test(int fd, int argc, char *argv[])
{
struct aji_client *client;
+ struct aji_resource *resource;
client = ASTOBJ_CONTAINER_FIND(&clients,"asterisk");
ast_aji_send(client, "mogorman at astjab.org", "blahblah");
if(client) {
@@ -1475,7 +1651,15 @@
ast_verbose("User: %s\n",iterator->user);
ast_verbose("Pass: %s\n",iterator->pass);
ast_verbose("Host: %s\n",iterator->host);
- ast_verbose("status: %d\n",iterator->status);
+ resource = iterator->resources;
+ while(resource) {
+ ast_verbose("Resource: %s\n",resource->resource);
+ ast_verbose(" Jingle Capable: %d\n",resource->jinglecapable);
+ ast_verbose(" Priority: %d\n",resource->priority);
+ ast_verbose(" Status: %d\n",resource->status);
+ ast_verbose(" Message: %s\n",resource->description);
+ resource=resource->next;
+ }
ast_verbose("DefChannel: %s\n\n",iterator->channel);
ASTOBJ_UNLOCK(iterator);
});
@@ -1610,6 +1794,7 @@
channel++;
ast_copy_string(buddy->channel,channel,sizeof(buddy->channel));
}
+ buddy->resources= NULL;
ast_copy_string(buddy->name,label,sizeof(buddy->name));
return 1;
}
@@ -1714,28 +1899,27 @@
if(!aji_load_config()) {
ast_log(LOG_ERROR, "JABBER: Failed to load\n");
return 0;
- } else {
- ASTOBJ_CONTAINER_TRAVERSE(&clients,1, {
- ASTOBJ_RDLOCK(iterator);
- switch (iterator->component){
-
- case AJI_COMPONENT:
- res = aji_component_initialize(iterator);
- break;
- case AJI_CLIENT:
- res = aji_client_initialize(iterator);
- break;
- }
- if(res != -1)
- ast_pthread_create(&iterator->thread, NULL, aji_recv_loop, iterator);
- ASTOBJ_UNLOCK(iterator);
- });
- ast_register_application(app_ajisend, aji_send_exec, ajisend_synopsis, ajisend_descrip);
- ast_register_application(app_ajistatus,aji_status_exec,ajistatus_synopsis,ajistatus_descrip);
- ast_cli_register_multiple(aji_cli,sizeof(aji_cli) / sizeof(aji_cli[0]));
- ast_log(LOG_NOTICE, "res_jabber.so loaded.\n");
- return 0;
- }
+ }
+ ASTOBJ_CONTAINER_TRAVERSE(&clients,1, {
+ ASTOBJ_RDLOCK(iterator);
+ switch (iterator->component){
+
+ case AJI_COMPONENT:
+ res = aji_component_initialize(iterator);
+ break;
+ case AJI_CLIENT:
+ res = aji_client_initialize(iterator);
+ break;
+ }
+ if(res != -1)
+ ast_pthread_create(&iterator->thread, NULL, aji_recv_loop, iterator);
+ ASTOBJ_UNLOCK(iterator);
+ });
+ ast_register_application(app_ajisend, aji_send_exec, ajisend_synopsis, ajisend_descrip);
+ ast_register_application(app_ajistatus,aji_status_exec,ajistatus_synopsis,ajistatus_descrip);
+ ast_cli_register_multiple(aji_cli,sizeof(aji_cli) / sizeof(aji_cli[0]));
+ ast_log(LOG_NOTICE, "res_jabber.so loaded.\n");
+ return 0;
}
static const char *description(void)
@@ -1743,7 +1927,7 @@
return tdesc;
}
-static const char *key()
+static const char *key(void)
{
return ASTERISK_GPL_KEY;
}
More information about the asterisk-commits
mailing list