Added content data to request
[cascardo/atompub.git] / atom / request.c
1 /*
2  *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19
20 #include <atompub/atom.h>
21
22 #include <glib.h>
23
24 #include <string.h>
25
26 struct _atom_request
27 {
28   int type;
29   char *request;
30   char *content;
31   size_t content_len;
32 };
33
34 AtomRequest *
35 atom_request_new (int type, char *request)
36 {
37   AtomRequest *req;
38   req = g_slice_new (AtomRequest);
39   req->type = type;
40   req->request = g_strdup (request);
41   req->content = NULL;
42   req->content_len = 0;
43   return req;
44 }
45
46 void
47 atom_request_delete (AtomRequest *req)
48 {
49   if (req->request)
50     g_free (req->request);
51   if (req->content)
52     g_free (req->content);
53   g_slice_free (AtomRequest, req);
54 }
55
56 int
57 atom_request_type (AtomRequest *req)
58 {
59   return req->type;
60 }
61
62 char *
63 atom_request_request (AtomRequest *req)
64 {
65   return req->request;
66 }
67
68 void
69 atom_request_content_set (AtomRequest *req, char *content, size_t len)
70 {
71   if (req->content)
72     g_free (req->content);
73   req->content = g_malloc (len);
74   memcpy (req->content, content, len);
75   req->content_len = len;
76 }
77
78 void
79 atom_request_content (AtomRequest *req, char **content, size_t *len)
80 {
81   if (content)
82     *content = req->content;
83   if (len)
84     *len = req->content_len;
85 }