changeset 29:86837ff0554c

[/trunk] Changeset 45 by mikael * Switch to libjabber. (Does NOT work at all yet) jabglue.c is a wrapper around the libjabber library.
author mikael
date Mon, 28 Mar 2005 20:12:48 +0000
parents 0cd8025eebee
children 4ea2df449381
files mcabber/src/Makefile mcabber/src/jabglue.c mcabber/src/jabglue.h mcabber/src/main.c mcabber/src/screen.c mcabber/src/screen.h
diffstat 6 files changed, 736 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/Makefile	Mon Mar 28 10:36:47 2005 +0000
+++ b/mcabber/src/Makefile	Mon Mar 28 20:12:48 2005 +0000
@@ -33,7 +33,7 @@
 endif
 CFLAGS = -Wall -W -pedantic
 LD = $(CC)
-LDLIBS = -lncurses -lpanel
+LDLIBS = -lncurses -lpanel -L../libjabber -L../connwrap -llibjabber -lconnwrap -lssl
 
 ifeq ($(DEBUG),1)
 CFLAGS += -O0 -g -DDEBUG=1
@@ -54,6 +54,7 @@
     utils.c \
     buddies.c \
     parsecfg.c \
+    jabglue.c \
     server.c \
     socket.c \
     lang.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcabber/src/jabglue.c	Mon Mar 28 20:12:48 2005 +0000
