return ret;
}
+
+/*
+ * Generate an authorization response.
+ *
+ * You probably don't want this unless you're writing an AIM server.
+ *
+ */
+unsigned long aim_sendauthresp(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ char *sn, char *bosip,
+ char *cookie, char *email,
+ int regstatus)
+{
+ struct command_tx_struct tx;
+ struct aim_tlvlist_t *tlvlist = NULL;
+
+ tx.conn = conn;
+
+ tx.commandlen = 1152; /* arbitrarily large */
+ tx.data = malloc(tx.commandlen);
+ memset(tx.data, 0x00, tx.commandlen);
+
+ tx.lock = 1;
+ tx.type = 0x01; /* XXX: right? */
+
+ if (sn)
+ aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn));
+ else
+ aim_addtlvtochain_str(&tlvlist, 0x0001, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
+
+ if (sess->logininfo.errorcode) {
+ aim_addtlvtochain16(&tlvlist, 0x0008, sess->logininfo.errorcode);
+ aim_addtlvtochain_str(&tlvlist, 0x0004, sess->logininfo.errorurl, strlen(sess->logininfo.errorurl));
+ } else {
+ aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip));
+ aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
+ aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email));
+ aim_addtlvtochain16(&tlvlist, 0x0013, regstatus);
+ }
+
+ tx.commandlen = aim_writetlvchain(tx.data, tx.commandlen, &tlvlist);
+ tx.lock = 0;
+ aim_tx_enqueue(sess, &tx);
+
+ return 0;
+}
+
+/*
+ * Generate a random cookie. (Non-client use only)
+ */
+int aim_gencookie(unsigned char *buf)
+{
+ int i;
+
+ srand(time(NULL));
+
+ for (i=0; i < AIM_COOKIELEN; i++)
+ buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0));
+
+ return i;
+}
+
+/*
+ * Send Server Ready. (Non-client)
+ */
+int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn)
+{
+ struct command_tx_struct tx;
+ int i = 0;
+
+ tx.conn = conn;
+
+ tx.commandlen = 10 + 0x20;
+ tx.data = malloc(tx.commandlen);
+ memset(tx.data, 0x00, tx.commandlen);
+
+ tx.lock = 1;
+ tx.type = 0x02;
+
+ i += aimutil_put16(tx.data+i, 0x0001);
+ i += aimutil_put16(tx.data+i, 0x0003);
+ i += aimutil_put16(tx.data+i, 0x0000);
+ i += aimutil_put16(tx.data+i, 0x0000);
+ i += aimutil_put16(tx.data+i, 0x0000);
+
+ i += aimutil_put16(tx.data+i, 0x0001);
+ i += aimutil_put16(tx.data+i, 0x0002);
+ i += aimutil_put16(tx.data+i, 0x0003);
+ i += aimutil_put16(tx.data+i, 0x0004);
+ i += aimutil_put16(tx.data+i, 0x0006);
+ i += aimutil_put16(tx.data+i, 0x0008);
+ i += aimutil_put16(tx.data+i, 0x0009);
+ i += aimutil_put16(tx.data+i, 0x000a);
+ i += aimutil_put16(tx.data+i, 0x000b);
+ i += aimutil_put16(tx.data+i, 0x000c);
+
+ tx.lock = 0;
+
+ aim_tx_enqueue(sess, &tx);
+
+ return 0;
+}
+
+
+/*
+ * Send service redirect. (Non-Client)
+ */
+unsigned long aim_sendredirect(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ unsigned short servid,
+ char *ip,
+ char *cookie)
+{
+ struct command_tx_struct tx;
+ struct aim_tlvlist_t *tlvlist = NULL;
+ int i = 0;
+
+ tx.conn = conn;
+
+ tx.commandlen = 1152; /* arbitrarily large */
+ tx.data = malloc(tx.commandlen);
+ memset(tx.data, 0x00, tx.commandlen);
+
+ tx.lock = 1;
+ tx.type = 0x02;
+
+ i += aimutil_put16(tx.data+i, 0x0001);
+ i += aimutil_put16(tx.data+i, 0x0005);
+ i += aimutil_put16(tx.data+i, 0x0000);
+ i += aimutil_put16(tx.data+i, 0x0000);
+ i += aimutil_put16(tx.data+i, 0x0000);
+
+ aim_addtlvtochain16(&tlvlist, 0x000d, servid);
+ aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip));
+ aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
+
+ tx.commandlen = aim_writetlvchain(tx.data+i, tx.commandlen-i, &tlvlist)+i;
+ aim_freetlvchain(&tlvlist);
+
+ tx.lock = 0;
+ aim_tx_enqueue(sess, &tx);
+
+ return 0;
+}
*/
#include <faim/aim.h>
+#include <ctype.h>
int aimutil_put8(u_char *buf, u_char data)
{
}
return toReturn;
}
+
+/*
+ * int snlen(const char *)
+ *
+ * This takes a screen name and returns its length without
+ * spaces. If there are no spaces in the SN, then the
+ * return is equal to that of strlen().
+ *
+ */
+int aim_snlen(const char *sn)
+{
+ int i = 0;
+ const char *curPtr = NULL;
+
+ if (!sn)
+ return 0;
+
+ curPtr = sn;
+ while ( (*curPtr) != (char) NULL)
+ {
+ if ((*curPtr) != ' ')
+ i++;
+ curPtr++;
+ }
+
+ return i;
+}
+
+/*
+ * int sncmp(const char *, const char *)
+ *
+ * This takes two screen names and compares them using the rules
+ * on screen names for AIM/AOL. Mainly, this means case and space
+ * insensitivity (all case differences and spacing differences are
+ * ignored).
+ *
+ * Return: 0 if equal
+ * non-0 if different
+ *
+ */
+
+int aim_sncmp(const char *sn1, const char *sn2)
+{
+ const char *curPtr1 = NULL, *curPtr2 = NULL;
+
+ if (aim_snlen(sn1) != aim_snlen(sn2))
+ return 1;
+
+ curPtr1 = sn1;
+ curPtr2 = sn2;
+ while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) )
+ {
+ if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') )
+ {
+ if (*curPtr1 == ' ')
+ curPtr1++;
+ if (*curPtr2 == ' ')
+ curPtr2++;
+ }
+ else
+ {
+ if ( toupper(*curPtr1) != toupper(*curPtr2))
+ return 1;
+ curPtr1++;
+ curPtr2++;
+ }
+ }
+
+ return 0;
+}
int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
-int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str);
+int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
+int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
+int aim_counttlvchain(struct aim_tlvlist_t **list);
/*
* Get command from connections / Dispatch commands
int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
int aim_encode_password(const char *, u_char *);
-
-
+unsigned long aim_sendauthresp(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ char *sn, char *bosip,
+ char *cookie, char *email,
+ int regstatus);
+int aim_gencookie(unsigned char *buf);
+int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
+unsigned long aim_sendredirect(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ unsigned short servid,
+ char *ip,
+ char *cookie);
void aim_purge_rxqueue(struct aim_session_t *);
int aimutil_itemcnt(char *toSearch, char dl);
char *aimutil_itemidx(char *toSearch, int index, char dl);
+int aim_snlen(const char *sn);
+int aim_sncmp(const char *sn1, const char *sn2);
+
#endif /* __AIM_H__ */