Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

JContact.c File Reference

#include "libjwgc.h"

Go to the source code of this file.

Functions

void insert_resource_into_contact (int pos, char *resource, char *status)
void insert_into_contact_list (char *contact, char *status, char *resource)
void remove_from_contact_list (char *contact)
void insert_into_agent_list (char *jid, char *name, char *service, int flags)
int update_contact_status (char *jid, char *status, char *resource)
int contact_status_change (jabpacket packet)
void list_contacts (jwgconn jwg, char *matchstr, int strictmatch, int skipnotavail)
xode find_contact_group (xode base, char *target)
void list_contacts_bygroup (jwgconn jwg, char *matchstr, int strictmatch, int skipnotavail)
void list_agents (xode x)
void update_nickname (char *target, char *nickname)
void update_group (char *target, char *group)
char * find_jid_from_nickname (char *nickname)
char * find_nickname_from_jid (char *jid)
int test_match (char *matchstr, xode contact, int exactmatch)
char * find_match (char *searchstr)

Variables

xodecontact_list = NULL
int num_contacts = 0
xodeagent_list = NULL
int num_agents = 0


Function Documentation

int contact_status_change jabpacket  packet  ) 
 

Definition at line 190 of file JContact.c.

References dExecution, dprintf(), jabpacket, JABPACKET__AVAILABLE, JABPACKET__UNAVAILABLE, jabpacket_struct::subtype, update_contact_status(), jabpacket_struct::x, xode, xode_get_attrib(), xode_get_data(), and xode_get_tag().

Referenced by process_presence().

00191 {
00192         char *temp, *pos;
00193         xode x;
00194         char *from = xode_get_attrib(packet->x, "from");
00195         char *resource = "NULL";
00196         int ret = 0;
00197         if (!from) {
00198                 return;
00199         }
00200 
00201         pos = (char *) strchr(from, '/');
00202         if (pos) {
00203                 *pos = '\0';
00204                 resource = pos + 1;
00205         }
00206 
00207         switch (packet->subtype) {
00208                 case JABPACKET__AVAILABLE:
00209                         x = xode_get_tag(packet->x, "show");
00210                         if (x) {
00211                                 temp = xode_get_data(x);
00212                                 update_contact_status(from, temp, resource);
00213                                 ret = 1;
00214                         }
00215                         else {
00216                                 update_contact_status(from, "available", resource);
00217                                 ret = 1;
00218                         }
00219 
00220                         dprintf(dExecution, "%s is available\n", from);
00221                         break;
00222 
00223                 case JABPACKET__UNAVAILABLE:
00224                         dprintf(dExecution, "%s is unavailable\n", from);
00225                         update_contact_status(from, "unavailable", resource);
00226                         ret = 1;
00227                         break;
00228 
00229                 default:
00230                         dprintf(dExecution, "%s is unknown(?) -> %d\n", from, packet->subtype);
00231                         update_contact_status(from, "unknown", resource);
00232                         ret = 1;
00233                         break;
00234         }
00235 }

xode find_contact_group xode  base,
char *  target
 

Definition at line 298 of file JContact.c.

References target, xode, xode_get_attrib(), xode_get_nextsibling(), and xode_get_tag().

Referenced by list_contacts_bygroup().

00301 {
00302         xode x;
00303         char *name;
00304 
00305         if (!target) {
00306                 return NULL;
00307         }
00308 
00309         x = xode_get_tag(base, "group");
00310         while (x) {
00311                 name = xode_get_attrib(x, "name");
00312                 if (name && !strcmp(name, target)) {
00313                         return x;
00314                 }
00315                 x = xode_get_nextsibling(x);
00316         }
00317 
00318         return NULL;
00319 }

char* find_jid_from_nickname char *  nickname  ) 
 

Definition at line 461 of file JContact.c.

References contact_list, and xode_get_attrib().

