Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 374:bd5638c21834
Improve logging system (traces)
There are now two trace logging levels:
* tracelog_level = 1:
Most messages from the log window are written to disk (LPRINT_LOG)
* tracelog_level =2:
LPRINT_LOG & LPRINT_DEBUG messages are written to disk
The trace file name is set with the "tracelog_file" option.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Jul 2005 21:46:35 +0100 |
parents | 33b8e801ffa6 |
children | 39c5da51b387 d59e9b8c91d3 |
comparison
equal
deleted
inserted
replaced
373:af2f8ddf6a1b | 374:bd5638c21834 |
---|---|
58 | 58 |
59 | 59 |
60 void statehandler(jconn, int); | 60 void statehandler(jconn, int); |
61 void packethandler(jconn, jpacket); | 61 void packethandler(jconn, jpacket); |
62 | 62 |
63 void screen_logger(jconn j, int io, const char *buf) | 63 static void logger(jconn j, int io, const char *buf) |
64 { | 64 { |
65 scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); | 65 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
66 } | |
67 | |
68 void file_logger(jconn j, int io, const char *buf) | |
69 { | |
70 ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf); | |
71 } | |
72 | |
73 void big_logger(jconn j, int io, const char *buf) | |
74 { | |
75 screen_logger(j, io, buf); | |
76 file_logger(j, io, buf); | |
77 } | 66 } |
78 | 67 |
79 /* | 68 /* |
80 static void jidsplit(const char *jid, char **user, char **host, | 69 static void jidsplit(const char *jid, char **user, char **host, |
81 char **res) | 70 char **res) |
143 | 132 |
144 s_id = 1; | 133 s_id = 1; |
145 jc = jab_new((char*)jid, (char*)pass, port, ssl); | 134 jc = jab_new((char*)jid, (char*)pass, port, ssl); |
146 | 135 |
147 /* These 3 functions can deal with a NULL jc, no worry... */ | 136 /* These 3 functions can deal with a NULL jc, no worry... */ |
148 jab_logger(jc, file_logger); | 137 jab_logger(jc, logger); |
149 jab_packet_handler(jc, &packethandler); | 138 jab_packet_handler(jc, &packethandler); |
150 jab_state_handler(jc, &statehandler); | 139 jab_state_handler(jc, &statehandler); |
151 | 140 |
152 if (jc && jc->user) { | 141 if (jc && jc->user) { |
153 online = TRUE; | 142 online = TRUE; |
219 | 208 |
220 jstate = STATE_GETAUTH; | 209 jstate = STATE_GETAUTH; |
221 } | 210 } |
222 | 211 |
223 if (!jc || jc->state == JCONN_STATE_OFF) { | 212 if (!jc || jc->state == JCONN_STATE_OFF) { |
224 scr_LogPrint("Unable to connect to the server"); | 213 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server"); |
225 online = FALSE; | 214 online = FALSE; |
226 } | 215 } |
227 } | 216 } |
228 | 217 |
229 if (!jc) { | 218 if (!jc) { |
382 | 371 |
383 cleanjid = jidtodisp(jid); | 372 cleanjid = jidtodisp(jid); |
384 | 373 |
385 // If the current buddy is an agent, unsubscribe from it | 374 // If the current buddy is an agent, unsubscribe from it |
386 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { | 375 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { |
387 scr_LogPrint("Unregistering from the %s agent", cleanjid); | 376 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
388 | 377 |
389 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | 378 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); |
390 xmlnode_put_attrib(x, "to", cleanjid); | 379 xmlnode_put_attrib(x, "to", cleanjid); |
391 y = xmlnode_get_tag(x, "query"); | 380 y = xmlnode_get_tag(x, "query"); |
392 xmlnode_insert_tag(y, "remove"); | 381 xmlnode_insert_tag(y, "remove"); |
558 /* | 547 /* |
559 //char *u, *h, *r; | 548 //char *u, *h, *r; |
560 //jidsplit(from, &u, &h, &r); | 549 //jidsplit(from, &u, &h, &r); |
561 // Maybe we should remember the resource? | 550 // Maybe we should remember the resource? |
562 if (r) | 551 if (r) |
563 scr_LogPrint("There is an extra part in message (resource?): %s", r); | 552 scr_LogPrint(LPRINT_NORMAL, |
564 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); | 553 "There is an extra part in message (resource?): %s", r); |
554 //scr_LogPrint(LPRINT_NORMAL, "Msg from <%s>, type=%s", | |
555 // jidtodisp(from), type); | |
565 */ | 556 */ |
566 | 557 |
567 jid = jidtodisp(from); | 558 jid = jidtodisp(from); |
568 hk_message_in(jid, timestamp, buffer, type); | 559 hk_message_in(jid, timestamp, buffer, type); |
569 g_free(jid); | 560 g_free(jid); |
572 | 563 |
573 void statehandler(jconn conn, int state) | 564 void statehandler(jconn conn, int state) |
574 { | 565 { |
575 static int previous_state = -1; | 566 static int previous_state = -1; |
576 | 567 |
577 ut_WriteLog("StateHandler called (state=%d).\n", state); | 568 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
578 | 569 |
579 switch(state) { | 570 switch(state) { |
580 case JCONN_STATE_OFF: | 571 case JCONN_STATE_OFF: |
581 if (previous_state != JCONN_STATE_OFF) | 572 if (previous_state != JCONN_STATE_OFF) |
582 scr_LogPrint("[Jabber] Not connected to the server"); | 573 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
583 | 574 |
584 online = FALSE; | 575 online = FALSE; |
585 mystatus = offline; | 576 mystatus = offline; |
586 roster_free(); | 577 roster_free(); |
587 update_roster = TRUE; | 578 update_roster = TRUE; |
588 break; | 579 break; |
589 | 580 |
590 case JCONN_STATE_CONNECTED: | 581 case JCONN_STATE_CONNECTED: |
591 scr_LogPrint("[Jabber] Connected to the server"); | 582 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
592 break; | 583 break; |
593 | 584 |
594 case JCONN_STATE_AUTH: | 585 case JCONN_STATE_AUTH: |
595 scr_LogPrint("[Jabber] Authenticating to the server"); | 586 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
596 break; | 587 break; |
597 | 588 |
598 case JCONN_STATE_ON: | 589 case JCONN_STATE_ON: |
599 scr_LogPrint("[Jabber] Communication with the server established"); | 590 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
591 "established"); | |
600 online = TRUE; | 592 online = TRUE; |
601 break; | 593 break; |
602 | 594 |
603 case JCONN_STATE_CONNECTING: | 595 case JCONN_STATE_CONNECTING: |
604 if (previous_state != state) | 596 if (previous_state != state) |
605 scr_LogPrint("[Jabber] Connecting to the server"); | 597 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
606 break; | 598 break; |
607 | 599 |
608 default: | 600 default: |
609 break; | 601 break; |
610 } | 602 } |
677 if (!strcmp(type, "result")) { | 669 if (!strcmp(type, "result")) { |
678 | 670 |
679 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { | 671 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
680 int iid = atoi(p); | 672 int iid = atoi(p); |
681 | 673 |
682 ut_WriteLog("iid = %d\n", iid); | 674 scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid); |
683 if (iid == s_id) { | 675 if (iid == s_id) { |
684 if (!regmode) { | 676 if (!regmode) { |
685 if (jstate == STATE_GETAUTH) { | 677 if (jstate == STATE_GETAUTH) { |
686 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) | 678 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
687 if (!xmlnode_get_tag(x, "digest")) { | 679 if (!xmlnode_get_tag(x, "digest")) { |
703 if (!strcmp(p, "VCARDreq")) { | 695 if (!strcmp(p, "VCARDreq")) { |
704 x = xmlnode_get_firstchild(packet->x); | 696 x = xmlnode_get_firstchild(packet->x); |
705 if (!x) x = packet->x; | 697 if (!x) x = packet->x; |
706 | 698 |
707 //jhook.gotvcard(ic, x); TODO | 699 //jhook.gotvcard(ic, x); TODO |
708 scr_LogPrint("Got VCARD"); | 700 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); |
709 return; | 701 return; |
710 } else if (!strcmp(p, "versionreq")) { | 702 } else if (!strcmp(p, "versionreq")) { |
711 // jhook.gotversion(ic, packet->x); TODO | 703 // jhook.gotversion(ic, packet->x); TODO |
712 scr_LogPrint("Got version"); | 704 scr_LogPrint(LPRINT_LOGNORM, "Got version"); |
713 return; | 705 return; |
714 } | 706 } |
715 } | 707 } |
716 | 708 |
717 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { | 709 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
738 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, | 730 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, |
739 ROSTER_TYPE_AGENT); | 731 ROSTER_TYPE_AGENT); |
740 g_free(cleanjid); | 732 g_free(cleanjid); |
741 } | 733 } |
742 if (alias && name && desc) { | 734 if (alias && name && desc) { |
743 scr_LogPrint("Agent: %s / %s / %s / type=%d", | 735 scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d", |
744 alias, name, desc, atype); | 736 alias, name, desc, atype); |
745 | 737 |
746 if (atype == search) { | 738 if (atype == search) { |
747 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); | 739 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
748 xmlnode_put_attrib(x, "to", alias); | 740 xmlnode_put_attrib(x, "to", alias); |
771 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { | 763 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { |
772 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; | 764 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; |
773 | 765 |
774 if (!strcmp(id, "Agent info")) { | 766 if (!strcmp(id, "Agent info")) { |
775 // jhook.gotagentinfo(packet->x); TODO | 767 // jhook.gotagentinfo(packet->x); TODO |
776 scr_LogPrint("Got agent info"); | 768 scr_LogPrint(LPRINT_LOGNORM, "Got agent info"); |
777 } else if (!strcmp(id, "Lookup")) { | 769 } else if (!strcmp(id, "Lookup")) { |
778 // jhook.gotsearchresults(packet->x); TODO | 770 // jhook.gotsearchresults(packet->x); TODO |
779 scr_LogPrint("Got search results"); | 771 scr_LogPrint(LPRINT_LOGNORM, "Got search results"); |
780 } else if (!strcmp(id, "Register")) { | 772 } else if (!strcmp(id, "Register")) { |
781 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); | 773 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); |
782 xmlnode_put_attrib(x, "to", from); | 774 xmlnode_put_attrib(x, "to", from); |
783 xmlnode_put_attrib(x, "id", "Agent info"); | 775 xmlnode_put_attrib(x, "id", "Agent info"); |
784 jab_send(conn, x); | 776 jab_send(conn, x); |
833 | 825 |
834 } | 826 } |
835 */ | 827 */ |
836 } | 828 } |
837 #endif | 829 #endif |
838 scr_LogPrint("Error code from server (%d)", code); | 830 scr_LogPrint(LPRINT_LOGNORM, "Error code from server (%d)", code); |
839 | 831 |
840 } | 832 } |
841 break; | 833 break; |
842 | 834 |
843 case JPACKET_PRESENCE: | 835 case JPACKET_PRESENCE: |
872 g_free(r); | 864 g_free(r); |
873 if (p) free(p); | 865 if (p) free(p); |
874 break; | 866 break; |
875 | 867 |
876 case JPACKET_S10N: | 868 case JPACKET_S10N: |
877 scr_LogPrint("Received (un)subscription packet (type=%s)", | 869 scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet " |
878 ((type) ? type : "")); | 870 "(type=%s)", ((type) ? type : "")); |
879 | 871 |
880 if (!strcmp(type, "subscribe")) { | 872 if (!strcmp(type, "subscribe")) { |
881 int isagent; | 873 int isagent; |
882 r = jidtodisp(from); | 874 r = jidtodisp(from); |
883 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; | 875 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
884 g_free(r); | 876 g_free(r); |
885 scr_LogPrint("isagent=%d", isagent); // XXX DBG | 877 scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG |
886 if (!isagent) { | 878 if (!isagent) { |
887 scr_LogPrint("<%s> wants to subscribe " | 879 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
888 "to your network presence updates", from); | 880 "to your network presence updates", from); |
889 // FIXME we accept everybody... | 881 // FIXME we accept everybody... |
890 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); | 882 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
891 jab_send(jc, x); | 883 jab_send(jc, x); |
892 xmlnode_free(x); | 884 xmlnode_free(x); |
897 } | 889 } |
898 } else if (!strcmp(type, "unsubscribe")) { | 890 } else if (!strcmp(type, "unsubscribe")) { |
899 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); | 891 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
900 jab_send(jc, x); | 892 jab_send(jc, x); |
901 xmlnode_free(x); | 893 xmlnode_free(x); |
902 scr_LogPrint("<%s> has unsubscribed to your presence updates", from); | 894 scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed to " |
895 "your presence updates", from); | |
903 } | 896 } |
904 break; | 897 break; |
905 | 898 |
906 default: | 899 default: |
907 break; | 900 break; |