blob: 45a4cbafc852e884fc0be5714ef244acc9b31a95 [file] [log] [blame]
Benny Prijono85598d92006-01-07 18:44:25 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include "test.h"
Benny Prijono40f2f642006-01-30 18:40:05 +000020#include <pjsip.h>
Benny Prijono85598d92006-01-07 18:44:25 +000021#include <pjlib.h>
22
23#define THIS_FILE "msg_logger.c"
24
25static pj_bool_t msg_log_enabled;
26
27static pj_bool_t on_rx_msg(pjsip_rx_data *rdata)
28{
29 if (msg_log_enabled) {
30 PJ_LOG(4,(THIS_FILE, "RX %d bytes %s from %s:%d:\n"
31 "%s\n"
32 "--end msg--",
33 rdata->msg_info.len,
34 pjsip_rx_data_get_info(rdata),
35 rdata->pkt_info.src_name,
36 rdata->pkt_info.src_port,
37 rdata->msg_info.msg_buf));
38 }
39
40 return PJ_FALSE;
41}
42
43static pj_status_t on_tx_msg(pjsip_tx_data *tdata)
44{
45 if (msg_log_enabled) {
46 PJ_LOG(4,(THIS_FILE, "TX %d bytes %s to %s:%d:\n"
47 "%s\n"
48 "--end msg--",
49 (tdata->buf.cur - tdata->buf.start),
50 pjsip_tx_data_get_info(tdata),
51 tdata->tp_info.dst_name,
52 tdata->tp_info.dst_port,
53 tdata->buf.start));
54 }
55 return PJ_SUCCESS;
56}
57
58
59/* Message logger module. */
60static pjsip_module mod_msg_logger =
61{
62 NULL, NULL, /* prev and next */
63 { "mod-msg-logger", 14}, /* Name. */
64 -1, /* Id */
65 PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */
66 NULL, /* User data. */
Benny Prijono85598d92006-01-07 18:44:25 +000067 NULL, /* load() */
68 NULL, /* start() */
69 NULL, /* stop() */
70 NULL, /* unload() */
71 &on_rx_msg, /* on_rx_request() */
72 &on_rx_msg, /* on_rx_response() */
73 &on_tx_msg, /* on_tx_request() */
74 &on_tx_msg, /* on_tx_response() */
75 NULL, /* on_tsx_state() */
76};
77
78int init_msg_logger(void)
79{
80 pj_status_t status;
81
82 if (mod_msg_logger.id != -1)
83 return 0;
84
85 status = pjsip_endpt_register_module(endpt, &mod_msg_logger);
86 if (status != PJ_SUCCESS) {
87 app_perror(" error registering module", status);
88 return -10;
89 }
90
91 return 0;
92}
93
94int msg_logger_set_enabled(pj_bool_t enabled)
95{
96 int val = msg_log_enabled;
97 msg_log_enabled = enabled;
98 return val;
99}
100