@@ -0,0 +1,663 @@
+/*
+ * jabglue.c    -- Jabber protocol handling
+ * 
+ * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
+ * Parts come from the centericq project:
+ * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "../libjabber/jabber.h"
+#include "jabglue.h"
+#include "screen.h"
+#include "utils.h"
+
+#define JABBERPORT      5222
+#define JABBERSSLPORT   5223
+
+jconn jc;
+
+enum {
+  STATE_CONNECTING,
+  STATE_GETAUTH,
+  STATE_SENDAUTH,
+  STATE_LOGGED
+} jstate;
+
+
+static void jidsplit(const char *jid, char **user, char **host,
+        char **res)
+{
+  char *tmp, *ptr;
+  tmp = strdup(jid);
+
+  if ((ptr = strchr(tmp, '/')) != NULL) {
+    *res = strdup(ptr+1);
+    *ptr = 0;
+  } else
+    *res = NULL;
+
+  if ((ptr = strchr(tmp, '@')) != NULL) {
+    *host = strdup(ptr+1);
+    *ptr = 0;
+  } else
+    *host = NULL;
+
+  *user = strdup(tmp);
+  free(tmp);
+}
+
+char *jidtodisp(const char *jid)
+{
+  char *ptr;
+  char *alias = strdup(jid);
+  if ((ptr = strchr(alias, '/')) != NULL) {
+    *ptr = 0;
+  }
+  return alias;
+}
+
+void statehandler(jconn conn, int state)
+{
+  static int previous_state = -1;
+
+  switch(state) {
+    case JCONN_STATE_OFF:
+        /*
+           jhook.flogged = jhook.fonline = false;
+
+           if(previous_state != JCONN_STATE_OFF) {
+           logger.putourstatus(jhook.proto, jhook.getstatus(), jhook.ourstatus = offline);
+           jhook.log(logDisconnected);
+           jhook.roster.clear();
+           jhook.agents.clear();
+           clist.setoffline(jhook.proto);
+           face.update();
+           }
+           */
+        break;
+
+    case JCONN_STATE_CONNECTED:
+        break;
+
+    case JCONN_STATE_AUTH:
+        break;
+
+    case JCONN_STATE_ON:
+        // if(jhook.regmode) jhook.fonline = true;
+        break;
+
+    default:
+        break;
+  }
+  previous_state = state;
+}
+
+void packethandler(jconn conn, jpacket packet)
+{
+  char *p;
+  xmlnode x, y;
+  // string from, type, body, enc, ns, id, u, h, s;
+  char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
+  char *ns=NULL;
+  //char *id=NULL;
+  // imstatus ust;
+  // int npos;
+  // bool isagent;
+
+  jpacket_reset(packet);
+
+  p = xmlnode_get_attrib(packet->x, "from"); if(p) from = p;
+  p = xmlnode_get_attrib(packet->x, "type"); if(p) type = p;
+  //imcontact ic(jidtodisp(from), jhook.proto);
+
+  switch (packet->type) {
+    case JPACKET_MESSAGE:
+        x = xmlnode_get_tag(packet->x, "body");
+        p = xmlnode_get_data(x); if(p) body = p;
+
+        if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
+          if ((p = xmlnode_get_data(x)) != NULL) {
+            char *tmp = malloc(strlen(body)+strlen(p)+3);
+            strcpy(tmp, p);
+            strcat(tmp, ": ");
+            strcat(tmp, body);
+            body = tmp; // XXX check it is free'd later...
+          }
+
+        /* there can be multiple <x> tags. we're looking for one with
+           xmlns = jabber:x:encrypted */
+
+        for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
+          if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
+            if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcasecmp(p, "jabber:x:encrypted"))
+              if ((p = xmlnode_get_data(x)) != NULL) {
+                enc = p;
+                break;
+              }
+        }
+
+        // FIXME:
+        if (body) {
+          scr_LogPrint("Message received");
+          scr_LogPrint("Type: %s", type);
+          gotmessage(type, from, body, enc);
+        }
+
+        break;
+
+    case JPACKET_IQ:
+        if (!strcmp(type, "result")) {
+          scr_LogPrint("Received a result packet");
+          /*
+          if (p = xmlnode_get_attrib(packet->x, "id")) {
+            int iid = atoi(p);
+
+            if (iid == jhook.id) {
+              if (!jhook.regmode) {
+                if (jhook.jstate == STATE_GETAUTH) {
+                  if (x = xmlnode_get_tag(packet->x, "query"))
+                    if (!xmlnode_get_tag(x, "digest")) {
+                      jhook.jc->sid = 0;
+                    }
+
+                  jhook.id = atoi(jab_auth(jhook.jc));
+                  jhook.jstate = STATE_SENDAUTH;
+
+                } else {
+                  jhook.gotloggedin();
+                  jhook.jstate = STATE_LOGGED;
+                }
+
+              } else {
+                jhook.regdone = true;
+
+              }
+              return;
+            }
+
+            if(!strcmp(p, "VCARDreq")) {
+              x = xmlnode_get_firstchild(packet->x);
+              if(!x) x = packet->x;
+
+              jhook.gotvcard(ic, x);
+              return;
+
+            } else if(!strcmp(p, "versionreq")) {
+              jhook.gotversion(ic, packet->x);
+              return;
+
+            }
+          }
+
+          if(x = xmlnode_get_tag(packet->x, "query")) {
+            p = xmlnode_get_attrib(x, "xmlns"); if(p) ns = p;
+
+            if(ns == NS_ROSTER) {
+              jhook.gotroster(x);
+
+            } else if(ns == NS_AGENTS) {
+              for(y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
+                const char *alias = xmlnode_get_attrib(y, "jid");
+
+                if(alias) {
+                  const char *name = xmlnode_get_tag_data(y, "name");
+                  const char *desc = xmlnode_get_tag_data(y, "description");
+                  const char *service = xmlnode_get_tag_data(y, "service");
+                  agent::agent_type atype = agent::atUnknown;
+
+                  if(xmlnode_get_tag(y, "groupchat")) atype = agent::atGroupchat; else
+                    if(xmlnode_get_tag(y, "transport")) atype = agent::atTransport; else
+                      if(xmlnode_get_tag(y, "search")) atype = agent::atSearch;
+
+                  if(alias && name && desc) {
+                    jhook.agents.push_back(agent(alias, name, desc, atype));
+
+                    if(atype == agent::atSearch) {
+                      x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
+                      xmlnode_put_attrib(x, "to", alias);
+                      xmlnode_put_attrib(x, "id", "Agent info");
+                      jab_send(conn, x);
+                      xmlnode_free(x);
+                    }
+
+                    if(xmlnode_get_tag(y, "register")) {
+                      x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
+                      xmlnode_put_attrib(x, "to", alias);
+                      xmlnode_put_attrib(x, "id", "Agent info");
+                      jab_send(conn, x);
+                      xmlnode_free(x);
+                    }
+                  }
+                }
+              }
+
+              if(find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
+                jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
+                            _("Default Jabber conference server"), agent::atGroupchat));
+
+            } else if(ns == NS_SEARCH || ns == NS_REGISTER) {
+              p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : "";
+
+              if(id == "Agent info") {
+                jhook.gotagentinfo(packet->x);
+              } else if(id == "Lookup") {
+                jhook.gotsearchresults(packet->x);
+              } else if(id == "Register") {
+                x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
+                xmlnode_put_attrib(x, "to", from.c_str());
+                xmlnode_put_attrib(x, "id", "Agent info");
+                jab_send(conn, x);
+                xmlnode_free(x);
+              }
+
+            }
+          }
+          */
+
+        } else if (!strcmp(type, "set")) {
+        } else if (!strcmp(type, "error")) {
+          char *name=NULL, *desc=NULL;
+          int code;
+
+          x = xmlnode_get_tag(packet->x, "error");
+          p = xmlnode_get_attrib(x, "code"); if(p) code = atoi(p);
+          p = xmlnode_get_attrib(x, "id"); if(p) name = p;
+          p = xmlnode_get_tag_data(packet->x, "error"); if(p) desc = p;
+
+          switch(code) {
+            case 401: /* Unauthorized */
+            case 302: /* Redirect */
+            case 400: /* Bad request */
+            case 402: /* Payment Required */
+            case 403: /* Forbidden */
+            case 404: /* Not Found */
+            case 405: /* Not Allowed */
+            case 406: /* Not Acceptable */
+            case 407: /* Registration Required */
+            case 408: /* Request Timeout */
+            case 409: /* Conflict */
+            case 500: /* Internal Server Error */
+            case 501: /* Not Implemented */
+            case 502: /* Remote Server Error */
+            case 503: /* Service Unavailable */
+            case 504: /* Remote Server Timeout */
+            default:
+                /*
+                if(!jhook.regmode) {
+                  face.log(desc.empty() ?
+                          _("+ [jab] error %d") :
+                          _("+ [jab] error %d: %s"),
+                          code, desc.c_str());
+
+                  if(!jhook.flogged && code != 501) {
+                    close(jhook.jc->fd);
+                    jhook.jc->fd = -1;
+                  }
+
+                } else {
+                  jhook.regerr = desc;
+
+                }
+                */
+          }
+          scr_LogPrint("Error code from server (%d)", code);
+
+        }
+        break;
+
+    case JPACKET_PRESENCE:
+        x = xmlnode_get_tag(packet->x, "show");
+        //ust = available;
+
+        if (x) {
+          p = xmlnode_get_data(x); if(p) ns = p;
+
+          if (ns) {
+            scr_LogPrint("New status: %s", ns);
+            /*
+            if (ns == "away") ust = away; else
+              if (ns == "dnd") ust = dontdisturb; else
+                if (ns == "xa") ust = notavail; else
+                  if (ns == "chat") ust = freeforchat;
+            */
+          }
+        }
+
+        if (!strcmp(type, "unavailable")) {
+          scr_LogPrint("New status: unavailable/offline");
+          // XXX
+          //  ust = offline;
+        }
+
+        /*
+        jidsplit(from, u, h, s);
+        id = u + "@" + h;
+
+        if(clist.get(imcontact((string) "#" + id, jhook.proto))) {
+          if(ust == offline) {
+            vector<string>::iterator im = find(jhook.chatmembers[id].begin(), jhook.chatmembers[id].end(), s);
+            if(im != jhook.chatmembers[id].end())
+              jhook.chatmembers[id].erase(im);
+
+          } else {
+            jhook.chatmembers[id].push_back(s);
+
+          }
+
+        } else {
+          icqcontact *c = clist.get(ic);
+
+          if(c)
+            if(c->getstatus() != ust) {
+              if(c->getstatus() == offline)
+                jhook.awaymsgs[ic.nickname] = "";
+
+              logger.putonline(c, c->getstatus(), ust);
+              c->setstatus(ust);
+
+              if(x = xmlnode_get_tag(packet->x, "status"))
+                if(p = xmlnode_get_data(x))
+                  jhook.awaymsgs[ic.nickname] = p;
+
+#ifdef HAVE_GPGME
+              if(x = xmlnode_get_tag(packet->x, "x"))
+                if(p = xmlnode_get_attrib(x, "xmlns"))
+                  if((string) p == "jabber:x:signed")
+                    if(p = xmlnode_get_data(x))
+                      c->setpgpkey(pgp.verify(p, jhook.awaymsgs[ic.nickname]));
+#endif
+
+            }
+        }
+        */
+        break;
+
+    case JPACKET_S10N:
+        scr_LogPrint("Received subscription packet");
+        /*
+        isagent = find(jhook.agents.begin(), jhook.agents.end(), from) != jhook.agents.end();
+
+        if(type == "subscribe") {
+          if(!isagent) {
+            em.store(imauthorization(ic, imevent::incoming,
+                        imauthorization::Request, _("The user wants to subscribe to your network presence updates")));
+
+          } else {
+            auto_ptr<char> cfrom(strdup(from.c_str()));
+            x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0);
+            jab_send(jhook.jc, x);
+            xmlnode_free(x);
+          }
+
+        } else if(type == "unsubscribe") {
+          auto_ptr<char> cfrom(strdup(from.c_str()));
+          x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom.get(), 0);
+          jab_send(jhook.jc, x);
+          xmlnode_free(x);
+          em.store(imnotification(ic, _("The user has removed you from his contact list (unsubscribed you, using the Jabber language)")));
+
+        }
+        */
+
+        break;
+
+    default:
+        break;
+  }
+}
+
+jconn jb_connect(const char *servername, unsigned int port, int ssl,
+                  const char *jid, const char *pass,
+                  const char *resource)
+{
+  if (!port) {
+    if (ssl)
+      port = JABBERSSLPORT;
+    else
+      port = JABBERPORT;
+  }
+
+  if (jc)
+    free(jc);
+
+  //jc = jab_new(jid, pass, port, ssl);
+  jc = jab_new("mctest@lilotux.net/mcabber", (char*)pass, (int)port, ssl);
+
+  jab_packet_handler(jc, &packethandler);
+  jab_state_handler(jc, &statehandler);
+
+  if (jc->user) {
+    //fonline = true;
+    scr_LogPrint("+ State_Connecting");
+    jstate = STATE_CONNECTING;
+    statehandler(0, -1);
+    jab_start(jc);
+  }
+
+  return jc;
+}
+
+void jb_disconnect(void)
+{
+  statehandler(jc, JCONN_STATE_OFF);
+}
+
+void jb_keepalive()
+{
+  if (jc) {
+    // XXX Only if connected...
+    jab_send_raw(jc, " ");
+  }
+}
+
+void jb_main()
+{
+  xmlnode x, z;
+  char *cid;
+
+  if (jc && jc->state == JCONN_STATE_CONNECTING) {
+    jab_start(jc);
+    return;
+  }
+
+  jab_poll(jc, 0);
+
+  if (jstate == STATE_CONNECTING) {
+    if (jc) {
+      x = jutil_iqnew(JPACKET__GET, NS_AUTH);
+      cid = jab_getid(jc);
+      xmlnode_put_attrib(x, "id", cid);
+      // id = atoi(cid);
+
+      z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username");
+      xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1);
+      jab_send(jc, x);
+      xmlnode_free(x);
+
+      jstate = STATE_GETAUTH;
+    }
+
+    if (!jc || jc->state == JCONN_STATE_OFF) {
+      scr_LogPrint("Unable to connect to the server");
+      // fonline = false;
+    }
+  }
+
+  if (!jc) {
+    statehandler(jc, JCONN_STATE_OFF);
+  } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
+    statehandler(jc, JCONN_STATE_OFF);
+  }
+}
+
+void setjabberstatus(enum imstatus st, char *msg)
+{
+  xmlnode x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
+
+  switch(st) {
+    case away:
+        xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
+                (unsigned) -1);
+        break;
+
+    case occupied:
+    case dontdisturb:
+        xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
+                (unsigned) -1);
+        break;
+
+    case freeforchat:
+        xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
+                (unsigned) -1);
+        break;
+
+    case notavail:
+        xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
+                (unsigned) -1);
+        break;
+
+    case invisible:
+        xmlnode_put_attrib(x, "type", "invisible");
+        break;
+  }
+
+  /*
+  if(!add["prio"].empty())
+    xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
+            add["prio"].c_str(), (unsigned) -1);
+  */
+
+  if (!msg || !*msg) {
+    msg  = "unknownStatus";
+    //msg = imstatus2str(st);
+  }
+
+  xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg,
+          (unsigned) -1);
+
+  jab_send(jc, x);
+  xmlnode_free(x);
+
+  //sendvisibility();
+
+  // XXX logger.putourstatus(proto, getstatus(), ourstatus = st);
+}
+
+void gotloggedin(void)
+{
+  xmlnode x;
+
+  /*
+  x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
+  xmlnode_put_attrib(x, "id", "Agent List");
+  jab_send(jc, x);
+  xmlnode_free(x);
+  */
+
+  x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
+  xmlnode_put_attrib(x, "id", "Roster");
+  jab_send(jc, x);
+  xmlnode_free(x);
+}
+
+void gotroster(xmlnode x)
+{
+  xmlnode y; // z;
+
+  for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
+    const char *alias = xmlnode_get_attrib(y, "jid");
+    const char *sub = xmlnode_get_attrib(y, "subscription");
+    const char *name = xmlnode_get_attrib(y, "name");
+    //const char *group = 0;
+
+    //z = xmlnode_get_tag(y, "group");
+    //if(z) group = xmlnode_get_data(z);
+
+    if (alias) {
+      char *buddyname = jidtodisp(alias);
+      if (buddyname) {
+        scr_LogPrint("New buddy: %s", buddyname);
+        free(buddyname);
+      }
+    }
+  }
+
+  postlogin();
+}
+
+void postlogin()
+{
+  //int i;
+
+  //flogged = true;
+  //ourstatus = available;
+
+  //setautostatus(jhook.manualstatus);
+
+  /*
+  for (i = 0; i < clist.count; i++) {
+    c = (icqcontact *) clist.at(i);
+
+    if (c->getdesc().pname == proto)
+      if (ischannel(c))
+        if (c->getbasicinfo().requiresauth)
+          c->setstatus(available);
+  }
+  */
+
+  /*
+  agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
+  agents.begin()->params[agent::ptRegister].enabled = true;
+
+  string buf;
+  ifstream f(conf.getconfigfname("jabber-infoset").c_str());
+
+  if (f.is_open()) {
+    icqcontact *c = clist.get(contactroot);
+
+    c->clear();
+    icqcontact::basicinfo bi = c->getbasicinfo();
+    icqcontact::reginfo ri = c->getreginfo();
+
+    ri.service = agents.begin()->name;
+    getstring(f, buf); c->setnick(buf);
+    getstring(f, buf); bi.email = buf;
+    getstring(f, buf); bi.fname = buf;
+    getstring(f, buf); bi.lname = buf;
+    f.close();
+
+    c->setbasicinfo(bi);
+    c->setreginfo(ri);
+
+    sendupdateuserinfo(*c);
+    unlink(conf.getconfigfname("jabber-infoset").c_str());
+  }
+  */
+}
+
+void gotmessage(char *type, const char *from, const char *body,
+        const char *enc)
+{
+  char *u, *h, *r;
+
+  jidsplit(from, &u, &h, &r);
+  if (*r)
+    scr_LogPrint("There is an extra part in message: %s", *r);
+  scr_WriteIncomingMessage(from, body);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcabber/src/jabglue.h	Mon Mar 28 20:12:48 2005 +0000
@@ -0,0 +1,32 @@
+#ifndef __JABGLUE_H__
+#define __JABGLUE_H__ 1
+
+#include "../libjabber/jabber.h"
+
+extern jconn jc;
+
+enum imstatus {
+    offline = 0,
+    available,
+    invisible,
+    freeforchat,
+    dontdisturb,
+    occupied,
+    notavail,
+    away,
+    imstatus_size
+};
+
+static char imstatus2char[imstatus_size] = {
+    '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a'
+};
+
+jconn jb_connect(const char *servername, unsigned int port, int ssl,
+                 const char *jid, const char *pass,
+                 const char *resource);
+void jb_disconnect(void);
+void jb_keepalive();
+void jb_main();
+//int  jb_status();
+
+#endif /* __JABGLUE_H__ */
--- a/mcabber/src/main.c	Mon Mar 28 10:36:47 2005 +0000
+++ b/mcabber/src/main.c	Mon Mar 28 20:12:48 2005 +0000
@@ -14,21 +14,22 @@
 #include "server.h"
 #include "harddefines.h"
 #include "socket.h"
+#include "jabglue.h"
 
-int sock;
+//int sock;
 
 void sig_handler(int signum)
 {
   switch (signum) {
   case SIGALRM:
-    sk_send(sock, " ");
+    jb_keepalive();
     break;
 
   case SIGTERM:
     bud_TerminateBuddies();
     scr_TerminateCurses();
-    srv_setpresence(sock, "unavailable");
-    close(sock);
+    // TODO srv_setpresence(sock, "unavailable");
+    // TODO close(sock);
     printf("Killed by SIGTERM\nBye!\n");
     exit(EXIT_SUCCESS);
     break;
@@ -70,7 +71,7 @@
   char configFile[4096];
   char *username, *password, *resource;
   char *servername;
-  char *idsession;
+  //char *idsession;
   char *portstring;
   int key;
   unsigned int port;
@@ -144,39 +145,29 @@
   ut_WriteLog("Initializing N-Curses...\n");
   scr_InitCurses();
 
+  ut_WriteLog("Drawing main window...\n");
+  scr_DrawMainWindow();
+
   /* Connect to server */
   portstring = cfg_read("port");
   port = (portstring != NULL) ? (unsigned int) atoi(portstring) : -1U;
 
   ut_WriteLog("Connecting to server: %s:%d\n", servername, port);
-  if ((sock = srv_connect(servername, port)) < 0) {
+  scr_LogPrint("Connecting to server: %s:%d", servername, port);
+  jc = jb_connect(servername, port, 0, username, password, resource);
+  if (!jc) {
     ut_WriteLog("\terror!!!\n");
     fprintf(stderr, "Error connecting to (%s)\n", servername);
     scr_TerminateCurses();
     return -2;
   }
 
-  ut_WriteLog("Sending login string...\n");
-  if ((idsession = srv_login(sock, servername, username, password, 
-                             resource)) == NULL) {
-
-    ut_WriteLog("\terror!!!\n");
-    fprintf(stderr, "Error sending login string...\n");
-    scr_TerminateCurses();
-    return -3;
-  }
-  ut_WriteLog("Connected to %.48s: %s\n", servername, idsession);
-  free(idsession);
-
-  ut_WriteLog("Requesting roster...\n");
-  bud_InitBuddies(sock);
+  /*
+  bud_InitBuddies(sock); // TODO
 
   ut_WriteLog("Sending presence...\n");
   srv_setpresence(sock, "Online!");
-
-
-  ut_WriteLog("Drawing main window...\n");
-  scr_DrawMainWindow();
+  */
 
   ping = 15;
   if (cfg_read("pinginterval"))
@@ -187,10 +178,21 @@
   ut_WriteLog("Entering into main loop...\n\n");
   ut_WriteLog("Ready to send/receive messages...\n");
 
+  sleep(1);
+  jb_main();
+  sleep(1);
+  jb_main();
+  sleep(2);
+  jb_disconnect();
+  sleep(1);
+  jb_main();
+  scr_TerminateCurses(); exit(0); // XXX
   while (ret != 255) {
     int x;
     alarm(ping);
-    x = check_io(sock, 0);
+    //x = check_io(sock, 0);
+    x = check_io(0, 0); // FIXME
+    /*
     if ((x & 1) == 1) {
       srv_msg *incoming = readserver(sock);
 
@@ -211,9 +213,11 @@
       free(incoming);
     }
     if ((x & 2) == 2) {
+    */
+    if (x) {
       keypad(scr_GetInputWindow(), TRUE);
       key = scr_Getch();
-      ret = process_key(key, sock);
+      ret = process_key(key);
       /*
       switch (key) {
       case KEY_IC:
@@ -241,9 +245,8 @@
   bud_TerminateBuddies();
   scr_TerminateCurses();
 
-  srv_setpresence(sock, "unavailable");
-
-  close(sock);
+  //srv_setpresence(sock, "unavailable");
+  //close(sock);
 
   printf("\n\nHave a nice day!\nBye!\n");
 
--- a/mcabber/src/screen.c	Mon Mar 28 10:36:47 2005 +0000
+++ b/mcabber/src/screen.c	Mon Mar 28 20:12:48 2005 +0000
@@ -612,7 +612,7 @@
   return FALSE;
 }
 
-void send_message(int sock, char *msg)
+void send_message(char *msg)
 {
   char **submsgs;
   char *buffer = (char *) calloc(1, 24+strlen(msg));
@@ -642,17 +642,17 @@
   refresh();
   sprintf(buffer2, "%s@%s/%s", cfg_read("username"),
           cfg_read("server"), cfg_read("resource"));
-  srv_sendtext(sock, tmp->jid, msg, buffer2);
+  // FIXME srv_sendtext(sock, tmp->jid, msg, buffer2);
   free(buffer);
   free(buffer2);
 
   top_panel(inputPanel);
 }
 
-int process_line(char *line, int sock)
+int process_line(char *line)
 {
   if (*line != '/') {
-    send_message(sock, line);
+    // FIXME send_message(sock, line);
     return 0;
   }
   if (!strcasecmp(line, "/quit")) {
@@ -688,7 +688,7 @@
   }
 }
 
-int process_key(int key, int sock)
+int process_key(int key)
 {
   if (isprint(key)) {
     char tmpLine[INPUTLINE_LENGTH+1];
@@ -735,7 +735,7 @@
             scr_ShowBuddyWindow();
             break;
           }
-          if (process_line(inputLine, sock))
+          if (process_line(inputLine))
             return 255;
           ptr_inputline = inputLine;
           *ptr_inputline = 0;
--- a/mcabber/src/screen.h	Mon Mar 28 10:36:47 2005 +0000
+++ b/mcabber/src/screen.h	Mon Mar 28 20:12:48 2005 +0000
@@ -37,6 +37,6 @@
 
 int scr_Getch(void);
 
-int process_key(int, int sock);
+int process_key(int);
 
 #endif