Пример #1
0
int ie_savebin(struct bin_file *fajl)
{
 int f,i=0,l;
 char *r;

#ifdef POSIX
 f = a_open( fajl->filename, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD|S_IWRITE);
#else
 f = a_sopen( fajl->filename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC,
     SH_COMPAT | SH_DENYNONE, S_IREAD|S_IWRITE );
#endif
 if ( f == -1 ) return 2; //error while opening

 while(i<fajl->len)
 {
  r=ie_getswap(fajl->lineadr[i]);
  if (r!=NULL)
  {
   l=fajl->linesize[i];
   if(write(f,&l,sizeof(unsigned short))!=sizeof(unsigned short)) 
    {a_close (f); return 4;} //write error!
   if(write(f,r,l)!=l) 
    {a_close (f); return 4;} //write error!
  }//endif
  i++;
 }//loop
 a_close(f);
 fajl->modified=0;
 return 1;
}//end sub
Пример #2
0
enum io_result a_open_listen_ip6 (int *result, int_8 addr[16], int_16 port)
{
    int fd;
    struct sockaddr_in6 addr_in;
    union { int_16 i; int_8 c[2]; } a;

    if ((fd = sys_socket(AF_INET6, SOCK_STREAM, 0)) < 0)
    {
        return io_unrecoverable_error;
    }

    a.c[0] = (port >> 8) & 0xff;
    a.c[1] = (port)      & 0xff;

    addr_in.sin6_family           = AF_INET6;
    addr_in.sin6_port             = a.i;
    addr_in.sin6_addr.s6_addr[0]  = addr[0];
    addr_in.sin6_addr.s6_addr[1]  = addr[1];
    addr_in.sin6_addr.s6_addr[2]  = addr[2];
    addr_in.sin6_addr.s6_addr[3]  = addr[3];
    addr_in.sin6_addr.s6_addr[4]  = addr[4];
    addr_in.sin6_addr.s6_addr[5]  = addr[5];
    addr_in.sin6_addr.s6_addr[6]  = addr[6];
    addr_in.sin6_addr.s6_addr[7]  = addr[7];
    addr_in.sin6_addr.s6_addr[8]  = addr[8];
    addr_in.sin6_addr.s6_addr[9]  = addr[9];
    addr_in.sin6_addr.s6_addr[10] = addr[10];
    addr_in.sin6_addr.s6_addr[11] = addr[11];
    addr_in.sin6_addr.s6_addr[12] = addr[12];
    addr_in.sin6_addr.s6_addr[13] = addr[13];
    addr_in.sin6_addr.s6_addr[14] = addr[14];
    addr_in.sin6_addr.s6_addr[15] = addr[15];

    if (sys_bind(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in6)) < 0)
    {
        a_close (fd);
        return io_unrecoverable_error;
    }

    if (sys_listen(fd, 32) == -1)
    {
        a_close (fd);
        return io_unrecoverable_error;
    }

    *result = fd;

    return io_complete;
}
Пример #3
0
enum io_result a_open_socket(int *result, const char *path)
{
    int fd, i;
    struct sockaddr_un addr_un;
    char *tc = (char *)&(addr_un);

    if ((fd = sys_socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
    {
        return io_unrecoverable_error;
    }

    for (i = 0; i < sizeof(struct sockaddr_un); i++)
    {
        tc[i] = (char)0;
    }

    addr_un.sun_family = AF_UNIX;
    for (i = 0; (i < (sizeof(addr_un.sun_path)-1)) && (path[i] != (char)0); i++)
    {
        addr_un.sun_path[i] = path[i];
    }

    if (sys_connect(fd, (struct sockaddr *) &addr_un, sizeof(struct sockaddr_un)) < 0)
    {
        a_close (fd);
        return io_unrecoverable_error;
    }

    *result = fd;

    return io_complete;
}
Пример #4
0
enum io_result a_open_ip4 (int *result, int_32 addr, int_16 port)
{
    int fd;
    struct sockaddr_in addr_in;
    union { int_16 i; int_8 c[2]; } a;
    union { int_32 i; int_8 c[4]; } b;

    if ((fd = sys_socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        return io_unrecoverable_error;
    }

    a.c[0] = (port >> 8) & 0xff;
    a.c[1] = (port)      & 0xff;

    b.c[0] = (addr >> 24) & 0xff;
    b.c[1] = (addr >> 16) & 0xff;
    b.c[2] = (addr >> 8)  & 0xff;
    b.c[3] = (addr)       & 0xff;

    addr_in.sin_family      = AF_INET;
    addr_in.sin_port        = a.i;
    addr_in.sin_addr.s_addr = b.i;

    if (sys_connect(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in)) < 0)
    {
        a_close (fd);
        return io_unrecoverable_error;
    }

    *result = fd;

    return io_complete;
}
Пример #5
0
long calcexe(char *exename,long offset)
{
 long x=0;
 int i=0,step[5]={7,3,1,2,7},j=0;
 int f=a_open(exename,O_RDONLY|O_BINARY);
 char *buf=farmalloc(CHECKBUF+1);

 if(buf)
 {
  if(f>=0)
  {
   lseek(f, offset, SEEK_SET);
   a_read(f,buf,CHECKBUF);

   while(j<CHECKBUF)
   {
    x+=buf[j];
    j+=step[i++];
    if(i==4)i=0;
   }

   a_close(f);

   return x;
  }
  farfree(buf);
 }

 puts("?!");
 exit(0);
}
Пример #6
0
static void async_test(const char *fname, int block_size, int nblocks, int rsize)
{
	int fd;
	struct aio_ring *ring;
	off_t offset=0;
	char buf[rsize];
	int i=0;

	offset=0;
	start_timer();
	fd = open(fname, O_RDONLY);
	if (fd == -1) {
		perror(fname);
		exit(1);
	}

	ring = a_init(fd, block_size, nblocks);
	if (ring == NULL) {
		fprintf(stderr, "a_init faild\n");
		exit(1);
	}

	while (a_read(ring, buf, sizeof(buf), offset) > 0) {
		offset += sizeof(buf);
		if (++i % 5 == 0) {
			offset -= 2*sizeof(buf);
		}
	}

	printf("async: %.3f MByte/sec\n", 1.0e-6 * offset / end_timer());
	a_close(ring);
}
Пример #7
0
int    a_close (int fd)
{
    int rv = close (fd);
    if (rv < 0) {
        examine_error();

        if (last_error_recoverable_p == (char)1) return a_close (fd);
    }
    return rv;
}
Пример #8
0
void tex::close_files()
	{
	int	k;
	
	for (k = 0; k < 16; incr(k))
		if (write_open[k])
			a_close(write_file[k]);
	fin_dvi();

	std::cout << std::flush;
	std::cerr << std::flush;
	}
Пример #9
0
int cmain(void) {
/* test the a_create() and a_close() functions */
    int fd, i, j;
    char buffer[TESTDATA_SIZE];

    fd = a_create ("to-curie-test-data", 0660);
    if (fd < 0) return 1;

    i = a_close(fd);
    if (i < 0) return 2;

/* test the a_write() and a_open_write() functions */
    fd = a_open_write ("to-curie-test-data");
    if (fd < 0) return 3;

    i = a_write(fd, TESTDATA, (unsigned int)TESTDATA_SIZE);
    if (i < 0) return 4;
    if (i != TESTDATA_SIZE) return 5;

/* close file descriptor */
    i = a_close(fd);
    if (i < 0) return 6;

/* test the a_read() and a_open_read() functions */
    fd = a_open_read ("to-curie-test-data");
    if (fd < 0) return 7;

    i = a_read (fd, buffer, (unsigned int)TESTDATA_SIZE);
    if (i < 0) return 8;
    if (i != TESTDATA_SIZE) return 9;

    for (j = 0; j < i; j++) {
      if (buffer[j] != TESTDATA[j]) return 10;
    }

    return 0;
}
Пример #10
0
void main(char argc,char **argv)
{
 int f;
 long checksum,offset;

 if(argc==3)
 {
  puts("Calculating...");
  offset=atol(argv[2]);
  checksum=calcexe(argv[1],offset);
  puts("Updating...");
  f=a_open(argv[1],O_WRONLY|O_BINARY|O_APPEND);
  if(f>=0)
  {
   write(f,&offset,4);
   write(f,&checksum,4);
   a_close(f);
  }
 }
 else
  puts("MARKEXE filename offset");
}
Пример #11
0
int ftpsession(struct Url *url,struct HTTPrecord *cache,char *uploadfile)
{
 longword host;
 char str[256];
 char buffer[BUFLEN+2];
 tcp_Socket datasocket;
 word dataport=0;
 int rv=0,len;
 char *ptr,*datahostptr,datahost[80];
 char isdir=0,retry=0;//,ascii=0;
 long total=0;

//!!glennmcc: Nov 11, 2007 -- for 'dblp code' below
 int dblp=0;
//!!glennmcc: end

//!!glennmcc: Nov 13, 2007 -- for EZNOS2 fix below
int eznos2=0;
//!!glennmcc: end
int log;

 if(!tcpip)return 0;
 free_socket();

 if((!url->file[0] || url->file[strlen(url->file)-1]=='/') && !uploadfile)
  isdir=1;

 sprintf(str,msg_askdns,url->host);
 outs(str);

 GlobalLogoStyle=0;			//SDL set resolve animation
 host=resolve_fn( url->host, (sockfunct_t) TcpIdleFunc ); //SDL
// host=resolve( url->host );
 if(!host)
 {
  DNSerr(url->host);
  return 0;
 }

// if(!uploadfile) //!glennmcc: Oct 20, 2012 - commented-out to make upload log more verbose
   log=a_open("FTP.LOG",O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);

 GlobalLogoStyle=2;			//SDL set connect animation
 if (!tcp_open( socket, locport(), host, url->port, NULL ))
 {
  sprintf(str,msg_errcon,url->host);
  outs(str);
  return 0;
 }
 sprintf(str,msg_con,url->host,url->port);
 outs(str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
 sock_wait_established(socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		       &status);		//SDL

 GlobalLogoStyle=1;		//SDL set data animation
 sock_mode( socket, TCP_MODE_ASCII );
 outs(MSG_LOGIN);

 do
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);


//  printf("FTP daemon said>");
//  puts(buffer);
  if ( *buffer != '2' && buffer[0]!=' ') goto quit;
 }
 while(buffer[3]=='-' || buffer[0]==' '); //continued message!

 if(!url->user[0])
  ptr="anonymous";
 else
  ptr=url->user;

 sprintf( str, "USER %s", ptr);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
 sock_puts(socket,(unsigned char *)str);
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);

//  printf("FTP daemon said>");
//  puts(buffer);

//!!glennmcc: May 11, 2005
//removed due to the fact that not all sites use '3'
//see additional info below with respect to anonymous password
// if ( *buffer != '3' ) goto quit;
//!!glennmcc: end

