2 * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
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.
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.
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.
20 #include <atompub/content.h>
21 #include <atompub/content-xml.h>
24 #include <libxml/tree.h>
33 xmlNodePtr xmlcontent;
37 atom_content_new (char *type, char *buffer, size_t len)
40 content = g_slice_new0 (AtomContent);
41 content->type = g_strdup (type);
42 content->content = g_malloc (len);
43 memcpy (content->content, buffer, len);
44 content->content_len = len;
49 atom_content_new_src (char *type, char *src)
52 content = g_slice_new0 (AtomContent);
53 content->type = g_strdup (type);
54 content->src = g_strdup (src);
59 atom_content_new_data_len (char *buffer, size_t len)
61 /* TODO: Here we decode the XML to find content type, possible
67 atom_content_delete (AtomContent *content)
70 g_free (content->type);
72 g_free (content->src);
74 g_free (content->content);
75 if (content->xmlcontent)
76 xmlFreeNode (content->xmlcontent);
77 g_slice_free (AtomContent, content);
81 atom_content_type (AtomContent *content)
87 atom_content_type_set (AtomContent *content, char *type)
90 g_free (content->type);
91 content->type = g_strdup (type);
95 atom_content_src (AtomContent *content)
101 atom_content_src_set (AtomContent *content, char *src)
104 g_free (content->src);
105 content->src = g_strdup (src);
109 atom_content_content (AtomContent *content, char **buffer, size_t *len)
111 /* TODO: Copy the content or allocated the buffer? */
115 atom_content_content_set (AtomContent *content, char *buffer, size_t len)
117 if (content->content)
118 g_free (content->content);
119 content->content = g_malloc (len);
120 memcpy (content->content, buffer, len);
124 atom_content_string (AtomContent *content, char **buffer, size_t *len)
126 /* TODO: convert everything into a string, like
127 "<content type="html"><br></content>" */
131 atom_content_new_xmlnode (char *type, xmlNodePtr node)
133 AtomContent *content;
134 content = g_slice_new0 (AtomContent);
135 content->type = g_strdup (type);
136 content->xmlcontent = xmlCopyNodeList (node);
141 atom_content_to_xmlnode (AtomContent *content)
143 /* TODO: Convert everything into a xmlnode */
148 atom_content_content_xmlnode (AtomContent *content)
150 return content->xmlcontent;
154 atom_content_content_set_xmlnode (AtomContent *content, xmlNodePtr node)
156 if (content->xmlcontent)
157 xmlFreeNode (content->xmlcontent);
158 content->xmlcontent = xmlCopyNodeList (node);