#include <faim/aim.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <sys/utsname.h> /* for aim_directim_initiate */
#include <arpa/inet.h> /* for inet_ntoa */
aim_filetransfer_accept aim_im.c
aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored.
establish aim_misc.c
- aim_get_command_rendezvous aim_rxqueue.c
+ aim_get_command_rendezvous aim_r
oft_getfh aim_rxqueue.c
*/
-int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
+faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
{
int acceptfd = 0;
rxcallback_t userfunc;
* msg - null-terminated string to send
*/
-int aim_send_im_direct(struct aim_session_t *sess,
- struct aim_conn_t *conn,
- char *msg)
+faim_export int aim_send_im_direct(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ char *msg)
{
struct command_tx_struct *newpacket , *newpacket2;
i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006);
i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
- i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, priv->cookie, 8);
+ i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006);
i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
- i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, priv->cookie, 8);
+ i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
*/
-struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
- struct aim_conn_t *conn,
- struct aim_directim_priv *priv,
- char *destsn)
+faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ struct aim_directim_priv *priv,
+ char *destsn)
{
struct command_tx_struct *newpacket;
struct aim_conn_t *newconn;
struct hostent *hptr;
struct utsname myname;
- char cap[16];
+ unsigned char cap[16];
char d[4]; /* XXX: IPv6. *cough* */
/*
}
-struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
- struct aim_conn_t *conn,
- struct aim_directim_priv *priv )
+faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ struct aim_directim_priv *priv )
{
struct aim_conn_t *newconn = NULL;;
return newconn;
}
-u_long aim_accepttransfer(struct aim_session_t *sess,
- struct aim_conn_t *conn,
- struct aim_conn_t *oftconn,
- char *sn,
- char *cookie,
- unsigned short rendid)
+faim_export unsigned long aim_accepttransfer(struct aim_session_t *sess,
+ struct aim_conn_t *conn,
+ struct aim_conn_t *oftconn,
+ char *sn,
+ char *cookie,
+ unsigned short rendid)
{
struct command_tx_struct *newpacket, *newoft;
struct aim_fileheader_t *listingfh;
*
*/
-struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess)
+faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess)
{
struct aim_fileheader_t *fh;
* returns your fd
*/
-int aim_listenestablish(u_short portnum)
+faim_internal int aim_listenestablish(u_short portnum)
{
int listenfd;
const int on = 1;
return listenfd;
}
-int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
+faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
{
/* XXX: NOT THREAD SAFE RIGHT NOW. the locks are acting up. deal. -- jbm */
memset(hdrbuf1, 0, sizeof(hdrbuf1));
+ faim_mutex_lock(&conn->active); /* gets locked down for the entirety */
+
if ( (hdrlen = read(conn->fd, hdrbuf1, 6)) < 6) {
if(hdrlen < 0)
perror("read");
printf("faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen);
- aim_conn_kill(sess, &conn);
- return -1; /* return -1 prematurely signal'd a bad read(). it's *
- * direct, so we don't really care if the connection *
- * falls apart. -- jbm */
+ faim_mutex_unlock(&conn->active);
+ aim_conn_close(conn);
+ return -1;
}
hdrlen = aimutil_get16(hdrbuf1+4);
if (!(hdr = malloc(hdrlen)))
return -1;
- // faim_mutex_lock(&conn->active);
if (read(conn->fd, hdr, hdrlen) < hdrlen) {
perror("read");
printf("faim: rend: read2 error\n");
free(hdr);
- // faim_mutex_unlock(&conn->active);
- aim_conn_kill(sess, &conn);
+ faim_mutex_unlock(&conn->active);
+ aim_conn_close(conn);
return 0; /* see comment on previous read check */
}
- // faim_mutex_unlock(&conn->active);
-
hdrtype = aimutil_get16(hdr);
switch (hdrtype) {
payloadlength = aimutil_get32(hdr+22);
flags = aimutil_get16(hdr+32);
- snptr = hdr+38;
+ snptr = (char *)hdr+38;
strncpy(priv->sn, snptr, MAXSNLEN);
- /* printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); */
+#if 0
+ printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr);
+#endif
if (flags == 0x000e) {
- // printf("faim: directim: %s has started typing. yippee.\n", snptr);
+ faim_mutex_unlock(&conn->active);
if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
return userfunc(sess, NULL, snptr);
} else if ((flags == 0x0000) && payloadlength) {
unsigned char *msg;
- if(! (msg = calloc(1, payloadlength+1)) )
+
+ if(! (msg = calloc(1, payloadlength+1)) ) {
+ faim_mutex_unlock(&conn->active);
return 0;
+ }
- /* XXX: theres got to be a better way */
- /* XXX: that's a moot point, as the locks never seem to be free. */
- /*
- faim_mutex_lock(&conn->active);
- */
-
if (recv(conn->fd, msg, payloadlength, MSG_WAITALL) < payloadlength) {
perror("read");
printf("faim: rend: read3 error\n");
free(msg);
- // faim_mutex_unlock(&conn->active);
- aim_conn_kill(sess, &conn);
- return 0;
+ faim_mutex_unlock(&conn->active);
+ aim_conn_close(conn);
+ return -1;
}
- // faim_mutex_unlock(&conn->active);
+ faim_mutex_unlock(&conn->active);
msg[payloadlength] = '\0';
- // printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+#if 0
+ printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+#endif
if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
i = userfunc(sess, NULL, conn, snptr, msg);
struct aim_fileheader_t *fh;
struct aim_msgcookie_t *cook;
-
int commandlen;
char *data;
if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+ faim_mutex_unlock(&conn->active);
return 0;
}
memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
- cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+ cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
if(cook->data)
free(cook->data); /* XXX */
if (write(conn->fd, data, commandlen) != commandlen) {
perror("listing write error");
}
+ faim_mutex_unlock(&conn->active);
printf("jbm: hit end of 1209\n");
if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+ faim_mutex_unlock(&conn->active);
return 0;
}
memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
- cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+ cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
if(cook->data)
free(cook->data); /* XXX: integrate cookie caching */
cook->data = ft;
aim_cachecookie(sess, cook);
+
+ faim_mutex_unlock(&conn->active);
break;
}
if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+ faim_mutex_unlock(&conn->active);
return 0;
}
if(hdrlen != 0x100)
printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n");
- listingfh = aim_oft_getfh((char *)hdr);
+ listingfh = aim_oft_getfh(hdr);
memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t));
- cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+ cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
if(cook->data)
free(cook->data); /* XXX */
aim_cachecookie(sess, cook);
+ faim_mutex_unlock(&conn->active);
+
printf("faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0/*listingfh->size*/))) {
curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0 /*listingfh->nrecvd*/);
curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0/*listingfh->recvcsum*/);
- strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
+ strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
curbyte += 32;
curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, 0x20 /*listingfh->flags */);
curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode);
curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage);
- strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
+ strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
curbyte += 64;
free(listingfh);
int i;
struct aim_fileheader_t *fh;
- fh = aim_oft_getfh((char *)hdr);
+ fh = aim_oft_getfh(hdr);
c = (char *)calloc(1, fh->size);
printf("whoopsy, didn't write it all...\n");
}
+ faim_mutex_unlock(&conn->active);
+
break;
}
case 0x0204: { /* get file: finished. close it up */
printf("looks like we're done with a transfer (oft 0x0204)\n");
- aim_conn_kill(sess, &conn);
+ faim_mutex_unlock(&conn->active);
+ aim_conn_close(conn);
break;
}
default: {
printf("OFT frame: type %04x\n", hdrtype);
/* data connection may be unreliable here */
+ faim_mutex_unlock(&conn->active);
break;
}
} /* switch */
* this currently feeds totally bogus data
*/
-struct aim_fileheader_t *aim_oft_getfh(char *hdr)
+faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr)
{
struct aim_fileheader_t *fh;
int i, j;