changeset 1186:c00fc3adfd66

[gaim-migrate @ 1196] mostly libfaim updates, and a fix for something i broke in the import dialog. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 02 Dec 2000 18:41:58 +0000
parents 47cf56b72d4b
children 6a8e8c06baa5
files ChangeLog libfaim/CHANGES libfaim/aim_chat.c libfaim/aim_conn.c libfaim/aim_ft.c libfaim/aim_msgcookie.c libfaim/aim_rxhandlers.c libfaim/faim/aim.h src/dialogs.c src/oscar.c
diffstat 10 files changed, 122 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Dec 02 04:48:10 2000 +0000
+++ b/ChangeLog	Sat Dec 02 18:41:58 2000 +0000
@@ -13,6 +13,7 @@
 	* small change in the way away messages are displayed
 	  (Thanks Ryan C. Gordon)
 	* Plugin system uses GModule now (improves portability, adds features)
+	  (Requires recompile and probably modifications of most plugins)
 	* Perl got updates (reread plugins/PERL-HOWTO)
 	* Spell checker now uses gtkspell
 	* Auto-Away (thanks, yet again, to bmiller ;)
--- a/libfaim/CHANGES	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/CHANGES	Sat Dec 02 18:41:58 2000 +0000
@@ -1,6 +1,12 @@
 
 No release numbers
 ------------------
+ - Sat Dec  2 02:14:45 UTC 2000
+  - Dumb bug in aim_clearhandlers()
+
+ - Fri Dec  1 23:48:38 UTC 2000
+  - Store exchange along with room name in the great chat hack
+
  - Fri Dec  1 22:25:56 UTC 2000
   - Fix numerous tiny (but sometimes catastrophic) bugs dealing
       with connection death (particularly with chat connections)
--- a/libfaim/aim_chat.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/aim_chat.c	Sat Dec 02 18:41:58 2000 +0000
@@ -155,10 +155,8 @@
   i+= aimutil_put16(newpacket->data+i, 2+1+strlen(roomname)+2);
   i+= aimutil_put16(newpacket->data+i, exchange);
   i+= aimutil_put8(newpacket->data+i, strlen(roomname));
-  memcpy(newpacket->data+i, roomname, strlen(roomname));
-  i+= strlen(roomname);
-  //i+= aimutil_putstr(newpacket->data+i, roomname, strlen(roomname));
-  i+= aimutil_put16(newpacket->data+i, 0x0000);
+  i+= aimutil_putstr(newpacket->data+i, roomname, strlen(roomname));
+  i+= aimutil_put16(newpacket->data+i, 0x0000); /* instance? */
 
   /*
    * Chat hack.
@@ -169,8 +167,8 @@
    *      redirect!
    *
    */
-  sess->pendingjoin = (char *)malloc(strlen(roomname)+1);
-  strcpy(sess->pendingjoin, roomname);
+  sess->pendingjoin = strdup(roomname);
+  sess->pendingjoinexchange = exchange;
 
   newpacket->lock = 0;
   aim_tx_enqueue(sess, newpacket);
--- a/libfaim/aim_conn.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/aim_conn.c	Sat Dec 02 18:41:58 2000 +0000
@@ -709,7 +709,9 @@
   sess->queue_outgoing = NULL;
   sess->queue_incoming = NULL;
   sess->pendingjoin = NULL;
+  sess->pendingjoinexchange = 0;
   aim_initsnachash(sess);
+  sess->msgcookies = NULL;
   sess->snac_nextid = 0x00000001;
 
   sess->flags = 0;
--- a/libfaim/aim_ft.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/aim_ft.c	Sat Dec 02 18:41:58 2000 +0000
@@ -1572,86 +1572,6 @@
 }
 
 /*
- * int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
- * conn is the OFT connection to shove the data down,
- * tosend is the FILE * for the file to send
- * fh is the filled-in fh value
- * pos is the position to start at (at beginning should be 0, after 5
- *  bytes are sent should be 5); -1 for "don't seek"
- * bufsize is the size of the chunk to send
- *
- * returns -1 on error, new pos on success.
- *
- * 
- * Notes on usage: 
- * You don't really have to keep track of pos if you don't want
- *  to. just always call with -1 for pos, and it'll use the one
- *  contained within the FILE *.
- *
- * if (pos + chunksize > fh->size), we only send as much data as we
- *  can get (ie: up to fh->size.  
- */
-
-faim_export int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
-{
-  int bufpos; 
-  char *buf;
-
-  /* sanity checks */
-  if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->type != AIM_CONN_SUBTYPE_OFT_GETFILE) {
-    faimdprintf(1, "faim: getfile_send_chunk: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
-    return -1;
-  }
-  
-  if(!tosend) {
-    faimdprintf(1, "faim: getfile_send_chunk: file pointer isn't valid\n");
-    return -1;
-  }
-
-  if(!fh) {
-    faimdprintf(1, "faim: getfile_send_chunk: fh isn't valid\n");
-    return -1;
-  }
-
-  /* real code */
-
-  if(!(buf = (char *)calloc(1, bufsize))) {
-    perror("faim: getfile_send_chunk: calloc:");
-    faimdprintf(2, "faim: getfile_send_chunk calloc error\n");
-    return -1;
-  }
-  
-  if(pos != -1) {
-    if( fseek(tosend, pos, SEEK_SET) == -1) {
-      perror("faim: getfile_send_chunk:  fseek:");
-      faimdprintf(2, "faim: getfile_send_chunk fseek error\n");
-    }  
-  }
-
-  faimdprintf(2, "faim: getfile_send_chunk: using %i byte blocks\n", bufsize);
-
-  for(bufpos = 0; pos < fh->size; bufpos++, pos++) {
-    if( (buf[bufpos] = fgetc(tosend)) == EOF) {
-      if(pos != fh->size) {
-	faimdprintf(1, "faim: getfile_send_chunk: hrm... apparent early EOF at pos 0x%x of 0x%x\n", pos, fh->size);
-	free(buf);   
-	return -1;
-      }
-    }      
-  }
-
-  if( write(conn->fd, buf, bufpos+1) != (bufpos+1)) {
-    faimdprintf(1, "faim: getfile_send_chunk cleanup: whoopsy, didn't write it all...\n");
-    free(buf);   
-    return -1;
-  }
-
-  free(buf);   
-  
-  return (pos + bufpos);
-}
-
-/*
  * aim_tx_destroy:
  * free's tx_command_t's. if command is locked, doesn't free.
  * returns -1 on error (locked struct); 0 on success.
@@ -1882,3 +1802,92 @@
 }
 
 #endif
+
+/*
+ * int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
+ * conn is the OFT connection to shove the data down,
+ * tosend is the FILE * for the file to send
+ * fh is the filled-in fh value
+ * pos is the position to start at (at beginning should be 0, after 5
+ *  bytes are sent should be 5); -1 for "don't seek"
+ * bufsize is the size of the chunk to send
+ *
+ * returns -1 on error, new pos on success. 0 on EOF
+ *
+ * 
+ * Notes on usage: 
+ * You don't really have to keep track of pos if you don't want
+ *  to. just always call with -1 for pos, and it'll use the one
+ *  contained within the FILE *.
+ *
+ * if (pos + chunksize > fh->size), we only send as much data as we
+ *  can get (ie: up to fh->size.  
+ */
+
+faim_export int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
+{
+  int bufpos; 
+  int curpos;
+  char *buf;
+
+  /* sanity checks */
+  if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->subtype != AIM_CONN_SUBTYPE_OFT_GETFILE) {
+    faimdprintf(1, "faim: getfile_send_chunk: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
+    return -1;
+  }
+  
+  if(!tosend) {
+    faimdprintf(1, "faim: getfile_send_chunk: file pointer isn't valid\n");
+    return -1;
+  }
+
+  if(!fh) {
+    faimdprintf(1, "faim: getfile_send_chunk: fh isn't valid\n");
+    return -1;
+  }
+
+  /* real code */
+
+  if(!(buf = (char *)calloc(1, bufsize))) {
+    perror("faim: getfile_send_chunk: calloc:");
+    faimdprintf(2, "faim: getfile_send_chunk calloc error\n");
+    return -1;
+  }
+  
+  if(pos != -1) {
+    if( fseek(tosend, pos, SEEK_SET) == -1) {
+      perror("faim: getfile_send_chunk:  fseek:");
+      faimdprintf(2, "faim: getfile_send_chunk fseek error\n");
+    }  
+    curpos = pos;
+  } else 
+    pos = ftell(tosend);
+	
+
+  faimdprintf(2, "faim: getfile_send_chunk: using %i byte blocks\n", bufsize);
+
+  for(bufpos = 0; (bufpos < bufsize) && (pos < fh->size); bufpos++, pos++) {
+    if( (buf[bufpos] = fgetc(tosend)) == EOF) {
+#if 0 /* fuck checking */
+      if(pos != fh->size) {
+	fprintf(stderr, "faim: getfile_send_chunk: hrm... apparent early EOF at pos 0x%x of 0x%x\n", pos, fh->size);
+	perror("getfile_send_chunk: fgetc: ");
+	free(buf);   
+	return -1;
+      }
+#endif
+      return 0;
+    }      
+  }
+
+  if( write(conn->fd, buf, bufpos+1) != (bufpos+1)) {
+    faimdprintf(1, "faim: getfile_send_chunk cleanup: whoopsy, didn't write it all...\n");
+    perror("getfile_send_chunk: write: ");
+    free(buf);   
+    return -1;
+  }
+
+  free(buf);   
+  
+  return (pos+1);
+}
--- a/libfaim/aim_msgcookie.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/aim_msgcookie.c	Sat Dec 02 18:41:58 2000 +0000
@@ -123,7 +123,7 @@
     if (cur->addtime > (time(NULL) - maxage)) {
       struct aim_msgcookie_t *remed = NULL;
 
-#if DEBUG > 1
+#if 1
       printf("aimmsgcookie: WARNING purged obsolete message cookie %x%x%x%x %x%x%x%x\n",
 	     cur->cookie[0], cur->cookie[1], cur->cookie[2], cur->cookie[3],
 	     cur->cookie[4], cur->cookie[5], cur->cookie[6], cur->cookie[7]);
--- a/libfaim/aim_rxhandlers.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/aim_rxhandlers.c	Sat Dec 02 18:41:58 2000 +0000
@@ -228,14 +228,14 @@
  if (!conn)
    return -1;
 
- cur = conn->handlerlist;
- while(cur) {
+ for (cur = conn->handlerlist; cur; ) {
    struct aim_rxcblist_t *tmp;
 
    tmp = cur->next;
    free(cur);
    cur = tmp;
  }
+ conn->handlerlist = NULL;
 
  return 0;
 }
@@ -781,9 +781,10 @@
        */
       userfunc = aim_callhandler(command->conn, 0x0001, 0x0005);
       if (userfunc)
-	ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin);
+	ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange);
       free(sess->pendingjoin);
       sess->pendingjoin = NULL;