00462 {
00463         int i;
00464         char *name;
00465 
00466         for (i = 0; i < num_contacts; i++) {
00467                 name = xode_get_attrib(contact_list[i], "nick");
00468                 if (name && !strcasecmp(name, nickname)) {
00469                         return strdup(xode_get_attrib(contact_list[i], "jid"));
00470                 }
00471         }
00472 
00473         return NULL;
00474 }

char* find_match char *  searchstr  ) 
 

Definition at line 524 of file JContact.c.

References contact_list, dMatch, dprintf(), jid, and xode_get_attrib().

Referenced by jwg_on_event_handler().

00525 {
00526         int i;
00527         char *jid, *nick;
00528 
00529         /* Try exact jid match */
00530         for (i = 0; i < num_contacts; i++) {
00531                 jid = xode_get_attrib(contact_list[i], "jid");
00532                 dprintf(dMatch, "Exact Match: %s = %s\n", searchstr, jid);
00533                 if (!strcasecmp(jid, searchstr)) {
00534                         return strdup(jid);
00535                 }
00536         }
00537 
00538         /* Try exact nickname match */
00539         for (i = 0; i < num_contacts; i++) {
00540                 jid = xode_get_attrib(contact_list[i], "jid");
00541                 nick = xode_get_attrib(contact_list[i], "nick");
00542                 if (!nick) {
00543                         continue;
00544                 }
00545                 dprintf(dMatch, "Nick Match: %s = %s\n", searchstr, nick);
00546                 if (!strcasecmp(nick, searchstr)) {
00547                         return strdup(jid);
00548                 }
00549         }
00550 
00551         /* Try begging of jid match */
00552         for (i = 0; i < num_contacts; i++) {
00553                 jid = xode_get_attrib(contact_list[i], "jid");
00554                 dprintf(dMatch, "Part Match: %s = %s\n", searchstr, jid);
00555                 if (!strncasecmp(jid, searchstr, strlen(searchstr))) {
00556                         return strdup(jid);
00557                 }
00558         }
00559 
00560         /* No matches, sorry */
00561         return NULL;
00562 }

char* find_nickname_from_jid char *  jid  ) 
 

Definition at line 477 of file JContact.c.

References contact_list, jid, and xode_get_attrib().

Referenced by decode_notice().

00478 {
00479         int i;
00480         char *name, *nick;
00481 
00482         for (i = 0; i < num_contacts; i++) {
00483                 name = xode_get_attrib(contact_list[i], "jid");
00484                 if (name && !strcasecmp(name, jid)) {
00485                         nick = xode_get_attrib(contact_list[i], "nick");
00486                         if (nick) {
00487                                 return strdup(nick);
00488                         }
00489                         else {
00490                                 return strdup("");
00491                         }
00492                 }
00493         }
00494 
00495         return NULL;
00496 }

void insert_into_agent_list char *  jid,
char *  name,
char *  service,
int  flags
 

Definition at line 79 of file JContact.c.

References agent_list, dExecution, dprintf(), jid, num_agents, xode, xode_get_attrib(), xode_insert_tag(), xode_new(), and xode_put_attrib().

Referenced by process_iq_result().

00080 {
00081         int i, k;
00082 
00083         if (!jid) {
00084                 return;
00085         }
00086 
00087         num_agents++;
00088         agent_list = realloc(agent_list, sizeof(xode) * (num_agents));
00089         agent_list[num_agents - 1] = malloc(sizeof(xode));
00090 
00091         for (i = 0; i < (num_agents - 1) &&
00092              (strcasecmp(jid, xode_get_attrib(agent_list[i], "jid")) > 0);
00093              i++);
00094 
00095         for (k = (num_agents - 1); k > i; k--) {
00096                 agent_list[k] = agent_list[k - 1];
00097         }
00098 
00099         agent_list[k] = xode_new("agent");
00100         xode_put_attrib(agent_list[k], "jid", jid);
00101         if (name) {
00102                 xode_put_attrib(agent_list[k], "name", name);
00103         }
00104         if (service) {
00105                 xode_put_attrib(agent_list[k], "service", service);
00106         }
00107         if (flags & AGENT_TRANSPORT) {
00108                 xode_insert_tag(agent_list[k], "transport");
00109         }
00110         if (flags & AGENT_GROUPCHAT) {
00111                 xode_insert_tag(agent_list[k], "groupchat");
00112         }
00113         if (flags & AGENT_REGISTER) {
00114                 xode_insert_tag(agent_list[k], "register");
00115         }
00116         if (flags & AGENT_SEARCH) {
00117                 xode_insert_tag(agent_list[k], "search");
00118         }
00119 
00120         dprintf(dExecution, "Inserted %s into agent list at positiion %d\n", jid, i);
00121 }

