changeset 249:810c595258c8

[gaim-migrate @ 259] You can now get users' away messages. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 22 May 2000 01:18:32 +0000
parents cfc73b8501a7
children c5aa7bf99059
files libfaim/CHANGES.gaim libfaim/README.gaim libfaim/aim.h libfaim/aim_info.c src/buddy.c src/gaim.h src/oscar.c src/server.c
diffstat 8 files changed, 118 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/libfaim/CHANGES.gaim	Sun May 21 11:58:18 2000 +0000
+++ b/libfaim/CHANGES.gaim	Mon May 22 01:18:32 2000 +0000
@@ -1,3 +1,6 @@
+
+Mon May 22 01:14:36 UTC 2000 EWarmenhoven
+	- You can now get users' away messages
 
 Sun May 21 11:42:22 UTC 2000 EWarmenhoven
 	- There were small changes to the libfaim code, which I updated
--- a/libfaim/README.gaim	Sun May 21 11:58:18 2000 +0000
+++ b/libfaim/README.gaim	Mon May 22 01:18:32 2000 +0000
@@ -24,7 +24,10 @@
 Being away/coming back
 Being idle
 Setting your info
-Getting other users' info
+Getting users' info
+Getting users' away messages (PLEASE do not use oscar/libfaim just because of
+	this, gaim with libfaim still really buggy, none of you will listen to
+	me anyway)
 Telling the server who's on your permit/deny lists (buggy)
 Chat:
  - joining rooms
@@ -38,7 +41,6 @@
  - whispering
  - refreshing the chatlist in the preferences dialog
  - invitations (both to and from you)
-Getting users' away messages
 Getting/setting dir info
 Changing your password
 File transfer/IM images/voice chat/etc.
--- a/libfaim/aim.h	Sun May 21 11:58:18 2000 +0000
+++ b/libfaim/aim.h	Mon May 22 01:18:32 2000 +0000
@@ -400,7 +400,11 @@
 #define AIM_CAPS_GETFILE 0x10
 #define AIM_CAPS_SENDFILE 0x20
 extern u_char aim_caps[6][16];
-u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *);
+
+#define AIM_GETINFO_GENERALINFO 0x00001
+#define AIM_GETINFO_AWAYMESSAGE 0x00003
+
+u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
--- a/libfaim/aim_info.c	Sun May 21 11:58:18 2000 +0000
+++ b/libfaim/aim_info.c	Mon May 22 01:18:32 2000 +0000
@@ -9,9 +9,15 @@
 
 #include <aim.h>
 
+struct aim_priv_inforeq {
+  char sn[MAXSNLEN];
+  unsigned short infotype;
+};
+
 u_long aim_getinfo(struct aim_session_t *sess,
 		   struct aim_conn_t *conn, 
-		   const char *sn)
+		   const char *sn,
+		   unsigned short infotype)
 {
   struct command_tx_struct *newpacket;
   int i = 0;
@@ -26,7 +32,7 @@
 
   i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
 
-  i += aimutil_put16(newpacket->data+i, 0x0001);
+  i += aimutil_put16(newpacket->data+i, infotype);
   i += aimutil_put8(newpacket->data+i, strlen(sn));
   i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
 
@@ -41,8 +47,9 @@
     snac.type = 0x0005;
     snac.flags = 0x0000;
 
-    snac.data = malloc(strlen(sn)+1);
-    strcpy(snac.data, sn);
+    snac.data = malloc(sizeof(struct aim_priv_inforeq));
+    strcpy(((struct aim_priv_inforeq *)snac.data)->sn, sn);
+    ((struct aim_priv_inforeq *)snac.data)->infotype = infotype;
 
     aim_newsnac(sess, &snac);
   }
@@ -356,59 +363,78 @@
 			      struct command_rx_struct *command)
 {
   struct aim_userinfo_s userinfo;
-  char *prof_encoding = NULL;
-  char *prof = NULL;
+  char *text_encoding = NULL;
+  char *text = NULL;
   u_int i = 0;
   rxcallback_t userfunc=NULL;
   struct aim_tlvlist_t *tlvlist;
-
-  {
-    u_long snacid = 0x000000000;
-    struct aim_snac_t *snac = NULL;
-
-    snacid = aimutil_get32(&command->data[6]);
-    snac = aim_remsnac(sess, snacid);
+  struct aim_snac_t *origsnac = NULL;
+  u_long snacid;
+  struct aim_priv_inforeq *inforeq;
+  
+  snacid = aimutil_get32(&command->data[6]);
+  origsnac = aim_remsnac(sess, snacid);
 
-    if (snac)
-      {
-	if (snac->data)
-	  free(snac->data);
-	else
-	  printf("faim: parse_userinfo_middle: warning: no ->data in cached SNAC\n");
-	free(snac);
-      }
-    else
-      printf("faim: parseuserinfo_middle: warning: no SNAC cached with for this response (%08lx)\n", snacid);
+  if (!origsnac || !origsnac->data) {
+    printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
+    return 1;
+  }
+
+  inforeq = (struct aim_priv_inforeq *)origsnac->data;
+
+  switch (inforeq->infotype) {
+  case AIM_GETINFO_GENERALINFO:
+  case AIM_GETINFO_AWAYMESSAGE:
+    i = 10;
 
-  }
-  
-  i = 10;
-
-  /*
-   * extractuserinfo will give us the basic metaTLV information
-   */
-  i += aim_extractuserinfo(command->data+i, &userinfo);
+    /*
+     * extractuserinfo will give us the basic metaTLV information
+     */
+    i += aim_extractuserinfo(command->data+i, &userinfo);
   
-  /*
-   * However, in this command, there's usually more TLVs following...
-   */ 
-  tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
-  prof_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
-  prof = aim_gettlv_str(tlvlist, 0x0002, 1);
+    /*
+     * However, in this command, there's usually more TLVs following...
+     */ 
+    tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
-  if (userfunc)
-    {
+    /* 
+     * Depending on what informational text was requested, different
+     * TLVs will appear here.
+     *
+     * Profile will be 1 and 2, away message will be 3 and 4.
+     */
+    if (aim_gettlv(tlvlist, 0x0001, 1)) {
+      text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
+      text = aim_gettlv_str(tlvlist, 0x0002, 1);
+    } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
+      text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
+      text = aim_gettlv_str(tlvlist, 0x0004, 1);
+    }
+
+    userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
+    if (userfunc) {
       i = userfunc(sess,
 		   command, 
 		   &userinfo, 
-		   prof_encoding, 
-		   prof); 
+		   text_encoding, 
+		   text,
+		   inforeq->infotype); 
     }
   
-  free(prof_encoding);
-  free(prof);
-  aim_freetlvchain(&tlvlist);
+    free(text_encoding);
+    free(text);
+    aim_freetlvchain(&tlvlist);
+    break;
+  default:
+    printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
+    break;
+  }
+
+  if (origsnac) {
+    if (origsnac->data)
+      free(origsnac->data);
+    free(origsnac);
+  }
 
   return 1;
 }
