1 /* 2 * Ostatnia aktualizacja: 3 * 4 * - $Id: libtlen.h,v 1.69 2003/10/18 08:56:08 mati Exp $ 5 * 6 */ 7 8 // Deklaracja naglowka 9 #ifndef __LIBTLEN_H 10 #define __LIBTLEN_H 11 12 // Inkludy 13 #include <string.h> 14 #include <stdlib.h> 15 #include <sys/types.h> 16 #include <sys/wait.h> 17 #include <stdio.h> 18 #include <setjmp.h> 19 #include <sys/stat.h> 20 #include <fcntl.h> 21 #include <errno.h> 22 #include <signal.h> 23 #include <syslog.h> 24 #include <string.h> 25 #include <unistd.h> 26 #include <sys/param.h> 27 #include <sys/socket.h> 28 #include <netinet/in.h> 29 #include <netdb.h> 30 #include <arpa/inet.h> 31 #include <sys/time.h> 32 #include <stdarg.h> 33 #include <ctype.h> 34 #include <time.h> 35 #include "xmlparse.h" 36 #include "str.h" 37 38 // Coby sie g++ kompilowalo 39 #ifdef __cplusplus 40 extern "C" 41 { 42 #endif 43 44 // Deklaracje hostow 45 #define TLEN_HUB "idi.tlen.pl" 46 #define TLEN_FALLBACK_SERVER "s1.tlen.pl" 47 #define TLEN_FALLBACK_PORT 443 48 49 // Deklaracje bledow 50 #define TLEN_ERROR_UNAUTHORIZED 1 51 #define TLEN_ERROR_BADRESPONSE 2 52 #define TLEN_ERROR_MALLOC 3 53 #define TLEN_ERROR_OTHER 4 54 #define TLEN_ERROR_NETWORK 5 55 56 // Deklaracje status�w 57 58 #define TLEN_STATUS_AVAILABLE 2 59 #define TLEN_STATUS_EXT_AWAY 3 60 #define TLEN_STATUS_AWAY 4 61 #define TLEN_STATUS_DND 5 62 #define TLEN_STATUS_CHATTY 6 63 #define TLEN_STATUS_INVISIBLE 7 64 #define TLEN_STATUS_UNAVAILABLE 8 65 66 // Deklaracje stan�w 67 68 #define TLEN_STATE_CONNECTING_HUB 1 69 #define TLEN_STATE_CONNECTING 2 70 #define TLEN_STATE_CONNECTED 3 71 72 // Deklaracje checkow 73 74 #define TLEN_CHECK_READ 1 75 #define TLEN_CHECK_WRITE 2 76 77 struct tlen_writebuffer_item 78 { 79 void *data_mem; 80 void *data_ptr; 81 size_t data_len; 82 struct tlen_writebuffer_item *next; 83 }; 84 85 // tlen_session 86 // -- 87 // struktura sesji tlen.pl, tutaj przechowywane sa informacje o kontaktach, 88 // ktore "subskrybuje" user, oraz wszelkie info o userze, ktory jest 89 // zalogowany. Struktura wypelniana przez funkcje tlen_login. 90 91 struct tlen_session 92 { 93 int fd; // socket 94 int error; // kod bledu 95 int state; // stan 96 int check; // typ sprawdzania 97 XML_Parser parser; // parser strumienia XML 98 struct tlen_event *event; 99 spool buffer; // bufor na XML 100 pool bufferpool; 101 int buffering; // czy zbieramy do bufora 102 char *sid; // ID sesji 103 char *username; // nazwa uzytkownika przed @tlen.pl 104 char *password; // haselko 105 int status; // stan 106 int hub_blocking; // blokowanie huba 107 char *description; // opis 108 int nestlevel; // poziom zagnie�dzenia w parsowanym XML-u 109 int resolv_pid; // PID resolvera 110 int proxy_enabled; // czy uzywamy proxy? 111 char *proxy_addr; // adres proxy 112 int proxy_port; // port proxy 113 struct tlen_writebuffer_item *writebuffer; // bufor danych do wys�ania przez socket 114 struct tlen_writebuffer_item *writebuffer_last_item; // ostatni element bufora 115 }; 116 117 // tlen_user 118 // -- 119 // struktura danych o u�ytkowniku - zawiera nazw�, identyfikator @tlen.pl, 120 // grup� w kt�rej u�ytkownik "siedzi", oraz poziom autoryzacji. 121 122 struct tlen_user 123 { 124 char *name; 125 char *jid; 126 char *group; 127 char *subscription; 128 char *ask;//jesli ask zawiera 'subscribe' to znaczy ze czekamy na 129 //autoryzacje u tej osoby 130 }; 131 132 133 // tlen_message 134 // -- 135 // tutaj znajdziesz wiadomo�� - struktura wype�niana przez 136 // tlen_watch_fd. 137 138 #define TLEN_MESSAGE 0 139 #define TLEN_CHAT 1 140 141 struct tlen_message 142 { 143 char *from; // od kogo 144 char *body; // tre�� ju� zdekodowana urldecodem 145 char *stamp; // data wyslania wiadomosci, jesli byla przechowywana 146 int type; // typ wiadomo�ci 147 }; 148 149 // tlen_presence 150 // -- 151 // tutaj znajdziesz presence - struktura wype�niana przez 152 // tlen_watch_fd. 153 154 struct tlen_presence 155 { 156 char *from; // od kogo 157 int status; // status w postaci liczbowej 158 char *description; // opis do statusu 159 }; 160 161 // tlen_subscription 162 // -- 163 // tutaj znajdziesz informacje o subskrybcji - struktura 164 // wypelniana przez tlen_watch_fd 165 166 struct tlen_subscription 167 { 168 char *jid; 169 }; 170 171 // tlen_newmail 172 // -- 173 // informacje o nowym mailu na skrzynce, od kogo i jaki tytul 174 175 struct tlen_newmail 176 { 177 char *from; 178 char *subject; 179 }; 180 181 // tlen_grouchat 182 // -- 183 // struktura opisuj�ca konferencj�, identyfikatory, hashe, etc. 184 185 struct tlen_groupchat 186 { 187 char *conf; // Identyfikator w formie idSEKUNDA@conf 188 char *secret; // Haslo, wysylanie jako totalny random przy two�eniu konferencji 189 }; 190 191 // tlen_webmsg 192 // -- 193 // wiadomosc wyslana ze strony ludzie.tlen.pl/login_name 194 195 struct tlen_webmsg 196 { 197 char *from; 198 char *email; 199 char *site; 200 char *body; 201 }; 202 203 // tlen_notify 204 // -- 205 // powiadomienia - pisze, przestal pisac, wiadomosc dzwiekowa 206 207 #define TLEN_NOTIFY_TYPING 1 208 #define TLEN_NOTIFY_NOTTYPING 2 209 #define TLEN_NOTIFY_SOUNDALERT 3 210 211 struct tlen_notify 212 { 213 char *from; // od kogo 214 char *to; // do kogo 215 int type; // typ powiadomienia 216 }; 217 218 // tlen_advert 219 // -- 220 // reklama wyskauj�ca 221 struct tlen_advert 222 { 223 char *url; // adres reklamy 224 char *name; // nazwa rekalmodawcy 225 int width; // szerokosc okienka wyskakujacego 226 int height; // wysokosc okienka wyskakujacego 227 }; 228 229 // ********************************************************** 230 // KATALOG PUBLICZNY 231 232 // zawody - sorry za polskie, ale bez sensu bylo to angielszczyc 233 #define TLEN_PUBDIR_JOB_NONE 0 234 #define TLEN_PUBDIR_JOB_UCZEN 1 235 #define TLEN_PUBDIR_JOB_STUDENT 2 236 #define TLEN_PUBDIR_JOB_ROLNIK 3 237 #define TLEN_PUBDIR_JOB_MENEDZER 4 238 // specjalista, wolny zawod 239 #define TLEN_PUBDIR_JOB_SPEC_WOL 5 240 // urzednik, uslugi, administracja 241 #define TLEN_PUBDIR_JOB_UUA 6 242 #define TLEN_PUBDIR_JOB_BEZROBOTNY 7 243 // emeryt, rencista 244 #define TLEN_PUBDIR_JOB_EMERYT 8 245 #define TLEN_PUBDIR_JOB_GOSPODYNI 9 246 #define TLEN_PUBDIR_JOB_NAUCZYCIEL 10 247 #define TLEN_PUBDIR_JOB_LEKARZ 11 248 #define TLEN_PUBDIR_JOB_INNY 12 249 250 // p�cie 251 252 #define TLEN_PUBDIR_GENDER_NONE 0 253 #define TLEN_PUBDIR_GENDER_MALE 1 254 #define TLEN_PUBDIR_GENDER_FEMALE 2 255 256 // plany 257 258 #define TLEN_PUBDIR_WANT_NONE 0 259 #define TLEN_PUBDIR_WANT_CINEMA 1 260 //...trzeba dopisac 261 262 // szukam... 263 264 #define TLEN_PUBDIR_LOOK_NONE 0 265 #define TLEN_PUBDIR_LOOK_TALK 1 266 #define TLEN_PUBDIR_LOOK_FRIEND 2 267 #define TLEN_PUBDIR_LOOK_FLIRT 3 268 #define TLEN_PUBDIR_LOOK_LOVE 4 269 270 // Glos 271 272 #define TLEN_PUBDIR_VOICE_DISABLED 0 273 #define TLEN_PUBDIR_VOICE_ENABLED 1 274 275 // Widocznosc 276 277 #define TLEN_PUBDIR_VISIBLE_NO 0 278 #define TLEN_PUBDIR_VISIBLE_YES 1 279 280 // Status 281 282 #define TLEN_PUBDIR_STATUS_AVAILABLE 2 283 #define TLEN_PUBDIR_STATUS_CHATTY 3 284 285 // Oznaczenia: 286 // *PS* - katalog i szukanie 287 // *S* - samo szukanie 288 // *SR* - szukanie i tylko wartosc zwracana 289 290 struct tlen_pubdir 291 { 292 char *firstname; // *PS* Imi� 293 char *lastname; // *PS* Nazwisko 294 char *nick; // *PS* Nick 295 int gender; // *PS* P�e� 296 char *city; // *PS* Miasto 297 char *email; // *PS* Email 298 int age; // *SR* ZWRACANY wiek 299 int age_min; // *S* min. wiek 300 int age_max; // *S* max. wiek 301 int look_for; // *PS* poszukuj�... 302 char *school; // *PS* szko�a 303 int job; // *PS* zaw�d 304 int status; // *S* stan 305 int voice; // *PS* z mo�liwo�ci� rozmowy g�osowej 306 char *id; // *S* identyfikator 307 int plans; // *PS* plany 308 int birthyear; // *P* rok urodzenia 309 int visible; // *P* czy moj status ma byc widoczny? 310 }; 311 312 313 // ********************************************************** 314 315 316 #define TLEN_EVENT_UNKNOWN -1 317 #define TLEN_EVENT_AUTHORIZED 3 318 #define TLEN_EVENT_GOTROSTERITEM 5 319 #define TLEN_EVENT_MESSAGE 6 320 #define TLEN_EVENT_SUBSCRIBE 7 321 #define TLEN_EVENT_PRESENCE 8 322 #define TLEN_EVENT_UNSUBSCRIBE 9 323 #define TLEN_EVENT_ENDROSTER 10 324 #define TLEN_EVENT_SUBSCRIBED 11 325 #define TLEN_EVENT_UNSUBSCRIBED 12 326 #define TLEN_EVENT_NEWMAIL 14 327 #define TLEN_EVENT_GOTSEARCHITEM 15 328 #define TLEN_EVENT_ENDSEARCH 16 329 #define TLEN_EVENT_PUBDIR_GOTDATA 17 330 #define TLEN_EVENT_PUBDIR_GOTUPDATEOK 18 331 #define TLEN_EVENT_WEBMSG 19 332 #define TLEN_EVENT_NOTIFY 20 333 #define TLEN_EVENT_ADVERT 21 334 335 // tlen_event 336 // -- 337 // struktura wype�niana przez tlen_watch_fd, type wskazuje na typ 338 // zdarzenia (typy powyrzej), je�eli message to od razu wype�nione 339 // jest pole message, je�eli presence to presence - tak wi�c 340 // �atwo si� do wszystkiego dobra�. 341 342 struct tlen_event 343 { 344 int type; // typ zdarzenia - definicje wyzej 345 struct tlen_presence *presence; // jezeli zdarzenie to status, tutaj sa jego dane 346 struct tlen_message *message; // jezeli zdarzenie to wiadomosc, tutaj znajdziesz jej wlasciwosci 347 struct tlen_subscription *subscribe; // jezeli zdarzenie to subskrybcja, tutaj znajdziesz jej dane 348 struct tlen_user *roster; // jezeli zdarzenie to ksiazka adresowa, tutaj jest tablica uzytkownikow 349 struct tlen_newmail *newmail; //dla zdarzenia newmail 350 struct tlen_webmsg *webmsg; //dla zdarzenia webmsg 351 struct tlen_pubdir *pubdir; //do pubdira (search i katalog) 352 struct tlen_notify *notify; //do powiadomien - pisze, przestal pisac, sygnal dzwiekowy 353 struct tlen_advert *advert; //reklama wyskakujaca 354 struct tlen_event *next_event; 355 }; 356 357 // funkcje obslugi sesji 358 struct tlen_session *tlen_init(void); 359 void tlen_set_hub_blocking(struct tlen_session *sess, int blocking); 360 void tlen_set_auth(struct tlen_session *sess, char *username, char *password); 361 void tlen_set_proxy(struct tlen_session *sess, char *addr, int port); 362 void tlen_login (struct tlen_session *sess); 363 int tlen_freesession (struct tlen_session *sesja); 364 365 // funkcje obslugi gniazd 366 int tlen_socket_create (const char *address, int port); 367 int tlen_socket_write_string (struct tlen_session *sess, const void *string); 368 int tlen_socket_write (struct tlen_session *sess, const void *data, size_t len); 369 int tlen_socket_destroy (struct tlen_session *sess); 370 371 // funkcje obslugi autoryzacji 372 char *tlen_hash (const char *pass, const char *id); 373 int tlen_getid (struct tlen_session *sesja); 374 int tlen_authorize (struct tlen_session *sesja); 375 376 // funkcje obslugi ksiazki adresowej 377 int tlen_getroster (struct tlen_session *sesja); 378 int tlen_addcontact (struct tlen_session *sesja, const char *name, 379 const char *jid, const char *group); 380 int tlen_removecontact (struct tlen_session *sesja, const char *jid); 381 int tlen_request_subscribe (struct tlen_session *sesja, const char *jid); 382 int tlen_request_unsubscribe (struct tlen_session *sesja, const char *jid); 383 int tlen_accept_subscribe (struct tlen_session *sesja, const char *jid); 384 int tlen_accept_unsubscribe (struct tlen_session *sesja, const char *jid); 385 386 387 // funkcje obslugi status�w 388 int tlen_presence (struct tlen_session *sesja, int status, 389 const char *description); 390 int tlen_presence_disconnect (struct tlen_session *sesja); 391 int tlen_presence_invisible (struct tlen_session *sesja); 392 393 // funkcje obslugi zdarze� 394 void tlen_watch_fd (struct tlen_session *sesja); 395 396 // funkcje obslugi messagow 397 int tlen_sendmsg (struct tlen_session *sesja, 398 const char *destination, const char *message, int type); 399 int tlen_sendnotify (struct tlen_session *sesja, 400 const char *destination, int type); 401 402 // funkcje obs�ugi konferencji 403 int tlen_get_second(); 404 int tlen_groupchat_create(struct tlen_session *sesja); 405 406 // funkcje obslugi wyszukiwania 407 int tlen_search (struct tlen_session *sesja, struct tlen_pubdir *search); 408 struct tlen_pubdir *tlen_new_pubdir (); 409 int tlen_free_pubdir (struct tlen_pubdir *pubdir); 410 int tlen_get_pubdir (struct tlen_session *sesja); 411 int tlen_change_pubdir (struct tlen_session *sesja, struct tlen_pubdir *pubdir); 412 413 // utilsy :-D 414 void tlen_ping (struct tlen_session *); 415 char *tlen_encode (const char *); 416 char *tlen_decode (const char *); 417 418 void tlen_debug_raw (const char *name, char *format, ...); 419 #define tlen_debug(...) tlen_debug_raw(__func__,__VA_ARGS__) 420 421 void tlen_parsebuffer(struct tlen_session *sesja); 422 int tlen_stripresource(char *jid); 423 int tlen_setdebug (int dbg); 424 char *tlen_base64_encode(const char *buf); 425 char *tlen_base64_decode(const char *buf); 426 427 // events 428 struct tlen_event* tlen_newevent(int type); 429 void tlen_freeevent (struct tlen_event* e); 430 void tlen_addevent(struct tlen_session *sesja, struct tlen_event *e); 431 struct tlen_event* tlen_getevent(struct tlen_session *sesja); 432 433 // handlery 434 435 void tlen_starttag_handler(void *userData, const XML_Char *name, const XML_Char **atts); 436 void tlen_endtag_handler (void *userData, const XML_Char *name); 437 void tlen_char_handler (void *userData, const XML_Char *s, int len); 438 439 // hub 440 441 int tlen_connect_hub (struct tlen_session *sess, int blocking); 442 443 // ********************************************* 444 // ********************************************* 445 // NIE MOJE, WZI�TE Z INNYCH PROGRAM�W, ITP.: 446 // gaim, ekg, expat, itd. itp. 447 // ********************************************* 448 // ********************************************* 449 450 // Obsluga stringow 451 452 #ifndef HAVE_SNPRINTF 453 extern int ap_snprintf (char *, size_t, const char *, ...); 454 #define snprintf ap_snprintf 455 #endif 456 457 #ifndef HAVE_VSNPRINTF 458 extern int ap_vsnprintf (char *, size_t, const char *, va_list ap); 459 #define vsnprintf ap_vsnprintf 460 #endif 461 462 #define ZONE zonestr(__FILE__,__LINE__) 463 char *zonestr (char *file, int line); 464 465 // prostee metody ograniczania pasma jabbera (wziete z gaim) 466 467 typedef struct jlimit_struct 468 { 469 char *key; 470 int start; 471 int points; 472 int maxt, maxp; 473 pool p; 474 } 475 *jlimit, _jlimit; 476 477 jlimit jlimit_new (int maxt, int maxp); 478 void jlimit_free (jlimit r); 479 int jlimit_check (jlimit r, char *key, int points); 480 481 // Hashtable (z expat) 482 483 typedef struct xhn_struct 484 { 485 struct xhn_struct *next; 486 const char *key; 487 void *val; 488 } 489 *xhn, _xhn; 490 491 typedef struct xht_struct 492 { 493 pool p; 494 int prime; 495 struct xhn_struct *zen; 496 } 497 *xht, _xht; 498 499 xht xhash_new (int prime); 500 void xhash_put (xht h, const char *key, void *val); 501 void *xhash_get (xht h, const char *key); 502 void xhash_zap (xht h, const char *key); 503 void xhash_free (xht h); 504 typedef void (*xhash_walker) (xht h, const char *key, void *val, 505 void *arg); 506 void xhash_walk (xht h, xhash_walker w, void *arg); 507 508 // "Staromodne" hashtable (z expat) 509 510 typedef int (*KEYHASHFUNC) (const void *key); 511 typedef int (*KEYCOMPAREFUNC) (const void *key1, const void *key2); 512 typedef int (*TABLEWALKFUNC) (void *user_data, const void *key, 513 void *data); 514 515 typedef void *HASHTABLE; 516 517 HASHTABLE ghash_create (int buckets, KEYHASHFUNC hash, 518 KEYCOMPAREFUNC cmp); 519 HASHTABLE ghash_create_pool (pool p, int buckets, KEYHASHFUNC hash, 520 KEYCOMPAREFUNC cmp); 521 void ghash_destroy (HASHTABLE tbl); 522 void *ghash_get (HASHTABLE tbl, const void *key); 523 int ghash_put (HASHTABLE tbl, const void *key, void *value); 524 int ghash_remove (HASHTABLE tbl, const void *key); 525 int ghash_walk (HASHTABLE tbl, TABLEWALKFUNC func, void *user_data); 526 int str_hash_code (const char *s); 527 528 // Wezly xml (xmlnodes) (z expat) 529 530 #define NTYPE_TAG 0 531 #define NTYPE_ATTRIB 1 532 #define NTYPE_CDATA 2 533 534 #define NTYPE_LAST 2 535 #define NTYPE_UNDEF -1 536 537 /* -------------------------------------------------------------------------- 538 Node structure. Do not use directly! Always use accessor macros 539 and methods! 540 -------------------------------------------------------------------------- */ 541 typedef struct xmlnode_t 542 { 543 char *name; 544 unsigned short type; 545 char *data; 546 int data_sz; 547 int complete; 548 pool p; 549 struct xmlnode_t *parent; 550 struct xmlnode_t *firstchild; 551 struct xmlnode_t *lastchild; 552 struct xmlnode_t *prev; 553 struct xmlnode_t *next; 554 struct xmlnode_t *firstattrib; 555 struct xmlnode_t *lastattrib; 556 } 557 _xmlnode, *xmlnode; 558 559 /* Node creation routines */ 560 xmlnode xmlnode_wrap (xmlnode x, const char *wrapper); 561 xmlnode xmlnode_new_tag (const char *name); 562 xmlnode xmlnode_new_tag_pool (pool p, const char *name); 563 xmlnode xmlnode_insert_tag (xmlnode parent, const char *name); 564 xmlnode xmlnode_insert_cdata (xmlnode parent, const char *CDATA, 565 unsigned int size); 566 xmlnode xmlnode_insert_tag_node (xmlnode parent, xmlnode node); 567 void xmlnode_insert_node (xmlnode parent, xmlnode node); 568 xmlnode xmlnode_str (char *str, int len); 569 xmlnode xmlnode_file (char *file); 570 char *xmlnode_file_borked (char *file); /* same as _file but returns the parsing error */ 571 xmlnode xmlnode_dup (xmlnode x); /* duplicate x */ 572 xmlnode xmlnode_dup_pool (pool p, xmlnode x); 573 574 /* Node Memory Pool */ 575 pool xmlnode_pool (xmlnode node); 576 xmlnode _xmlnode_new (pool p, const char *name, unsigned int type); 577 578 /* Node editing */ 579 void xmlnode_hide (xmlnode child); 580 void xmlnode_hide_attrib (xmlnode parent, const char *name); 581 582 /* Node deletion routine, also frees the node pool! */ 583 void xmlnode_free (xmlnode node); 584 585 /* Locates a child tag by name and returns it */ 586 xmlnode xmlnode_get_tag (xmlnode parent, const char *name); 587 char *xmlnode_get_tag_data (xmlnode parent, const char *name); 588 589 /* Attribute accessors */ 590 void xmlnode_put_attrib (xmlnode owner, const char *name, 591 const char *value); 592 char *xmlnode_get_attrib (xmlnode owner, const char *name); 593 void xmlnode_put_expat_attribs (xmlnode owner, const char **atts); 594 595 /* Bastard am I, but these are fun for internal use ;-) */ 596 void xmlnode_put_vattrib (xmlnode owner, const char *name, 597 void *value); 598 void *xmlnode_get_vattrib (xmlnode owner, const char *name); 599 600 /* Node traversal routines */ 601 xmlnode xmlnode_get_firstattrib (xmlnode parent); 602 xmlnode xmlnode_get_firstchild (xmlnode parent); 603 xmlnode xmlnode_get_lastchild (xmlnode parent); 604 xmlnode xmlnode_get_nextsibling (xmlnode sibling); 605 xmlnode xmlnode_get_prevsibling (xmlnode sibling); 606 xmlnode xmlnode_get_parent (xmlnode node); 607 608 /* Node information routines */ 609 char *xmlnode_get_name (xmlnode node); 610 char *xmlnode_get_data (xmlnode node); 611 int xmlnode_get_datasz (xmlnode node); 612 int xmlnode_get_type (xmlnode node); 613 614 int xmlnode_has_children (xmlnode node); 615 int xmlnode_has_attribs (xmlnode node); 616 617 /* Node-to-string translation */ 618 char *xmlnode2str (xmlnode node); 619 620 /* Node-to-terminated-string translation 621 -- useful for interfacing w/ scripting langs */ 622 char *xmlnode2tstr (xmlnode node); 623 624 int xmlnode_cmp (xmlnode a, xmlnode b); /* compares a and b for equality */ 625 626 int xmlnode2file (char *file, xmlnode node); /* writes node to file */ 627 628 /* Expat callbacks */ 629 void expat_startElement (void *userdata, const char *name, 630 const char **atts); 631 void expat_endElement (void *userdata, const char *name); 632 void expat_charData (void *userdata, const char *s, int len); 633 634 /*********************** 635 * XSTREAM Section 636 ***********************/ 637 638 #define XSTREAM_MAXNODE 1000000 639 #define XSTREAM_MAXDEPTH 100 640 641 #define XSTREAM_ROOT 0 /* root element */ 642 #define XSTREAM_NODE 1 /* normal node */ 643 #define XSTREAM_CLOSE 2 /* closed </stream:stream> */ 644 #define XSTREAM_ERR 4 /* parser error */ 645 646 typedef void (*xstream_onNode) (int type, xmlnode x, void *arg); /* xstream event handler */ 647 648 typedef struct xstream_struct 649 { 650 XML_Parser parser; 651 xmlnode node; 652 char *cdata; 653 int cdata_len; 654 pool p; 655 xstream_onNode f; 656 void *arg; 657 int status; 658 int depth; 659 } 660 *xstream, _xstream; 661 662 xstream xstream_new (pool p, xstream_onNode f, void *arg); /* create a new xstream */ 663 int xstream_eat (xstream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */ 664 665 /* convience functions */ 666 xmlnode xstream_header (char *namespace, char *to, char *from); 667 char *xstream_header_char (xmlnode x); 668 669 typedef struct 670 { 671 XML_Parser parser; 672 xmlnode current; 673 } 674 *xmlstr2xmlnode_parser, xmlstr2xmlnode_parser_struct; 675 676 void xmlstr2xmlnode_charData (void *userdata, const char *s, 677 int slen); 678 void xmlstr2xmlnode_startElement (void *userdata, const char *name, 679 const char **attribs); 680 void xmlstr2xmlnode_endElement (void *userdata, const char *name); 681 xmlnode xmlstr2xmlnode (char *xmlstring); 682 683 typedef struct 684 { 685 unsigned long H[5]; 686 unsigned long W[80]; 687 int lenW; 688 unsigned long sizeHi, sizeLo; 689 } 690 j_SHA_CTX; 691 692 693 void shaInit (j_SHA_CTX * ctx); 694 void shaUpdate (j_SHA_CTX * ctx, unsigned char *dataIn, int len); 695 void shaFinal (j_SHA_CTX * ctx, unsigned char hashout[20]); 696 void shaBlock (unsigned char *dataIn, int len, 697 unsigned char hashout[20]); 698 699 // zamkniecie kilku definicji 700 701 #ifdef __cplusplus 702 } 703 #endif 704 705 #endif /* __LIBTLEN_H typedef struct */ 706