 //open cache filename:

//!glennmcc: Oct 20, 2012 - commented-out to make upload log more verbose
// if(uploadfile)
//  strcpy(cache->locname,"FTP.LOG");
// else
//!glennmcc end: Oct 20, 2012

 {
//!!glennmcc: Oct 22, 2008 -- strchr() was preventing the use of 'CachePath .\cache\'
//  ptr=strchr(cache->locname,'.');
  ptr=strrchr(cache->locname,'.');
//!!glennmcc: end
  if(ptr)
  {
   strcpy(&ptr[1],"FTP");
   strcpy(cache->rawname,cache->locname);
  }
 }

 cache->handle=a_open(cache->locname,O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
 if(cache->handle<0)
  goto quit;

 strcpy(cache->mime,"text/plain");

 if(url->password[0])
  ptr=url->password;
 else
 {
  if(url->user[0] && !strcmp(url->host,AUTHENTICATION->host)
		  && !strcmp(AUTHENTICATION->realm,"$ftp"))
   ptr=AUTHENTICATION->password;
  else
  {
   ptr=configvariable(&ARACHNEcfg,"FakeFTPeMail",NULL);
   if(!ptr || !strchr(ptr,'@'))
   {
    ptr=configvariable(&ARACHNEcfg,"eMail",NULL);
    if(!ptr)
     ptr="@";
   }
  }
 }

//!!glennmcc: May 11, 2005
//some sites do not require a password after 'anonymous'
//therefer, this entire block is now within this 'if()' so that
//the password (email address), will only be sent if asked for
//!!glennmcc: Nov 13, 2007 -- EZNOS2 says "Enter PASS command"
if (strstr(buffer,"sword") || strstr(buffer,"Enter PASS command"))
//if (strstr(buffer,"sword"))//original line
{
 sprintf( str, "PASS %s", ptr);
 sock_puts(socket,(unsigned char *)str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
}//!!glennmcc: inserted Mar 02, 2008
//Some servers need the following 'do/while' section,
//therefore, only the section above for sending the password needs to be
//'blocked' when no password was requested.

 do
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);
//  printf("FTP daemon said>");
//  puts(buffer);
if (strstr(buffer,"Enter PASS command")) eznos2=1;

  if (*buffer != '2' && buffer[0]!=' ' && !eznos2)
  {
   write(cache->handle,buffer,strlen(buffer));
   rv=1;
   goto quit;
  }
  else if ((buffer[3]=='-' || buffer[0]==' ') && (isdir || uploadfile))
  {
   strcat(buffer,"\r\n");
   rv=1;
   write(cache->handle,buffer,strlen(buffer));
  }
 }
 while(buffer[3]=='-' || buffer[0]==' ' || buffer[0]=='3'); //continued message!
//}//!!glennmcc: end May 11, 2005 -- removed on Mar 02, 2008

 //ask server where we have to connect:

 sock_puts(socket,(unsigned char *)"PASV");
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);



//  printf("FTP daemon said>");
//  puts(buffer);

 //2xx Entering passive mode (a,b,c,d,x,y)

 if ( *buffer != '2' ) goto quit;
 datahostptr=strchr(buffer,'(');
//!!glennmcc: Nov 13, 2007 -- EZNOS2 doesn't enclose the info in ()
//therefore, if '(' is not found... look for the last 'space'.
 if(!datahostptr) {datahostptr=strrchr(buffer,' '); eznos2=1;}
//if that still fails... 'quit'
//!!glennmcc: end
 if(!datahostptr) goto quit;//original line

 ptr=++datahostptr;
 {
  int carka=0;
  char *portptr=NULL;

  while(*ptr)
  {
   if(*ptr==',')
   {
    carka++;
    if(carka<4)
     *ptr='.';
    else if(carka==4)
    {
     *ptr='\0';
     portptr=ptr+1;
    }
    else if (carka==5)
    {
     *ptr='\0';
     dataport=256*(word)atoi(portptr);  // ,x,y -> 256*x+y
     portptr=ptr+1;
//!!glennmcc: Nov 13, 2007 -- part of above fix for EZNO2 info not in ()
 if(eznos2) dataport+=atoi(portptr);      // ,x,y -> 256*x+y
//!!glennmcc: end
    }
   }
   else if(*ptr==')' && portptr)
   {
//!!glennmcc: Nov 11, 2007 -- some servers have double ')'
// at the end of the port address info...
// this 'dblp code' will prevent that from adding the final set twice
//eg: (99,167,219,186,234,255)) instead of.... (99,167,219,186,234,255)
//without this fix ... 255 gets added a 2nd time and
//we end-up-with... port 60414 instead of the correct port of 60159
    *ptr='\0';
    if(!dblp)//!!glennmcc: Nov 11, 2007
    dataport+=atoi(portptr);      // ,x,y -> 256*x+y
    dblp=1;//!!glennmcc: Nov 11, 2007
   }
   ptr++;
  }
 }

 if(!dataport)
  goto quit;