@@ -499,3 +525,4 @@
 
   return 0;
 }
+
--- a/src/buddy.c	Sun May 21 11:58:18 2000 +0000
+++ b/src/buddy.c	Mon May 22 01:18:32 2000 +0000
@@ -394,6 +394,12 @@
 
 }
 
+void pressed_away_msg(GtkWidget *widget, struct buddy *b)
+{
+        serv_get_away_msg(b->name);
+
+}
+
 void handle_click_buddy(GtkWidget *widget, GdkEventButton *event, struct buddy *b)
 {
         if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
@@ -430,6 +436,14 @@
 		gtk_menu_append(GTK_MENU(menu), button);
 		gtk_widget_show(button);
 
+#ifdef USE_OSCAR /* FIXME : someday maybe TOC can do this too */
+		button = gtk_menu_item_new_with_label("Away Msg");
+		gtk_signal_connect(GTK_OBJECT(button), "activate",
+				   GTK_SIGNAL_FUNC(pressed_away_msg), b);
+		gtk_menu_append(GTK_MENU(menu), button);
+		gtk_widget_show(button);
+#endif
+
 		button = gtk_menu_item_new_with_label("Toggle Logging");
 		gtk_signal_connect(GTK_OBJECT(button), "activate",
 				   GTK_SIGNAL_FUNC(log_callback), b->name);
--- a/src/gaim.h	Sun May 21 11:58:18 2000 +0000
+++ b/src/gaim.h	Mon May 22 01:18:32 2000 +0000
@@ -337,7 +337,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 257 $"
+#define REVISION "gaim:$Revision: 259 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -504,6 +504,7 @@
 extern void serv_finish_login();
 extern void serv_send_im(char *, char *, int);
 extern void serv_get_info(char *);
+extern void serv_get_away_msg(char *);
 extern void serv_get_dir(char *);
 extern void serv_set_idle(int);
 extern void serv_set_info(char *);
--- a/src/oscar.c	Sun May 21 11:58:18 2000 +0000
+++ b/src/oscar.c	Mon May 22 01:18:32 2000 +0000
@@ -511,6 +511,7 @@
 			 struct command_rx_struct *command, ...) {
 	struct aim_userinfo_s *info;
 	char *prof_enc = NULL, *prof = NULL;
+	u_short infotype;
 	char buf[BUF_LONG];
 	va_list ap;
 
@@ -518,8 +519,14 @@
 	info = va_arg(ap, struct aim_userinfo_s *);
 	prof_enc = va_arg(ap, char *);
 	prof = va_arg(ap, char *);
+	infotype = va_arg(ap, u_short);
 	va_end(ap);
 
+	if (prof == NULL || !strlen(prof)) {
+		do_error_dialog("User has no away message.", "Gaim - Away Msg");
+		return 1;
+	}
+
 	snprintf(buf, sizeof buf, "Username : <B>%s</B>\n<BR>"
 				  "Warning Level : <B>%d %%</B>\n<BR>"
 				  "Online Since : <B>%s</B><BR>"
--- a/src/server.c	Sun May 21 11:58:18 2000 +0000
+++ b/src/server.c	Mon May 22 01:18:32 2000 +0000
@@ -172,7 +172,17 @@
         g_snprintf(buf, MSG_LEN, "toc_get_info %s", normalize(name));
         sflap_send(buf, -1, TYPE_DATA);
 #else
-	aim_getinfo(gaim_sess, gaim_conn, name);
+	aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_GENERALINFO);
+#endif
+}
+
+void serv_get_away_msg(char *name)
+{
+	char buf[MSG_LEN];
+#ifndef USE_OSCAR
+	/* HAHA! TOC doesn't have this yet */
+#else
+	aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_AWAYMESSAGE);
 #endif
 }