void insert_into_contact_list char *  contact,
char *  status,
char *  resource
 

Definition at line 30 of file JContact.c.

References contact_list, dExecution, dprintf(), insert_resource_into_contact(), num_contacts, xode, xode_get_attrib(), xode_insert_tag(), xode_new(), and xode_put_attrib().

Referenced by update_contact_status().

00031 {
00032         int i, k;
00033 
00034         num_contacts++;
00035         contact_list = realloc(contact_list, sizeof(xode) * (num_contacts));
00036         contact_list[num_contacts - 1] = malloc(sizeof(xode));
00037 
00038         for (i = 0; i < (num_contacts - 1) &&
00039              (strcasecmp(contact, xode_get_attrib(contact_list[i], "jid")) > 0);
00040              i++);
00041 
00042         for (k = (num_contacts - 1); k > i; k--) {
00043                 contact_list[k] = contact_list[k - 1];
00044         }
00045 
00046         contact_list[k] = xode_new("contact");
00047         xode_put_attrib(contact_list[k], "jid", contact);
00048         xode_insert_tag(contact_list[k], "resources");
00049 
00050         insert_resource_into_contact(i, resource, status);
00051 
00052         dprintf(dExecution, "Inserted %s into contact list at position %d\n", contact, i);
00053 }

void insert_resource_into_contact int  pos,
char *  resource,
char *  status
 

Definition at line 12 of file JContact.c.

References contact_list, xode, xode_get_tag(), xode_insert_tag(), and xode_put_attrib().

Referenced by insert_into_contact_list(), and update_contact_status().

00013 {
00014         int i, k;
00015         xode r, s;
00016 
00017         if (!resource) {
00018                 return;
00019         }
00020 
00021         r = xode_get_tag(contact_list[pos], "resources");
00022         s = xode_insert_tag(r, "resource");
00023         xode_put_attrib(s, "name", resource);
00024         if (status) {
00025                 xode_put_attrib(s, "status", status);
00026         }
00027 }

void list_agents xode  x  ) 
 

Definition at line 420 of file JContact.c.

References agent_list, xode, xode_dup(), xode_insert_node(), and xode_insert_tag().

Referenced by show_status().

00421 {
00422         int i;
00423         xode y, z;
00424 
00425         y = xode_insert_tag(x, "agents");
00426         for (i = 0; i < num_agents; i++) {
00427                 z = xode_dup(agent_list[i]);
00428                 xode_insert_node(y, z);
00429         }
00430 }

void list_contacts jwgconn  jwg,
char *  matchstr,
int  strictmatch,
int  skipnotavail
 

Definition at line 238 of file JContact.c.

References contact_list, dprintf(), dXML, jwg_servsend(), jwgconn, test_match(), xode, xode_dup(), xode_free(), xode_get_attrib(), xode_get_firstchild(), xode_get_nextsibling(), xode_get_tag(), xode_has_children(), xode_hide(), xode_insert_node(), xode_new(), and xode_to_prettystr().

Referenced by jwg_on_event_handler().

00243 {
00244         int i, k;
00245         xode x, y, ny, z, r, nr;
00246 
00247         x = xode_new("contacts");
00248         for (i = 0; i < num_contacts; i++) {
00249                 y = xode_dup(contact_list[i]);
00250                 xode_insert_node(x, y);
00251         }
00252 
00253         if (matchstr) {
00254                 ny = y = xode_get_firstchild(x);
00255                 while (ny) {
00256                         ny = xode_get_nextsibling(ny);
00257                         if (!test_match(matchstr, y, strictmatch)) {
00258                                 dprintf(dXML, "HIDE-A:\n%s\n",
00259                                         xode_to_prettystr(y));
00260                                 xode_hide(y);
00261                         }
00262                         y = ny;
00263                 }
00264         }
00265 
00266         if (skipnotavail) {
00267                 ny = y = xode_get_firstchild(x);
00268                 while (ny) {
00269                         z = xode_get_tag(y, "resources");
00270                         nr = r = xode_get_firstchild(z);
00271                         while (nr) {
00272                                 char *curstatus;
00273                                 nr = xode_get_nextsibling(nr);
00274                                 curstatus = xode_get_attrib(r, "status");
00275                                 if (!curstatus || !strcmp(curstatus,
00276                                                 "unavailable")) {
00277                                         dprintf(dXML, "HIDE-B:\n%s\n",
00278                                                 xode_to_prettystr(r));
00279                                         xode_hide(r);
00280                                 }
00281                                 r = nr;
00282                         }
00283                         ny = xode_get_nextsibling(ny);
00284                         if (!xode_has_children(z)) {
00285                                 dprintf(dXML, "HIDE-C:\n%s\n",
00286                                         xode_to_prettystr(y));
00287                                 xode_hide(y);
00288                         }
00289                         y = ny;
00290                 }
00291         }
00292 
00293         jwg_servsend(jwg, x);
00294         xode_free(x);
00295 }

void list_contacts_bygroup jwgconn  jwg,
char *  matchstr,
int  strictmatch,
int  skipnotavail
 

Definition at line 322 of file JContact.c.

References contact_list, dprintf(), dXML, find_contact_group(), jwg_servsend(), jwgconn, test_match(), xode, xode_dup(), xode_free(), xode_get_attrib(), xode_get_firstchild(), xode_get_nextsibling(), xode_get_tag(), xode_has_children(), xode_hide(), xode_hide_attrib(), xode_insert_node(), xode_insert_tag(), xode_new(), xode_put_attrib(), and xode_to_prettystr().

Referenced by jwg_on_event_handler().

00327 {
00328         int i, k;
00329         xode x, y, ny, z, r, nr, g, ng;
00330         char *group;
00331 
00332         x = xode_new("contacts");
00333         for (i = 0; i < num_contacts; i++) {
00334                 y = xode_dup(contact_list[i]);
00335                 group = xode_get_attrib(y, "group");
00336                 if (!group) {
00337                         group = "Unknown";
00338                 }
00339                 z = find_contact_group(x, group);
00340                 if (!z) {
00341                         z = xode_insert_tag(x, "group");
00342                         xode_put_attrib(z, "name", group);
00343                 }
00344                 xode_hide_attrib(y, "group");
00345                 xode_insert_node(z, y);
00346         }
00347 
00348         if (matchstr) {
00349                 ng = g = xode_get_firstchild(x);
00350                 while (ng) {
00351                         ny = y = xode_get_firstchild(g);
00352                         while (ny) {
00353                                 ny = xode_get_nextsibling(y);
00354                                 if (!test_match(matchstr, y, strictmatch)) {
00355                                         dprintf(dXML,
00356                                                 "HIDE-D:\n%s\n",
00357                                                 xode_to_prettystr(y));
00358                                         xode_hide(y);
00359                                 }
00360                                 y = ny;
00361                         }
00362 
00363                         ng = xode_get_nextsibling(ng);
00364                         if (!xode_has_children(g)) {
00365                                 dprintf(dXML, "HIDE-E:\n%s\n",
00366                                         xode_to_prettystr(g));
00367                                 xode_hide(g);
00368                         }
00369                         g = ng;
00370                 }
00371         }
00372 
00373         if (skipnotavail) {
00374                 ng = g = xode_get_firstchild(x);
00375                 while (ng) {
00376                         ny = y = xode_get_firstchild(g);
00377                         while (ny) {
00378                                 z = xode_get_tag(y, "resources");
00379                                 nr = r = xode_get_firstchild(z);
00380                                 while (nr) {
00381                                         char *curstatus;
00382                                         nr = xode_get_nextsibling(nr);
00383                                         curstatus = xode_get_attrib(r,
00384                                                                 "status");
00385                                         if (!curstatus || !strcmp(curstatus,
00386                                                         "unavailable")) {
00387                                                 dprintf(dXML,
00388                                                         "HIDE-F:\n%s\n",
00389                                                         xode_to_prettystr(r));
00390                                                 xode_hide(r);
00391                                         }
00392                                         r = nr;
00393                                 }
00394 
00395                                 ny = xode_get_nextsibling(ny);
00396                                 if (!xode_has_children(z)) {
00397                                         dprintf(dXML,
00398                                                 "HIDE-G:\n%s\n",
00399                                                 xode_to_prettystr(y));
00400                                         xode_hide(y);
00401                                 }
00402                                 y = ny;
00403                         }
00404 
00405                         ng = xode_get_nextsibling(ng);
00406                         if (!xode_has_children(g)) {
00407                                 dprintf(dXML, "HIDE-H:\n%s\n",
00408                                         xode_to_prettystr(g));
00409                                 xode_hide(g);
00410                         }
00411                         g = ng;
00412                 }
00413         }
00414 
00415         jwg_servsend(jwg, x);
00416         xode_free(x);
00417 }

void remove_from_contact_list char *  contact  ) 
 

Definition at line 56 of file JContact.c.

References contact_list, dExecution, dprintf(), num_contacts, and xode_get_attrib().

Referenced by jwg_on_event_handler(), and process_iq_set().

00057 {
00058         int i;
00059         int k;
00060 
00061         for (i = 0; i < num_contacts &&
00062             (strcasecmp(contact, xode_get_attrib(contact_list[i], "jid")) != 0);
00063             i++);
00064 
00065         if (i == num_contacts) {
00066                 return;
00067         }
00068 
00069         free(contact_list[i]);
00070         for (k = i; k < (num_contacts - 1); k++) {
00071                 contact_list[k] = contact_list[k + 1];
00072         }
00073         num_contacts--;
00074 
00075         dprintf(dExecution, "Removed %s from contact list at position %d\n", contact, i);
00076 }

int test_match char *  matchstr,
xode  contact,
int  exactmatch
 

Definition at line 499 of file JContact.c.

References exactmatch, NULL, xode, and xode_get_attrib().

Referenced by list_contacts(), and list_contacts_bygroup().

00503 {
00504         char *nick;
00505 
00506         if (!strcasecmp(xode_get_attrib(contact, "jid"), matchstr)) {
00507                 return 1;
00508         }
00509 
00510         if ((nick = xode_get_attrib(contact, "nick")) != NULL &&
00511                         !strcasecmp(nick, matchstr)) {
00512                 return 1;
00513         }
00514 
00515         if (!exactmatch && !strncasecmp(xode_get_attrib(contact, "jid"),
00516                                         matchstr, strlen(matchstr))) {
00517                 return 1;
00518         }
00519 
00520         return 0;
00521 }

int update_contact_status char *  jid,
char *  status,
char *  resource
 

Definition at line 124 of file JContact.c.

References contact_list, dExecution, dprintf(), insert_into_contact_list(), insert_resource_into_contact(), jid, xode, xode_get_attrib(), xode_get_firstchild(), xode_get_nextsibling(), xode_get_tag(), xode_hide_attrib(), and xode_put_attrib().

Referenced by contact_status_change(), and process_iq_result().

