source: protocols/jabber/jutil.c @ 22bf64e

Last change on this file since 22bf64e was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[b7d3cc34]1/* --------------------------------------------------------------------------
2 *
3 * License
4 *
5 * The contents of this file are subject to the Jabber Open Source License
6 * Version 1.0 (the "JOSL").  You may not copy or use this file, in either
7 * source code or executable form, except in compliance with the JOSL. You
8 * may obtain a copy of the JOSL at http://www.jabber.org/ or at
9 * http://www.opensource.org/. 
10 *
11 * Software distributed under the JOSL is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the JOSL
13 * for the specific language governing rights and limitations under the
14 * JOSL.
15 *
16 * Copyrights
17 *
18 * Portions created by or assigned to Jabber.com, Inc. are
19 * Copyright (c) 1999-2002 Jabber.com, Inc.  All Rights Reserved.  Contact
20 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
21 *
22 * Portions Copyright (c) 1998-1999 Jeremie Miller.
23 *
24 * Acknowledgements
25 *
26 * Special thanks to the Jabber Open Source Contributors for their
27 * suggestions and support of Jabber.
28 *
29 * Alternatively, the contents of this file may be used under the terms of the
30 * GNU General Public License Version 2 or later (the "GPL"), in which case
31 * the provisions of the GPL are applicable instead of those above.  If you
32 * wish to allow use of your version of this file only under the terms of the
33 * GPL and not to allow others to use your version of this file under the JOSL,
34 * indicate your decision by deleting the provisions above and replace them
35 * with the notice and other provisions required by the GPL.  If you do not
36 * delete the provisions above, a recipient may use your version of this file
37 * under either the JOSL or the GPL.
38 *
39 *
40 * --------------------------------------------------------------------------*/
41
42#include "jabber.h"
43#include <glib.h>
44#include "nogaim.h"
45
46/* util for making presence packets */
47xmlnode jutil_presnew(int type, char *to, char *status)
48{
49    xmlnode pres;
50
51    pres = xmlnode_new_tag("presence");
52    switch(type)
53    {
54    case JPACKET__SUBSCRIBE:
55        xmlnode_put_attrib(pres,"type","subscribe");
56        break;
57    case JPACKET__UNSUBSCRIBE:
58        xmlnode_put_attrib(pres,"type","unsubscribe");
59        break;
60    case JPACKET__SUBSCRIBED:
61        xmlnode_put_attrib(pres,"type","subscribed");
62        break;
63    case JPACKET__UNSUBSCRIBED:
64        xmlnode_put_attrib(pres,"type","unsubscribed");
65        break;
66    case JPACKET__PROBE:
67        xmlnode_put_attrib(pres,"type","probe");
68        break;
69    case JPACKET__UNAVAILABLE:
70        xmlnode_put_attrib(pres,"type","unavailable");
71        break;
72    case JPACKET__INVISIBLE:
73        xmlnode_put_attrib(pres,"type","invisible");
74        break;
75    }
76    if(to != NULL)
77        xmlnode_put_attrib(pres,"to",to);
78    if(status != NULL)
79        xmlnode_insert_cdata(xmlnode_insert_tag(pres,"status"),status,strlen(status));
80
81    return pres;
82}
83
84/* util for making IQ packets */
85xmlnode jutil_iqnew(int type, char *ns)
86{
87    xmlnode iq;
88
89    iq = xmlnode_new_tag("iq");
90    switch(type)
91    {
92    case JPACKET__GET:
93        xmlnode_put_attrib(iq,"type","get");
94        break;
95    case JPACKET__SET:
96        xmlnode_put_attrib(iq,"type","set");
97        break;
98    case JPACKET__RESULT:
99        xmlnode_put_attrib(iq,"type","result");
100        break;
101    case JPACKET__ERROR:
102        xmlnode_put_attrib(iq,"type","error");
103        break;
104    }
105    xmlnode_put_attrib(xmlnode_insert_tag(iq,"query"),"xmlns",ns);
106
107    return iq;
108}
109
110/* util for making stream packets */
111xmlnode jutil_header(char* xmlns, char* server)
112{
113     xmlnode result;
114     if ((xmlns == NULL)||(server == NULL))
115          return NULL;
116     result = xmlnode_new_tag("stream:stream");
117     xmlnode_put_attrib(result, "xmlns:stream", "http://etherx.jabber.org/streams");
118     xmlnode_put_attrib(result, "xmlns", xmlns);
119     xmlnode_put_attrib(result, "to", server);
120
121     return result;
122}
Note: See TracBrowser for help on using the repository browser.