root/cherokee/trunk/cherokee/admin_request.c

Revision 1131, 2.0 kB (checked in by alo, 7 months ago)

--

Line 
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4  *
5  * Authors:
6  *      Alvaro Lopez Ortega <alvaro@alobbs.com>
7  *
8  * Copyright (C) 2001-2008 Alvaro Lopez Ortega
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program 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
22  * USA
23  */
24
25 #include "common-internal.h"
26 #include "admin_request.h"
27 #include "list_ext.h"
28 #include "pickle.h"
29
30
31 struct cherokee_admin_request {
32         cherokee_buffer_t req;
33         int               num;
34         struct list_head  list;
35 };
36
37
38 ret_t cherokee_admin_request_new  (cherokee_admin_request_t **req)
39 {
40         CHEROKEE_NEW_STRUCT (n, admin_request);
41            
42         INIT_LIST_HEAD(&n->list);
43         cherokee_buffer_init (&n->req);
44         n->num = 0;
45            
46         *req = n;
47         return ret_ok;
48 }
49
50
51 ret_t
52 cherokee_admin_request_free (cherokee_admin_request_t *req)
53 {
54         cherokee_list_content_free (&req->list, free);
55         cherokee_buffer_mrproper (&req->req);
56
57         free (req);
58         return ret_ok;
59 }
60
61
62 ret_t
63 cherokee_admin_request_add (cherokee_admin_request_t *req, char *key)
64 {
65         cherokee_list_add_tail_content (&req->list, strdup(key));
66         req->num++;
67         return ret_ok;
68 }
69
70
71 ret_t
72 cherokee_admin_request_serialize (cherokee_admin_request_t *req)
73 {
74         list_t *i;
75
76         /* Add the number of elements
77          */
78         cherokee_pickle_add_uint (&req->req, req->num);
79
80         /* Add each string
81          */
82         list_for_each (i, &req->list) {
83                 char *str = (char *)LIST_ITEM_INFO(i);
84                 cherokee_pickle_add_string (&req->req, str, strlen(str));
85         }
86
87         /* Clean the list
88          */
89         cherokee_list_content_free (&req->list, free);     
90         return ret_ok;
91 }
92
Note: See TracBrowser for help on using the browser.