//!!glennmcc: Aug 31, 2009
//EZNOS2 sends the IP of the machine on a router as datahost
//therefore we need to go back to the original host
if(eznos2)
{
makestr(datahost,url->host,79);
outs(datahost);
Piip();
}
else
//!!glennmcc:end

 makestr(datahost,datahostptr,79);//original line

 retry:

 if(isdir)
 {
  if(url->file[0])
  {
//!!glennmcc: Oct 15, 2007 -- fix problems with CWD on FTP servers
//which interpret the leading '/' as an attempted CD to 'root'
   if(url->file[0]=='/')
   sprintf( str, "CWD %s", url->file+1);
   else
//!!glennmcc: end Oct 15, 2007
   sprintf( str, "CWD %s", url->file);
   sock_puts(socket,(unsigned char *)str);
   do
   {
    sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		     &status );		//SDL
    sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
    outs(buffer);

//!!glennmcc: Apr 08, 2005 -- commented-out this block
// to fix the problem of 'broken dir listing' when the
// 'FTP welcome message' contains linefeeds
// such as at ftp://ftp.cdrom.com/.2/simtelnet/
/*
    if ( *buffer != '2' && buffer[0]!=' ')
    {
     write(cache->handle,buffer,strlen(buffer));
     rv=1;
     goto quit;
    }
    else if (buffer[3]=='-' || buffer[0]==' ')
*/
//!!glennmcc: end
    {
     strcat(buffer,"\r\n");
     rv=1;
     write(cache->handle,buffer,strlen(buffer));
    }
   }
//!!glennmcc: Apr 08, 2005 -- added a test for !=' ' which is also
// needed for the same fix at ftp://ftp.cdrom.com/.2/simtelnet/
   while(buffer[3]=='-' || buffer[3]!=' ' || buffer[0]==' '); //continued message!
//   while(buffer[3]=='-' || buffer[0]==' '); //continued message!
//!!glennmcc: end

  }
  strcpy(cache->mime,"ftp/list");
  sprintf( str, "LIST");
 }
 else
 {
  char *fnameptr;
  char mimestr[80]="ftp/binary";

  fnameptr=strrchr(url->file,'/');
  if(!fnameptr)
  {
   fnameptr=strrchr(url->file,'\\');
   if(!fnameptr)
    fnameptr=url->file;
   else
    fnameptr++;
   }
   else
    fnameptr++;

  sprintf( str, "TYPE I");
  if(fnameptr)
  {
   char ext[5];
   strcpy(mimestr,"file/");
   strncat(mimestr,fnameptr,70);
   mimestr[79]='\0';
   get_extension(mimestr,ext);
   if(!strncmpi(ext,"TXT",3) || !strncmpi(ext,"HTM",3))
   {
//!!glennmcc: begin June 09, 2002
//optionally upload TXT and HTM in binary mode
    ptr=configvariable(&ARACHNEcfg,"UseBinaryFTP",NULL);
    if(!ptr || toupper(*ptr)=='N')
//!!glennmcc: end
    sprintf( str, "TYPE A");
//    ascii=1;
   }
  }
  strcpy(cache->mime,mimestr);

  sock_puts(socket,(unsigned char *)str);
  write(log,str,strlen(str));
  write(log,"\r\n",2);
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);
//  printf("FTP daemon said>");
//  puts(buffer);
  if ( *buffer != '2' || uploadfile)
  {
   strcat(buffer,"\n");
   write(cache->handle,buffer,strlen(buffer));
  }
  if ( *buffer != '2' )
  {
   rv=1;
   goto quit;
  }
  if(!uploadfile)

//!!glennmcc: Oct 17, 2007 -- fix problems with FTP servers
//which interpret the leading '/' as an attempted CD to 'root'
   if(url->file[0]=='/')
   sprintf( str, "RETR %s", url->file+1);
   else
   sprintf( str, "RETR %s", url->file);
//original single line above this comment
//!!glennmcc: end
  else
   sprintf( str, "STOR %s", url->file);
 }
 sock_puts(socket,(unsigned char *)str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);

//!!glennmcc: Oct 19, 2008 -- back to original fix
//!!glennmcc: Nov 15, 2007 -- always 'close' the connection when done
//with both dir listings and file downloads
//Apr 10, 2007 fix did it only for dir listings
if(isdir || strstr(str,"RETR"))
//if(isdir)
 sock_puts(socket,(unsigned char *)"QUIT");//!!glennmcc: Apr 10, 2007
//!!glennmcc: end

 if(!retry)
 {
  //get file using datahost & dataport
  GlobalLogoStyle=0;		//SDL set resolve animation
  host=resolve_fn( datahost, (sockfunct_t) TcpIdleFunc );	//SDL
//  host=resolve( datahost );
  if(!host)
   goto quit;

  GlobalLogoStyle=2;		//SDL set connect animation
  if (!tcp_open( &datasocket, locport(), host, dataport, NULL ))
  {
   sprintf(str,msg_errcon,datahost);
   outs(str);
   goto quit;
  }
  sprintf(str,msg_con,datahost,dataport);
  outs(str);
  write(log,str,strlen(str));
  write(log,"\r\n",2);

  //wait for datasocket to open:
  sock_wait_established(&datasocket, sock_delay, (sockfunct_t) TcpIdleFunc,
			&status);	//SDL

//!!glennmcc: Sep 27, 2008 -- increase D/L speed on cable & DSL
//many thanks to 'mik' for pointing me in the right direction. :)
{
#ifdef DEBUG
 char sp[80];
 sprintf(sp,"Available stack = %u bytes",_SP);
 outs(sp);
 Piip(); Piip();
#endif
 if(_SP>(1024*SETBUFSIZE))
 {
  char setbuf[1024*SETBUFSIZE];
  sock_setbuf(&datasocket, (unsigned char *)setbuf, 1024*SETBUFSIZE);
 }
}
//!!glennmcc: end

  GlobalLogoStyle=1;		//SDL set data animation
 }
 //wait for "110 openning connection" (or "550 ....error....")
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL

 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);


// printf("FTP daemon said>");
// puts(buffer);
 if ( *buffer != '1' || uploadfile)
 {
  strcat(buffer,"\n");
  write(cache->handle,buffer,strlen(buffer));
 }

 if ( *buffer != '1' )
 {
  if(!strncmp(buffer,"550",3) && !retry)
  {
   retry=1;
   isdir=1-isdir;
   if(isdir)
    strcat(url->file,"/");
   else
   {
    int i=strlen(url->file);
    if(i>0 && url->file[i-1]=='/')
     url->file[i-1]='\0';
   }
   goto retry;
  }

  strcpy(cache->mime,"text/plain");
  rv=1;
  goto dataquit;
 }

 if(!uploadfile) //-------------------------------------- download ---------------
 {
  while ( 1 )
  {
   xChLogoTICK(1);
   if(GUITICK())
    if(GLOBAL.gotolocation || GLOBAL.abort)
     goto dataquit;

   if (sock_dataready( &datasocket ))
   {
    len = sock_fastread( &datasocket, (unsigned char*)buffer, BUFLEN );
    write(cache->handle,buffer,len);
    total+=len;
    sprintf(str,MSG_BYTESR,MSG_DOWNLD,total);
    outs(str);
   }
   else
    sock_tick( &datasocket, &status ); //shift TCP/IP
  }
 }
 else //-------------------------------------- upload ------------------
 {
  int f,lenread,done;
  long length;
  char pom[256];

/*  if(ascii)
   f=a_sopen(uploadfile,O_RDONLY|O_TEXT, SH_DENYNO, S_IREAD);
  else*/
   f=a_sopen(uploadfile,O_RDONLY|O_BINARY, SH_DENYNO, S_IREAD);

  if(f<0)
   goto dataquit;

  lenread=done=0;
  length=0l;

  {
   long filel=a_filelength(f);
   while(1)
   {
    sprintf(pom,MSG_UPLOAD,length,filel);
    outs(pom);
//!!glennmcc:Oct 23, 2008 -- 'reversed the logic'
// to keep from overflowing at 21megs
    if(filel>100)
    percentbar((int)(length/(filel/100)));
//  percentbar((int)(100*length/filel));
    lenread=a_read(f,buffer,BUFLEN);
    length+=lenread;
    if(lenread<=0)
     done=1;

    //wait until we can write to socket:
    while(sock_tbleft(&datasocket)<lenread) //SDL
//    while( datasocket.datalen > 1024)
    {
     sock_tick(&datasocket,&status);
     xChLogoTICK(1); // animation of logo
     if(GUITICK())
      goto dataquit;
    }

    if(done)
    {
     sock_close( &datasocket );
     a_close(f);
     goto dataclose;
    }

    sock_fastwrite(&datasocket,(unsigned char *)buffer,lenread);
    sock_tick(&datasocket,&status);
   }//loop
  }
 }


