int jabber_connect (void) { int e; j_parser = iks_stream_new (IKS_NS_CLIENT, NULL, (iksStreamHook *) on_stream); j_user = iks_id_new (iks_parser_stack (j_parser), prefs.jid); if (j_user->resource == NULL) { char buf[512]; sprintf (buf, "%s/sozluk", j_user->partial); j_user = iks_id_new (iks_parser_stack (j_parser), buf); } log_event ("Bağlanmayı deniyorum (%s)", j_user->full); //iks_set_log_hook (j_parser, (iksLogHook *) on_log); authorized = 0; e = iks_connect_tcp (j_parser, j_user->server, IKS_JABBER_PORT); switch (e) { case IKS_OK: return 0; case IKS_NET_NODNS: case IKS_NET_NOCONN: default: log_event ("jabber bork"); return -1; } }
void test_cmp (char *stra, char *strb, int parts, int diff) { iksid *a, *b; a = iks_id_new (my_stack, stra); b = iks_id_new (my_stack, strb); if (diff != iks_id_cmp (a, b, parts)) exit (1); }
void test_id (char *id, char *partial, char *user, char *server, char *resource) { iksid *a; a = iks_id_new (my_stack, id); if ((a->partial || partial) && iks_strcmp (a->partial, partial) != 0) BUG(a); if ((a->user || user) && iks_strcmp (a->user, user) != 0) BUG(a); if ((a->server || server) && iks_strcmp (a->server, server) != 0) BUG(a); if ((a->resource || resource) && iks_strcmp (a->resource, resource) != 0) BUG(a); }
/* * this function returns a jabber id and returns * it directly */ iksid *create_id(char *jabberid, struct netdata * net) { iksid *myjabberid = NULL; if(jabberid) { if(!(myjabberid = iks_id_new(iks_parser_stack(net->parser), jabberid))) error("cannot create jabberid"); } else { /* * create a new jabberid */ if(!(myjabberid = iks_id_new(iks_parser_stack(net->parser), JABBERID))) error("cannot create jabberid"); } /* * again, only for testing purposes */ #ifdef DEBUG printf("%s@%s\n", myjabberid->user, myjabberid->server); #endif return myjabberid; }
ikspak * iks_packet (iks *x) { ikspak *pak; ikstack *s; char *tmp; s = iks_stack (x); pak = iks_stack_alloc (s, sizeof (ikspak)); if (!pak) return NULL; memset (pak, 0, sizeof (ikspak)); pak->x = x; tmp = iks_find_attrib (x, "from"); if (tmp) pak->from = iks_id_new (s, tmp); pak->id = iks_find_attrib (x, "id"); tmp = iks_find_attrib (x, "type"); if (strcmp (iks_name (x), "message") == 0) { pak->type = IKS_PAK_MESSAGE; if (tmp) { if (strcmp (tmp, "chat") == 0) pak->subtype = IKS_TYPE_CHAT; else if (strcmp (tmp, "groupchat") == 0) pak->subtype = IKS_TYPE_GROUPCHAT; else if (strcmp (tmp, "headline") == 0) pak->subtype = IKS_TYPE_HEADLINE; else if (strcmp (tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } } else if (strcmp (iks_name (x), "presence") == 0) { pak->type = IKS_PAK_S10N; if (tmp) { if (strcmp (tmp, "unavailable") == 0) { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_UNAVAILABLE; pak->show = IKS_SHOW_UNAVAILABLE; } else if (strcmp (tmp, "probe") == 0) { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_PROBE; } else if(strcmp(tmp, "subscribe") == 0) pak->subtype = IKS_TYPE_SUBSCRIBE; else if(strcmp(tmp, "subscribed") == 0) pak->subtype = IKS_TYPE_SUBSCRIBED; else if(strcmp(tmp, "unsubscribe") == 0) pak->subtype = IKS_TYPE_UNSUBSCRIBE; else if(strcmp(tmp, "unsubscribed") == 0) pak->subtype = IKS_TYPE_UNSUBSCRIBED; else if(strcmp(tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } else { pak->type = IKS_PAK_PRESENCE; pak->subtype = IKS_TYPE_AVAILABLE; tmp = iks_find_cdata (x, "show"); pak->show = IKS_SHOW_AVAILABLE; if (tmp) { if (strcmp (tmp, "chat") == 0) pak->show = IKS_SHOW_CHAT; else if (strcmp (tmp, "away") == 0) pak->show = IKS_SHOW_AWAY; else if (strcmp (tmp, "xa") == 0) pak->show = IKS_SHOW_XA; else if (strcmp (tmp, "dnd") == 0) pak->show = IKS_SHOW_DND; } } } else if (strcmp (iks_name (x), "iq") == 0) { iks *q; pak->type = IKS_PAK_IQ; if (tmp) { if (strcmp (tmp, "get") == 0) pak->subtype = IKS_TYPE_GET; else if (strcmp (tmp, "set") == 0) pak->subtype = IKS_TYPE_SET; else if (strcmp (tmp, "result") == 0) pak->subtype = IKS_TYPE_RESULT; else if (strcmp (tmp, "error") == 0) pak->subtype = IKS_TYPE_ERROR; } for (q = iks_child (x); q; q = iks_next (q)) { if (IKS_TAG == iks_type (q)) { char *ns; ns = iks_find_attrib (q, "xmlns"); if (ns) { pak->query = q; pak->ns = ns; break; } } } } return pak; }