http_async_client: add parameters to enable/set tcp keepalive
[sip-router] / src / modules / http_async_client / hm_hash.h
1 /**
2  * Copyright 2016 (C) Federico Cabiddu <federico.cabiddu@gmail.com>
3  * Copyright 2016 (C) Giacomo Vacca <giacomo.vacca@gmail.com>
4  * Copyright 2016 (C) Orange - Camille Oudot <camille.oudot@orange.com>
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * This file is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  *
14  * This file is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  */
24
25 /*! \file
26  * \brief  Kamailio http_async_client :: Hash functions
27  * \ingroup http_async_client
28  */
29
30
31 #ifndef _HM_HASH_
32 #define _HM_HASH_
33
34 #include <curl/curl.h>
35 #include "../../core/dprint.h"
36 #include "../../core/mem/mem.h"
37 #include "../../core/ut.h"
38 #include "../../core/hashes.h"
39
40 extern struct http_m_table *hm_table;
41
42 typedef struct http_m_reply
43 {
44         long retcode;
45         str *result;
46         char error[CURL_ERROR_SIZE];
47 } http_m_reply_t;
48
49 typedef void (*http_multi_cbe_t)(struct http_m_reply *reply, void *param);
50
51 typedef struct http_m_request
52 {
53         http_multi_cbe_t cb;
54         char *url;
55         str *result;
56         void *param;
57 } http_m_request_t;
58
59 typedef struct http_m_global
60 {
61         struct event_base *evbase;
62         struct event *timer_event;
63         CURLM *multi;
64         int still_running;
65 } http_m_global_t;
66
67 typedef struct hm_params {
68         int timeout;
69         int tls_verify_host;
70         int tls_verify_peer;
71         struct curl_slist* headers;
72         int method;
73         char* tls_client_cert;
74         char* tls_client_key;
75         char* tls_ca_path;
76         str body;
77         
78         unsigned int authmethod;
79         char* username;
80         char* password;
81         int tcp_keepalive;
82         int tcp_ka_idle;
83         int tcp_ka_interval;
84 } http_m_params_t;
85
86 typedef struct http_m_cell
87 {
88         struct http_m_cell      *next;
89         struct http_m_cell      *prev;
90         //unsigned int          hmt_id;
91         unsigned int            hmt_entry;
92
93         struct http_m_global *global;
94
95         CURL *easy;
96         curl_socket_t sockfd;
97         int action;
98         http_m_params_t params;
99
100         struct event *ev;
101         int evset;
102
103         char *url;
104         char error[CURL_ERROR_SIZE];
105
106         http_multi_cbe_t cb;
107         void *param;
108
109         struct http_m_reply *reply;
110 } http_m_cell_t;
111
112 typedef struct http_m_entry
113 {
114         struct http_m_cell      *first;
115         struct http_m_cell      *last;
116 } http_m_entry_t;
117
118 /*! main http multi table */
119 typedef struct http_m_table
120 {
121         unsigned int            size;
122         struct http_m_entry     *entries;
123 } http_m_table_t;
124
125 int init_http_m_table(unsigned int size);
126 struct http_m_cell* build_http_m_cell(void *p);
127 void link_http_m_cell(struct http_m_cell *cell);
128 struct http_m_cell *http_m_cell_lookup(CURL *p);
129 void free_http_m_cell(struct http_m_cell *cell);
130
131 static inline void unlink_http_m_cell(struct http_m_cell *hmt_cell)
132 {
133         struct http_m_entry     *hmt_entry;
134
135         if (hmt_cell) {
136                 hmt_entry = &(hm_table->entries[hmt_cell->hmt_entry]);
137                 if (hmt_cell->next)
138                         hmt_cell->next->prev = hmt_cell->prev;
139                 else
140                         hmt_entry->last = hmt_cell->prev;
141                 if (hmt_cell->prev)
142                         hmt_cell->prev->next = hmt_cell->next;
143                 else
144                         hmt_entry->first = hmt_cell->next;
145
146                 hmt_cell->next = hmt_cell->prev = 0;
147         }
148         return;
149 }
150 #endif