dataquit:
//!!glennmcc: Nov 15,  2007 -- removed sock_abort because it was
// sometimes preventing the connection from being closed,
// therefore preventing access to several files within a short time
// due to too many connections open from the same IP
// sock_abort( &datasocket );//original line
//!!glennmcc: end

dataclose:
 outs(MSG_CLOSE);

 sock_puts(socket,(unsigned char *)"QUIT");//!!glennmcc: Dec 04, 2006
 sock_wait_closed( &datasocket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL

 if(uploadfile)
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
 }

quit:
  sock_puts(socket,(unsigned char *)"QUIT");
  sock_close( socket );
  closing[socknum]=1;
  sock_keepalive[socknum][0]='\0';
//    sock_wait_closed( socket, sock_delay, NULL, &status );

//we will better wait because we are about to deallocate datasocket

sock_err:
    switch (status) {
	case 1 : /* foreign host closed */
		 write(log,MSG_CLOSE,strlen(MSG_CLOSE));
		 write(log,"\r\n",2);
		 close(log);
		 break;
	case -1: /* timeout */
		 sprintf(str,MSG_TCPERR, sockerr(socket));
		 outs(str);
		 write(log,str,strlen(str));
		 write(log,"\r\n",2);
		 close(log);
		 break;
    }

 if(total)
 {
  cache->knowsize=1;
  cache->size=total;
  rv=1;
 }
 if(cache->handle>=0)
 {
  a_close(cache->handle);
  rv=1;
 }

 return rv;
}
Пример #12
0
// ------------- haro -----------------------
int drawGIF(struct picinfo *gif)
{
//picinfo (in/out) - jmeno gifu a kam nakreslit
//hPicinfo(in) - handle picinfo (jen pro anim.gify)
//ModPic  (out)- zda uchovat zmeny v picinfo
//   char   drive[8], dir[80], name[16], ext[8];
//   char *ext;
   struct GIFGLB GifGlb;
   struct GIFIMG GifImg;
   int    ist, mark, interlac, NumImg = 0;
   int    *mapio=NULL, *Mmapio[2];
   int     i, ire=1, TraCol, Prepni;
   unsigned int backg,code_start;
   int    Transp = 0, GrCtrl = 0;
   short int    tAnim  = 0; // cas animace v setinach vteriny
   int    disp   = 0; // dispozice
   int    ReaPal = 0; // zda se cetla local paleta
   int    GlbPal = 0; // zda se cetla globalni paleta
#ifdef XANIMGIF
   int    vdx = 0, vdy = 0;
#endif
   long   CurPos, ReaBytes, BckAdr;
   char   *pAktpal;
   unsigned char *pLocPal=NULL; // lolalni gif paleta
   int    nLocPal=0;    // delka loc. palety
   int    bSaveBck1=0,bSaveBck2=0;// zda ukladat background pro animovane

   //*ModPic = 0; nahrazeno swapmod !!
   //basebackg=-1; //mp!!

//   fnsplit(gif->filename, drive, dir, name, ext);

/* //no longer needed - drawGIF is always called from drawanyimage()

   ext=strrchr(gif->filename,'.');
   if(ext && strcmpi(ext,".bmp") == 0)
   { // Kresli bmp
     ist = XCHdrawBMP(gif);
     return( ist );
   }
*/
/*
#ifdef XANIMGIF
   if(gif->palonly==0 && gif->sizeonly==0 && gif->IsInXms)
   {  // Uz je v xms -> krelit z ni
     ist = XGifFromXms(gif, xg_video_XMS, vdx, vdy, &tAnim);
     return( ist );
   }
#endif
*/


   New_read_gif:
   NumImg = 0;
   ist = ReadGHeader(gif, &GifGlb, &GlbPal);
   if((ist&1) == 0) //failure
   { /*ire = ist*/
     a_close (filx);
     if(ist==6) //mp: kdyz to neni GIF, zkusit BMP
      return XCHdrawBMP(gif);
     else
      return 0;
   }

   pLocPal = farmalloc(768);     // Buf. na lokalni palety
   if(pLocPal==NULL) memerr();

   g_DrawFce = DrawLine;   // fce volana uvnitr dekomprese
/**
#ifdef XANIMGIF
   if(ReaPal && gif->palonly==0 && gif->sizeonly==0)
   { if(pGifPal==NULL)
     { pGifPal = farmalloc(768);
       if(pGifPal==NULL) memerr();
     }
     memcpy(pGifPal, gif->pal, 3*gif->npal); // jen pro anim
     nGifPal = gif->npal;                   // schovat glb. paletu gifu
     for(i=0; i<3*nGifPal; i++) pGifPal[i]>>=2;
   }
#endif
**/
   // Hlavni cykl pres jednotlive bloky v GIFu
   Next_marker:
   mark = ReadGMarker();
   if(mark < 0)
   { /*ire = 8*/;
     //ERRGIF
     if(NumImg == 0)
       goto Only_sp;
     else if(NumImg == 1)
     {
      ire = 1; //mp!
      goto Err_frame;
     }
     else
     {
      ire = 1;
      goto Add_to_anim;
     }
     //ERRGIF
   }
   else if(mark == 1)     // Ext. blok
   {
     ist = ReadExtBlok(&Transp, &backg, &tAnim, &disp, &GrCtrl);
     if((ist&1)==0) { /*ire = 10*/ ire=1; goto Err_frame; } //mp!
     if(GrCtrl)  // Cetlo se grf. ext.
     { //if(backg >= gif->npal) backg = gif->npal-1;  // Toto se vyskytuje ??
       gif->bgindex = backg;   // back, nebo transp index
       swapmod = 1;            // mark XSWAP as modified

           //RGB001
           if(Transp && !gif->palismap && GlbPal)
	   { gif->pal[3*backg  ] = g_rT;
             gif->pal[3*backg+1] = g_gT;
             gif->pal[3*backg+2] = g_bT;
           }
     }
   }
   else if(mark == 2)     // Img. blok
   {
     ist = ReadImgBlok(gif, &GifImg, &interlac, &code_start, GlbPal,
		       &ReaPal, &nLocPal, pLocPal);
     if((ist&1)==0)   { /*ire = 12*/ ire=1; goto Err_frame; } //mp!
     if(gif->sizeonly){ ire = 1; goto Only_sp; }

     //SaveBck
     if( Transp )
         { //RGB001

           if(ReaPal==0 && GlbPal) //!!mp
            ReaPal=1;              //!!mp


           if(ReaPal ==1)
	   { gif->pal[3*backg  ] = g_rT;
             gif->pal[3*backg+1] = g_gT;
             gif->pal[3*backg+2] = g_bT;
           }
	   else if(ReaPal == 2)
           { pLocPal[3*backg  ] = g_rT;
             pLocPal[3*backg+1] = g_gT;
             pLocPal[3*backg+2] = g_bT;
           }

          //if(GifImg.screex2==GifGlb.screenwide && GifImg.screey2==GifGlb.screendeep)
          if(disp >= 2)
           bSaveBck1++;   // max. velikost s transp
	  else
           bSaveBck2++;   // mensi nez. cele s transp
     }

     if(!gif->palismap || gif->palonly || xg_256==MM_Hic)
     {
       gif->palismap=0;
       if(gif->palonly)
       { if(GlbPal == 0) // Zadna globalni->vezmu lokalni
         {
//mp!!begin
          //specialni filtry pro 16ti barevne mody
          if(egamode)
	   for(i=0; i<3*gif->npal; i++) gif->pal[i]=egafilter(gif->pal[i]);
          else if(vga16mode && !vgamono)
           for(i=0; i<3*gif->npal; i++) gif->pal[i]=vgafilter(gif->pal[i]);
          else
//mp!!end
           memcpy(gif->pal, pLocPal, 3*nLocPal);
           gif->npal = nLocPal;
         }
         ire = 1; goto Only_sp;
       }
     }

     CurPos = a_lseek(filx, 0, SEEK_CUR);
     // Pripravit scaling (bakground NE, pripadne vzdy zakazat),nebo oriznuti
     //if(NumImg == 0)
     { ist = PrepareScaleAndX(gif, NumImg, &Prepni);
       if(ist == 0) { ire = 1; goto Err_frame; }   // gif mimo scr
       //if(Prepni) goto Prepni; -> kreslit prvni frame gifu -> zacykleni
     }


     if(xg_256 != MM_Hic) // * * * * * * * * * * * * * 16 color, 256 color
     {
       // Kde vezmu Mmapio ??
       if(gif->palismap && ReaPal != 2)  // uz mam mapu a img mema loc.paletu
       { Mmapio[1]=(int *)(gif->pal);
       }
       else  // musim ji vyrobit
       { mapio=farmalloc(1024*sizeof(int)); if(!mapio) return(2);
         ist = PalForPaleteModes(gif, mapio, Mmapio, ReaPal, nLocPal, pLocPal);
	 if(ist != 1) { /*ire=ist*/ ire=1; goto Err_frame;} //mp!
       }

#ifdef XANIMGIF
       if(g_gifDrawXms == 0)
       { TraCol = IndexToTranspCol((int)gif->bgindex, (char*)Mmapio[1]);
         ist = XInitImgXms(gif, NumImg, Transp, TraCol, tAnim, disp);
         if(ist != 1)  // Neni misto v XMS : prepnout na screen a znovu
         { goto Prepni;
	 }
       }
#endif

       ire = draw_gif(gif,code_start,interlac,Transp,Mmapio[1],NULL, &ReaBytes);
       if(mapio) { farfree(mapio); mapio = 0; }

     }
     else // * * * * * * * * * * * * * * * * * * * * * * * * * * * Hicolor...
     {
       if( ReaPal==2 )
        pAktpal = (char *) pLocPal;
       else
	pAktpal = (char *)gif->pal;
#ifdef XANIMGIF
       if(g_gifDrawXms == 0)
       { TraCol = IndexToTranspCol((int)gif->bgindex, pAktpal);
	 ist = XInitImgXms(gif, NumImg, Transp, TraCol, tAnim, disp);
         if(ist != 1)  // neni XMS ?
         { Prepni:
           a_close(filx); goto New_read_gif;
         }
       }
#endif
      ire = draw_gif(gif,code_start,interlac,Transp,NULL,pAktpal, &ReaBytes);
     }


     ReaPal = 0;
     if(ire != 1)    // chyby pri dekompresi gifu
     { ire = 1;      // v NumImg je pocet OK framu //mp!
          // if(NumImg > 0)
           { goto Err_frame;
           }
          // else
          // { goto Only_sp;
          // }
     }

     NumImg++;
     CurPos = a_lseek(filx, CurPos+ReaBytes, SEEK_SET);
     disp = 0;
     //i=getch();
     if(g_gifDrawXms == 1 && NumImg > 0)
     { // Nakreslit vzdy jen prvni
       ire = 1; goto Only_sp;
     }
   }
   else if(mark == 0)     // OK end file
   {
     //char Msg[80];
     //sprintf(Msg,"EndGIFN: DrawXMS=%d NumImg=%d",g_gifDrawXms,NumImg);
     //outs(Msg);
     //getch();

     //ERRGIF
     Add_to_anim:
#ifdef XANIMGIF
     if(NumImg > 1 && g_gifDrawXms == 0) // pridat k animovanym
     {
       if(g_NumAnim < MAX_ANIMATEGIF)
       { g_TableAnim[g_NumAnim].hPicInf  = gif->hPicInfo; // ???
           g_TableAnim[g_NumAnim].NextAnim = 0;        // Cas pristi animace

           // SaveBck : Ulozit background ?
	   if(bSaveBck1 /*&& bSaveBck2*/)
           { ist = XSaveBackToXMS(gif, GifGlb.screenwide, GifGlb.screendeep, &BckAdr);
             if(ist==0)
             { if(BckAdr) XGifFreeXMS(); // uvolnit alloc. XMS pro pozadi
	     }
             else
             { gif->BckImg = BckAdr;
               swapmod = 1;
             }
           }
           g_NumAnim++;
         //outs("Add To Anim");
       }
     }

     Err_frame:
     if(NumImg == 0)
      goto Only_sp;

     if(g_gifDrawXms == 0 && gif->IsInXms)     // prvni obrazek z gifu v XMS
     { ist = XGifFromXms(gif, xg_video_XMS, vdx, vdy, &tAnim);
       // Je-li jeden frame, pak ho uvolnit
       if(NumImg == 1)
       { XGifFreeXMS();
       }
     }
#else
     Err_frame:
      ire = 1;
#endif
     goto Only_sp;
   }
   goto Next_marker;

   Only_sp:
   if(pLocPal) farfree(pLocPal);
   a_close(filx);
   return( ire );
}
Пример #13
0
// open/load from disk
//. Load binary structures from the disk.  Used only by cache.idx
int ie_openbin(struct bin_file *fajl) //load, or open, 1. or 2.
{
 int i,f=-1,rv;

 fajl->len=0;
// fajl->firstswap=0;

 fajl->lineadr=farmalloc((sizeof(XSWAP))*(IE_MAXLINES+2));
 if(fajl->lineadr==NULL) return 2;
 fajl->linesize=farmalloc((sizeof(unsigned short))*(IE_MAXLINES+2));
 if(fajl->linesize==NULL) return 2;

 i=0;
 while (i<IE_MAXLINES)
 {
  fajl->lineadr[i]=IE_NULL;
  fajl->linesize[i]=0;
  i++;
 }//loop

 if (swapstr == NULL ) return 2;

 if(fajl->filename[0])
#ifdef POSIX
  f=a_open(fajl->filename,O_RDONLY, 0);
#else
  f=a_sopen(fajl->filename,O_RDONLY|O_BINARY,SH_COMPAT | SH_DENYNONE, S_IREAD);
#endif

 if(f==-1)
 {
  //if(strlen(fajl->filename)==0) strcpy(fajl->filename,"NONAME.BIN");
  fajl->modified=0; //!!!
  return 1;
 }
 else
 {
  unsigned short linelen;
  char *inbuf;

  inbuf=farmalloc(16001);
  if(!inbuf)return 2;
  rv=1;

  fajl->modified=0; //!!!
  // load file
  while (1)
  {
   if(a_read(f,&linelen,sizeof(unsigned short))!=sizeof(unsigned short))
    goto exit_load; //end of file
   if(linelen>16000)
    {rv=6;goto exit_load;}
   if(a_read(f,inbuf,linelen)!=linelen)
    {rv=6;goto exit_load;}
   fajl->lineadr[fajl->len]=ie_putswap(inbuf,linelen,CONTEXT_SYSTEM);
   fajl->linesize[fajl->len]=linelen;
   if(fajl->len>IE_MAXLINES)
    {rv=5;goto exit_load;} //too many line, too large file
   fajl->len++;
  }//loop

  exit_load:
  farfree(inbuf);
  a_close (f);
  return rv;
 }//end if
}//end sub
Пример #14
0
int xsendmail(struct Url *url, char helo, char logfile)

