]> andersk Git - libfaim.git/blobdiff - aim_chat.c
- Fri Dec 1 23:48:38 UTC 2000
[libfaim.git] / aim_chat.c
index ab49d1205dc869d25641ad2c5f47bbd411891da9..85331edaf10b04e37660d4390b776604b0ddc658 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <faim/aim.h> 
 
-char *aim_chat_getname(struct aim_conn_t *conn)
+faim_export char *aim_chat_getname(struct aim_conn_t *conn)
 {
   if (!conn)
     return NULL;
@@ -17,7 +17,7 @@ char *aim_chat_getname(struct aim_conn_t *conn)
   return (char *)conn->priv; /* yuck ! */
 }
 
-struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name)
+faim_export struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name)
 {
   struct aim_conn_t *cur;
   
@@ -25,6 +25,10 @@ struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name)
   for (cur = sess->connlist; cur; cur = cur->next) {
     if (cur->type != AIM_CONN_TYPE_CHAT)
       continue;
+    if (!cur->priv) {
+      printf("faim: chat: chat connection with no name! (fd = %d)\n", cur->fd);
+      continue;
+    }
     if (strcmp((char *)cur->priv, name) == 0)
       break;
   }
@@ -33,20 +37,22 @@ struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name)
   return cur;
 }
 
-int aim_chat_attachname(struct aim_conn_t *conn, char *roomname)
+faim_export int aim_chat_attachname(struct aim_conn_t *conn, char *roomname)
 {
   if (!conn || !roomname)
     return -1;
 
-  conn->priv = malloc(strlen(roomname)+1);
-  strcpy(conn->priv, roomname);
+  if (conn->priv)
+    free(conn->priv);
+
+  conn->priv = strdup(roomname);
 
   return 0;
 }
 
-u_long aim_chat_send_im(struct aim_session_t *sess,
-                       struct aim_conn_t *conn, 
-                       char *msg)
+faim_export unsigned long aim_chat_send_im(struct aim_session_t *sess,
+                                          struct aim_conn_t *conn, 
+                                          char *msg)
 {   
 
   int curbyte,i;
@@ -68,7 +74,9 @@ u_long aim_chat_send_im(struct aim_session_t *sess,
    * Generate a random message cookie 
    */
   for (i=0;i<8;i++)
-    curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) random());
+    curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand());
+
+  aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL));
 
   /*
    * metaTLV start.  -- i assume this is a metaTLV.  it could be the
@@ -119,10 +127,10 @@ u_long aim_chat_send_im(struct aim_session_t *sess,
  * and room name.
  *
  */
-u_long aim_chat_join(struct aim_session_t *sess,
-                    struct aim_conn_t *conn, 
-                    u_short exchange,
-                    const char *roomname)
+faim_export unsigned long aim_chat_join(struct aim_session_t *sess,
+                                       struct aim_conn_t *conn, 
+                                       u_short exchange,
+                                       const char *roomname)
 {
   struct command_tx_struct *newpacket;
   int i;
@@ -147,10 +155,8 @@ u_long aim_chat_join(struct aim_session_t *sess,
   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.
@@ -161,8 +167,8 @@ u_long aim_chat_join(struct aim_session_t *sess,
    *      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);
@@ -186,7 +192,7 @@ u_long aim_chat_join(struct aim_session_t *sess,
   return (sess->snac_nextid++);
 }
 
-int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo)
+faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo)
 {
   int namelen = 0;
   int i = 0;
@@ -209,7 +215,7 @@ int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo)
   i += 2;
   
   return i;
-};
+}
 
 
 /*
@@ -221,8 +227,8 @@ int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo)
  *
  * SNAC 000e/0002
  */
