Ejemplo n.º 1
0
int main( int argc, char** argv )
{
	SOCKADDR *sa;
   int n;
	if( argc < 2 )
	{
		printf( "usage: %s <Telnet IP[:port]>\n", argv[0] );
		return 0;
	}
	SystemLog( "Starting the network" );
	NetworkStart();
	SystemLog( "Started the network" );
   sa = CreateSockAddress( argv[1], 23 );
	//if( argc >= 3 ) port = atoi( argv[2] ); else port = 23;
	pc_user = OpenTCPClientAddrExx( sa, ReadComplete, Closed, NULL, Connected );

	if( !pc_user )
	{
		SystemLog( "Failed to open some port as telnet" );
		printf( "failed to open %s%s\n", argv[1], strchr(argv[1],':')?"":":telnet[23]" );
		return 0;
	}
	for( n = 0; n < 1000; n++ )
	{
		if( (rand() & 3) != 0 )
		{
         WakeableSleep( rand() %1000 );
		}
      lprintf( "..." );
		RemoveClient( pc_user );
		pc_user = OpenTCPClientAddrExx( sa, ReadComplete, Closed, NULL, Connected );
		lprintf( "..." );
		if( (rand() &3) < 3 )
		{
         fflush( stdout );
			while( !connected )
				Relinquish();
		}
		if( connected )
		{
         lprintf( "send." );
			SendTCP( pc_user, "test", 4 );
		}
	}
	return -1;
}
Ejemplo n.º 2
0
int _tmain(int argc, TCHAR *argv[])
{
	RawLogStart(0, _T("debug.log"));
	SystemLog(Error) << _T("Test\n") << _T("TTT");
	SystemLog(Message) << _T("Test2\n") << _T("TTT2");
	SystemLog(Warning) << _T("Test3");
	SystemLog(Debug) << _T("Test4");
	RawLogStop(0);
/*
	Log.Init(MainLog, "mainlog.txt");
	Log.Init(SystemLog, "systemlog.txt");

	SystemLog << Message << "Message";
	SystemLog 
		<< Header << "Header"
		<< Message << "Message after header";

	MainLog << Warning << "Warning";	
*/
	return 0;
}
Ejemplo n.º 3
0
static void VLog(OutputLevel level, const char *errstr, const char *fmt, va_list args)
{
    char buffer[CF_BUFSIZE], output[CF_BUFSIZE];
    Item *mess = NULL;

    if ((fmt == NULL) || (strlen(fmt) == 0))
    {
        return;
    }

    memset(output, 0, CF_BUFSIZE);
    vsnprintf(buffer, CF_BUFSIZE - 1, fmt, args);

    if (Chop(buffer, CF_EXPANDSIZE) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator");
    }

    AppendItem(&mess, buffer, NULL);

    if ((errstr == NULL) || (strlen(errstr) > 0))
    {
        snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr());
        AppendItem(&mess, output, NULL);
    }

    switch (level)
    {
    case OUTPUT_LEVEL_INFORM:

        if (INFORM || VERBOSE || DEBUG)
        {
            LogListStdout(mess, VERBOSE);
        }
        break;

    case OUTPUT_LEVEL_VERBOSE:

        if (VERBOSE || DEBUG)
        {
            LogListStdout(mess, VERBOSE);
        }
        break;

    case OUTPUT_LEVEL_ERROR:
    case OUTPUT_LEVEL_REPORTING:
    case OUTPUT_LEVEL_CMDOUT:

        LogListStdout(mess, VERBOSE);
        SystemLog(mess, level);
        break;

    case OUTPUT_LEVEL_LOG:

        if (VERBOSE || DEBUG)
        {
            LogListStdout(mess, VERBOSE);
        }
        SystemLog(mess, OUTPUT_LEVEL_VERBOSE);
        break;

    default:

        ProgrammingError("Report level unknown");
        break;
    }

    DeleteItemList(mess);
}
Ejemplo n.º 4
0
void cfPS(EvalContext *ctx, OutputLevel level, PromiseResult status, const char *errstr, const Promise *pp, Attributes attr, const char *fmt, ...)
{
    if ((fmt == NULL) || (strlen(fmt) == 0))
    {
        return;
    }

    va_list ap;
    va_start(ap, fmt);
    char buffer[CF_BUFSIZE];
    vsnprintf(buffer, CF_BUFSIZE - 1, fmt, ap);
    va_end(ap);

    if (Chop(buffer, CF_EXPANDSIZE) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator");
    }

    Item *mess = NULL;
    AppendItem(&mess, buffer, NULL);

    if ((errstr == NULL) || (strlen(errstr) > 0))
    {
        char output[CF_BUFSIZE];
        snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr());
        AppendItem(&mess, output, NULL);
    }

    if (level == OUTPUT_LEVEL_ERROR)
    {
        AmendErrorMessageWithPromiseInformation(ctx, &mess, pp);
    }

    int verbose = (attr.transaction.report_level == OUTPUT_LEVEL_VERBOSE) || VERBOSE;

    switch (level)
    {
    case OUTPUT_LEVEL_INFORM:

        if (INFORM || (attr.transaction.report_level == OUTPUT_LEVEL_INFORM)
                || VERBOSE || (attr.transaction.report_level == OUTPUT_LEVEL_VERBOSE)
                || DEBUG)
        {
            LogListStdout(mess, verbose);
        }

        if (attr.transaction.log_level == OUTPUT_LEVEL_INFORM)
        {
            SystemLog(mess, level);
        }
        break;

    case OUTPUT_LEVEL_VERBOSE:

        if (VERBOSE || (attr.transaction.log_level == OUTPUT_LEVEL_VERBOSE)
                || DEBUG)
        {
            LogListStdout(mess, verbose);
        }

        if (attr.transaction.log_level == OUTPUT_LEVEL_VERBOSE)
        {
            SystemLog(mess, level);
        }

        break;

    case OUTPUT_LEVEL_ERROR:

        LogListStdout(mess, verbose);

        if (attr.transaction.log_level == OUTPUT_LEVEL_ERROR)
        {
            SystemLog(mess, level);
        }
        break;

    case OUTPUT_LEVEL_NONE:
        break;

    default:
        ProgrammingError("Unexpected output level (%d) passed to cfPS", level);
    }

    if (pp != NULL)
    {
        LogPromiseResult(pp->promiser, pp->promisee.type, pp->promisee.item, status, attr.transaction.log_level, mess);
    }

    /* Now complete the exits status classes and auditing */

    if (pp != NULL)
    {
        ClassAuditLog(ctx, pp, attr, status);
        UpdatePromiseComplianceStatus(status, pp, buffer);
    }

    DeleteItemList(mess);
}
Ejemplo n.º 5
0
//int ftpsget(STR *ip,STR *id,STR *pw,STR * Localfilename, STR * Remofilename,BYTE isSSL)
USHORT ECC_FTPGetFile(STR *ip,STR *id,STR *pw,STR * Localfilename, STR * Remofilename,BYTE isSSL)
{
  CURL *curl;
  CURLcode res;
  struct FtpFile ftpfile={
    "tmpfile", /* name to store the file as if succesful */
    NULL
  };

  curl_global_init(CURL_GLOBAL_DEFAULT);

  curl = curl_easy_init();
  if(curl) {
    /*
     * You better replace the URL with one that works! Note that we use an
     * FTP:// URL with standard explicit FTPS. You can also do FTPS:// URLs if
     * you want to do the rarer kind of transfers: implicit.
     */
      BYTE URL[128];
      BYTE IDPW[64];
      BYTE errstr[64];
      memset(URL,0x00,sizeof(URL));
      sprintf(URL,"FTPS://%s%s",ip,Remofilename);
      memset(IDPW,0x00,sizeof(IDPW));
      sprintf(IDPW,"%s:%s",id,pw);
     curl_easy_setopt(curl, CURLOPT_URL,URL);
     curl_easy_setopt(curl, CURLOPT_USERPWD,IDPW);
    // curl_easy_setopt(curl, d,1);
  
 // curl_easy_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE, 1024*1024*2);
   //curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1024*1024*2);
  // curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 1024*50);
    /* Define our callback to get called when there's data to be written */
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
    /* Set a pointer to our struct to pass to the callback */
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

    /* cert is stored PEM coded in file... */
      /* since PEM is default, we needn't set it for PEM */
  //    curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
  //    curl_easy_setopt(curl,CURLOPT_SSLCERT,"CMAS-FTP.pem");
  /* if we use a key stored in a crypto engine,
         we must set the key type to "ENG" */
  //    curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,"PEM");

      /* set the private key (file or ID in engine) */
 //     curl_easy_setopt(curl,CURLOPT_SSLKEY,"CMAS-FTP.pem");

      /* set the cert for client authentication */
  //     curl_easy_setopt(curl,CURLOPT_CAINFO,"CMAS-FTP.pem"); 
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
   //  curl_easy_setopt(curl,CURLOPT_SSLCERT,"CMAS-FTP.pem");
   /* We activate SSL and we require it for both control and data */
    curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
  
    
    //   curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1);
    //   curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION, 1);
  
    // curl_easy_setopt(curl, CURLOPT_FTPSSLAUTH,"AUTH TLS");
  
   //  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
   
    /* Switch on full protocol/debug output */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
   
    if(CURLE_OK != res) {
      /* we failed */
      sprintf(errstr, "curl told us %d\n",(int ) res);
      SystemLog("ECC_FTPGetFile",errstr);
      return d_Fail;
    }
  }

  if(ftpfile.stream)
    fclose(ftpfile.stream); /* close the local file */
 //  rename(ftpfile.filename,Localfilename);
 
    ULONG lsize=File_GetLen((char *)ftpfile.filename);
    if(lsize<=0) return d_Fail; 
    remove(Localfilename); 
   int iret= copyFiles((char *)ftpfile.filename, Localfilename);
   remove(ftpfile.filename); 
  curl_global_cleanup();

  return d_OK;
}
Ejemplo n.º 6
0
USHORT ECC_FTPGetFileShowStatusForTest(STR *title,STR *ip,STR *id,STR *pw,STR * Localfilename, STR * Remofilename,BYTE isSSL)
{
  CURL *curl;
  CURLcode res;
  double totaltime,filesize;
  BYTE statusline2[64];
  struct FtpFile ftpfile={
    "tmpfile", /* name to store the file as if succesful */
    NULL
  };
   CTOS_LCDSelectMode(d_LCD_TEXT_320x240_MODE); 
   CTOS_LCDGClearCanvas();
   ShowTitle(title);
   ShowLine(0,40+16,Big_Font_Size,"資料下載中.",FALSE);
  
   ShowLine(0,40+40+16+10,Med_Font_Size,"下載進度",FALSE);
   curl_global_init(CURL_GLOBAL_DEFAULT);
   BYTE processstr[32];
   curl = curl_easy_init();
   if(curl) {
      BYTE URL[128];
      BYTE IDPW[64];
      BYTE DNS[64];
      BYTE *errstr;
      memset(URL,0x00,sizeof(URL));
      sprintf(URL,"FTPS://%s%s",ip,Remofilename);
 
      memset(IDPW,0x00,sizeof(IDPW));
      sprintf(IDPW,"%s:%s",id,pw);
     curl_easy_setopt(curl, CURLOPT_URL,URL);
     curl_easy_setopt(curl, CURLOPT_USERPWD,IDPW);
  
   
    /* Define our callback to get called when there's data to be written */
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
    /* Set a pointer to our struct to pass to the callback */
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
    BYTE len=sizeof(DNS);
    USHORT ret = CTOS_EthernetConfigGet(d_ETHERNET_CONFIG_DNSIP, DNS,&len);
   
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); 
   curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 1024L*1000); 
    curl_easy_setopt(curl, CURLOPT_FTP_RESPONSE_TIMEOUT, 600); 
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 600); 
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600); 
    curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, DNS); 
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 
    curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
   
    /* Switch on full protocol/debug output */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);
  
    if(CURLE_OK != res) {
      /* we failed */      
       errstr=(BYTE*)curl_easy_strerror(res);
        ErrorMessageBox(gTransTitle,"錯誤訊息",errstr,"","",d_MB_CHECK);
        CTOS_PrinterPutString (errstr);
        SystemLog("ECC_FTPGetFile",errstr);
        return res;
    }   
    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize);
    if((CURLE_OK == res) && (filesize>0.0))
    {
     sprintf(statusline2,"filesize : %0.0f bytes", filesize);
     ShowLine(0,40+40+40+16+10,Med_Font_Size,statusline2,FALSE);
       CTOS_PrinterPutString (statusline2);
    }
    
    res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &totaltime);
    if((CURLE_OK == res) && (totaltime>0.0))
    {
     sprintf(statusline2,"totaltime : %0.0f sec", totaltime);
     ShowLine(0,40+40+40+40+16+10,Med_Font_Size,statusline2,FALSE);
     CTOS_PrinterPutString (statusline2);
    }
  }

  //curl_easy_cleanup(curl);
  curl_global_cleanup();
  CTOS_Delay(2000);
  return d_OK;
}
Ejemplo n.º 7
0
USHORT ECC_FTPGetFileShowStatus_S(STR *ip,STR *id,STR *pw,STR * Localfilename, STR * Remofilename,BYTE isSSL)
{
  CURL *curl;
  CURLcode res;
  double filesize = 0.0;
  double totaltime = 0.0;
  BYTE statusline2[64];
  struct FtpFile ftpfile={
    "tmpfile", /* name to store the file as if succesful */
    NULL
  };
   CTOS_LCDSelectMode(d_LCD_TEXT_320x240_MODE); 
   CTOS_LCDGClearCanvas();
   ShowTitle(gTransTitle);
   ShowLine(0,40+16,Big_Font_Size,"資料下載中.",FALSE);
  
   ShowLine(0,40+40+16+10,Med_Font_Size,"下載進度",FALSE);
   curl_global_init(CURL_GLOBAL_DEFAULT);
   BYTE processstr[32];
  
   USHORT  ret= Eth_Connect(bgNETWORKChannel,ip,990);
    curl_socket_t sockfd=Socketfd;
   curl = curl_easy_init();
   if(curl) {
      BYTE URL[128];
      BYTE IDPW[64];
      BYTE DNS[64];
      BYTE *errstr;
      memset(URL,0x00,sizeof(URL));
      sprintf(URL,"FTPS://%s%s",ip,Remofilename);
      memset(IDPW,0x00,sizeof(IDPW));
      sprintf(IDPW,"%s:%s",id,pw);
     curl_easy_setopt(curl, CURLOPT_URL,URL);
     curl_easy_setopt(curl, CURLOPT_USERPWD,IDPW);
  
   
    /* Define our callback to get called when there's data to be written */
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
    /* Set a pointer to our struct to pass to the callback */
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
    BYTE len=sizeof(DNS);
    USHORT ret = CTOS_EthernetConfigGet(d_ETHERNET_CONFIG_DNSIP, DNS,&len);
   
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); 
   /* call this function to get a socket */ 
    curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
    curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
    /* call this function to set options for the socket */ 
    curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
    curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 2024L); 
    curl_easy_setopt(curl, CURLOPT_FTP_RESPONSE_TIMEOUT, 10); 
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3); 
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600); 
 
    curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L); 
    curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, DNS); 
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 
    curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
   
    /* Switch on full protocol/debug output */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);
  
    if(CURLE_OK != res) {
      /* we failed */      
       errstr=(char*)curl_easy_strerror(res);
        ErrorMessageBox(gTransTitle,"錯誤訊息",errstr,"","",d_MB_CHECK);
        SystemLog("ECC_FTPGetFile",errstr);
      return d_Fail;
    }   
    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize);
    if((CURLE_OK == res) && (filesize>0.0))
    {
     sprintf(statusline2,"filesize : %0.0f bytes\n", filesize);
     ShowLine(0,40+40+40+16+10,Med_Font_Size,statusline2,FALSE);
    }
    
     res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &totaltime);
    if((CURLE_OK == res) && (totaltime>0.0))
    {
     sprintf(statusline2,"totaltime : %0.0f sec\n", totaltime);
     ShowLine(0,40+40+40+40+16+10,Med_Font_Size,statusline2,FALSE);
    }
  }
 
  if(ftpfile.stream)
    fclose(ftpfile.stream); /* close the local file */
 //  rename(ftpfile.filename,Localfilename);
 
    ULONG lsize=File_GetLen((char *)ftpfile.filename);
    if(lsize<=0) return d_Fail; 
    remove(Localfilename); 
   int iret= copyFiles((char *)ftpfile.filename, Localfilename);
   remove(ftpfile.filename); 
     /* always cleanup */
  curl_easy_cleanup(curl);
  curl_global_cleanup();
  CTOS_Delay(2000);
  return d_OK;
}
Ejemplo n.º 8
0
SDL::~SDL() 
{
    	SDL_Quit();
	SystemLog("Shut Down SDL");
}