ssl alpha support

This commit is contained in:
Xuan Sang LE 2018-02-10 12:24:01 +01:00
parent aba40b16f5
commit 708e54989d
6 changed files with 31 additions and 23 deletions

View File

@ -17,9 +17,8 @@ void accept_request(void* client)
struct stat st;
//char *query_string = NULL;
LOG("SOCK IS %d\n", ((antd_client_t*)client)->sock);
numchars = get_line(((antd_client_t*)client)->sock, buf, sizeof(buf));
printf("BUF: %s\n", buf);
//LOG("SOCK IS %d\n", ((antd_client_t*)client)->sock);
numchars = read_buf(client, buf, sizeof(buf));
i = 0; j = 0;
while (!ISspace(buf[j]) && (i < sizeof(method) - 1))
{
@ -236,7 +235,7 @@ void error_die(const char *sc)
* Returns: the number of bytes stored (excluding null) */
/**********************************************************************/
//This function is deprecate
int get_line(int sock, char *buf, int size)
/*int get_line(int sock, char *buf, int size)
{
int i = 0;
char c = '\0';
@ -266,7 +265,7 @@ int get_line(int sock, char *buf, int size)
buf[i] = '\0';
return(i);
}
}*/
/**********************************************************************/
@ -462,7 +461,6 @@ dictionary decode_request(void* client,const char* method, char* url)
while((read_buf(client,buf,sizeof(buf))) && strcmp("\r\n",buf))
{
line = buf;
printf("LINE1: %s \n", line);
trim(line, '\n');
trim(line, '\r');
token = strsep(&line,":");
@ -867,7 +865,7 @@ int execute_plugin(void* client, const char *path, const char *method, dictionar
memcpy(pfunc,rpath+npos+1,fpos);
pfunc[fpos-1]='\0';
}
LOG("Client %d\n",client );
LOG("Client %d\n",((antd_client_t*)client)->sock );
LOG("Path : '%s'\n", rpath);
LOG("Method:%s\n", method);
LOG("Plugin name '%s'\n",pname);

View File

@ -28,7 +28,7 @@ void accept_request(void*);
void cat(void*, FILE *);
void cannot_execute(void*);
void error_die(const char *);
int get_line(int, char *, int);
//int get_line(int, char *, int);
void not_found(void*);
void serve_file(void*, const char *);
int startup(unsigned *);

21
httpd.c
View File

@ -136,9 +136,9 @@ void load_config(const char* file)
{
LOG("Using configuration : %s\n", file);
#ifdef USE_OPENSSL
LOG("Enable %d\n", server_config.usessl);
LOG("cert %s\n", server_config.sslcert);
LOG("key %s\n", server_config.sslkey);
LOG("SSL enable %d\n", server_config.usessl);
LOG("SSL cert %s\n", server_config.sslcert);
LOG("SSL key %s\n", server_config.sslkey);
#endif
}
init_file_system();
@ -185,7 +185,7 @@ int main(int argc, char* argv[])
while (1)
{
antd_client_t client;
antd_client_t* client = (antd_client_t*)malloc(sizeof(antd_client_t));
client_sock = accept(server_sock,(struct sockaddr *)&client_name,&client_name_len);
if (client_sock == -1)
{
@ -195,26 +195,27 @@ int main(int argc, char* argv[])
/* accept_request(client_sock); */
#ifdef USE_OPENSSL
client.ssl = NULL;
client->ssl = NULL;
if(server_config.usessl == 1)
{
client.ssl = (void*)SSL_new(ctx);
SSL_set_fd((SSL*)client.ssl, client_sock);
client->ssl = (void*)SSL_new(ctx);
SSL_set_fd((SSL*)client->ssl, client_sock);
if (SSL_accept((SSL*)client.ssl) <= 0) {
if (SSL_accept((SSL*)client->ssl) <= 0) {
ERR_print_errors_fp(stderr);
continue;
}
}
#endif
client.sock = client_sock;
if (pthread_create(&newthread , NULL,(void *(*)(void *))accept_request, (void *)&client) != 0)
client->sock = client_sock;
if (pthread_create(&newthread , NULL,(void *(*)(void *))accept_request, (void *)client) != 0)
perror("pthread_create");
else
{
//reclaim the stack data when thread finish
pthread_detach(newthread) ;
}
//accept_request(&client);
}
close(server_sock);

View File

@ -70,10 +70,12 @@ int response(void* client, const char* data)
}
int antd_send(const void *src, const void* data, int len, int _ssl)
{
if(!src) return -1;
antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL
if(_ssl)
{
//LOG("SSL WRITE\n");
return SSL_write((SSL*) source->ssl, data, len);
}
else
@ -86,10 +88,12 @@ int antd_send(const void *src, const void* data, int len, int _ssl)
}
int antd_recv(const void *src, void* data, int len, int _ssl)
{
if(!src) return -1;
antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL
if(_ssl)
{
//LOG("SSL READ\n");
return SSL_read((SSL*) source->ssl, data, len);
}
else
@ -102,15 +106,18 @@ int antd_recv(const void *src, void* data, int len, int _ssl)
}
int antd_close(void* src)
{
if(!src) return -1;
antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL
if(source->ssl && usessl()){
SSL_free((SSL*) source->ssl);
LOG("Freeing SSL\n");
//LOG("Freeing SSL\n");
}
#endif
printf("Close sock %d\n", source->sock);
close(source->sock);
//printf("Close sock %d\n", source->sock);
int ret = close(source->sock);
free(src);
return ret;
}
int __ti(void* client,int data)
{

View File

@ -34,12 +34,13 @@ sqldb getdb()
}
#endif
#ifdef USE_OPENSSL
/*#ifdef USE_OPENSSL
int usessl()
{
LOG("CALLED from plugin \n");
return __plugin__.usessl;
}
#endif
#endif*/
char* route(const char* repath)
{

View File

@ -81,6 +81,7 @@ char* __s(const char* fstring,...)
*/
void trim(char* str, const char delim)
{
if(!str) return;
char * p = str;
int l = strlen(p);