-int aim_chat_parse_infoupdate(struct aim_session_t *sess,
-                             struct command_rx_struct *command)
+faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
+                                           struct command_rx_struct *command)
 {
   struct aim_userinfo_s *userinfo = NULL;
   rxcallback_t userfunc=NULL;  
@@ -248,7 +254,7 @@ int aim_chat_parse_infoupdate(struct aim_session_t *sess,
 
   if (detaillevel != 0x02) {
     if (detaillevel == 0x01)
-      printf("faim: chat_roomupdateinfo: detail level 2 not supported\n");
+      printf("faim: chat_roomupdateinfo: detail level 1 not supported\n");
     else
       printf("faim: chat_roomupdateinfo: unknown detail level %d\n", detaillevel);
     return 1;
@@ -356,8 +362,8 @@ int aim_chat_parse_infoupdate(struct aim_session_t *sess,
   return ret;
 }
 
-int aim_chat_parse_joined(struct aim_session_t *sess,
-                             struct command_rx_struct *command)
+faim_internal int aim_chat_parse_joined(struct aim_session_t *sess,
+                                       struct command_rx_struct *command)
 {
   struct aim_userinfo_s *userinfo = NULL;
   rxcallback_t userfunc=NULL;  
@@ -382,8 +388,8 @@ int aim_chat_parse_joined(struct aim_session_t *sess,
   return ret;
 }            
 
-int aim_chat_parse_leave(struct aim_session_t *sess,
-                             struct command_rx_struct *command)
+faim_internal int aim_chat_parse_leave(struct aim_session_t *sess,
+                                      struct command_rx_struct *command)
 {
 
   struct aim_userinfo_s *userinfo = NULL;
@@ -414,27 +420,34 @@ int aim_chat_parse_leave(struct aim_session_t *sess,
  * code as channel 0x0003, however, since only the start
  * would be the same, we might as well do it here.
  */
-int aim_chat_parse_incoming(struct aim_session_t *sess,
-                             struct command_rx_struct *command)
+faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
+                                         struct command_rx_struct *command)
 {
   struct aim_userinfo_s userinfo;
   rxcallback_t userfunc=NULL;  
   int ret = 1, i = 0, z = 0;
-  u_char cookie[8];
+  unsigned char cookie[8];
   int channel;
   struct aim_tlvlist_t *outerlist;
   char *msg = NULL;
+  struct aim_msgcookie_t *ck;
 
   memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
 
   i = 10; /* skip snac */
 
   /*
-   * ICBM Cookie.  Ignore it.
+   * ICBM Cookie.  Cache it.
    */ 
   for (z=0; z<8; z++,i++)
     cookie[z] = command->data[i];
 
+  if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) {
+    if (ck->data)
+      free(ck->data);
+    free(ck);
+  }
+
   /*
    * Channel ID
    *
@@ -507,8 +520,8 @@ int aim_chat_parse_incoming(struct aim_session_t *sess,
   return ret;
 }            
 
-u_long aim_chat_clientready(struct aim_session_t *sess,
-                           struct aim_conn_t *conn)
+faim_export unsigned long aim_chat_clientready(struct aim_session_t *sess,
+                                              struct aim_conn_t *conn)
 {
   struct command_tx_struct *newpacket;
   int i;
@@ -538,12 +551,12 @@ u_long aim_chat_clientready(struct aim_session_t *sess,
   return (sess->snac_nextid++);
 }
 
-int aim_chat_leaveroom(struct aim_session_t *sess, char *name)
+faim_export int aim_chat_leaveroom(struct aim_session_t *sess, char *name)
 {
   struct aim_conn_t *conn;
 
   if ((conn = aim_chat_getconn(sess, name)))
-    aim_conn_kill(sess, &conn);
+    aim_conn_close(conn);
 
   if (!conn)
     return -1;
@@ -553,19 +566,22 @@ int aim_chat_leaveroom(struct aim_session_t *sess, char *name)
 /*
  * conn must be a BOS connection!
  */
-u_long aim_chat_invite(struct aim_session_t *sess,
-                      struct aim_conn_t *conn,
-                      char *sn,
-                      char *msg,
-                      u_short exchange,
-                      char *roomname,
-                      u_short instance)
+faim_export unsigned long aim_chat_invite(struct aim_session_t *sess,
+                                         struct aim_conn_t *conn,
+                                         char *sn,
+                                         char *msg,
+                                         u_short exchange,
+                                         char *roomname,
+                                         u_short instance)
 {
   struct command_tx_struct *newpacket;
   int i,curbyte=0;
 
   if (!sess || !conn || !sn || !msg || !roomname)
-    return 0;
+    return -1;
+
+  if (conn->type != AIM_CONN_TYPE_BOS)
+    return -1;
 
   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
     return -1;
@@ -580,6 +596,9 @@ u_long aim_chat_invite(struct aim_session_t *sess,
   for (i=0;i<8;i++)
     curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand());
 
+  /* XXX this should get uncached by the unwritten 'invite accept' handler */
+  aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL));
+
   /*
    * Channel (2)
    */
This page took 0.093953 seconds and 4 git commands to generate.