+      sess->pendingjoinexchange = 0;
     }
   else
     {
--- a/libfaim/faim/aim.h	Sat Dec 02 04:48:10 2000 +0000
+++ b/libfaim/faim/aim.h	Sat Dec 02 18:41:58 2000 +0000
@@ -338,6 +338,7 @@
    * request and the resulting redirect.)
    */ 
   char *pendingjoin;
+  unsigned short pendingjoinexchange;
 
   /*
    * Outstanding snac handling 
--- a/src/dialogs.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/src/dialogs.c	Sat Dec 02 18:41:58 2000 +0000
@@ -2934,6 +2934,7 @@
 	char g_screenname[64];
 	int i;
         FILE *f;
+	gboolean from_dialog = FALSE;
 
         if ( !gc ) {
         	file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
@@ -2945,6 +2946,7 @@
 		}
 		/* FIXME : import buddy list file. moderately important */
 		gc = connections->data;
+		from_dialog = TRUE;
         }
         else {
 		for (i = 0; i < strlen(gc->username); i++)
@@ -3022,7 +3024,7 @@
 
 	fclose( f );
 
-	if ( !gc ) {
+	if ( from_dialog ) {
 		/* save what we just did to cache */
 
 		do_export( (GtkWidget *) NULL, 0 );
--- a/src/oscar.c	Sat Dec 02 04:48:10 2000 +0000
+++ b/src/oscar.c	Sat Dec 02 18:41:58 2000 +0000
@@ -76,9 +76,11 @@
 
 struct chat_connection {
 	char *name;
+	int exchange;
 	int fd; /* this is redundant since we have the conn below */
 	struct aim_conn_t *conn;
 	int inpa;
+	int id;
 };
 
 struct direct_im {
@@ -151,14 +153,14 @@
 	return n;
 }
 
-struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) {
+struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) {
 	GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats;
 	struct chat_connection *c = NULL;
 	if (gc->protocol != PROTO_OSCAR) return NULL;
 
 	while (g) {
 		c = (struct chat_connection *)g->data;
-		if (!strcmp(name, c->name))
+		if (c->id == id)
 			break;
 		g = g->next;
 		c = NULL;
@@ -569,6 +571,7 @@
 		      struct command_rx_struct *command, ...) {
 	static int id = 1;
 	struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
+	struct chat_connection *chatcon;
 	switch (command->conn->type) {
 	case AIM_CONN_TYPE_BOS:
 		aim_setversions(sess, command->conn);
@@ -592,6 +595,8 @@
 		aim_bos_reqrate(sess, command->conn);
 		aim_bos_ackrateresp(sess, command->conn);
 		aim_chat_clientready(sess, command->conn);
+		chatcon = find_oscar_chat_by_conn(gc, command->conn);
+		chatcon->id = id;
 		serv_got_joined_chat(gc, id++, aim_chat_getname(command->conn));
 		break;
 	case AIM_CONN_TYPE_RENDEZVOUS:
@@ -651,18 +656,20 @@
 		{
 		struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
 		char *roomname = va_arg(ap, char *);
+		int exchange = va_arg(ap, int);
 		struct chat_connection *ccon;
 		if (tstconn == NULL || tstconn->status & AIM_CONN_STATUS_RESOLVERR) {
 			debug_print("unable to connect to chat server\n");
 			return 1;
 		}
-		sprintf(debug_buff, "Connected to chat room %s\n", roomname);
+		sprintf(debug_buff, "Connected to chat room %s exchange %d\n", roomname, exchange);
 		debug_print(debug_buff);
 
 		ccon = g_new0(struct chat_connection, 1);
 		ccon->conn = tstconn;
 		ccon->fd = tstconn->fd;
 		ccon->name = g_strdup(roomname);
+		ccon->exchange = exchange;
 		
 		ccon->inpa = gdk_input_add(tstconn->fd,
 				GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
@@ -1755,7 +1762,7 @@
 				b->name, count);
 	debug_print(debug_buff);
 	
-	c = find_oscar_chat(g, b->name);
+	c = find_oscar_chat(g, b->id);
 	if (c != NULL) {
 		if (odata)
 			odata->oscar_chats = g_slist_remove(odata->oscar_chats, c);