00125 {
00126         int contactfound = 0;
00127         int resourcefound = 0;
00128         int i;
00129         char *pos;
00130         xode x, y;
00131         int ret = 0;
00132 
00133         dprintf(dExecution, "Updating %s/%s status to %s.\n",
00134                         jid,
00135                         resource ? resource : "NULL",
00136                         status ? status : "NULL");
00137 
00138         for (i = 0; i < num_contacts; i++) {
00139                 if (!strcasecmp(xode_get_attrib(contact_list[i], "jid"),
00140                                                         jid)) {
00141                         contactfound = 1;
00142                         if (!resource) {
00143                                 break;
00144                         }
00145                         x = xode_get_tag(contact_list[i], "resources");
00146                         y = xode_get_firstchild(x);
00147                         while (y) {
00148                                 if (!strcmp(xode_get_attrib(y, "name"),
00149                                                                 resource)) {
00150                                         char *curstatus;
00151                                         resourcefound = 1;
00152 
00153                                         curstatus = xode_get_attrib(y,
00154                                                                 "status");
00155                                         if (curstatus && !status) {
00156                                                 xode_hide_attrib(y, "status");
00157                                                 ret = 1;
00158                                         }
00159                                         else if (status && (!curstatus ||
00160                                                 strcmp(curstatus, status))) {
00161                                                 xode_put_attrib(y,
00162                                                         "status",
00163                                                         status);
00164                                                 ret = 1;
00165                                         }
00166                                         break;
00167                                 }
00168                                 y = xode_get_nextsibling(y);
00169                         }
00170 
00171                         if (!resourcefound) {
00172                                 insert_resource_into_contact(i,
00173                                                 resource, status);
00174                                 ret = 1;
00175                         }
00176 
00177                         break;
00178                 }
00179         }
00180 
00181         if (!contactfound) {
00182                 insert_into_contact_list(jid, status, resource);
00183                 ret = 1;
00184         }
00185 
00186         return ret;
00187 }

void update_group char *  target,
char *  group
 

Definition at line 447 of file JContact.c.

References contact_list, target, xode_get_attrib(), and xode_put_attrib().

Referenced by jwg_on_event_handler(), and process_iq_result().

00448 {
00449         int i;
00450 
00451         for (i = 0; i < num_contacts; i++) {
00452                 if (!strcasecmp(xode_get_attrib(contact_list[i], "jid"),
00453                                                                 target)) {
00454                         xode_put_attrib(contact_list[i], "group", group);
00455                         return;
00456                 }
00457         }
00458 }

void update_nickname char *  target,
char *  nickname
 

Definition at line 433 of file JContact.c.

References contact_list, target, xode_get_attrib(), and xode_put_attrib().

Referenced by jwg_on_event_handler(), and process_iq_result().

00434 {
00435         int i;
00436 
00437         for (i = 0; i < num_contacts; i++) {
00438                 if (!strcasecmp(xode_get_attrib(contact_list[i], "jid"),
00439                                                                 target)) {
00440                         xode_put_attrib(contact_list[i], "nick", nickname);
00441                         return;
00442                 }
00443         }
00444 }


Variable Documentation

xode* agent_list = NULL
 

Definition at line 8 of file JContact.c.

Referenced by insert_into_agent_list(), and list_agents().

xode* contact_list = NULL
 

Definition at line 5 of file JContact.c.

Referenced by find_jid_from_nickname(), find_match(), find_nickname_from_jid(), insert_into_contact_list(), insert_resource_into_contact(), list_contacts(), list_contacts_bygroup(), remove_from_contact_list(), update_contact_status(), update_group(), and update_nickname().

int num_agents = 0
 

Definition at line 9 of file JContact.c.

Referenced by insert_into_agent_list().

int num_contacts = 0
 

Definition at line 6 of file JContact.c.

Referenced by insert_into_contact_list(), and remove_from_contact_list().



Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo

Source Perspective by Fisheye