00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00052 #ifdef HAVE_CONFIG_H
00053 # include <config.h>
00054 #endif
00055
00056 #ifndef N_
00057 # define N_(n) (n)
00058 #endif
00059
00060 #include <cstring>
00061 #include <cstdlib>
00062 #include <sys/types.h>
00063 #include <stdio.h>
00064 #include <setjmp.h>
00065 #include <sys/stat.h>
00066 #include <fcntl.h>
00067 #include <errno.h>
00068 #include <signal.h>
00069 #include <syslog.h>
00070 #include <strings.h>
00071 #include <unistd.h>
00072 #include <sys/param.h>
00073 #include <sys/socket.h>
00074 #include <netinet/in.h>
00075 #include <netdb.h>
00076 #include <arpa/inet.h>
00077 #include <arpa/nameser.h>
00078 #include <sys/time.h>
00079 #include <stdarg.h>
00080 #include <ctype.h>
00081 #include <ctime>
00082 #include <pth.h>
00083
00084 #include <expat.h>
00085
00086 #include <utility>
00087 #include <list>
00088
00089 #ifdef HAS_TR1_UNORDERED_MAP
00090 # include <tr1/unordered_map>
00091 #else
00092 # include <map>
00093 #endif
00094
00095 #include <glibmm.h>
00096
00097
00098
00099
00100
00101 #define MAXSHORTSTR 203
00102 #define QUAD_T unsigned long long
00103
00104 #ifdef __STDC__
00105
00106 #include <stdarg.h>
00107
00108 # define VA_LOCAL_DECL va_list ap;
00109 # define VA_START(f) va_start(ap, f)
00110 # define VA_END va_end(ap)
00111
00112 #else
00113
00114 # include <varargs.h>
00115
00116 # define VA_LOCAL_DECL va_list ap;
00117 # define VA_START(f) va_start(ap)
00118 # define VA_END va_end(ap)
00119
00120 #endif
00121
00122
00123 #ifndef INCL_LIB_H
00124 #define INCL_LIB_H
00125
00126 #include <string>
00127 #include <vector>
00128 #include <sstream>
00129 #include <stdexcept>
00130 #include <set>
00131
00132 namespace xmppd {
00133
00134
00135
00143 template<class pointed_type> class pointer {
00144 public:
00148 pointer();
00149
00161 pointer(pointed_type* pointed_object, bool malloc_allocated = false);
00162
00170 pointer(const pointer<pointed_type>& src);
00171
00178 ~pointer();
00179
00186 void delete_object();
00187
00196 pointer<pointed_type>& operator=(const pointer<pointed_type>& src);
00197
00206 pointed_type& operator*();
00207
00217 pointed_type* operator->() const;
00218
00224 bool points_to_NULL() const;
00225 private:
00229 void point_nothing();
00230
00234 pointed_type* pointed_object;
00235
00239 std::set<pointer<pointed_type>*>* all_pointers_to_this_object;
00240
00246 bool malloc_allocated;
00247 };
00248
00249
00250
00254 class hash {
00255 public:
00256 virtual void update(const std::string& data) =0;
00257 virtual std::vector<uint8_t> final() =0;
00258 std::string final_hex();
00259 };
00260
00264 class sha1 : public hash {
00265 public:
00269 sha1();
00270
00276 void update(const std::string& data);
00277
00283 void update(const std::vector<uint8_t> data);
00284
00292 std::vector<uint8_t> final();
00293 private:
00297 bool padded;
00298
00302 std::vector<uint8_t> current_block;
00303
00307 std::vector<uint32_t> W;
00308
00314 unsigned W_pos;
00315
00319 std::vector<uint32_t> H;
00320
00324 void hash_block();
00325
00329 inline static uint32_t circular_shift(uint32_t X, int n);
00330
00334 inline static uint32_t f_0_19(uint32_t B, uint32_t C, uint32_t D);
00335
00339 inline static uint32_t f_20_39(uint32_t B, uint32_t C, uint32_t D);
00340
00344 inline static uint32_t f_40_59(uint32_t B, uint32_t C, uint32_t D);
00345
00349 inline static uint32_t f_60_79(uint32_t B, uint32_t C, uint32_t D);
00350
00354 uint64_t l;
00355 };
00356 }
00357
00358 #define ZONE zonestr(__FILE__,__LINE__)
00359 char *zonestr(char const* file, int line);
00360
00361
00362
00363
00364
00365
00366
00367 #ifdef POOL_DEBUG
00368 # define POOL_NUM 40009
00369 #endif
00370
00371
00372 struct pheap
00373 {
00374 void *block;
00375 int size, used;
00376 };
00377
00378
00379
00380
00381 typedef void (*pool_cleaner)(void *arg);
00382
00383
00384
00385 struct pfree
00386 {
00387 pool_cleaner f;
00388 void *arg;
00389 struct pheap *heap;
00390 struct pfree *next;
00391 };
00392
00393
00394
00395 typedef struct pool_struct
00396 {
00397 int size;
00398 struct pfree *cleanup;
00399 struct pheap *heap;
00400 #ifdef POOL_DEBUG
00401 char name[8], zone[32];
00402 int lsize;
00403 } _pool, *pool;
00404 #define pool_new() _pool_new(__FILE__,__LINE__)
00405 #define pool_heap(i) _pool_new_heap(i,__FILE__,__LINE__)
00406 #else
00407 } _pool, *pool;
00408 #define pool_heap(i) _pool_new_heap(i, NULL, 0)
00409 #define pool_new() _pool_new(NULL, 0)
00410 #endif
00411
00412 pool _pool_new(char *zone, int line);
00413 pool _pool_new_heap(int size, char *zone, int line);
00414 void *pmalloc(pool p, int size);
00415 void *pmalloc_x(pool p, int size, char c);
00416 void *pmalloco(pool p, int size);
00417 char *pstrdup(pool p, const char *src);
00418 void pool_stat(int full);
00419 char *pstrdupx(pool p, const char *src);
00420 void pool_cleanup(pool p, pool_cleaner f, void *arg);
00421 void pool_free(pool p);
00422 int pool_size(pool p);
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 #ifndef MAXHOSTNAMELEN
00433 #define MAXHOSTNAMELEN 64
00434 #endif
00435
00436 #define NETSOCKET_SERVER 0
00437 #define NETSOCKET_CLIENT 1
00438 #define NETSOCKET_UDP 2
00440 #ifndef WIN32
00441 int make_netsocket(u_short port, char const* host, int type);
00442 int make_netsocket2(Glib::ustring servname, Glib::ustring nodename, int type);
00443 struct in_addr *make_addr(char const* host);
00444 #ifdef WITH_IPV6
00445 struct in6_addr *make_addr_ipv6(char const* host);
00446 #endif
00447 #endif
00448
00449
00450
00451
00452
00453
00454
00455 char *j_strdup(const char *str);
00456 char *j_strcat(char *dest, char *txt);
00457 int j_strcmp(const char *a, const char *b);
00458 int j_strcasecmp(const char *a, const char *b);
00459 int j_strncmp(const char *a, const char *b, int i);
00460 int j_strncasecmp(const char *a, const char *b, int i);
00461 int j_strlen(const char *a);
00462 int j_atoi(const char *a, int def);
00463 void str_b64decode(char *str);
00464
00465 namespace xmppd {
00466 class to_lower {
00467 public:
00468 to_lower(std::locale const& l) : loc(l) {}
00469 char operator() (char c) const { return std::tolower(c, loc); }
00470 private:
00471 std::locale const& loc;
00472 };
00473 }
00474
00475
00476
00477
00478
00479
00480 int base64_encode(unsigned char *source, size_t sourcelen, char *target, size_t targetlen);
00481 size_t base64_decode(const char *source, unsigned char *target, size_t targetlen);
00482
00483
00484
00485
00486
00487
00488
00489 #if (SIZEOF_INT == 4)
00490 typedef unsigned int uint32;
00491 #elif (SIZEOF_SHORT == 4)
00492 typedef unsigned short uint32;
00493 #else
00494 typedef unsigned int uint32;
00495 #endif
00496
00497 char *shahash(char const* str);
00498 void shahash_r(const char* str, char hashbuf[41]);
00499 void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]);
00500
00501
00502
00503
00504
00505
00506
00507 void crc32_r(const char *str, char crc32buf[9]);
00508
00509
00510
00511
00512
00513
00514 namespace xmppd {
00515
00527 template <class value_type> class xhash :
00528 #ifdef HAS_TR1_UNORDERED_MAP
00529 public std::tr1::unordered_map<std::string, value_type>
00530 #else
00531 public std::map<std::string, value_type>
00532 #endif
00533 {
00534 public:
00545 typename xhash<value_type>::iterator get_by_domain(std::string domainkey);
00546 };
00547 }
00548
00549 typedef xmppd::xhash<void*>* xht;
00550
00551 xht xhash_new(int prime);
00552 void xhash_put(xht h, const char *key, void *val);
00553 void *xhash_get(xht h, const char *key);
00554 void *xhash_get_by_domain(xht h, const char *domain);
00555 void xhash_zap(xht h, const char *key);
00556 void xhash_free(xht h);
00557 typedef void (*xhash_walker)(xht h, const char *key, void *val, void *arg);
00558 void xhash_walk(xht h, xhash_walker w, void *arg);
00559
00560
00561
00562
00563
00564
00565 char *strescape(pool p, char *buf);
00566 char *strunescape(pool p, char *buf);
00567 std::string strescape(std::string s);
00568
00569
00570
00571
00572
00573
00574
00575 #define NTYPE_TAG 0
00576 #define NTYPE_ATTRIB 1
00577 #define NTYPE_CDATA 2
00579 #define NTYPE_LAST 2
00580 #define NTYPE_UNDEF -1
00582 #define XMLNS_SEPARATOR ' '
00584
00585
00586
00587
00588 typedef struct xmlnode_t {
00589 char* name;
00590 char* prefix;
00591 char* ns_iri;
00592 unsigned short type;
00593 char* data;
00594 int data_sz;
00595
00596 pool p;
00597 struct xmlnode_t* parent;
00598 struct xmlnode_t* firstchild;
00599 struct xmlnode_t* lastchild;
00600 struct xmlnode_t* prev;
00601 struct xmlnode_t* next;
00602 struct xmlnode_t* firstattrib;
00603 struct xmlnode_t* lastattrib;
00604 } _xmlnode, *xmlnode;
00605
00606 namespace xmppd {
00607
00611 class ns_decl_list : private std::list<std::pair<std::string, std::string> > {
00612 public:
00613 ns_decl_list();
00614 ns_decl_list(const xmlnode node);
00615 void update(const std::string& prefix, const std::string& ns_iri);
00616 void delete_last(const std::string& prefix);
00617 char const* get_nsprefix(const std::string& iri) const;
00618 char const* get_nsprefix(const std::string& iri, bool accept_default_prefix) const;
00619 char const* get_nsiri(const std::string& prefix) const;
00620 bool check_prefix(const std::string& prefix, const std::string& ns_iri) const;
00621 private:
00622 };
00623
00624 }
00625
00634 typedef std::vector<xmlnode> xmlnode_vector;
00635
00636
00637 xmlnode xmlnode_wrap(xmlnode x,const char* wrapper);
00638 xmlnode xmlnode_wrap_ns(xmlnode x,const char* name, const char *prefix, const char *ns_iri);
00639 xmlnode xmlnode_new_tag(const char* name);
00640 xmlnode xmlnode_new_tag_ns(const char* name, const char* prefix, const char *ns_iri);
00641 xmlnode xmlnode_new_tag_pool(pool p, const char* name);
00642 xmlnode xmlnode_new_tag_pool_ns(pool p, const char* name, const char* prefix, const char *ns_iri);
00643 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name);
00644 xmlnode xmlnode_insert_tag_ns(xmlnode parent, const char* name, const char *prefix, const char *ns_iri);
00645 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size);
00646 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node);
00647 void xmlnode_insert_node(xmlnode parent, xmlnode node);
00648 xmlnode xmlnode_str(const char *str, int len);
00649 xmlnode xmlnode_file(const char *file);
00650 char const* xmlnode_file_borked(char const *file);
00651 xmlnode xmlnode_dup(xmlnode x);
00652 xmlnode xmlnode_dup_pool(pool p, xmlnode x);
00653
00654
00655 pool xmlnode_pool(xmlnode node);
00656
00657
00658 void xmlnode_hide(xmlnode child);
00659 void xmlnode_hide_attrib(xmlnode parent, const char *name);
00660 void xmlnode_hide_attrib_ns(xmlnode parent, const char *name, const char *ns_iri);
00661
00662
00663 void xmlnode_free(xmlnode node);
00664
00665
00666 xmlnode xmlnode_get_tag(xmlnode parent, const char* name);
00667 char* xmlnode_get_tag_data(xmlnode parent, const char* name);
00668 xmlnode_vector xmlnode_get_tags(xmlnode context_node, const char *path, xht namespaces);
00669 xmlnode xmlnode_get_list_item(const xmlnode_vector& first, unsigned int i);
00670 char* xmlnode_get_list_item_data(const xmlnode_vector& first, unsigned int i);
00671 xmlnode xmlnode_select_by_lang(const xmlnode_vector& nodes, const char* lang);
00672
00673
00674 void xmlnode_put_attrib(xmlnode owner, const char* name, const char* value);
00675 void xmlnode_put_attrib_ns(xmlnode owner, const char* name, const char* prefix, const char *ns_iri, const char* value);
00676 char* xmlnode_get_attrib(xmlnode owner, const char* name);
00677 char* xmlnode_get_attrib_ns(xmlnode owner, const char* name, const char *ns_iri);
00678 void xmlnode_put_expat_attribs(xmlnode owner, const char** atts, xmppd::ns_decl_list& nslist);
00679
00680 const char* xmlnode_get_lang(xmlnode node);
00681
00682
00683 xmlnode xmlnode_get_firstattrib(xmlnode parent);
00684 xmlnode xmlnode_get_firstchild(xmlnode parent);
00685 xmlnode xmlnode_get_lastchild(xmlnode parent);
00686 xmlnode xmlnode_get_nextsibling(xmlnode sibling);
00687 xmlnode xmlnode_get_prevsibling(xmlnode sibling);
00688 xmlnode xmlnode_get_parent(xmlnode node);
00689
00690
00691 char* xmlnode_get_name(xmlnode node);
00692 char* xmlnode_get_data(xmlnode node);
00693 int xmlnode_get_type(xmlnode node);
00694 const char* xmlnode_get_localname(xmlnode node);
00695 const char* xmlnode_get_namespace(xmlnode node);
00696 const char* xmlnode_get_nsprefix(xmlnode node);
00697 void xmlnode_change_namespace(xmlnode node, const char *ns_iri);
00698
00699 int xmlnode_has_children(xmlnode node);
00700
00701
00702 char* xmlnode_serialize_string(xmlnode_t const* node, const xmppd::ns_decl_list& nslist, int stream_type);
00703
00704 int xmlnode2file(char const* file, xmlnode node);
00705 int xmlnode2file_limited(char const* file, xmlnode node, size_t sizelimit);
00706
00707
00708 void expat_startElement(void* userdata, const char* name, const char** atts);
00709 void expat_endElement(void* userdata, const char* name);
00710 void expat_charData(void* userdata, const char* s, int len);
00711
00712
00713 xmlnode xhash_to_xml(xht h);
00714 xht xhash_from_xml(xmlnode hash, pool p);
00715
00716
00717
00718
00719
00720 #define XSTREAM_MAXNODE 1000000
00721 #define XSTREAM_MAXDEPTH 100
00722
00723 #define XSTREAM_ROOT 0
00724 #define XSTREAM_NODE 1
00725 #define XSTREAM_CLOSE 2
00726 #define XSTREAM_ERR 4
00727
00728 typedef void (*xstream_onNode)(int type, xmlnode x, void *arg);
00729
00730 typedef struct xstream_struct {
00731 XML_Parser parser;
00732 xmlnode node;
00733 char *cdata;
00734 int cdata_len;
00735 pool p;
00736 xstream_onNode f;
00737 void *arg;
00738 int status;
00739 int depth;
00740
00741 const char *root_lang;
00743 xmppd::ns_decl_list *ns_root;
00744 xmppd::ns_decl_list *ns_stanza;
00745 } *xstream, _xstream;
00746
00747 xstream xstream_new(pool p, xstream_onNode f, void *arg);
00748 int xstream_eat(xstream xs, char *buff, int len);
00749
00750
00751 xmlnode xstream_header(const char *to, const char *from);
00752 char *xstream_header_char(xmlnode x, int stream_type);
00753
00755 typedef enum {
00756 unknown_error_type,
00757 bad_format,
00758 bad_namespace_prefix,
00759 conflict,
00760 connection_timeout,
00761 host_gone,
00762 host_unknown,
00763 improper_addressing,
00764 internal_server_error,
00765 invalid_from,
00766 invalid_id,
00767 invalid_namespace,
00768 invalid_xml,
00769 not_authorized,
00770 policy_violation,
00771 remote_connection_failed,
00772 resource_constraint,
00773 restricted_xml,
00774 see_other_host,
00775 system_shutdown,
00776 undefined_condition,
00777 unsupported_encoding,
00778 unsupported_stanza_type,
00779 unsupported_version,
00780 xml_not_well_formed
00781 } streamerr_reason;
00782
00784 typedef enum {
00785 normal,
00786 configuration,
00787 feature_lack,
00788 unknown,
00789 error
00790 } streamerr_severity;
00791
00793 typedef struct streamerr_struct {
00794 char *text;
00795 char *lang;
00796 streamerr_reason reason;
00797 streamerr_severity severity;
00798 } *streamerr, _streamerr;
00799
00800 void xstream_format_error(std::ostream& out, streamerr errstruct);
00801 streamerr_severity xstream_parse_error(pool p, xmlnode errnode, streamerr errstruct);
00802
00803 typedef struct {
00804 unsigned long H[5];
00805 unsigned long W[80];
00806 int lenW;
00807 unsigned long sizeHi,sizeLo;
00808 } j_SHA_CTX;
00809
00810
00811 void shaInit(j_SHA_CTX *ctx);
00812 void shaUpdate(j_SHA_CTX *ctx, unsigned char *dataIn, int len);
00813 void shaFinal(j_SHA_CTX *ctx, unsigned char hashout[20]);
00814 void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]);
00815
00816
00817
00818 void hmac_sha1_ascii_r(char const* secret, unsigned char const* message, size_t len, char hmac[41]);
00819
00820
00821
00822 namespace xmppd {
00823
00827 class jabberid {
00828 public:
00835 jabberid(const Glib::ustring& jid);
00836
00843 void set_node(const Glib::ustring& node);
00844
00851 void set_domain(const Glib::ustring& domain);
00852
00859 void set_resource(const Glib::ustring& resource);
00860
00866 const Glib::ustring& get_node() { return node; };
00867
00873 bool has_node() { return node.length() > 0; };
00874
00880 const Glib::ustring& get_domain() { return domain; };
00881
00887 const Glib::ustring& get_resource() { return resource; };
00888
00894 bool has_resource() { return resource.length() > 0; };
00895
00902 bool operator==(const jabberid& otherjid);
00903
00913 bool compare(const jabberid& otherjid, bool compare_resource = false, bool compare_node = true, bool compare_domain = true);
00914
00920 jabberid get_user();
00921
00927 Glib::ustring full();
00928 private:
00934 Glib::ustring node;
00935
00941 Glib::ustring domain;
00942
00948 Glib::ustring resource;
00949 };
00950
00956 class jabberid_pool : public jabberid {
00957 public:
00965 jabberid_pool(const Glib::ustring& jid, ::pool p);
00966
00972 char* full_pooled();
00973
00980 void set_node(const Glib::ustring& node);
00981
00988 void set_domain(const Glib::ustring& domain);
00989
00996 void set_resource(const Glib::ustring& resource);
00997
01003 pool get_pool() { return p; };
01004
01008 jabberid_pool* next;
01009 private:
01015 ::pool p;
01016
01022 char* jid_full;
01023 };
01024 }
01025
01026
01027
01028
01029
01030
01031 #define JID_RESOURCE 1
01032 #define JID_USER 2
01033 #define JID_SERVER 4
01034
01035 typedef xmppd::jabberid_pool* jid;
01036
01037 jid jid_new(pool p, const char *idstr);
01038 void jid_set(jid id, const char *str, int item);
01039 char* jid_full(jid id);
01040 int jid_cmp(jid a, jid b);
01041 int jid_cmpx(jid a, jid b, int parts);
01042 jid jid_user(jid a);
01043 jid jid_user_pool(jid a, pool p);
01044 jid jid_append(jid a, jid b);
01045
01046
01047
01048
01049
01050
01051 #define JPACKET_UNKNOWN 0x00
01052 #define JPACKET_MESSAGE 0x01
01053 #define JPACKET_PRESENCE 0x02
01054 #define JPACKET_IQ 0x04
01055 #define JPACKET_S10N 0x08
01056
01057 #define JPACKET__UNKNOWN 0
01058 #define JPACKET__NONE 1
01059 #define JPACKET__ERROR 2
01060 #define JPACKET__CHAT 3
01061 #define JPACKET__GROUPCHAT 4
01062 #define JPACKET__GET 5
01063 #define JPACKET__SET 6
01064 #define JPACKET__RESULT 7
01065 #define JPACKET__SUBSCRIBE 8
01066 #define JPACKET__SUBSCRIBED 9
01067 #define JPACKET__UNSUBSCRIBE 10
01068 #define JPACKET__UNSUBSCRIBED 11
01069 #define JPACKET__AVAILABLE 12
01070 #define JPACKET__UNAVAILABLE 13
01071 #define JPACKET__PROBE 14
01072 #define JPACKET__HEADLINE 15
01073 #define JPACKET__INVISIBLE 16
01074
01075 typedef struct jpacket_struct
01076 {
01077 unsigned char type;
01078 int subtype;
01079 int flag;
01080 void* aux1;
01081 xmlnode x;
01082 jid to;
01083 jid from;
01084 char* iqns;
01085 xmlnode iq;
01086 pool p;
01087 } *jpacket, _jpacket;
01088
01089 jpacket jpacket_new(xmlnode x);
01090 jpacket jpacket_reset(jpacket p);
01091 int jpacket_subtype(jpacket p);
01092
01093
01094
01095
01096
01097
01098
01099 typedef struct jlimit_struct
01100 {
01101 char *key;
01102 int start;
01103 int points;
01104 int maxt, maxp;
01105 pool p;
01106 } *jlimit, _jlimit;
01107
01108 jlimit jlimit_new(int maxt, int maxp);
01109 void jlimit_free(jlimit r);
01110 int jlimit_check(jlimit r, char *key, int points);
01111
01112
01113
01114
01115 #define KARMA_READ_MAX(k) (abs(k)*100)
01116 #define KARMA_INIT 5
01117 #define KARMA_HEARTBEAT 2
01118 #define KARMA_MAX 10
01119 #define KARMA_INC 1
01120 #define KARMA_DEC 0
01121
01122 #define KARMA_PENALTY -5
01123 #define KARMA_RESTORE 5
01124 #define KARMA_RESETMETER 0
01125
01126 struct karma {
01127 int reset_meter;
01128 int val;
01129 long bytes;
01130 int max;
01131 int inc,dec;
01132 int penalty,restore;
01133 time_t last_update;
01134 };
01135
01136 struct karma *karma_new(pool p);
01137 void karma_copy(struct karma *new_instance, struct karma *old);
01138 void karma_increment(struct karma *k);
01139 void karma_decrement(struct karma *k, long bytes_read);
01140 int karma_check(struct karma *k,long bytes_read);
01141
01142
01143
01144
01145
01146
01147
01148
01149 typedef struct terror_struct
01150 {
01151 int code;
01152 char msg[64];
01153 } terror;
01154
01155 #define TERROR_BAD (terror){400,"Bad Request"}
01156 #define TERROR_AUTH (terror){401,"Unauthorized"}
01157 #define TERROR_PAY (terror){402,"Payment Required"}
01158 #define TERROR_FORBIDDEN (terror){403,"Forbidden"}
01159 #define TERROR_NOTFOUND (terror){404,"Not Found"}
01160 #define TERROR_NOTALLOWED (terror){405,"Not Allowed"}
01161 #define TERROR_NOTACCEPTABLE (terror){406,"Not Acceptable"}
01162 #define TERROR_REGISTER (terror){407,"Registration Required"}
01163 #define TERROR_REQTIMEOUT (terror){408,"Request Timeout"}
01164 #define TERROR_CONFLICT (terror){409,"Conflict"}
01165
01166 #define TERROR_INTERNAL (terror){500,"Internal Server Error"}
01167 #define TERROR_NOTIMPL (terror){501,"Not Implemented"}
01168 #define TERROR_EXTERNAL (terror){502,"Remote Server Error"}
01169 #define TERROR_UNAVAIL (terror){503,"Service Unavailable"}
01170 #define TERROR_EXTTIMEOUT (terror){504,"Remote Server Timeout"}
01171 #define TERROR_DISCONNECTED (terror){510,"Disconnected"}
01172
01173
01174 #define HAS_XTERROR
01175
01176 typedef struct xterror_struct
01177 {
01178 int code;
01179 char msg[256];
01180 char type[9];
01181 char condition[64];
01182 } xterror;
01183
01184 #define XTERROR_BAD (xterror){400, N_("Bad Request"),"modify","bad-request"}
01185 #define XTERROR_CONFLICT (xterror){409, N_("Conflict"), "cancel", "conflict"}
01186 #define XTERROR_NOTIMPL (xterror){501, N_("Not Implemented"), "cancel", "feature-not-implemented"}
01187 #define XTERROR_FORBIDDEN (xterror){403, N_("Forbidden"), "auth", "forbidden"}
01188 #define XTERROR_GONE (xterror){302, N_("Gone"), "modify", "gone"}
01189 #define XTERROR_INTERNAL (xterror){500, N_("Internal Server Error"), "wait", "internal-server-error"}
01190 #define XTERROR_NOTFOUND (xterror){404, N_("Not Found"), "cancel", "item-not-found"}
01191 #define XTERROR_JIDMALFORMED (xterror){400, N_("Bad Request"), "modify", "jid-malformed"}
01192 #define XTERROR_NOTACCEPTABLE (xterror){406, N_("Not Acceptable"), "modify", "not-acceptable"}
01193 #define XTERROR_NOTALLOWED (xterror){405, N_("Not Allowed"), "cancel", "not-allowed"}
01194 #define XTERROR_AUTH (xterror){401, N_("Unauthorized"), "auth", "not-authorized"}
01195 #define XTERROR_PAY (xterror){402, N_("Payment Required"), "auth", "payment-required"}
01196 #define XTERROR_RECIPIENTUNAVAIL (xterror){404, N_("Recipient Is Unavailable"), "wait", "recipient-unavailable"}
01197 #define XTERROR_REDIRECT (xterror){302, N_("Redirect"), "modify", "redirect"}
01198 #define XTERROR_REGISTER (xterror){407, N_("Registration Required"), "auth", "registration-required"}
01199 #define XTERROR_REMOTENOTFOUND (xterror){404, N_("Remote Server Not Found"), "cancel", "remote-server-not-found"}
01200 #define XTERROR_REMOTETIMEOUT (xterror){504, N_("Remote Server Timeout"), "wait", "remote-server-timeout"}
01201 #define XTERROR_RESCONSTRAINT (xterror){500, N_("Resource Constraint"), "wait", "resource-constraint"}
01202 #define XTERROR_UNAVAIL (xterror){503, N_("Service Unavailable"), "cancel", "service-unavailable"}
01203 #define XTERROR_SUBSCRIPTIONREQ (xterror){407, N_("Subscription Required"), "auth", "subscription-required"}
01204 #define XTERROR_UNDEF_CANCEL (xterror){500, NULL, "cancel", "undefined-condition"}
01205 #define XTERROR_UNDEF_CONTINUE (xterror){500, NULL, "continue", "undefined-condition"}
01206 #define XTERROR_UNDEF_MODIFY (xterror){500, NULL, "modify", "undefined-condition"}
01207 #define XTERROR_UNDEF_AUTH (xterror){500, NULL, "auth", "undefined-condition"}
01208 #define XTERROR_UNDEF_WAIT (xterror){500, NULL, "wait", "undefined-condition"}
01209 #define XTERROR_UNEXPECTED (xterror){400, N_("Unexpected Request"), "wait", "unexpected-request"}
01210
01211 #define XTERROR_REQTIMEOUT (xterror){408, N_("Request Timeout"), "wait", "remote-server-timeout"}
01212 #define XTERROR_EXTERNAL (xterror){502, N_("Remote Server Error"), "wait", "service-unavailable"}
01213 #define XTERROR_EXTTIMEOUT (xterror){504, N_("Remote Server Timeout"), "wait", "remote-server-timeout"}
01214 #define XTERROR_DISCONNECTED (xterror){510, N_("Disconnected"), "cancel", "service-unavailable"}
01215 #define XTERROR_STORAGE_FAILED (xterror){500, N_("Storage Failed"), "wait", "internal-server-error"}
01216
01217
01218
01219
01220
01221
01222 #define NSCHECK(x,n) (j_strcmp(xmlnode_get_namespace(x), n) == 0)
01223
01224 #define NS_STREAM "http://etherx.jabber.org/streams"
01225 #define NS_FLASHSTREAM "http://www.jabber.com/streams/flash"
01226 #define NS_CLIENT "jabber:client"
01227 #define NS_SERVER "jabber:server"
01228 #define NS_DIALBACK "jabber:server:dialback"
01229 #define NS_COMPONENT_ACCEPT "jabber:component:accept"
01230 #define NS_AUTH "jabber:iq:auth"
01231 #define NS_AUTH_CRYPT "jabber:iq:auth:crypt"
01232 #define NS_REGISTER "jabber:iq:register"
01233 #define NS_ROSTER "jabber:iq:roster"
01234 #define NS_OFFLINE "jabber:x:offline"
01235 #define NS_AGENT "jabber:iq:agent"
01236 #define NS_AGENTS "jabber:iq:agents"
01237 #define NS_DELAY "jabber:x:delay"
01238 #define NS_VERSION "jabber:iq:version"
01239 #define NS_TIME "jabber:iq:time"
01240 #define NS_VCARD "vcard-temp"
01241 #define NS_PRIVATE "jabber:iq:private"
01242 #define NS_SEARCH "jabber:iq:search"
01243 #define NS_OOB "jabber:iq:oob"
01244 #define NS_XOOB "jabber:x:oob"
01245 #define NS_FILTER "jabber:iq:filter"
01246 #define NS_AUTH_0K "jabber:iq:auth:0k"
01247 #define NS_BROWSE "jabber:iq:browse"
01248 #define NS_EVENT "jabber:x:event"
01249 #define NS_CONFERENCE "jabber:iq:conference"
01250 #define NS_SIGNED "jabber:x:signed"
01251 #define NS_ENCRYPTED "jabber:x:encrypted"
01252 #define NS_GATEWAY "jabber:iq:gateway"
01253 #define NS_LAST "jabber:iq:last"
01254 #define NS_ENVELOPE "jabber:x:envelope"
01255 #define NS_EXPIRE "jabber:x:expire"
01256 #define NS_PRIVACY "jabber:iq:privacy"
01257 #define NS_XHTML "http://www.w3.org/1999/xhtml"
01258 #define NS_DISCO_INFO "http://jabber.org/protocol/disco#info"
01259 #define NS_DISCO_ITEMS "http://jabber.org/protocol/disco#items"
01260 #define NS_DATA "jabber:x:data"
01261 #define NS_FLEXIBLE_OFFLINE "http://jabber.org/protocol/offline"
01262 #define NS_IQ_AUTH "http://jabber.org/features/iq-auth"
01263 #define NS_REGISTER_FEATURE "http://jabber.org/features/iq-register"
01264 #define NS_MSGOFFLINE "msgoffline"
01265 #define NS_BYTESTREAMS "http://jabber.org/protocol/bytestreams"
01266 #define NS_COMMAND "http://jabber.org/protocol/commands"
01267
01268
01269 #define NS_XDBNSLIST "jabber:xdb:nslist"
01270
01271 #define NS_XMPP_STANZAS "urn:ietf:params:xml:ns:xmpp-stanzas"
01272 #define NS_XMPP_TLS "urn:ietf:params:xml:ns:xmpp-tls"
01273 #define NS_XMPP_STREAMS "urn:ietf:params:xml:ns:xmpp-streams"
01274 #define NS_XMPP_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
01275
01276 #define NS_XMPP_PING "urn:xmpp:ping"
01277
01278 #define NS_JABBERD_STOREDPRESENCE "http://jabberd.org/ns/storedpresence"
01279 #define NS_JABBERD_STOREDPEERPRESENCE "http://jabberd.org/ns/storedpeerpresence"
01280 #define NS_JABBERD_STOREDREQUEST "http://jabberd.org/ns/storedsubscriptionrequest"
01281 #define NS_JABBERD_STOREDSTATE "http://jabberd.org/ns/storedstate"
01282 #define NS_JABBERD_HISTORY "http://jabberd.org/ns/history"
01283 #define NS_JABBERD_HASH "http://jabberd.org/ns/hash"
01284 #define NS_JABBERD_XDB "http://jabberd.org/ns/xdb"
01285 #define NS_JABBERD_WRAPPER "http://jabberd.org/ns/wrapper"
01286 #define NS_JABBERD_XDBSQL "http://jabberd.org/ns/xdbsql"
01287 #define NS_JABBERD_ACL "http://jabberd.org/ns/acl"
01288 #define NS_JABBERD_LOOPCHECK "http://jabberd.org/ns/loopcheck"
01289 #define NS_JABBERD_ERRMSG "http://jabberd.org/ns/errmsg"
01291 #define NS_SESSION "http://jabberd.jabberstudio.org/ns/session/1.0"
01293 #define NS_XMLNS "http://www.w3.org/2000/xmlns/"
01294 #define NS_XML "http://www.w3.org/XML/1998/namespace"
01296 #define NS_JABBERD_CONFIGFILE "http://jabberd.org/ns/configfile"
01297 #define NS_JABBERD_CONFIGFILE_REPLACE "http://jabberd.org/ns/configfile/replace"
01298 #define NS_JABBERD_CONFIGFILE_ROUTER "http://xmppd.org/ns/configfile/router"
01299 #define NS_JABBERD_CONFIG_XDBFILE "jabber:config:xdb_file"
01300 #define NS_JABBERD_CONFIG_DIALBACK "jabber:config:dialback"
01301 #define NS_JABBERD_CONFIG_DNSRV "jabber:config:dnsrv"
01302 #define NS_JABBERD_CONFIG_JSM "jabber:config:jsm"
01303 #define NS_JABBERD_CONFIG_PTHCSOCK "jabber:config:pth-csock"
01304 #define NS_JABBERD_CONFIG_XDBSQL "jabber:config:xdb_sql"
01305 #define NS_JABBERD_CONFIG_DYNAMICHOST "http://xmppd.org/ns/dynamichost"
01307
01308
01309
01310
01311
01312 xmlnode jutil_presnew(int type, char const* to, const char *status);
01313 xmlnode jutil_iqnew(int type, char const* ns);
01314 xmlnode jutil_msgnew(char const* type, char const* to, char const* subj, char const* body);
01315
01316 int jutil_priority(xmlnode x);
01317 void jutil_tofrom(xmlnode x);
01318 xmlnode jutil_iqresult(xmlnode x);
01319 char* jutil_timestamp(void);
01320 char* jutil_timestamp_ms(char *buffer);
01321 void jutil_error(xmlnode x, terror E);
01322 void jutil_error_xmpp(xmlnode x, xterror E);
01323 void jutil_error_map(terror old, xterror *mapped);
01324 void jutil_delay(xmlnode msg, char const* reason);
01325 char* jutil_regkey(char *key, char *seed);
01326
01327
01328
01329
01330
01331
01332 void messages_set_mapping(const char* lang, const char* locale_name);
01333 const char* messages_get(const char* lang, const char* message);
01334
01335
01336
01337
01338
01339
01340 namespace xmppd {
01341 namespace lwresc {
01342
01343 class invalid_packet : public std::logic_error {
01344 public:
01345 invalid_packet(const std::string& __arg);
01346 };
01347
01348
01349 class lwquery;
01350
01354 std::ostream& operator<<(std::ostream& os, const lwquery& lwq);
01355
01359 class lwquery {
01360 public:
01361 friend std::ostream& operator<<(std::ostream& os, const lwquery& lwq);
01362
01363 uint32_t getSerial() const;
01364
01365 protected:
01370 lwquery();
01371
01375 virtual ~lwquery();
01376
01384 void write_header(std::ostream& os, uint32_t opcode, size_t rdata_len) const;
01385
01392 static void write_uint16(std::ostream& os, uint16_t value);
01393
01400 static void write_uint32(std::ostream& os, uint32_t value);
01401
01405 uint16_t flags;
01406
01410 uint32_t serial;
01411
01412 private:
01419 virtual void write_to_stream(std::ostream& os) const =0;
01420
01424 static int next_serial;
01425 };
01426
01430 class rrsetbyname : public lwquery {
01431 public:
01435 rrsetbyname(const std::string& hostname, ::ns_class qclass, ::ns_type qtype);
01436 private:
01440 std::string hostname;
01441
01445 ::ns_class qclass;
01446
01450 ::ns_type qtype;
01451
01457 void write_to_stream(std::ostream& os) const;
01458 };
01459
01460 class rrecord {
01461 public:
01462 virtual ~rrecord();
01463 };
01464
01465 class srv_record : public rrecord {
01466 public:
01467 srv_record(std::istream& is);
01468
01469
01470 uint16_t getPrio() const;
01471 uint16_t getWeight() const;
01472 uint16_t getPort() const;
01473 const std::string& getDName() const;
01474 private:
01475 uint16_t prio;
01476 uint16_t weight;
01477 uint16_t port;
01478 std::string dname;
01479 };
01480
01481 class aaaa_record : public rrecord {
01482 public:
01483 aaaa_record(std::istream& is);
01484
01485
01486 const std::string& getAddress() const;
01487 private:
01488 std::string address;
01489 };
01490
01491 class a_record : public rrecord {
01492 public:
01493 a_record(std::istream& is);
01494
01495
01496 const std::string& getAddress() const;
01497 private:
01498 std::string address;
01499 };
01500
01501 class lwresult_rdata {
01502 public:
01503 virtual ~lwresult_rdata();
01504 };
01505
01506 class lwresult_rrset : public lwresult_rdata {
01507 public:
01508 lwresult_rrset(std::istream& is, uint32_t rdata_len);
01509 ~lwresult_rrset();
01510
01511
01512 uint32_t getTTL() const;
01513 std::vector<rrecord *> getRR() const;
01514 private:
01515 uint32_t flags;
01516 ::ns_class rclass;
01517 ::ns_type rtype;
01518 uint32_t ttl;
01519 uint16_t number_rr;
01520 uint16_t number_sig;
01521 std::string real_name;
01522
01523 std::vector<rrecord*> rr;
01524 };
01525
01529 class lwresult {
01530 public:
01536 lwresult(std::istream& is);
01537
01541 ~lwresult();
01542
01550 static uint16_t read_uint16(std::istream& is);
01551
01559 static uint32_t read_uint32(std::istream& is);
01560
01570 static std::string read_string(std::istream& is);
01571
01581 static std::string read_qname(std::istream& is);
01582
01586 enum QueryResult {
01587 res_success = 0,
01588 res_nomemory = 1,
01589 res_timeout = 2,
01590 res_notfound = 3,
01591 res_unexpectedend = 4,
01592 res_failure = 5,
01593 res_ioerror = 6,
01594 res_notimplemented = 7,
01595 res_unexpected = 8,
01596 res_trailingdata = 9,
01597 res_incomplete = 10,
01598 res_retry = 11,
01599 res_typenotfound = 12,
01600 res_toolarge = 13
01601 };
01602
01603
01604
01605 uint32_t getSerial() const;
01606 QueryResult getResult() const;
01607 lwresult_rdata const* getRData() const;
01608
01609 private:
01610 uint32_t length;
01611 uint16_t version;
01612 uint16_t flags;
01613 uint32_t serial;
01614 uint32_t opcode;
01615 uint32_t result;
01616 uint32_t recv_len;
01617 uint16_t auth_type;
01618 uint16_t auth_len;
01619
01620 lwresult_rdata* rdata;
01621 };
01622
01623 }
01624 }
01625
01626 #include <pointer.tcc>
01627
01628 #endif