Example #1
0
File: main_rc.c Project: fzoli/C
// Very basic main: we send GET / and print the response.
int main(int argc, char **argv) {
    sslInit();

    SSL_CTX* ctx = sslCreateCtx(SSLv23_client_method());
    if (ctx == NULL) return EXIT_FAILURE;
    
    connection *c;
    char *response;

    c = sslConnect(ctx);
    
    sslWriteByte(c, 1);
    sslWriteByte(c, 0);
    
    sslWrite(c, "OK\r\n");
    
    response = sslRead(c);

    if (response) printf("%s\n", response);

    sleep(2);
    
    free(response);

    sslDisconnect(c);
    
    sslDestroyCtx(ctx);
    
    sslDestroy();
    
    return EXIT_SUCCESS;
}
Example #2
0
// Very basic main: we send GET / and print the response.
int main (int argc, char **argv)
{
  connection *c;
  char *response;

  c = sslConnect ();

  sslWrite (c, "GET /\r\n\r\n");
  response = sslRead (c);

  printf ("%s\n", response);

  sslDisconnect (c);
  free (response);

  return 0;
}
Example #3
0
// Send the data using a telnet session on a TLS connection
void sendByTelnet(sensor_data data, char * token, char * metric, char * additional_tags) {

	ssl_connection *c;
	char *response, *response_auth, query[1024];
	time_t now;

	// Initiate the connection
	c = sslConnect ();

	// Initiate the authentication
	snprintf(query, 1023, "auth %s\n", token);
	sslWrite (c, query);
	response_auth = sslRead (c);

	// Read the response from the server (should send 'ok' if the token is valid)
	if (0 == strcmp("ok\n", response_auth)) {
		time(&now);

		// Send the put commands one after the other
		snprintf(query, 1023, "put %s.hum %ld %s %s\n", metric, now, data.hum, additional_tags);
		sslWrite (c, query);

		snprintf(query, 1023, "put %s.temp %ld %s %s\n", metric, now, data.temp, additional_tags);
		sslWrite (c, query);
	} else {
		printf("Error auth, response is %s\n", response_auth);
	}

	free (response_auth);

	sslWrite (c, "exit\n");
	// Read the response from the server. No response means no error
	response = sslRead (c);
	if (0 != strcmp("", response)) {
		printf ("Command put error\n  \"%s\"\n", response);
	}
	free(response);

	// Disconnect from the server
	sslDisconnect (c);
}
Example #4
0
// Very basic main: we send GET / and print the response.
int SSLSendandRecv ()
{
  connection *c;
  char *response;
  BYTE recvbuf[1024];
  c = sslConnect ();
  int size=0;
  unsigned char  SendPack[1024];
  memset(SendPack,0x00,sizeof(SendPack));
  USHORT   ret=usReadFileData(SendFile,&size,(BYTE *)&SendPack);
  if(ret!=d_OK) return ret;
  
  
  int iret=sslWrite (c, SendPack,size);
  
  response = sslRead (c);
 
  sslDisconnect (c);
  free (response);

  return 0;
}
Example #5
0
int main (int argc, char **argv)
{
   int i;
   connection *c;
   char request[1024]="";
   char key[1024]="";
   char terms[1024]="";
   char filename[128]="";
   FILE* pSearchTerms = NULL;

   /*****************************************/
   /* Open the search term file for reading */
   /*****************************************/
   sprintf(filename, "./%s", argv[1]);
   pSearchTerms = fopen(filename, "r");

   if(pSearchTerms == NULL)
   {
      fprintf(stderr, "Error opening search terms file %s!\n", filename);
      return (EXIT_FAILURE);
   }

   /***************************************/
   /* Open the results file for appending */
   /***************************************/
   sprintf(filename, "./%s.res", argv[1]);
   pResults = fopen(filename, "w+");

   if(pResults == NULL)
   {
      fprintf(stderr, "Error opening results file %s!\n", filename);
      return (EXIT_FAILURE);
   }

   /***********************************/
   /* Read from the search terms file */
   /***********************************/
   fgets(terms, 1024, pSearchTerms);
   terms[strlen(terms)-1] = '\0';

   /**************************/
   /* Get our search results */
   /**************************/
   for(i = 0; i < NUM_QUERIES; i++)
   {
      c = sslConnect ();
      sprintf(key, "/customsearch/v1?key=GOOGLE_API_SECRET&cx=003397780648636422832:u25rx3s92ro&fields=items(link)&start=%d&q=%s", ((i* 10) + 1), terms);
      sprintf(request, "GET https://%s%s\r\n\r\n", SERVER, key);
      fprintf(stdout, "%s", request);
      sslWrite(c, request);
      sslRead(c);
      sslDisconnect (c);
   }

   /***************************/
   /* Close the file pointers */
   /***************************/
   fclose(pSearchTerms);
   fclose(pResults);

   /************************/
   /* Call the JSON parser */
   /************************/

   /*****************************************/
   /* Call the Text Processor and Retriever */
   /*****************************************/

   /****************************/
   /* Call the Site Classifier */
   /****************************/

   return (EXIT_SUCCESS);
}
MailConnection::~MailConnection()
{
    if (conn)
        sslDisconnect();
}
void MailConnection::CloseConnection()
{
    if (conn)
        sslDisconnect();
}
Example #8
0
void SSLSocket::close() {
    if (closed) return;
    closed = true;
    sslDisconnect(conn);
    sslDestroyCtx(ctx);
}