Skip to content
Snippets Groups Projects
Commit 21ed2fcd authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

... more fixes

parent e31416a9
No related branches found
No related tags found
No related merge requests found
Pipeline #7222 passed with stage
in 10 seconds
...@@ -137,7 +137,7 @@ void dap_http_delete( dap_server_t *a_server, void * a_arg ) ...@@ -137,7 +137,7 @@ void dap_http_delete( dap_server_t *a_server, void * a_arg )
* @param a_write_callback Callback for write in DATA state * @param a_write_callback Callback for write in DATA state
* @param a_error_callback Callback for error processing * @param a_error_callback Callback for error processing
*/ */
void dap_http_add_proc(dap_http_t *a_http, const char *a_url_path, void *a_inheritor dap_http_url_proc_t * dap_http_add_proc(dap_http_t *a_http, const char *a_url_path, void *a_inheritor
,dap_http_client_callback_t a_new_callback ,dap_http_client_callback_t a_new_callback
,dap_http_client_callback_t a_delete_callback ,dap_http_client_callback_t a_delete_callback
,dap_http_client_callback_t a_headers_read_callback ,dap_http_client_callback_t a_headers_read_callback
......
...@@ -119,21 +119,20 @@ void dap_http_simple_module_deinit( void ) ...@@ -119,21 +119,20 @@ void dap_http_simple_module_deinit( void )
* @param a_reply_size_max Maximum reply size * @param a_reply_size_max Maximum reply size
* @param a_callback Callback for data processing * @param a_callback Callback for data processing
*/ */
struct dap_http_simple_url_proc * dap_http_simple_proc_add( dap_http_t *a_http, const char *a_url_path, size_t a_reply_size_max, dap_http_simple_callback_t a_callback ) struct dap_http_url_proc * dap_http_simple_proc_add( dap_http_t *a_http, const char *a_url_path, size_t a_reply_size_max, dap_http_simple_callback_t a_callback )
{ {
dap_http_simple_url_proc_t *l_url_proc = DAP_NEW_Z( dap_http_simple_url_proc_t ); dap_http_simple_url_proc_t *l_url_proc = DAP_NEW_Z( dap_http_simple_url_proc_t );
l_url_proc->proc_callback = a_callback; l_url_proc->proc_callback = a_callback;
l_url_proc->reply_size_max = a_reply_size_max; l_url_proc->reply_size_max = a_reply_size_max;
dap_http_add_proc( a_http, a_url_path, return dap_http_add_proc( a_http, a_url_path,
l_url_proc, // Internal structure l_url_proc, // Internal structure
s_http_client_new, // Contrustor s_http_client_new, // Contrustor
NULL, // Destructor s_http_client_delete, // Destructor
s_http_client_headers_read, NULL, // Headers read, write s_http_client_headers_read, NULL, // Headers read, write
s_http_client_data_read, s_http_client_data_write, // Data read, write s_http_client_data_read, s_http_client_data_write, // Data read, write
NULL); // errror NULL); // errror
return l_url_proc;
} }
static void _free_user_agents_list() static void _free_user_agents_list()
...@@ -324,7 +323,6 @@ bool s_proc_queue_callback(dap_proc_thread_t * a_thread, void * a_arg ) ...@@ -324,7 +323,6 @@ bool s_proc_queue_callback(dap_proc_thread_t * a_thread, void * a_arg )
s_set_writable_flags( l_http_simple); s_set_writable_flags( l_http_simple);
dap_proc_thread_assign_on_worker_inter(a_thread, l_http_simple->worker, l_http_simple->esocket); dap_proc_thread_assign_on_worker_inter(a_thread, l_http_simple->worker, l_http_simple->esocket);
s_http_simple_delete( l_http_simple );
return true; return true;
} }
/** /**
...@@ -337,6 +335,7 @@ static void s_http_client_new( dap_http_client_t *a_http_client, void *a_arg ) ...@@ -337,6 +335,7 @@ static void s_http_client_new( dap_http_client_t *a_http_client, void *a_arg )
(void) a_arg; (void) a_arg;
a_http_client->_inheritor = DAP_NEW_Z( dap_http_simple_t ); a_http_client->_inheritor = DAP_NEW_Z( dap_http_simple_t );
dap_http_simple_t * l_http_simple = DAP_HTTP_SIMPLE(a_http_client); dap_http_simple_t * l_http_simple = DAP_HTTP_SIMPLE(a_http_client);
dap_http_simple_url_proc_t * l_http_simple_url_proc = DAP_HTTP_SIMPLE_URL_PROC( a_http_client->proc );
// log_it(L_DEBUG,"dap_http_simple_headers_read"); // log_it(L_DEBUG,"dap_http_simple_headers_read");
// Sleep(300); // Sleep(300);
...@@ -372,7 +371,7 @@ static void s_http_client_headers_read( dap_http_client_t *a_http_client, void * ...@@ -372,7 +371,7 @@ static void s_http_client_headers_read( dap_http_client_t *a_http_client, void *
{ {
(void) a_arg; (void) a_arg;
dap_http_simple_t * l_http_simple = DAP_HTTP_SIMPLE(a_http_client); dap_http_simple_t * l_http_simple = DAP_HTTP_SIMPLE(a_http_client);
assert(l_http_simple);
if( a_http_client->in_content_length ) { if( a_http_client->in_content_length ) {
// dbg if( a_http_client->in_content_length < 3){ // dbg if( a_http_client->in_content_length < 3){
if( a_http_client->in_content_length > 0){ if( a_http_client->in_content_length > 0){
...@@ -387,7 +386,6 @@ static void s_http_client_headers_read( dap_http_client_t *a_http_client, void * ...@@ -387,7 +386,6 @@ static void s_http_client_headers_read( dap_http_client_t *a_http_client, void *
log_it(L_ERROR, "Not defined content-length %u in request", a_http_client->in_content_length); log_it(L_ERROR, "Not defined content-length %u in request", a_http_client->in_content_length);
} else { } else {
log_it( L_DEBUG, "No data section, execution proc callback" ); log_it( L_DEBUG, "No data section, execution proc callback" );
a_http_client->_inheritor = NULL;
dap_events_socket_remove_from_worker_unsafe(l_http_simple->esocket ,l_http_simple->worker); dap_events_socket_remove_from_worker_unsafe(l_http_simple->esocket ,l_http_simple->worker);
dap_proc_queue_add_callback_inter( l_http_simple->worker->proc_queue_input, s_proc_queue_callback, l_http_simple); dap_proc_queue_add_callback_inter( l_http_simple->worker->proc_queue_input, s_proc_queue_callback, l_http_simple);
...@@ -455,8 +453,6 @@ void s_http_client_data_read( dap_http_client_t *a_http_client, void * a_arg ) ...@@ -455,8 +453,6 @@ void s_http_client_data_read( dap_http_client_t *a_http_client, void * a_arg )
// bool isOK=true; // bool isOK=true;
log_it( L_INFO,"Data for http_simple_request collected" ); log_it( L_INFO,"Data for http_simple_request collected" );
dap_events_socket_remove_from_worker_unsafe(a_http_client->esocket,a_http_client->esocket->worker); dap_events_socket_remove_from_worker_unsafe(a_http_client->esocket,a_http_client->esocket->worker);
a_http_client->_inheritor = NULL;
l_http_simple->http_client_uuid = a_http_client->esocket->uuid;
dap_proc_queue_add_callback_inter( l_http_simple->worker->proc_queue_input , s_proc_queue_callback, l_http_simple); dap_proc_queue_add_callback_inter( l_http_simple->worker->proc_queue_input , s_proc_queue_callback, l_http_simple);
} }
} }
......
...@@ -87,27 +87,38 @@ void dap_http_client_new( dap_events_socket_t *a_esocket, void *a_arg ) ...@@ -87,27 +87,38 @@ void dap_http_client_new( dap_events_socket_t *a_esocket, void *a_arg )
l_http_client->state_read = DAP_HTTP_CLIENT_STATE_START; l_http_client->state_read = DAP_HTTP_CLIENT_STATE_START;
l_http_client->state_write = DAP_HTTP_CLIENT_STATE_NONE; l_http_client->state_write = DAP_HTTP_CLIENT_STATE_NONE;
pthread_rwlock_rdlock(&l_http_client->http->url_proc->cache_rwlock); if(l_http_client->http && l_http_client->http->url_proc){
dap_http_cache_t * l_http_cache = l_http_client->http->url_proc->cache; // Check if present cache
if(l_http_cache){ pthread_rwlock_rdlock(&l_http_client->http->url_proc->cache_rwlock);
if ( ! l_http_cache->ts_expire || l_http_cache->ts_expire >= time(NULL) ){ dap_http_cache_t * l_http_cache = l_http_client->http->url_proc->cache;
l_http_client->out_headers = dap_http_headers_dup(l_http_cache->headers); if(l_http_cache){
l_http_client->out_content_length = l_http_cache->body_size; if ( ! l_http_cache->ts_expire || l_http_cache->ts_expire >= time(NULL) ){
l_http_client->reply_status_code = l_http_cache->response_code; l_http_client->out_headers = dap_http_headers_dup(l_http_cache->headers);
if(l_http_cache->response_phrase) l_http_client->out_content_length = l_http_cache->body_size;
strncpy(l_http_client->reply_reason_phrase,l_http_cache->response_phrase,sizeof (l_http_client->reply_reason_phrase)-1); l_http_client->reply_status_code = l_http_cache->response_code;
if(l_http_cache->response_phrase)
if(s_debug_http) strncpy(l_http_client->reply_reason_phrase,l_http_cache->response_phrase,sizeof (l_http_client->reply_reason_phrase)-1);
log_it(L_DEBUG,"%d Out: prepare cached headers", l_http_client->esocket->socket);
if(s_debug_http)
}else if (l_http_cache){ log_it(L_DEBUG,"%d Out: prepare cached headers", l_http_client->esocket->socket);
pthread_rwlock_unlock(&l_http_client->http->url_proc->cache_rwlock);
pthread_rwlock_wrlock(&l_http_client->http->url_proc->cache_rwlock); }else if (l_http_cache){
dap_http_cache_delete(l_http_cache); pthread_rwlock_unlock(&l_http_client->http->url_proc->cache_rwlock);
l_http_client->http->url_proc->cache = NULL; pthread_rwlock_wrlock(&l_http_client->http->url_proc->cache_rwlock);
dap_http_cache_delete(l_http_cache);
l_http_client->http->url_proc->cache = NULL;
l_http_cache == NULL;
}
} }
if (l_http_cache == NULL){
pthread_rwlock_unlock(&l_http_client->http->url_proc->cache_rwlock);
// Call client constructor if we're not in cache mode
if(l_http_client->http->url_proc->new_callback)
l_http_client->http->url_proc->new_callback(l_http_client, NULL);
}else
pthread_rwlock_unlock(&l_http_client->http->url_proc->cache_rwlock);
} }
pthread_rwlock_unlock(&l_http_client->http->url_proc->cache_rwlock);
return; return;
} }
...@@ -135,7 +146,6 @@ void dap_http_client_delete( dap_events_socket_t * a_esocket, void *a_arg ) ...@@ -135,7 +146,6 @@ void dap_http_client_delete( dap_events_socket_t * a_esocket, void *a_arg )
} }
} }
DAP_DEL_Z(l_http_client->_inheritor) DAP_DEL_Z(l_http_client->_inheritor)
} }
......
...@@ -72,7 +72,7 @@ void dap_http_deinit( ); // Deinit module ...@@ -72,7 +72,7 @@ void dap_http_deinit( ); // Deinit module
int dap_http_new( dap_server_t *a_server, const char *a_server_name ); // Create dap_http structure in the internal data field of dap_server_t instance int dap_http_new( dap_server_t *a_server, const char *a_server_name ); // Create dap_http structure in the internal data field of dap_server_t instance
void dap_http_delete( dap_server_t *a_server, void *a_arg ); // Clear dap_http structure in the internal data field of dap_server_t instance void dap_http_delete( dap_server_t *a_server, void *a_arg ); // Clear dap_http structure in the internal data field of dap_server_t instance
void dap_http_add_proc(dap_http_t *sh, const char *url_path, void *internal dap_http_url_proc_t * dap_http_add_proc(dap_http_t *sh, const char *url_path, void *internal
,dap_http_client_callback_t new_callback ,dap_http_client_callback_t new_callback
,dap_http_client_callback_t delete_callback ,dap_http_client_callback_t delete_callback
,dap_http_client_callback_t headers_read_callback ,dap_http_client_callback_t headers_read_callback
......
...@@ -65,7 +65,7 @@ typedef struct dap_http_simple { ...@@ -65,7 +65,7 @@ typedef struct dap_http_simple {
#define DAP_HTTP_SIMPLE(a) ((dap_http_simple_t*) (a)->_inheritor ) #define DAP_HTTP_SIMPLE(a) ((dap_http_simple_t*) (a)->_inheritor )
struct dap_http_simple_url_proc * dap_http_simple_proc_add( dap_http_t *sh, const char *url_path, size_t reply_size_max, dap_http_simple_callback_t cb ); // Add simple processor struct dap_http_url_proc * dap_http_simple_proc_add( dap_http_t *sh, const char *url_path, size_t reply_size_max, dap_http_simple_callback_t cb ); // Add simple processor
int dap_http_simple_module_init( void ); int dap_http_simple_module_init( void );
void dap_http_simple_module_deinit(void); void dap_http_simple_module_deinit(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment