⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ft.c

📁 AnyQ服务端源代码(2004/10/28)源码
💻 C
📖 第 1 页 / 共 4 页
字号:
						  fu16_t listingsize, 						  fu32_t listingchecksum, 						  fu16_t rendid){       return NULL;	#if 0  struct command_tx_struct *newpacket, *newoft;  struct aim_conn_t *newconn;  struct aim_fileheader_t *fh;  struct aim_filetransfer_priv *priv;  struct aim_msgcookie_t *cachedcook;  int curbyte, i;  if (!sess || !conn || !sn || !cookie || !ip) {    return NULL;  }  newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);  if (!newconn || (newconn->fd == -1)) {    perror("aim_newconn");    faimdprintf(sess, 2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0);    return newconn;  } else {    priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));    memcpy(priv->cookie, cookie, 8);    priv->state = 0;    strncpy(priv->sn, sn, MAXSNLEN);    strncpy(priv->ip, ip, sizeof(priv->ip));    newconn->priv = (void *)priv;    faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd);  }  if (rendid == AIM_CAPS_GETFILE)  {    newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;      faimdprintf(sess, 2, "faim: getfile request accept\n");      if (!(newoft = aim_tx_new(sess, newconn, AIM_FRAMETYPE_OFT, 0x1108, 0))) { 	faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n");	/* XXX: conn leak here */	return NULL;      }       newoft->lock = 1;      memcpy(newoft->hdr.oft.magic, "OFT2", 4);      newoft->hdr.oft.hdr2len = 0x100 - 8;      if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) {	/* XXX: conn leak here */	perror("calloc");	return NULL;      }      fh->encrypt = 0x0000;      fh->compress = 0x0000;      fh->totfiles = listingfiles;      fh->filesleft = listingfiles;      /* is this right -- total parts and parts left?*/      fh->totparts = 0x0001;      fh->partsleft = 0x0001;      fh->totsize = listingtotsize;      fh->size = listingsize;      /* ls -l listing.txt */      fh->modtime = (int)time(NULL); /* we'll go with current time for now */      fh->checksum = listingchecksum;      fh->rfcsum = 0x00000000;      fh->rfsize = 0x00000000;      fh->cretime = 0x00000000;      fh->rfcsum = 0x00000000;      fh->nrecvd = 0x00000000;      fh->recvcsum = 0x00000000;      memset(fh->idstring, 0, sizeof(fh->idstring));      memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring));      fh->flags = 0x02;      fh->lnameoffset = 0x1a;      fh->lsizeoffset = 0x10;      memset(fh->dummy, 0, sizeof(fh->dummy));      memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo));      /* we need to figure out these encodings for filenames */      fh->nencode = 0x0000;      fh->nlanguage = 0x0000;      memset(fh->name, 0, sizeof(fh->name));      memcpy(fh->name, "listing.txt", sizeof(fh->name));      if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { 	newoft->lock = 0;	aim_frame_destroy(newoft);	/* XXX: conn leak */	perror("calloc (1)");	return NULL;      }       memcpy(fh->bcookie, cookie, 8);      if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh)))	faimdprintf(sess, 1, "eek, bh fail!\n");      newoft->lock = 0;      aim_tx_enqueue(sess, newoft);         if (!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) { 	faimdprintf(sess, 1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n");	/* XXX: more cleanup, conn leak */	perror("calloc (2)");	return NULL;      }      memcpy(&(priv->fh), fh, sizeof(struct aim_fileheader_t));      memcpy(cachedcook->cookie, cookie, 8);      cachedcook->type = AIM_COOKIETYPE_OFTGET;      cachedcook->data = (void *)priv;      if (aim_cachecookie(sess, cachedcook) == -1)	faimdprintf(sess, 1, "faim: ERROR caching message cookie\n");      free(fh);            /* OSCAR CAP accept packet */         if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) {	return NULL;      }  } else {    return NULL;  }    newpacket->lock = 1;  curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);  for (i = 0; i < 8; i++)    curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);  curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn));  curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn));  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);  curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a);  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept*/);  for (i = 0;i < 8; i++)     curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);  curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);  newpacket->lock = 0;  aim_tx_enqueue(sess, newpacket);  return newconn;#endif}/** * aim_getlisting(FILE *file) -- get an aim_fileheader_t for a given FILE* *  @file is an opened listing file *  * returns a pointer to the filled-in fileheader_t * * Currently omits checksum. we'll fix this when AOL breaks us, i * guess. * */faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *file) {	return NULL;#if 0  struct aim_fileheader_t *fh;  u_long totsize = 0, size = 0, checksum = 0xffff0000;  short totfiles = 0;  char *linebuf, sizebuf[9];    int linelength = 1024;  /* XXX: if we have a line longer than 1024chars, God help us. */  if ( (linebuf = (char *)calloc(1, linelength)) == NULL ) {    faimdprintf(sess, 2, "linebuf calloc failed\n");    return NULL;  }    if (fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */    perror("getlisting END1 fseek:");    faimdprintf(sess, 2, "getlising fseek END1 error\n");  }  if ((size = ftell(file)) == -1) {    perror("getlisting END1 getpos:");    faimdprintf(sess, 2, "getlising getpos END1 error\n");  }  if (fseek(file, 0, SEEK_SET) != 0) {    perror("getlesting fseek(SET):");    faimdprintf(sess, 2, "faim: getlisting: couldn't seek to beginning of listing file\n");  }  memset(linebuf, 0, linelength);  size = 0;  while(fgets(linebuf,  linelength, file)) {    totfiles++;    memset(sizebuf, 0, 9);    size += strlen(linebuf);        if (strlen(linebuf) < 23) {      faimdprintf(sess, 2, "line \"%s\" too short. skipping\n", linebuf);      continue;    }    if (linebuf[strlen(linebuf)-1] != '\n') {      faimdprintf(sess, 2, "faim: OFT: getlisting -- hit EOF or line too long!\n");    }    memcpy(sizebuf, linebuf+17, 8);    totsize += strtol(sizebuf, NULL, 10);    memset(linebuf, 0, linelength);  }     if (fseek(file, 0, SEEK_SET) == -1) {    perror("getlisting END2 fseek:");    faimdprintf(sess, 2, "getlising fseek END2 error\n");  }    free(linebuf);  /* we're going to ignore checksumming the data for now -- that   * requires walking the whole listing.txt. it should probably be   * done at register time and cached, but, eh. */    if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))    return NULL;  fh->encrypt     = 0x0000;  fh->compress    = 0x0000;   fh->totfiles    = totfiles;  fh->filesleft   = totfiles; /* is this right ?*/  fh->totparts    = 0x0001;  fh->partsleft   = 0x0001;  fh->totsize     = totsize;  fh->size        = size; /* ls -l listing.txt */  fh->modtime     = (int)time(NULL); /* we'll go with current time for now */  fh->checksum    = checksum; /* XXX: checksum ! */  fh->rfcsum      = 0x00000000;  fh->rfsize      = 0x00000000;  fh->cretime     = 0x00000000;  fh->rfcsum      = 0x00000000;  fh->nrecvd      = 0x00000000;  fh->recvcsum    = 0x00000000;  /*  memset(fh->idstring, 0, sizeof(fh->idstring)); */  memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring));  memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring));  fh->flags       = 0x02;  fh->lnameoffset = 0x1a;  fh->lsizeoffset = 0x10;  /*  memset(fh->dummy, 0, sizeof(fh->dummy)); */  memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo));  fh->nencode     = 0x0000; /* we need to figure out these encodings for filenames */  fh->nlanguage   = 0x0000;  /*  memset(fh->name, 0, sizeof(fh->name)); */  memcpy(fh->name, "listing.txt", sizeof(fh->name));  memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name));  faimdprintf(sess, 2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));  return fh;#endif}/** * aim_listenestablish - create a listening socket on a port. * @portnum: the port number to bind to.   * * you need to call accept() when it's connected. returns your fd  * * XXX: give the client author the responsibility of setting up a * listener, then we no longer have a libfaim problem with broken * solaris *innocent smile* -jbm */static int listenestablish(fu16_t portnum){#if HAVE_GETADDRINFO	int listenfd;	const int on = 1;	struct addrinfo hints, *res, *ressave;	char serv[5];	snprintf(serv, sizeof(serv), "%d", portnum);	memset(&hints, 0, sizeof(struct addrinfo));	hints.ai_flags = AI_PASSIVE;	hints.ai_family = AF_UNSPEC;	hints.ai_socktype = SOCK_STREAM;	if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) {		perror("getaddrinfo");		return -1;	} 	ressave = res;	do { 		listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);    		if (listenfd < 0)			continue;		setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));		if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)			break;		/* success */		close(listenfd);	} while ( (res = res->ai_next) );	if (!res)		return -1;	if (listen(listenfd, 1024)!=0) { 		perror("listen");		return -1;	} 	freeaddrinfo(ressave);	return listenfd;#else	int listenfd;	const int on = 1;	struct sockaddr_in sockin;	if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {		perror("socket(listenfd)");		return -1;	}	if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) {		perror("setsockopt(listenfd)");		close(listenfd);		return -1;	} 	memset(&sockin, 0, sizeof(struct sockaddr_in));	sockin.sin_family = AF_INET;	sockin.sin_port = htons(portnum);	if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {		perror("bind(listenfd)");		close(listenfd);		return -1;	}	if (listen(listenfd, 4) != 0) {		perror("listen(listenfd)");		close(listenfd);		return -1;	}	return listenfd;#endif} static int getcommand_getfile(aim_session_t *sess, aim_conn_t *conn){#if 0	struct aim_filetransfer_priv *ft;	aim_rxcallback_t userfunc;	ft = conn->priv;	if (ft->state == 2) {		/* waiting on listing data */		int ret = 0;		char *listing;		struct command_tx_struct *newoft;		if (!(listing = malloc(ft->fh.size)))			return -1;		ft->state = 0;		if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size)				faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size);		if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) {			faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n");			faim_mutex_unlock(&conn->active);			free(listing);			aim_conn_close(conn);			return -1;		}		memcpy(newoft->hdr.oft.magic, "OFT2", 4);		newoft->hdr.oft.hdr2len = 0x100 - 8;		/* Protocol BS - set nrecvd to size of listing, recvcsum to listing checksum, flags to 0 */		ft->fh.nrecvd = ft->fh.size;		ft->fh.recvcsum = ft->fh.checksum;		ft->fh.flags = 0;		if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {			aim_frame_destroy(newoft);			free(listing);			return -1;		}		if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh))))			faimdprintf(sess, 2, "eek! bh fail listing\n");		/* send the 120b */		aim_tx_enqueue(sess, newoft);		if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) )			ret = userfunc(sess, NULL, conn, ft, listing);		free(listing);		return ret;	}	if (ft->state == 3) { 		/* waiting on file data */		if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) 			return userfunc(sess, NULL, conn, ft);		return 0;	}	if (ft->state == 4) {		if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) )			return userfunc(sess, NULL, conn);		aim_conn_close(conn);		return 0;	}		return 0;#else	return -1;#endif}static void connclose_sendfile(aim_session_t *sess, aim_conn_t *conn){	aim_msgcookie_t *cook;	struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv;	cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);	aim_cookie_free(sess, cook);	return;}static void connkill_sendfile(aim_session_t *sess, aim_conn_t *conn){		free(conn->internal);	return;}static void connclose_getfile(aim_session_t *sess, aim_conn_t *conn){	aim_msgcookie_t *cook;	struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv;	cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);	aim_cookie_free(sess, cook);	return;}static void connkill_getfile(aim_session_t *sess, aim_conn_t *conn){		free(conn->internal);	return;}static void connclose_directim(aim_session_t *sess, aim_conn_t *conn){	struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal;	aim_msgcookie_t *cook;	cook = aim_uncachecookie(sess, intdata->cookie, AIM_COOKIETYPE_OFTIM);	aim_cookie_free(sess, cook);	return;}static void connkill_directim(aim_session_t *sess, aim_conn_t *conn){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -