1231 |
|
|
1232 |
|
|
1233 |
/** |
/** |
|
* Receives a string data package though the ssl connection |
|
|
* @param ssl ssl connection |
|
|
* @param buffer array to hold the data |
|
|
* @param len size of the data container |
|
|
* @return pointer to buffer, NULL if failed |
|
|
*/ |
|
|
char *gets_ssl_socket(ssl_connection *ssl, char *buffer, int len ) { |
|
|
|
|
|
#ifdef HAVE_OPENSSL |
|
|
|
|
|
int i=0; |
|
|
char c; |
|
|
|
|
|
ASSERT(ssl); |
|
|
ASSERT(buffer); |
|
|
|
|
|
while(i <= len - 1) { |
|
|
|
|
|
switch ( recv_ssl_socket(ssl, (void *) &c, 1, NET_TIMEOUT)) { |
|
|
|
|
|
case 1: |
|
|
|
|
|
buffer[i]=c; |
|
|
break; |
|
|
|
|
|
case 0: |
|
|
|
|
|
goto eot; |
|
|
|
|
|
default: |
|
|
|
|
|
return NULL; |
|
|
|
|
|
} |
|
|
|
|
|
if (c=='\n') { |
|
|
|
|
|
buffer[i+1]='\0'; |
|
|
goto eot; |
|
|
|
|
|
} |
|
|
|
|
|
i++; |
|
|
|
|
|
} |
|
|
|
|
|
eot: |
|
|
|
|
|
return buffer; |
|
|
|
|
|
#else |
|
|
|
|
|
return NULL; |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
* Sends a formated string though the ssl connection |
|
|
* @param ssl ssl connection |
|
|
* @param format string holding the format information |
|
|
* @param ... data for the string |
|
|
* @return number for characters transmitted |
|
|
*/ |
|
|
int printf_ssl_socket(ssl_connection *ssl, const char *format, ...) { |
|
|
|
|
|
#ifdef HAVE_OPENSSL |
|
|
|
|
|
char msg[STRLEN]; |
|
|
int len; |
|
|
|
|
|
va_list ap; |
|
|
|
|
|
ASSERT(ssl); |
|
|
ASSERT(format); |
|
|
|
|
|
va_start(ap,format); |
|
|
len=vsnprintf(msg, STRLEN, format, ap); |
|
|
va_end(ap); |
|
|
|
|
|
return send_ssl_socket(ssl, msg, len); |
|
|
|
|
|
#else |
|
|
|
|
|
return 0; |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
1234 |
* Start SSL support library. It has to be run before the SSL support |
* Start SSL support library. It has to be run before the SSL support |
1235 |
* can be used. |
* can be used. |
1236 |
* @return TRUE, or FALSE if an error has occured. |
* @return TRUE, or FALSE if an error has occured. |