{
 longword host;
 long length;
//!!glennmcc: Feb 05, 2008 -- increased from 128 to 512
 char str[512/*128*/],pom[512/*128*/];

//!!glennmcc Apr 30, 2004 -- for AuthSMTP
 char AuthSMTPusername[128]="",AuthSMTPpassword[128]="";
//!!glennmcc: end

 char buffer[BUFLEN];
 struct ffblk ff;
 char filename[80];
 int rv=0;             //default return value == error
 int f,nomoremail;
 int done,lenread,i,j,lastcarka,carka,field,success,u,z;
 int status,err=0;
 char *ptr;
 int log;

//!!glennmcc & Ray: Dec 14, 2006
 int bcc=0;
//!!glennmcc & Ray: end

 if(!tcpip)
  return 0;

 nomoremail=findfirst(&url->file[1],&ff,0);
 if(nomoremail)
  return 1;

 if(logfile)
  log= a_open( "SMTP.LOG" , O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE );
 else
  log=-1;

 free_socket();

 //reset requests on IDENT port:

 reset_detected=0;
 tcp_listen(sock[1-socknum], 113, 0, 0, (dataHandler_t) resetport , 0);

 sprintf(str,msg_askdns,url->host);
 outs(str);

 GlobalLogoStyle=0;		//SDL set resolve animation
 host = resolve_fn(url->host, (sockfunct_t) TcpIdleFunc);	//SDL
// host = resolve(url->host);
 if(!host)
 {
  DNSerr(url->host);
  return 0;
 }

 sprintf(str,msg_con,url->host,url->port);
 outs(str);

 GlobalLogoStyle=2;		//SDL set connect animation
 if (!tcp_open( socket, locport(), host, url->port, NULL ))
 {
  sprintf(str,msg_errcon,url->host);
  outs(str);
  return 0;
 }

 sock_wait_established( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
			&status);		//SDL
 GlobalLogoStyle=1;		//SDL set data animation

 sock_mode( socket, TCP_MODE_ASCII );
 outs(MSG_SMTP);

 //wait for daemon to appear:
 do
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  if(log!=-1)
  {
   write(log,buffer,strlen(buffer));
   write(log,"\r\n",2);
  }
  if ( *buffer != '2' ) goto quit;
 }
 while(buffer[3]=='-'); //continued message!

 if(log!=-1 && reset_detected)
 {
  strcpy(str,MSG_IDENT);
  write(log,str,strlen(str));
  write(log,"\r\n",2);
 }

 if(helo)
