1 /* strophe.h
2 ** strophe XMPP client library C API
3 **
4 ** Copyright (C) 2005-2009 Collecta, Inc.
5 **
6 **  This software is provided AS-IS with no warranty, either express or
7 **  implied.
8 **
9 **  This software is dual licensed under the MIT and GPLv3 licenses.
10 */
11 
12 /** @file
13  *  Strophe public C API definitions.
14  */
15 
16 #ifndef __LIBSTROPHE_STROPHE_H__
17 #define __LIBSTROPHE_STROPHE_H__
18 
19 #include <stddef.h> /* size_t */
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /* namespace defines */
26 /** @def XMPP_NS_CLIENT
27  *  Namespace definition for 'jabber:client'.
28  */
29 #define XMPP_NS_CLIENT "jabber:client"
30 /** @def XMPP_NS_COMPONENT
31  *  Namespace definition for 'jabber:component:accept'.
32  */
33 #define XMPP_NS_COMPONENT "jabber:component:accept"
34 /** @def XMPP_NS_STREAMS
35  *  Namespace definition for 'http://etherx.jabber.org/streams'.
36  */
37 #define XMPP_NS_STREAMS "http://etherx.jabber.org/streams"
38 /** @def XMPP_NS_STREAMS_IETF
39  *  Namespace definition for 'urn:ietf:params:xml:ns:xmpp-streams'.
40  */
41 #define XMPP_NS_STREAMS_IETF "urn:ietf:params:xml:ns:xmpp-streams"
42 /** @def XMPP_NS_STANZAS_IETF
43  *  Namespace definition for 'urn:ietf:params:xml:ns:xmpp-stanzas'.
44  */
45 #define XMPP_NS_STANZAS_IETF "urn:ietf:params:xml:ns:xmpp-stanzas"
46 /** @def XMPP_NS_TLS
47  *  Namespace definition for 'url:ietf:params:xml:ns:xmpp-tls'.
48  */
49 #define XMPP_NS_TLS "urn:ietf:params:xml:ns:xmpp-tls"
50 /** @def XMPP_NS_SASL
51  *  Namespace definition for 'urn:ietf:params:xml:ns:xmpp-sasl'.
52  */
53 #define XMPP_NS_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
54 /** @def XMPP_NS_BIND
55  *  Namespace definition for 'urn:ietf:params:xml:ns:xmpp-bind'.
56  */
57 #define XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
58 /** @def XMPP_NS_SESSION
59  *  Namespace definition for 'urn:ietf:params:xml:ns:xmpp-session'.
60  */
61 #define XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
62 /** @def XMPP_NS_AUTH
63  *  Namespace definition for 'jabber:iq:auth'.
64  */
65 #define XMPP_NS_AUTH "jabber:iq:auth"
66 /** @def XMPP_NS_DISCO_INFO
67  *  Namespace definition for 'http://jabber.org/protocol/disco#info'.
68  */
69 #define XMPP_NS_DISCO_INFO "http://jabber.org/protocol/disco#info"
70 /** @def XMPP_NS_DISCO_ITEMS
71  *  Namespace definition for 'http://jabber.org/protocol/disco#items'.
72  */
73 #define XMPP_NS_DISCO_ITEMS "http://jabber.org/protocol/disco#items"
74 /** @def XMPP_NS_ROSTER
75  *  Namespace definition for 'jabber:iq:roster'.
76  */
77 #define XMPP_NS_ROSTER "jabber:iq:roster"
78 /** @def XMPP_NS_REGISTER
79  *  Namespace definition for 'jabber:iq:register'.
80  */
81 #define XMPP_NS_REGISTER "jabber:iq:register"
82 
83 /* error defines */
84 /** @def XMPP_EOK
85  *  Success error code.
86  */
87 #define XMPP_EOK 0
88 /** @def XMPP_EMEM
89  *  Memory related failure error code.
90  *
91  *  This is returned on allocation errors and signals that the host may
92  *  be out of memory.
93  */
94 #define XMPP_EMEM -1
95 /** @def XMPP_EINVOP
96  *  Invalid operation error code.
97  *
98  *  This error code is returned when the operation was invalid and signals
99  *  that the Strophe API is being used incorrectly.
100  */
101 #define XMPP_EINVOP -2
102 /** @def XMPP_EINT
103  *  Internal failure error code.
104  */
105 #define XMPP_EINT -3
106 
107 /* initialization and shutdown */
108 void xmpp_initialize(void);
109 void xmpp_shutdown(void);
110 
111 /* version */
112 int xmpp_version_check(int major, int minor);
113 
114 /* run-time contexts */
115 
116 /* user-replaceable memory allocator */
117 typedef struct _xmpp_mem_t xmpp_mem_t;
118 
119 /* user-replaceable log object */
120 typedef struct _xmpp_log_t xmpp_log_t;
121 
122 /* opaque run time context containing the above hooks */
123 typedef struct _xmpp_ctx_t xmpp_ctx_t;
124 
125 typedef struct _xmpp_tlscert_t xmpp_tlscert_t;
126 
127 xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *mem, const xmpp_log_t *log);
128 void xmpp_ctx_free(xmpp_ctx_t *ctx);
129 
130 /* set the verbosity level of the ctx */
131 void xmpp_ctx_set_verbosity(xmpp_ctx_t *ctx, int level);
132 
133 /* free some blocks returned by other APIs, for example the
134    buffer you get from xmpp_stanza_to_text */
135 void xmpp_free(const xmpp_ctx_t *ctx, void *p);
136 
137 struct _xmpp_mem_t {
138     void *(*alloc)(size_t size, void *userdata);
139     void (*free)(void *p, void *userdata);
140     void *(*realloc)(void *p, size_t size, void *userdata);
141     void *userdata;
142 };
143 
144 typedef enum {
145     XMPP_LEVEL_DEBUG,
146     XMPP_LEVEL_INFO,
147     XMPP_LEVEL_WARN,
148     XMPP_LEVEL_ERROR
149 } xmpp_log_level_t;
150 
151 typedef enum { XMPP_UNKNOWN, XMPP_CLIENT, XMPP_COMPONENT } xmpp_conn_type_t;
152 
153 typedef void (*xmpp_log_handler)(void *userdata,
154                                  xmpp_log_level_t level,
155                                  const char *area,
156                                  const char *msg);
157 
158 struct _xmpp_log_t {
159     xmpp_log_handler handler;
160     void *userdata;
161 };
162 
163 /* return a default logger filtering at a given level */
164 xmpp_log_t *xmpp_get_default_logger(xmpp_log_level_t level);
165 
166 /* connection */
167 
168 /* opaque connection object */
169 typedef struct _xmpp_conn_t xmpp_conn_t;
170 typedef struct _xmpp_stanza_t xmpp_stanza_t;
171 
172 /* connection flags */
173 #define XMPP_CONN_FLAG_DISABLE_TLS (1UL << 0)
174 #define XMPP_CONN_FLAG_MANDATORY_TLS (1UL << 1)
175 #define XMPP_CONN_FLAG_LEGACY_SSL (1UL << 2)
176 /** @def XMPP_CONN_FLAG_TRUST_TLS
177  *  Trust server's certificate even if it is invalid.
178  */
179 #define XMPP_CONN_FLAG_TRUST_TLS (1UL << 3)
180 /** @def XMPP_CONN_FLAG_LEGACY_AUTH
181  *  Enable legacy authentication support.
182  */
183 #define XMPP_CONN_FLAG_LEGACY_AUTH (1UL << 4)
184 
185 /* connect callback */
186 typedef enum {
187     XMPP_CONN_CONNECT,
188     XMPP_CONN_RAW_CONNECT,
189     XMPP_CONN_DISCONNECT,
190     XMPP_CONN_FAIL
191 } xmpp_conn_event_t;
192 
193 typedef enum {
194     XMPP_SE_BAD_FORMAT,
195     XMPP_SE_BAD_NS_PREFIX,
196     XMPP_SE_CONFLICT,
197     XMPP_SE_CONN_TIMEOUT,
198     XMPP_SE_HOST_GONE,
199     XMPP_SE_HOST_UNKNOWN,
200     XMPP_SE_IMPROPER_ADDR,
201     XMPP_SE_INTERNAL_SERVER_ERROR,
202     XMPP_SE_INVALID_FROM,
203     XMPP_SE_INVALID_ID,
204     XMPP_SE_INVALID_NS,
205     XMPP_SE_INVALID_XML,
206     XMPP_SE_NOT_AUTHORIZED,
207     XMPP_SE_POLICY_VIOLATION,
208     XMPP_SE_REMOTE_CONN_FAILED,
209     XMPP_SE_RESOURCE_CONSTRAINT,
210     XMPP_SE_RESTRICTED_XML,
211     XMPP_SE_SEE_OTHER_HOST,
212     XMPP_SE_SYSTEM_SHUTDOWN,
213     XMPP_SE_UNDEFINED_CONDITION,
214     XMPP_SE_UNSUPPORTED_ENCODING,
215     XMPP_SE_UNSUPPORTED_STANZA_TYPE,
216     XMPP_SE_UNSUPPORTED_VERSION,
217     XMPP_SE_XML_NOT_WELL_FORMED
218 } xmpp_error_type_t;
219 
220 /** Certificate Elements
221  *
222  *  @ingroup TLS
223  */
224 typedef enum {
225     XMPP_CERT_VERSION,            /**< X.509 Version */
226     XMPP_CERT_SERIALNUMBER,       /**< SerialNumber */
227     XMPP_CERT_SUBJECT,            /**< Subject */
228     XMPP_CERT_ISSUER,             /**< Issuer */
229     XMPP_CERT_NOTBEFORE,          /**< Issued on */
230     XMPP_CERT_NOTAFTER,           /**< Expires on */
231     XMPP_CERT_KEYALG,             /**< Public Key Algorithm */
232     XMPP_CERT_SIGALG,             /**< Certificate Signature Algorithm */
233     XMPP_CERT_FINGERPRINT_SHA1,   /**< Fingerprint SHA-1 */
234     XMPP_CERT_FINGERPRINT_SHA256, /**< Fingerprint SHA-256 */
235     XMPP_CERT_ELEMENT_MAX         /**< Last element of the enum */
236 } xmpp_cert_element_t;
237 
238 typedef struct {
239     xmpp_error_type_t type;
240     char *text;
241     xmpp_stanza_t *stanza;
242 } xmpp_stream_error_t;
243 
244 typedef void (*xmpp_conn_handler)(xmpp_conn_t *conn,
245                                   xmpp_conn_event_t event,
246                                   int error,
247                                   xmpp_stream_error_t *stream_error,
248                                   void *userdata);
249 
250 /** The Handler function which will be called when the TLS stack can't
251  *  verify the authenticity of a Certificate that gets presented by
252  *  the server we're trying to connect to.
253  *
254  *  When this function is called and details of the `cert` have to be
255  *  kept, please copy them yourself. The `cert` object will be free'd
256  *  automatically when this function returns.
257  *
258  *  NB: `errormsg` is specific per certificate on OpenSSL and the same
259  *      for all certificates on GnuTLS.
260  *
261  *  @param cert a Strophe certificate object
262  *  @param errormsg The error that caused this.
263  *
264  *  @return 0 if the connection attempt should be terminated,
265  *          1 if the connection should be established.
266  *
267  *  @ingroup TLS
268  */
269 typedef int (*xmpp_certfail_handler)(const xmpp_tlscert_t *cert,
270                                      const char *const errormsg);
271 
272 void xmpp_send_error(xmpp_conn_t *conn, xmpp_error_type_t type, char *text);
273 xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx);
274 xmpp_conn_t *xmpp_conn_clone(xmpp_conn_t *conn);
275 int xmpp_conn_release(xmpp_conn_t *conn);
276 
277 long xmpp_conn_get_flags(const xmpp_conn_t *conn);
278 int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags);
279 const char *xmpp_conn_get_jid(const xmpp_conn_t *conn);
280 const char *xmpp_conn_get_bound_jid(const xmpp_conn_t *conn);
281 void xmpp_conn_set_jid(xmpp_conn_t *conn, const char *jid);
282 void xmpp_conn_set_cafile(xmpp_conn_t *const conn, const char *path);
283 void xmpp_conn_set_capath(xmpp_conn_t *const conn, const char *path);
284 void xmpp_conn_set_certfail_handler(xmpp_conn_t *const conn,
285                                     xmpp_certfail_handler hndl);
286 xmpp_tlscert_t *xmpp_conn_get_peer_cert(xmpp_conn_t *const conn);
287 void xmpp_conn_set_client_cert(xmpp_conn_t *conn,
288                                const char *cert,
289                                const char *key);
290 unsigned int xmpp_conn_cert_xmppaddr_num(xmpp_conn_t *conn);
291 char *xmpp_conn_cert_xmppaddr(xmpp_conn_t *conn, unsigned int n);
292 const char *xmpp_conn_get_pass(const xmpp_conn_t *conn);
293 void xmpp_conn_set_pass(xmpp_conn_t *conn, const char *pass);
294 xmpp_ctx_t *xmpp_conn_get_context(xmpp_conn_t *conn);
295 void xmpp_conn_disable_tls(xmpp_conn_t *conn);
296 int xmpp_conn_is_secured(xmpp_conn_t *conn);
297 void xmpp_conn_set_keepalive(xmpp_conn_t *conn, int timeout, int interval);
298 int xmpp_conn_is_connecting(xmpp_conn_t *conn);
299 int xmpp_conn_is_connected(xmpp_conn_t *conn);
300 int xmpp_conn_is_disconnected(xmpp_conn_t *conn);
301 
302 int xmpp_connect_client(xmpp_conn_t *conn,
303                         const char *altdomain,
304                         unsigned short altport,
305                         xmpp_conn_handler callback,
306                         void *userdata);
307 
308 int xmpp_connect_component(xmpp_conn_t *conn,
309                            const char *server,
310                            unsigned short port,
311                            xmpp_conn_handler callback,
312                            void *userdata);
313 
314 int xmpp_connect_raw(xmpp_conn_t *conn,
315                      const char *altdomain,
316                      unsigned short altport,
317                      xmpp_conn_handler callback,
318                      void *userdata);
319 int xmpp_conn_open_stream_default(xmpp_conn_t *conn);
320 int xmpp_conn_open_stream(xmpp_conn_t *conn,
321                           char **attributes,
322                           size_t attributes_len);
323 int xmpp_conn_tls_start(xmpp_conn_t *conn);
324 
325 void xmpp_disconnect(xmpp_conn_t *conn);
326 
327 void xmpp_send(xmpp_conn_t *conn, xmpp_stanza_t *stanza);
328 
329 void xmpp_send_raw_string(xmpp_conn_t *conn, const char *fmt, ...);
330 void xmpp_send_raw(xmpp_conn_t *conn, const char *data, size_t len);
331 
332 /* handlers */
333 
334 /* if the handler returns false it is removed */
335 typedef int (*xmpp_timed_handler)(xmpp_conn_t *conn, void *userdata);
336 
337 void xmpp_timed_handler_add(xmpp_conn_t *conn,
338                             xmpp_timed_handler handler,
339                             unsigned long period,
340                             void *userdata);
341 void xmpp_timed_handler_delete(xmpp_conn_t *conn, xmpp_timed_handler handler);
342 
343 /* if the handler returns false it is removed */
344 typedef int (*xmpp_global_timed_handler)(xmpp_ctx_t *ctx, void *userdata);
345 
346 void xmpp_global_timed_handler_add(xmpp_ctx_t *ctx,
347                                    xmpp_global_timed_handler handler,
348                                    unsigned long period,
349                                    void *userdata);
350 void xmpp_global_timed_handler_delete(xmpp_ctx_t *ctx,
351                                       xmpp_global_timed_handler handler);
352 
353 /* if the handler returns false it is removed */
354 typedef int (*xmpp_handler)(xmpp_conn_t *conn,
355                             xmpp_stanza_t *stanza,
356                             void *userdata);
357 
358 void xmpp_handler_add(xmpp_conn_t *conn,
359                       xmpp_handler handler,
360                       const char *ns,
361                       const char *name,
362                       const char *type,
363                       void *userdata);
364 void xmpp_handler_delete(xmpp_conn_t *conn, xmpp_handler handler);
365 
366 void xmpp_id_handler_add(xmpp_conn_t *conn,
367                          xmpp_handler handler,
368                          const char *id,
369                          void *userdata);
370 void xmpp_id_handler_delete(xmpp_conn_t *conn,
371                             xmpp_handler handler,
372                             const char *id);
373 
374 /*
375 void xmpp_register_stanza_handler(conn, stanza, xmlns, type, handler)
376 */
377 
378 /* stanzas */
379 
380 /* allocate and initialize a blank stanza */
381 xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx);
382 xmpp_stanza_t *xmpp_stanza_new_from_string(xmpp_ctx_t *ctx, const char *str);
383 
384 /* clone a stanza */
385 xmpp_stanza_t *xmpp_stanza_clone(xmpp_stanza_t *stanza);
386 
387 /* copies a stanza and all children */
388 xmpp_stanza_t *xmpp_stanza_copy(const xmpp_stanza_t *stanza);
389 
390 /* free a stanza object and it's contents */
391 int xmpp_stanza_release(xmpp_stanza_t *stanza);
392 
393 xmpp_ctx_t *xmpp_stanza_get_context(const xmpp_stanza_t *stanza);
394 
395 int xmpp_stanza_is_text(xmpp_stanza_t *stanza);
396 int xmpp_stanza_is_tag(xmpp_stanza_t *stanza);
397 
398 /* marshall a stanza into text for transmission or display */
399 int xmpp_stanza_to_text(xmpp_stanza_t *stanza, char **buf, size_t *buflen);
400 
401 xmpp_stanza_t *xmpp_stanza_get_children(xmpp_stanza_t *stanza);
402 xmpp_stanza_t *xmpp_stanza_get_child_by_name(xmpp_stanza_t *stanza,
403                                              const char *name);
404 xmpp_stanza_t *xmpp_stanza_get_child_by_ns(xmpp_stanza_t *stanza,
405                                            const char *ns);
406 xmpp_stanza_t *xmpp_stanza_get_child_by_name_and_ns(xmpp_stanza_t *stanza,
407                                                     const char *name,
408                                                     const char *ns);
409 xmpp_stanza_t *xmpp_stanza_get_next(xmpp_stanza_t *stanza);
410 int xmpp_stanza_add_child(xmpp_stanza_t *stanza, xmpp_stanza_t *child);
411 int xmpp_stanza_add_child_ex(xmpp_stanza_t *stanza,
412                              xmpp_stanza_t *child,
413                              int do_clone);
414 
415 const char *xmpp_stanza_get_attribute(xmpp_stanza_t *stanza, const char *name);
416 int xmpp_stanza_get_attribute_count(xmpp_stanza_t *stanza);
417 int xmpp_stanza_get_attributes(xmpp_stanza_t *stanza,
418                                const char **attr,
419                                int attrlen);
420 /* concatenate all child text nodes.  this function
421  * returns a string that must be freed by the caller */
422 char *xmpp_stanza_get_text(xmpp_stanza_t *stanza);
423 const char *xmpp_stanza_get_text_ptr(xmpp_stanza_t *stanza);
424 const char *xmpp_stanza_get_name(xmpp_stanza_t *stanza);
425 /* set_attribute adds/replaces attributes */
426 int xmpp_stanza_set_attribute(xmpp_stanza_t *stanza,
427                               const char *key,
428                               const char *value);
429 int xmpp_stanza_set_name(xmpp_stanza_t *stanza, const char *name);
430 int xmpp_stanza_set_text(xmpp_stanza_t *stanza, const char *text);
431 int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
432                                    const char *text,
433                                    size_t size);
434 int xmpp_stanza_del_attribute(xmpp_stanza_t *stanza, const char *name);
435 
436 /* common stanza helpers */
437 const char *xmpp_stanza_get_ns(xmpp_stanza_t *stanza);
438 const char *xmpp_stanza_get_type(xmpp_stanza_t *stanza);
439 const char *xmpp_stanza_get_id(xmpp_stanza_t *stanza);
440 const char *xmpp_stanza_get_to(xmpp_stanza_t *stanza);
441 const char *xmpp_stanza_get_from(xmpp_stanza_t *stanza);
442 int xmpp_stanza_set_ns(xmpp_stanza_t *stanza, const char *ns);
443 int xmpp_stanza_set_id(xmpp_stanza_t *stanza, const char *id);
444 int xmpp_stanza_set_type(xmpp_stanza_t *stanza, const char *type);
445 int xmpp_stanza_set_to(xmpp_stanza_t *stanza, const char *to);
446 int xmpp_stanza_set_from(xmpp_stanza_t *stanza, const char *from);
447 
448 /* allocate and initialize a stanza in reply to another */
449 xmpp_stanza_t *xmpp_stanza_reply(xmpp_stanza_t *stanza);
450 xmpp_stanza_t *xmpp_stanza_reply_error(xmpp_stanza_t *stanza,
451                                        const char *error_type,
452                                        const char *condition,
453                                        const char *text);
454 
455 /* stanza subclasses */
456 xmpp_stanza_t *xmpp_message_new(xmpp_ctx_t *ctx,
457                                 const char *type,
458                                 const char *to,
459                                 const char *id);
460 char *xmpp_message_get_body(xmpp_stanza_t *msg);
461 int xmpp_message_set_body(xmpp_stanza_t *msg, const char *text);
462 
463 xmpp_stanza_t *xmpp_iq_new(xmpp_ctx_t *ctx, const char *type, const char *id);
464 xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx);
465 xmpp_stanza_t *
466 xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t type, const char *text);
467 
468 /* jid */
469 
470 /* these return new strings that must be xmpp_free()'d */
471 char *xmpp_jid_new(xmpp_ctx_t *ctx,
472                    const char *node,
473                    const char *domain,
474                    const char *resource);
475 char *xmpp_jid_bare(xmpp_ctx_t *ctx, const char *jid);
476 char *xmpp_jid_node(xmpp_ctx_t *ctx, const char *jid);
477 char *xmpp_jid_domain(xmpp_ctx_t *ctx, const char *jid);
478 char *xmpp_jid_resource(xmpp_ctx_t *ctx, const char *jid);
479 
480 /* event loop */
481 
482 void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout);
483 void xmpp_run(xmpp_ctx_t *ctx);
484 void xmpp_stop(xmpp_ctx_t *ctx);
485 void xmpp_ctx_set_timeout(xmpp_ctx_t *ctx, unsigned long timeout);
486 
487 /* TLS certificates */
488 
489 xmpp_ctx_t *xmpp_tlscert_get_ctx(const xmpp_tlscert_t *cert);
490 xmpp_conn_t *xmpp_tlscert_get_conn(const xmpp_tlscert_t *cert);
491 const char *xmpp_tlscert_get_pem(const xmpp_tlscert_t *cert);
492 const char *xmpp_tlscert_get_dnsname(const xmpp_tlscert_t *cert, size_t n);
493 const char *xmpp_tlscert_get_string(const xmpp_tlscert_t *cert,
494                                     xmpp_cert_element_t elmnt);
495 const char *xmpp_tlscert_get_description(xmpp_cert_element_t elmnt);
496 void xmpp_tlscert_free(xmpp_tlscert_t *cert);
497 
498 /* UUID */
499 
500 char *xmpp_uuid_gen(xmpp_ctx_t *ctx);
501 
502 /* SHA1 */
503 
504 /** @def XMPP_SHA1_DIGEST_SIZE
505  *  Size of the SHA1 message digest.
506  */
507 #define XMPP_SHA1_DIGEST_SIZE 20
508 
509 typedef struct _xmpp_sha1_t xmpp_sha1_t;
510 
511 char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len);
512 void xmpp_sha1_digest(const unsigned char *data,
513                       size_t len,
514                       unsigned char *digest);
515 
516 xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx);
517 void xmpp_sha1_free(xmpp_sha1_t *sha1);
518 void xmpp_sha1_update(xmpp_sha1_t *sha1, const unsigned char *data, size_t len);
519 void xmpp_sha1_final(xmpp_sha1_t *sha1);
520 char *xmpp_sha1_to_string(xmpp_sha1_t *sha1, char *s, size_t slen);
521 char *xmpp_sha1_to_string_alloc(xmpp_sha1_t *sha1);
522 void xmpp_sha1_to_digest(xmpp_sha1_t *sha1, unsigned char *digest);
523 
524 /* Base64 */
525 
526 char *
527 xmpp_base64_encode(xmpp_ctx_t *ctx, const unsigned char *data, size_t len);
528 char *xmpp_base64_decode_str(xmpp_ctx_t *ctx, const char *base64, size_t len);
529 void xmpp_base64_decode_bin(xmpp_ctx_t *ctx,
530                             const char *base64,
531                             size_t len,
532                             unsigned char **out,
533                             size_t *outlen);
534 
535 #ifdef __cplusplus
536 }
537 #endif
538 
539 #endif /* __LIBSTROPHE_STROPHE_H__ */
540