From: Rob F. <rob...@us...> - 2002-10-11 03:14:03
|
Update of /cvsroot/gaim/gaim/src/protocols/jabber In directory usw-pr-cvs1:/tmp/cvs-serv28946/src/protocols/jabber Modified Files: jabber.c jabber.h lib.h libxode.h socket.c Added Files: Makefile.mingw Log Message: Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk. --- NEW FILE: Makefile.mingw --- # # Makefile.mingw # # Description: Makefile for win32 (mingw) version of libjabber # # # PATHS # INCLUDE_DIR := . GTK_TOP := ../../../../win32-dev/gtk_2_0 GAIM_TOP := ../../.. JABBER_ROOT := . GAIM_INSTALL_DIR := $(GAIM_TOP)/win32-install-dir ## ## VARIABLE DEFINITIONS ## TARGET = libjabber VERSION := $(shell cat $(GAIM_TOP)/VERSION) # Compiler Options CC = gcc CFLAGS = -O2 -Werror -Wall -mno-cygwin -fnative-struct DEFINES = -DAIM_BUILDDATE=\"`date +%Y%m%d`\" \ -DAIM_BUILDTIME=\"`date +%H%M%S`\" \ -DVERSION=\"$(VERSION)\" \ -DHAVE_CONFIG_H # Static or Plugin... ifeq ($(TYPE),STATIC) DEFINES += -DSTATIC DLL_INSTALL_DIR = $(GAIM_INSTALL_DIR) else ifeq ($(TYPE),PLUGIN) DLL_INSTALL_DIR = $(GAIM_INSTALL_DIR)/plugins endif endif ## ## INCLUDE MAKEFILES ## ## ## INCLUDE PATHS ## INCLUDE_PATHS += -I$(JABBER_ROOT) \ -I$(JABBER_ROOT)/win32 \ -I$(GTK_TOP)/include \ -I$(GTK_TOP)/include/gtk-2.0 \ -I$(GTK_TOP)/include/glib-2.0 \ -I$(GTK_TOP)/include/pango-1.0 \ -I$(GTK_TOP)/include/atk-1.0 \ -I$(GTK_TOP)/lib/glib-2.0/include \ -I$(GTK_TOP)/lib/gtk-2.0/include \ -I$(GAIM_TOP)/src \ -I$(GAIM_TOP)/src/win32 \ -I$(GAIM_TOP) LIB_PATHS = -L$(GTK_TOP)/lib \ -L$(GAIM_TOP)/src ## ## SOURCES, OBJECTS ## C_SRC = jabber.c \ expat.c \ genhash.c \ hashtable.c \ jconn.c \ jid.c \ jpacket.c \ jutil.c \ karma.c \ log.c \ pool.c \ pproxy.c \ rate.c \ sha.c \ snprintf.c \ socket.c \ str.c \ xhash.c \ xmlnode.c \ xmlparse.c \ xmlrole.c \ xmltok.c \ xstream.c \ win32/posix.uname.c OBJECTS = $(C_SRC:%.c=%.o) ## ## LIBRARIES ## LIBS = -lgtk-win32-2.0 -lglib-2.0 -lgdk-win32-2.0 -lgmodule-2.0 -lgobject-2.0 -lws2_32 -lintl -lgaim # -liberty ## ## RULES ## # How to make a C file %.o: %.c $(CC) $(CFLAGS) $(DEFINES) $(INCLUDE_PATHS) -o $@ -c $< ## ## TARGET DEFINITIONS ## .PHONY: all clean all: $(TARGET).dll install: cp $(JABBER_ROOT)/$(TARGET).dll $(DLL_INSTALL_DIR) ## ## BUILD Dependencies ## $(GAIM_TOP)/src/gaim.lib: $(MAKE) -C $(GAIM_TOP)/src -f Makefile.mingw gaim.lib ## ## BUILD DLL ## $(TARGET).def: $(OBJECTS) dlltool --dllname $(TARGET).dll -z $(TARGET).def \ $(OBJECTS) $(TARGET).base: $(OBJECTS) $(GAIM_TOP)/src/gaim.lib gcc -mdll -o junk.tmp -Wl,--base-file,$@ $(OBJECTS) $(LIB_PATHS) $(LIBS) rm -rf junk.tmp $(TARGET).exp: $(TARGET).def $(TARGET).base dlltool --dllname $(TARGET).dll --base-file $(TARGET).base \ --output-exp $(TARGET).exp --def $(TARGET).def rm -rf $(TARGET).base $(TARGET).dll: $(OBJECTS) $(TARGET).exp $(GAIM_TOP)/src/gaim.lib dlltool -D $(TARGET).dll -d $(TARGET).def -l $(TARGET).lib gcc -mdll -o $(TARGET).dll $(OBJECTS) -Wl,$(TARGET).exp $(LIB_PATHS) $(LIBS) rm -rf $(TARGET).exp ## ## CLEAN RULES ## clean: rm -rf *.o rm -rf ./win32/*.o rm -rf $(TARGET).dll rm -rf $(TARGET).lib rm -rf $(TARGET).def Index: jabber.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.c,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- jabber.c 9 Oct 2002 05:46:02 -0000 1.67 +++ jabber.c 11 Oct 2002 03:14:00 -0000 1.68 @@ -20,23 +20,27 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif - +#ifndef _WIN32 #include <netdb.h> -#include <unistd.h> -#include <errno.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/utsname.h> +#include <unistd.h> +#else +#include <winsock.h> +#include "utsname.h" +#endif + +#include <errno.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> -#include <sys/socket.h> -#include <sys/utsname.h> #include <sys/stat.h> #include "multi.h" #include "prpl.h" @@ -50,6 +54,10 @@ #include "jabber.h" #include "proxy.h" +#ifdef _WIN32 +#include "win32dep.h" +#endif + #include "pixmaps/protocols/jabber/available.xpm" #include "pixmaps/protocols/jabber/available-away.xpm" #include "pixmaps/protocols/jabber/available-chat.xpm" @@ -57,6 +65,9 @@ #include "pixmaps/protocols/jabber/available-dnd.xpm" #include "pixmaps/protocols/jabber/available-error.xpm" +/* for win32 compatability */ +G_MODULE_IMPORT GSList *connections; + /* The priv member of gjconn's is a gaim_connection for now. */ #define GJ_GC(x) ((struct gaim_connection *)(x)->priv) @@ -140,6 +151,7 @@ time_t idle; gboolean die; GHashTable *buddies; + GSList *file_transfers; }; /* @@ -229,6 +241,8 @@ static void jabber_handlevcard(gjconn, xmlnode, char *); +static char *jabber_normalize(const char *s); + static char *create_valid_jid(const char *given, char *server, char *resource) { char *valid; @@ -492,7 +506,11 @@ gjab_send_raw(gjc, "</stream:stream>"); gjc->state = JCONN_STATE_OFF; gjc->was_connected = 0; +#ifndef _WIN32 close(gjc->fd); +#else + closesocket(gjc->fd); +#endif gjc->fd = -1; XML_ParserFree(gjc->parser); gjc->parser = NULL; @@ -535,7 +553,11 @@ if (gjc && gjc->state != JCONN_STATE_OFF) { char *buf = xmlnode2str(x); if (buf) +#ifndef _WIN32 write(gjc->fd, buf, strlen(buf)); +#else + send(gjc->fd, buf, strlen(buf), 0); +#endif debug_printf("gjab_send: %s\n", buf); } } @@ -546,7 +568,11 @@ /* * JFIXME: No error detection?!?! */ +#ifndef _WIN32 if(write(gjc->fd, str, strlen(str)) < 0) { +#else + if(send(gjc->fd, str, strlen(str), 0) < 0) { +#endif fprintf(stderr, "DBG: Problem sending. Error: %d\n", errno); fflush(stderr); } @@ -636,8 +662,11 @@ if (!gjc || gjc->state == JCONN_STATE_OFF) return; - +#ifndef _WIN32 if ((len = read(gjc->fd, buf, sizeof(buf) - 1)) > 0) { +#else + if ((len = recv(gjc->fd, buf, sizeof(buf) - 1, 0)) > 0) { +#endif struct jabber_data *jd = GJ_GC(gjc)->proto_data; buf[len] = '\0'; debug_printf("input (len %d): %s\n", len, buf); @@ -727,7 +756,11 @@ gjconn gjc; if (!g_slist_find(connections, gc)) { +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif return; } @@ -1901,12 +1934,194 @@ xmlnode_free(x); } +struct jabber_file_transfer { + enum { JFT_SENDFILE_IN, JFT_SENDFILE_OUT } type; + struct file_transfer *xfer; + char *from; + struct g_url *url; + char *name; + GString *headers; + + int len; + int fd; + int watcher; + + gboolean sentreq; + gboolean newline; + gboolean startsaving; + + struct gaim_connection *gc; +}; + +static struct jabber_file_transfer *find_jft_by_xfer(struct gaim_connection *gc, + struct file_transfer *xfer) { + GSList *g = ((struct jabber_data *)gc->proto_data)->file_transfers; + struct jabber_file_transfer *f = NULL; + + while(g) { + f = (struct jabber_file_transfer *)g->data; + if(f->xfer == xfer) + break; + g = g->next; + f = NULL; + } + + return f; +} + +static void jabber_http_recv_callback(gpointer data, gint source, GaimInputCondition condition) { + struct jabber_file_transfer *jft = data; + char test; + + jft->fd = source; + if(!jft->sentreq) { + char buf[1024]; + g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", jft->url->page, jft->url->address); + write(source, buf, strlen(buf)); + fcntl(source, F_SETFL, O_NONBLOCK); + jft->sentreq = TRUE; + jft->watcher = gaim_input_add(source, GAIM_INPUT_READ, jabber_http_recv_callback,data); + return; + } + + if(!jft->startsaving) { + if(read(source, &test, sizeof(test)) > 0 || errno == EWOULDBLOCK) { + if(errno == EWOULDBLOCK) { + errno = 0; + return; + } + + jft->headers = g_string_append_c(jft->headers, test); + if(test == '\r') + return; + if(test == '\n') { + if(jft->newline) { + gchar *lenstr = strstr(jft->headers->str, "Content-Length: "); + if(lenstr) { + sscanf(lenstr, "Content-Length: %d", &jft->len); + } + jft->startsaving = TRUE; + } else + jft->newline = TRUE; + return; + } + jft->newline = FALSE; + return; + } else { + gaim_input_remove(jft->watcher); + close(source); + //FIXME: ft_cancel(NULL, jft->xfer); + } + return; + } + + /* we've parsed the headers, gotten the size, all is good. now we pass the reception of + * the file off to the core, and leave it in it's capable...err...hands?? */ + gaim_input_remove(jft->watcher); + jft->watcher = 0; + transfer_in_do(jft->xfer, jft->fd, jft->name, jft->len); +} + +static void jabber_file_transfer_cancel(struct gaim_connection *gc, struct file_transfer *xfer) { + struct jabber_data *jd = gc->proto_data; + struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer);\ + xmlnode x,y; + + jd->file_transfers = g_slist_remove(jd->file_transfers, jft); + + gaim_input_remove(jft->watcher); + close(jft->fd); + + x = xmlnode_new_tag("iq"); + xmlnode_put_attrib(x, "type", "error"); + xmlnode_put_attrib(x, "to", jft->from); + y = xmlnode_insert_tag(x, "error"); + /* FIXME: need to handle other kinds of errors here */ + xmlnode_put_attrib(y, "code", "406"); + xmlnode_insert_cdata(y, "File Transfer Refused", -1); + + gjab_send(jd->gjc, x); + + xmlnode_free(x); + + g_string_free(jft->headers, TRUE); + g_free(jft->from); + g_free(jft->url); + g_free(jft->name); + + g_free(jft); +} + +static void jabber_file_transfer_done(struct gaim_connection *gc, struct file_transfer *xfer) { + struct jabber_data *jd = gc->proto_data; + struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer); + xmlnode x; + + jd->file_transfers = g_slist_remove(jd->file_transfers, jft); + + gaim_input_remove(jft->watcher); + close(jft->fd); + + x = xmlnode_new_tag("iq"); + xmlnode_put_attrib(x, "type", "result"); + xmlnode_put_attrib(x, "to", jft->from); + + gjab_send(jd->gjc, x); + + xmlnode_free(x); + + g_string_free(jft->headers, TRUE); + g_free(jft->from); + g_free(jft->url); + g_free(jft->name); + + g_free(jft); +} + +static void jabber_file_transfer_in(struct gaim_connection *gc, struct file_transfer *xfer, int offset) { + struct jabber_file_transfer *jft = find_jft_by_xfer(gc, xfer); + + proxy_connect(jft->url->address, jft->url->port, jabber_http_recv_callback, jft); +} + +static void jabber_handleoob(gjconn gjc, xmlnode iqnode) { + struct jabber_file_transfer *jft; + struct jabber_data *jd = GJ_GC(gjc)->proto_data; + char *msg = NULL; + xmlnode querynode = xmlnode_get_tag(iqnode, "query"); + xmlnode urlnode,descnode; + + if(!querynode) + return; + urlnode = xmlnode_get_tag(querynode, "url"); + if(!urlnode) + return; + descnode = xmlnode_get_tag(querynode, "desc"); + if(descnode) + msg = xmlnode_get_data(descnode); + + jft = g_new0(struct jabber_file_transfer, 1); + jft->type = JFT_SENDFILE_IN; + jft->gc = GJ_GC(gjc); + jft->url = parse_url(xmlnode_get_data(urlnode)); + jft->from = g_strdup(xmlnode_get_attrib(iqnode, "from")); + jft->name = g_strdup(g_strrstr(jft->url->page,"/")); + if (!jft->name) + jft->name = g_strdup(jft->url->page); + jft->headers = g_string_new(""); + jft->len = -1; + + jd->file_transfers = g_slist_append(jd->file_transfers, jft); + + jft->xfer = transfer_in_add(GJ_GC(gjc), jft->from, jft->name, jft->len, 1, msg); +} + static void jabber_handlelast(gjconn gjc, xmlnode iqnode) { - xmlnode x, querytag; + xmlnode x, querytag; char *id, *from; struct jabber_data *jd = GJ_GC(gjc)->proto_data; char idle_time[32]; - + id = xmlnode_get_attrib(iqnode, "id"); from = xmlnode_get_attrib(iqnode, "from"); @@ -1979,6 +2194,8 @@ querynode = xmlnode_get_tag(p->x, "query"); if (NSCHECK(querynode, "jabber:iq:roster")) { jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); + } else if(NSCHECK(querynode, "jabber:iq:oob")) { + jabber_handleoob(gjc, p->x); } } else if (jpacket_subtype(p) == JPACKET__GET) { xmlnode querynode; @@ -2261,7 +2478,7 @@ xmlnode_insert_tag(y, "composing"); if (message && strlen(message)) { - char *utf8 = str_to_utf8(message); + char *utf8 = str_to_utf8((char*)message); y = xmlnode_insert_tag(x, "body"); xmlnode_insert_cdata(y, utf8, -1); g_free(utf8); @@ -2748,7 +2965,7 @@ g_free(subject); if (message && strlen(message)) { - char *utf8 = str_to_utf8(message); + char *utf8 = str_to_utf8((char*)message); y = xmlnode_insert_tag(x, "body"); xmlnode_insert_cdata(y, utf8, -1); g_free(utf8); @@ -3960,7 +4177,7 @@ static struct prpl *my_protocol = NULL; -void jabber_init(struct prpl *ret) +G_MODULE_EXPORT void jabber_init(struct prpl *ret) { /* the NULL's aren't required but they're nice to have */ struct proto_user_opt *puo; @@ -4009,7 +4226,12 @@ ret->send_typing = jabber_send_typing; ret->convo_closed = jabber_convo_closed; ret->rename_group = jabber_rename_group; - + ret->file_transfer_out = NULL; /* TODO */ + ret->file_transfer_in = jabber_file_transfer_in; + ret->file_transfer_data_chunk = NULL; /* TODO */ + ret->file_transfer_done = jabber_file_transfer_done; + ret->file_transfer_cancel = jabber_file_transfer_cancel; + puo = g_new0(struct proto_user_opt, 1); puo->label = g_strdup("Port:"); puo->def = g_strdup("5222"); @@ -4021,7 +4243,7 @@ #ifndef STATIC -void *gaim_prpl_init(struct prpl *prpl) +G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) { jabber_init(prpl); prpl->plug->desc.api_version = PLUGIN_API_VERSION; Index: jabber.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- jabber.h 31 Jul 2001 01:00:38 -0000 1.1 +++ jabber.h 11 Oct 2002 03:14:00 -0000 1.2 @@ -16,6 +16,18 @@ * Jabber * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ */ +#ifndef _WIN32 +#include <syslog.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <strings.h> +#include <unistd.h> +#else +#include <winsock.h> +#include "win32dep.h" +#endif #include <string.h> #include <stdlib.h> @@ -27,13 +39,6 @@ #include <errno.h> #include <signal.h> #include <stdarg.h> -#include <syslog.h> -#include <strings.h> -#include <unistd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> #include <sys/time.h> #include <time.h> #include <ctype.h> Index: lib.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/lib.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- lib.h 4 Apr 2002 03:04:57 -0000 1.1 +++ lib.h 11 Oct 2002 03:14:00 -0000 1.2 @@ -1,3 +1,21 @@ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#ifndef _WIN32 +#include <syslog.h> +#include <strings.h> +#include <sys/param.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <unistd.h> +#else +#include <winsock.h> +#include <stdlib.h> +#include "win32dep.h" +#endif #include <string.h> #include <stdlib.h> @@ -8,14 +26,6 @@ #include <fcntl.h> #include <errno.h> #include <signal.h> -#include <syslog.h> -#include <strings.h> -#include <unistd.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> #include <sys/time.h> #include <stdarg.h> #include <ctype.h> @@ -151,11 +161,9 @@ #define NETSOCKET_CLIENT 1 #define NETSOCKET_UDP 2 -#ifndef WIN32 int make_netsocket(u_short port, char *host, int type); struct in_addr *make_addr(char *host); int set_fd_close_on_exec(int fd, int flag); -#endif /* --------------------------------------------------------- */ Index: libxode.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/libxode.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- libxode.h 20 Dec 2001 19:58:43 -0000 1.2 +++ libxode.h 11 Oct 2002 03:14:00 -0000 1.3 @@ -1,3 +1,17 @@ +#ifndef _WIN32 +#include <syslog.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <strings.h> +#include <arpa/nameser.h> +#include <resolv.h> +#include <unistd.h> +#else + +#endif + #include <string.h> #include <stdlib.h> #include <sys/types.h> @@ -7,15 +21,6 @@ #include <fcntl.h> #include <errno.h> #include <signal.h> -#include <syslog.h> -#include <strings.h> -#include <unistd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> -#include <resolv.h> #include <sys/time.h> #include <time.h> @@ -152,11 +157,9 @@ #define NETSOCKET_CLIENT 1 #define NETSOCKET_UDP 2 -#ifndef WIN32 int make_netsocket(u_short port, char *host, int type); struct in_addr *make_addr(char *host); int set_fd_close_on_exec(int fd, int flag); -#endif /* --------------------------------------------------------- */ Index: socket.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/socket.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- socket.c 4 Apr 2002 03:04:57 -0000 1.2 +++ socket.c 11 Oct 2002 03:14:00 -0000 1.3 @@ -148,6 +148,7 @@ return NULL; } +#ifndef _WIN32 /* Sets a file descriptor to close on exec. "flag" is 1 to close on exec, 0 to * leave open across exec. * -- EJB 7/31/2000 @@ -166,4 +167,5 @@ return 0; return fcntl(fd,F_SETFL,(long)newflags); } +#endif |