// if(helo!=0)
 {
  //HELO protocol
  char *mydomain=strchr(url->user,'@');
  if(mydomain)
   mydomain++; // xx@->yyy
  else
//!!glennmcc: Feb 22, 2006 -- use host domain instead of user
  {
   mydomain=strchr(url->host,'.');
   mydomain++; // xx@->yyy
  }
//   mydomain=url->user;
//!!glennmcc: end

//!!glennmcc: begin Nov 09, 2003 --- EHLO == Authenticated SMTP
//finally finished it on Apr 30, 2004 ;-)
if(helo==2)
{
//!!glennmcc: Feb 14, 2006 -- use 'authuser' for AuthSMTP
     mydomain=strrchr(url->authuser,'@');
     if(mydomain)
      mydomain++; // xx@->yyy
      else
//!!glennmcc: Feb 22, 2006 -- use host domain instead of authuser
      {
       mydomain=strchr(url->host,'.');
       mydomain++; // xx@->yyy
      }
//     mydomain=url->authuser;
//!!glennmcc: end

  sprintf( str, "EHLO %s", mydomain);
  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);


  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '2' ) goto quit;
  }
  while(buffer[3]=='-'); //continued message!

  sprintf( str, "AUTH LOGIN");
  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);

  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '3' ) goto quit;
  }
  while(buffer[3]=='-'); //continued message!
//!!glennmcc: Sept 17, 2004
// changed so that "email" will always get used for "mail from"
//  base64code((unsigned char *)url->user,AuthSMTPusername);
  base64code((unsigned char *)url->authuser,AuthSMTPusername);
//!!glennmcc: end
  sprintf( str, AuthSMTPusername);
  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);

  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '3' ) goto quit;
  }
  while(buffer[3]=='-'); //continued message!

//!!glennmcc: Feb 17, 2006 -- switch to new variable 'authpassword'
  base64code((unsigned char *)url->authpassword,AuthSMTPpassword);
