1 /*
2  * purple - Jabber Service Discovery
3  *
4  * Purple is the legal property of its developers, whose names are too numerous
5  * to list here.  Please refer to the COPYRIGHT file distributed with this
6  * source distribution.
7  *
8  * This program 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  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
21  *
22  */
23 
24 #ifndef PURPLE_JABBER_DATA_H
25 #define PURPLE_JABBER_DATA_H
26 
27 #include "xmlnode.h"
28 #include "jabber.h"
29 
30 #include <glib.h>
31 
32 #define JABBER_DATA_MAX_SIZE 8192
33 
34 
35 typedef struct {
36 	char *cid;
37 	char *type;
38 	gsize size;
39 	gpointer data;
40 	gboolean ephemeral;
41 } JabberData;
42 
43 typedef void (JabberDataRequestCallback)(JabberData *data, gchar *alt,
44     gpointer userdata);
45 
46 
47 /* creates a JabberData instance from raw data */
48 JabberData *jabber_data_create_from_data(gconstpointer data, gsize size,
49 	const char *type, gboolean ephemeral, JabberStream *js);
50 
51 /* create a JabberData instance from an XML "data" element (as defined by
52   XEP 0231 */
53 JabberData *jabber_data_create_from_xml(xmlnode *tag);
54 
55 /* destroy a JabberData instance, NOT to be used on data that has been
56 	associated, since they get "owned" */
57 void jabber_data_destroy(JabberData *data);
58 
59 const char *jabber_data_get_cid(const JabberData *data);
60 const char *jabber_data_get_type(const JabberData *data);
61 
62 gsize jabber_data_get_size(const JabberData *data);
63 gpointer jabber_data_get_data(const JabberData *data);
64 
65 /* returns the XML definition for the data element */
66 xmlnode *jabber_data_get_xml_definition(const JabberData *data);
67 
68 /* returns an XHTML-IM "img" tag given a data instance */
69 xmlnode *jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt);
70 
71 void jabber_data_request(JabberStream *js, const gchar *cid, const gchar *who,
72     gchar *alt, gboolean ephemeral, JabberDataRequestCallback cb,
73     gpointer userdata);
74 
75 /* lookup functions */
76 const JabberData *jabber_data_find_local_by_alt(const gchar *alt);
77 const JabberData *jabber_data_find_local_by_cid(const gchar *cid);
78 const JabberData *jabber_data_find_remote_by_cid(JabberStream *js,
79     const gchar *who, const gchar *cid);
80 
81 /* store data objects */
82 void jabber_data_associate_local(JabberData *data, const gchar *alt);
83 void jabber_data_associate_remote(JabberStream *js, const gchar *who,
84     JabberData *data);
85 
86 /* handles iq requests */
87 void jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
88                        const char *id, xmlnode *data_node);
89 
90 void jabber_data_init(void);
91 void jabber_data_uninit(void);
92 
93 #endif /* PURPLE_JABBER_DATA_H */
94