~ubuntu-branches/ubuntu/vivid/keepalived/vivid

« back to all changes in this revision

Viewing changes to genhash/http.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2011-10-25 16:10:58 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20111025161058-bgqn5elt0xo1tq0a
Tags: 1:1.2.2-1ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - debian/rules: DEB_UPDATE_RCD_PARAMS := explicit init start/stop
    parameters (don't stop at 0 and 6)
  - debian/init.d: init script header adapted to stop rule
  - debian/keepalived.postinst: Remove shutdown and reboot links
* Build with libnl3, thanks to a patch from Marc - A. Dahlhaus.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *              as published by the Free Software Foundation; either version
20
20
 *              2 of the License, or (at your option) any later version.
21
21
 *
22
 
 * Copyright (C) 2001-2009 Alexandre Cassen, <acassen@freebox.fr>
 
22
 * Copyright (C) 2001-2011 Alexandre Cassen, <acassen@linux-vs.org>
23
23
 */
24
24
 
25
25
#include <errno.h>
56
56
 
57
57
/* free allocated pieces */
58
58
static void
59
 
free_all(thread * thread_obj)
 
59
free_all(thread_t * thread)
60
60
{
61
 
        SOCK *sock_obj = THREAD_ARG(thread_obj);
 
61
        SOCK *sock_obj = THREAD_ARG(thread);
62
62
 
63
63
        DBG("Total read size read = %d Bytes, fd:%d\n",
64
64
            sock_obj->total_size, sock_obj->fd);
71
71
         * => free the reserved thread
72
72
         */
73
73
        req->response_time = timer_tol(timer_now());
74
 
        thread_add_terminate_event(thread_obj->master);
 
74
        thread_add_terminate_event(thread->master);
75
75
}
76
76
 
77
77
/* Simple epilog functions. */
78
78
int
79
 
epilog(thread * thread_obj)
 
79
epilog(thread_t * thread)
80
80
{
81
81
        DBG("Timeout on URL : [%s]\n", req->url);
82
 
        free_all(thread_obj);
 
82
        free_all(thread);
83
83
        return 0;
84
84
}
85
85
 
86
86
/* Simple finalization function */
87
87
int
88
 
finalize(thread * thread_obj)
 
88
finalize(thread_t * thread)
89
89
{
90
 
        SOCK *sock_obj = THREAD_ARG(thread_obj);
 
90
        SOCK *sock_obj = THREAD_ARG(thread);
91
91
        unsigned char digest[16];
92
92
        int i;
93
93
 
106
106
        printf("\n\n");
107
107
 
108
108
        DBG("Finalize : [%s]\n", req->url);
109
 
        free_all(thread_obj);
 
109
        free_all(thread);
110
110
        return 0;
111
111
}
112
112
 
171
171
 
172
172
/* Asynchronous HTTP stream reader */
173
173
int
174
 
http_read_thread(thread * thread_obj)
 
174
http_read_thread(thread_t * thread)
175
175
{
176
 
        SOCK *sock_obj = THREAD_ARG(thread_obj);
 
176
        SOCK *sock_obj = THREAD_ARG(thread);
177
177
        int r = 0;
178
178
 
179
179
        /* Handle read timeout */
180
 
        if (thread_obj->type == THREAD_READ_TIMEOUT)
181
 
                return epilog(thread_obj);
 
180
        if (thread->type == THREAD_READ_TIMEOUT)
 
181
                return epilog(thread);
182
182
 
183
183
        /* read the HTTP stream */
184
184
        memset(sock_obj->buffer, 0, MAX_BUFFER_LENGTH);
185
 
        r = read(thread_obj->u.fd, sock_obj->buffer + sock_obj->size,
 
185
        r = read(thread->u.fd, sock_obj->buffer + sock_obj->size,
186
186
                 MAX_BUFFER_LENGTH - sock_obj->size);
187
187
 
188
188
        DBG(" [l:%d,fd:%d]\n", r, sock_obj->fd);
193
193
                        DBG("Read error with server [%s:%d]: %s\n",
194
194
                            inet_ntop2(req->addr_ip), ntohs(req->addr_port),
195
195
                            strerror(errno));
196
 
                        return epilog(thread_obj);
 
196
                        return epilog(thread);
197
197
                }
198
198
 
199
199
                /* All the HTTP stream has been parsed */
200
 
                finalize(thread_obj);
 
200
                finalize(thread);
201
201
        } else {
202
202
                /* Handle the response stream */
203
203
                http_process_stream(sock_obj, r);
206
206
                 * Register next http stream reader.
207
207
                 * Register itself to not perturbe global I/O multiplexer.
208
208
                 */
209
 
                thread_add_read(thread_obj->master, http_read_thread, sock_obj,
210
 
                                thread_obj->u.fd, HTTP_CNX_TIMEOUT);
 
209
                thread_add_read(thread->master, http_read_thread, sock_obj,
 
210
                                thread->u.fd, HTTP_CNX_TIMEOUT);
211
211
        }
212
212
 
213
213
        return 0;
218
218
 * Apply trigger check to this result.
219
219
 */
220
220
int
221
 
http_response_thread(thread * thread_obj)
 
221
http_response_thread(thread_t * thread)
222
222
{
223
 
        SOCK *sock_obj = THREAD_ARG(thread_obj);
 
223
        SOCK *sock_obj = THREAD_ARG(thread);
224
224
 
225
225
        /* Handle read timeout */
226
 
        if (thread_obj->type == THREAD_READ_TIMEOUT)
227
 
                return epilog(thread_obj);
 
226
        if (thread->type == THREAD_READ_TIMEOUT)
 
227
                return epilog(thread);
228
228
 
229
229
        /* Allocate & clean the get buffer */
230
230
        sock_obj->buffer = (char *) MALLOC(MAX_BUFFER_LENGTH);
234
234
 
235
235
        /* Register asynchronous http/ssl read thread */
236
236
        if (req->ssl)
237
 
                thread_add_read(thread_obj->master, ssl_read_thread, sock_obj,
238
 
                                thread_obj->u.fd, HTTP_CNX_TIMEOUT);
 
237
                thread_add_read(thread->master, ssl_read_thread, sock_obj,
 
238
                                thread->u.fd, HTTP_CNX_TIMEOUT);
239
239
        else
240
 
                thread_add_read(thread_obj->master, http_read_thread, sock_obj,
241
 
                                thread_obj->u.fd, HTTP_CNX_TIMEOUT);
 
240
                thread_add_read(thread->master, http_read_thread, sock_obj,
 
241
                                thread->u.fd, HTTP_CNX_TIMEOUT);
242
242
        return 0;
243
243
}
244
244
 
245
245
/* remote Web server is connected, send it the get url query.  */
246
246
int
247
 
http_request_thread(thread * thread_obj)
 
247
http_request_thread(thread_t * thread)
248
248
{
249
 
        SOCK *sock_obj = THREAD_ARG(thread_obj);
 
249
        SOCK *sock_obj = THREAD_ARG(thread);
250
250
        char *str_request;
251
251
        int ret = 0;
252
252
 
253
253
        /* Handle read timeout */
254
 
        if (thread_obj->type == THREAD_WRITE_TIMEOUT)
255
 
                return epilog(thread_obj);
 
254
        if (thread->type == THREAD_WRITE_TIMEOUT)
 
255
                return epilog(thread);
256
256
 
257
257
        /* Allocate & clean the GET string */
258
258
        str_request = (char *) MALLOC(GET_BUFFER_LENGTH);
279
279
                fprintf(stderr, "Cannot send get request to [%s:%d].\n",
280
280
                        inet_ntop2(req->addr_ip)
281
281
                        , ntohs(req->addr_port));
282
 
                return epilog(thread_obj);
 
282
                return epilog(thread);
283
283
        }
284
284
 
285
285
        /* Register read timeouted thread */
286
 
        thread_add_read(thread_obj->master, http_response_thread, sock_obj,
 
286
        thread_add_read(thread->master, http_response_thread, sock_obj,
287
287
                        sock_obj->fd, HTTP_CNX_TIMEOUT);
288
288
        return 1;
289
289
}