//  base64code((unsigned char *)url->password,AuthSMTPpassword);
  sprintf( str, AuthSMTPpassword);
  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);

  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '2' ) goto quit;
  }
  while(buffer[3]=='-'); //continued message!
}
else //begin else HELO
{
//!!glennmcc: end

  sprintf( str, "HELO %s", mydomain);
  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);

  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '2' ) goto quit;
  }
  while(buffer[3]=='-'); //continued message!

}//!!glennmcc: end of else HELO

 }

 //do for all messages
 while (!nomoremail)
 {
  //process msg body

  if(err)
  {
   outs("RSET");
   if(log!=-1)
   {
    write(log,"RSET\r\n",6);
   }
   sock_puts(socket,(unsigned char *)"RSET");

   do
   {
    sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
    sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
    outs(buffer);
    if(log!=-1)
    {
     write(log,buffer,strlen(buffer));
     write(log,"\r\n",2);
    }
    if ( *buffer != '2' ) goto quit; //cannot reset ??
   }
   while(buffer[3]=='-'); //continued message!
   err=0;
  }

  strcpy(filename,&url->file[1]);
  ptr=strrchr(filename,'\\');
  if(ptr)
   ptr++; //point after "\"
  else
   ptr=filename; //current dir ? (not likelky case)
  strcpy(ptr,ff.ff_name);

  //open file
  f=a_fast_open(filename, O_TEXT|O_RDONLY,0);
  if(f<0)
   goto cont; //go to next message!


  //start SMTP
  sprintf( str, "MAIL FROM: <%s>", url->user);

  outs(str);
  if(log!=-1)
  {
   write(log,str,strlen(str));
   write(log,"\r\n",2);
  }
  sock_puts(socket,(unsigned char *)str);
  do
  {
   sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		    &status );		//SDL
   sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
   outs(buffer);
   if(log!=-1)
   {
    write(log,buffer,strlen(buffer));
    write(log,"\r\n",2);
   }
   if ( *buffer != '2' ) goto quit; //I am not accepted ?!
  }
  while(buffer[3]=='-'); //continued message!

  //process msg header
  done=lenread=j=lastcarka=carka=field=success=u=z=0;
  i=1; //force reading!
  do
  {

   if(i>=lenread)
   {
    lenread=a_read(f,buffer,BUFLEN);
    if(lenread<=0)
     done=1;
    i=0;
   }

   str[j]=buffer[i++];

   if(str[j]=='\"')u=1-u;
   else
   if(str[j]=='(')z=1;
   else
   if(str[j]==')')z=0;
   else
   if(str[j]==',' && !u && !z)carka=1;

   if(j>=127 || str[j]=='\n' || carka || done)
   {
    str[j]='\0';

    if(!str[0] && !lastcarka) //empty line -> end of message header
    {
     done=1;
     field=0;
    }
    else
    if(!strncmpi("TO:",str,3) || !strncmpi("CC:",str,3))
    {
     ptr=&str[3];
     field=1;
    }
    else
    if(!strncmpi("BCC:",str,4))
    {
//!!glennmcc & Ray: Dec 14, 2006
     bcc=1;
//!!glennmcc & Ray: end
     ptr=&str[4];
     field=1;
    }
    else
    if(field && (lastcarka || str[0]==' '))
     ptr=str;
    else
     field=0;

    if(field)
    {
     struct ib_editor expandlist;
     int rcpt;

     if(ptr[0]==' ' && ptr[1]=='@') //expand mailing list
     {
      makestr(expandlist.filename,&ptr[2],79);
      if(ie_openf(&expandlist,CONTEXT_TMP)==1)
       field=-1;
      else
      {
       field=0;
       expandlist.filename[0]='\0';
      }
     }
     else
      expandlist.filename[0]='\0';

     if(field!=0)
      rcpt=1;
     else
      rcpt=0;

     while(rcpt)
     {
      if(field==1) //address in ptr
       rcpt=0;
      else
      {
       ptr=ie_getline(&expandlist,expandlist.y++);
       if(expandlist.y>=expandlist.lines)
       {
	rcpt=0;
	field=0;
       }
      }

      cutaddress(ptr);
      if(*ptr)
      {
       //add SMTP recipient
       sprintf( pom, "RCPT TO: <%s>", ptr);
       outs(pom);
       if(log!=-1)
       {
	write(log,pom,strlen(pom));
	write(log,"\r\n",2);
       }
       sock_puts(socket,(unsigned char *)pom);
       sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
			&status );		//SDL
       sock_gets( socket, (unsigned char *)pom, sizeof( pom ));
       outs(pom);
       if(log!=-1)
       {
	write(log,pom,strlen(pom));
	write(log,"\r\n",2);
       }
       if(*pom == '2')
	success++;
      }
     }//loop

     if(expandlist.filename[0])
     {
      ie_killcontext(CONTEXT_TMP); //clear temporary file
//      ie_closef(&expandlist);
     }
    }//end temp variables

    lastcarka=carka;
    carka=0;
    j=0;
   }
   else
    j++;

  }
  while(!done);

  if(!success) //cannot send to any recipient ?
  {
   err=1;
   goto cont;
  }


  //process msg body
  outs("DATA");
  if(log!=-1)
  {
   write(log,"DATA\r\n",6);
  }
  sock_puts(socket,(unsigned char *)"DATA");
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  if(log!=-1)
  {
   write(log,buffer,strlen(buffer));
   write(log,"\r\n",2);
  }
  if ( *buffer != '3')
  {
   err=1;
   goto cont; //failed ? try next message!
  }

  a_lseek(f,0L,SEEK_SET); //reset file
  j=lenread=done=0;
  i=1;
  length=0;
  {
   long fll=a_filelength(f);
   do
   {
    if(i>=lenread)
    {
     sprintf(pom,MSG_SEND,length,fll);
     outs(pom);
/*
//!!glennmcc:Oct 23, 2008 -- 'reversed the logic'
// to keep from overflowing at 21megs
     if(fll>100)
     percentbar((int)(length/(fll/100)));
*/
   percentbar((int)(100*length/fll));
     lenread=a_read(f,buffer,BUFLEN);
     length+=lenread;
     if(lenread<=0)
      done=1;
     i=0;
 //    printf("\nlenread=%d \n",lenread);
//!!glennmcc & Ray: Dec 14, 2006 -- bypass Bcc:
if(bcc)
  {
   char *ptr = strstr(buffer, "Bcc:");//Ray
   if(ptr)
     {
//Ray's method replaces the address(s) with spaces
//it also looks for '\r' (carrage return) as the end of the Bcc line
//      ptr += 4;                        // PASS 'Bcc:'
//    while(*ptr && *ptr != '\r')
//    *ptr++ = ' ';
//printf("After: \n\n%40s", ptr); getch(); // SEE THE RESULT

//!!glennmcc: this method works better by 'nulling-out' the Bcc line and
//looking for '\n' (new line) as the end of the Bcc line
/* method #1 */
/**/
      if(*ptr--=='\n')*ptr='\0';//remove previous '\r\n' if it exists
      do
      {*ptr='\0'; ptr++;}
      while( *ptr && *ptr!='\n');
/**/
/* end method #1 */

/* method *2 */
/*
      if(*ptr--=='\n')*ptr='\0';//remove previous '\r\n' if it exists
      while(*ptr && *ptr!='\n')
      *ptr++ ='\0';
      *ptr='\0';//also remove this '\n'
*/
/* end method #2 */
      bcc=0;
     }
  }
//!!glennmcc & Ray: end
    }
    str[j]=buffer[i++];

//!!glennmcc: Feb 05, 2008 -- prevent character from being lost at line break
//by breaking at a space instead of 127 explicitly
//also increased line length limit to the next space past 200
//instead of just 127 explicitly
    if((j>=200 && str[j]==' ') || str[j]=='\n' || done)
//  if(j>=127 || str[j]=='\n' || done) //original line
//!!glennmcc: end
    {

     str[j]='\0';
     length++; //ASCI mode !!!

     //wait until we can write to socket:
     while(sock_tbleft(socket)<j+1)	//SDL
//     while( socket->datalen > 1024)
     {
      sock_tick(socket,&status);
      xChLogoTICK(1); // animace loga
      if(GUITICK())
      goto quit;
     }

     if (str[0]=='.')			//SDL always double up
      sock_putc(socket,'.');  		//SDL leading periods
     sock_puts(socket,(unsigned char *)str);
     if(log!=-1)
     {
      write(log,str,strlen(str));
      write(log,"\r\n",2);
     }
     sock_tick(socket,&status);
     j=0;
    }
    else
     j++;
   }
   while(!done);
  }
  a_close(f);

  sock_puts(socket,(unsigned char *)".");
  if(log!=-1)
  {
   write(log,".\r\n",3);
  }
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  if(log!=-1)
  {
   write(log,buffer,strlen(buffer));
   write(log,"\r\n",2);
  }
  if ( *buffer != '2' )
  {
   err=1;
  }
  else
  {
   //delete or rename
   ptr=strrchr(filename,'\\');
   if(!ptr)
    ptr=filename;
   else
    ptr++;

   if(*ptr=='!')
    unlink(filename);
   else
   {
    strcpy(str,filename);
    ptr=strrchr(str,'.');
    if(ptr)
     strcpy(&ptr[1],"SNT");
    rename(filename,str);
   }
  }//endif

  cont:
  nomoremail=findnext(&ff);
 }//loop - next message

 rv=1;

quit:
    outs("QUIT");
    if(log!=-1)
    {
     write(log,"QUIT\r\n",6);
     close(log);
    }
    sock_puts(socket,(unsigned char *)"QUIT");
    sock_close( socket );
    closing[socknum]=1;
    sock_keepalive[socknum][0]='\0';

sock_err:
    switch (status) {
	case 1 : /* foreign host closed */
		 break;
	case -1: /* timeout */
                 sprintf(str,MSG_TCPERR, sockerr(socket));
                 outs(str);
		 break;
    }
 return rv;
}
Пример #15
0
char *ArachneDIAL(void)
{
 char *value;
 char str[80];
 char terminal[80]="\0",hangup[80]="\0",useterm=0,dospppd=0;
 char *pausemsg=ctrlbreak;
 char buf[5*IE_MAXLEN];
 char altnameserver[IE_MAXLEN];
 char *altdns="\0";
//!!glennmcc: Mar 06, 2006 -- allow use of %DNS1 with miniterm/epppd
 char nameserver[IE_MAXLEN];
 char *dns="\0";
//!!glennmcc: end

 process_form(0,IE_NULL); //updateovat Arachne.Cfg

 if(tcpip)
 {
  value=configvariable(&ARACHNEcfg,"Hangup",NULL);
  if(value)
  {
   makestr(hangup,value,128);
   strcat(hangup,"\n");
  }
 }

 value=configvariable(&ARACHNEcfg,"UseTerminal",NULL);
 if(value && toupper(*value)=='Y')
 {
  value=configvariable(&ARACHNEcfg,"TerminalWindow",NULL);
  useterm=1;
 }
 else
  value=configvariable(&ARACHNEcfg,"Dialer",NULL);

 if(value && strcmpi(value,"NUL"))
 {
  makestr(terminal,value,128);
  strcat(terminal,"\n");
 }
 else
  useterm=0;

#ifndef NOETHERPPP
 value=configvariable(&ARACHNEcfg,"Connection",NULL);
 if(!value)
  return ("");

 /*
 if(!strncmpi(value,"@PPP.EXE",8))
 {
  int f,l;

  //vytvorit CONFIG.PPP
  f=a_open(configvariable(&ARACHNEcfg,"PPPconfig",NULL),O_RDONLY|O_TEXT,0);
  if(f!=-1)
  {
   l=a_read(f,buf,BUF/2);
   buf[l]='\0';
   a_close(f);
   sprintf(&buf[BUF/2+1],buf,
     configvariable(&ARACHNEcfg,"PPPusername",NULL),
     configvariable(&ARACHNEcfg,"PPPpassword",NULL));
   f=a_open("config.ppp",O_TEXT|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
   write(f,&buf[BUF/2+1],strlen(&buf[BUF/2+1]));
   a_close(f);
  }


 }//end if ETHERPPP
 else
 */
//!!glennmcc: begin Dec 24, 2000
// changed "PPPD.EXE to "PPP" so that *any* .EXE, .COM or .BAT
// with "PPP" in the name will still result in a new PPPDRC.CFG file
// examples... epppd.exe ppp.exe myppp.exe lsppp.exe loadppp.bat ppp_drv.com
// if(strstr(strupr(value),"PPPD.EXE"))

//!!glennmcc: July 6, 2002 always write pppdrc.cfg
// if(strstr(strupr(value),"PPP"))
//!!glennmcc: end

//!!glennmcc: Jan 16, 2008 -- write data into both pppdrc.cfg & lsppp.cfg
 {
  int f=a_open("pppdrc.cfg",O_TEXT|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
  int f2=a_open("lsppp.cfg",O_TEXT|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
  if(f!=-1 && f2!=-1)
  {
   char *base,*default_base[4]={"0x3f8","0x2f8","0x3e8","0x2e8"};
   char *irq,*default_irq[4]={"4","3","4","3"};
   int port=0;

   value=configvariable(&ARACHNEcfg,"Port",NULL);
   if(value)
    port=atoi(value)-1;

   if(port>=0 && port<4)
   {
    irq=default_irq[port];
    base=default_base[port];
   }
   else
   {
    irq=configvariable(&ARACHNEcfg,"Irq",NULL);
    base=configvariable(&ARACHNEcfg,"Base",NULL);
   }

   dns=configvariable(&ARACHNEcfg,"NameServer",NULL);
   if(*dns=='%')
     {
      char *ptr=strchr(&dns[1],'%');
      if(ptr) *ptr='\0';
      dns=getenv(&dns[1]);
     }
   if(strlen(dns)>6)
      sprintf(nameserver,"namsrv %s\n",dns);
      else
      strcpy(nameserver,"\0");

   altdns=configvariable(&ARACHNEcfg,"AltNameServer",NULL);
   if(*altdns=='%')
     {
      char *ptr=strchr(&altdns[1],'%');
      if(ptr) *ptr='\0';
      altdns=getenv(&altdns[1]);
     }
   if(strlen(altdns)>6)
      sprintf(altnameserver,"namsrv %s\n",altdns);
      else
      strcpy(altnameserver,"\0");

//write pppdrc.cfg
   sprintf(buf,"\
%s\n\
irq %s\n\
base %s\n\
modem\n\
crtscts\n\
asyncmap 0\n\
%s\
%s\
user \"%s\"\n\
passwd \"%s\"\n",
   configvariable(&ARACHNEcfg,"Speed",NULL),
   irq,base,
   nameserver,
   altnameserver,
   configvariable(&ARACHNEcfg,"PPPusername",NULL),
   configvariable(&ARACHNEcfg,"PPPpassword",NULL));
   write(f,buf,strlen(buf));
   a_close(f);

//write lsppp.cfg
   sprintf(buf,"\
/M:%s\n\
/d:%s\n\
/B:%s\n\
/i:%s\n\
/b:%s\n\
/U:%s\n\
/P:%s\n\
/V:60\n",
   configvariable(&ARACHNEcfg,"InitString",NULL),
   configvariable(&ARACHNEcfg,"PhoneNumber",NULL),
   configvariable(&ARACHNEcfg,"Speed",NULL),
   irq,base,
   configvariable(&ARACHNEcfg,"PPPusername",NULL),
   configvariable(&ARACHNEcfg,"PPPpassword",NULL));
//!!glennmcc: Feb 14, 2008 -- also write DNSs into lsppp.cfg
if(strlen(dns)>6)
 {
  strcat(buf,"/N:");
  strcat(buf,dns);
 }
if(strlen(altdns)>6)
 {
  strcat(buf,",");
  strcat(buf,altdns);
 }
if(strlen(dns)>6)
   strcat(buf,"\n");
//!!glennmcc: end, Feb 14, 2008
   write(f2,buf,strlen(buf));
   a_close(f2);
  }
  dospppd=1;
  pausemsg=MSG_ESC;
 }
Пример #16
0
Файл: main.c Проект: kdhp/play
static int
play(struct conf *conf) {
	struct	afile a;
	int	i;
	int	j;
	assert(conf != NULL && conf->songs != NULL &&
	    conf->buffer != NULL);
	if (conf->flags & RFLAG) {
		arc4random_buf(conf->songs->shuffle,
		    conf->songs->cur * sizeof(uint16_t));
		shuffle(conf->songs->songs, conf->songs->shuffle,
		    conf->songs->cur);
	}
	for (i = 0; i < conf->songs->cur; i++) {
	#ifdef OSS
		if ((conf->out = a_open(conf->dev)) == NULL)
			err(EX_SOFTWARE, "a_open");
	#endif
		s_open(&a, conf->songs->songs[i]);
		if (conf->flags & VFLAG)
			puts(conf->songs->songs[i]);
		if (a.t == ANULL) {
			if (conf->flags & VFLAG)
				warn("s_open");
			if (errno == ENOMEM || errno == ENFILE ||
			    errno == EMFILE)
				err(EX_OSERR, "s_open %s",
				    conf->songs->songs[i]);
			/* remove the song from the list */
			free(conf->songs->songs[i]);
			for (j = i; j < conf->songs->cur; j++)
				conf->songs->songs[j] =
				    conf->songs->songs[j + 1];
			conf->songs->cur--;
			/* replay the current index */
			i--;
			continue;
		}
		switch (s_play(conf, &a)) {
		case CEXIT:
			s_close(&a);
			return CEXIT;
		case CREPLAY:
			i--;
			break;
		case CPREV:
			if (i == 0 && (conf->flags & RFLAG)) {
				/* replay */
				i--;
				break;
			}
			i -= 2;
			if (i < -1 && (conf->flags & LFLAG))
				i += conf->songs->cur;
			break;
		case CNEXT:
			break;
		}
		s_close(&a);
	#ifdef OSS
		a_close(conf->out);
	#endif
	}
	return CNULL;
}