Fri Mar 7 11:47:06 EST 2008 Pekka.Pessi@nokia.com

* tport: allow using TPTAG_LOG() and TPTAG_DUMP() with tport_set_params().



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7824 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-03-07 17:46:28 +00:00
parent 1073925bb4
commit 222fcbddb7
3 changed files with 39 additions and 21 deletions

View File

@ -532,7 +532,6 @@ tport_t *tport_tcreate(tp_stack_t *stack,
ta_start(ta, tag, value);
tport_set_params(mr->mr_master, ta_tags(ta));
tport_open_log(mr, ta_args(ta));
#if HAVE_SOFIA_STUN
tport_init_stun_server(mr, ta_args(ta));
@ -1233,12 +1232,12 @@ int tport_set_params(tport_t *self,
tag_type_t tag, tag_value_t value, ...)
{
ta_list ta;
int n;
int n, m = 0;
tport_params_t tpp[1], *tpp0;
usize_t mtu;
int connect, sdwn_error, reusable, stun_server, pong2ping;
if (self == NULL)
return su_seterrno(EINVAL);
@ -1272,10 +1271,13 @@ int tport_set_params(tport_t *self,
TPTAG_TOS_REF(tpp->tpp_tos),
TAG_END());
if (self == (tport_t *)self->tp_master)
m = tport_open_log(self->tp_master, ta_args(ta));
ta_end(ta);
if (n == 0)
return 0;
return m;
if (tpp->tpp_idle > 0 && tpp->tpp_idle < 100)
tpp->tpp_idle = 100;
@ -1314,7 +1316,7 @@ int tport_set_params(tport_t *self,
if (tport_is_secondary(self))
tport_set_secondary_timer(self);
return n;
return n + m;
}
extern tport_vtable_t const tport_udp_vtable;
@ -4260,6 +4262,7 @@ tport_t *tport_next(tport_t const *self)
return NULL;
else if (tport_is_master(self))
return ((tport_master_t *)self)->mr_primaries->pri_primary;
else if (tport_is_primary(self))
return ((tport_primary_t *)self)->pri_next->pri_primary;
else

View File

@ -283,9 +283,9 @@ struct tport_master {
/**< Timer reclaiming unused connections and compartment */
su_timer_t *mr_timer;
/** File to dump received and sent data */
/** FILE to dump received and sent data */
FILE *mr_dump_file;
char *mr_dump; /**< Filename for dumping received/sent data */
tport_primary_t *mr_primaries; /**< List of primary contacts */
tport_params_t mr_params[1];
@ -453,7 +453,7 @@ int tport_recv_error_report(tport_t *self);
void tport_error_report(tport_t *self, int errcode,
su_sockaddr_t const *addr);
void tport_open_log(tport_master_t *mr, tagi_t *tags);
int tport_open_log(tport_master_t *mr, tagi_t *tags);
void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
char const *via, su_time_t now);
void tport_dump_iovec(tport_t const *self, msg_t *msg,

View File

@ -94,30 +94,43 @@ su_log_t tport_log[] = {
/** Initialize logging. */
void tport_open_log(tport_master_t *mr, tagi_t *tags)
int tport_open_log(tport_master_t *mr, tagi_t *tags)
{
char const *log = NULL;
int log_msg = 0;
tl_gets(tags, TPTAG_LOG_REF(log_msg), TAG_END());
int log_msg = mr->mr_log != 0;
char const *dump = NULL;
int n;
n = tl_gets(tags,
TPTAG_LOG_REF(log_msg),
TPTAG_DUMP_REF(dump),
TAG_END());
if (getenv("MSG_STREAM_LOG") != NULL || getenv("TPORT_LOG") != NULL)
log_msg = 1;
mr->mr_log = log_msg ? MSG_DO_EXTRACT_COPY : 0;
tl_gets(tags, TPTAG_DUMP_REF(log), TAG_END());
if (getenv("MSG_DUMP"))
log = getenv("MSG_DUMP");
dump = getenv("MSG_DUMP");
if (getenv("TPORT_DUMP"))
log = getenv("TPORT_DUMP");
dump = getenv("TPORT_DUMP");
if (log) {
if (dump) {
time_t now;
char *dumpname;
if (strcmp(log, "-"))
mr->mr_dump_file = fopen(log, "ab"); /* XXX */
if (mr->mr_dump && strcmp(dump, mr->mr_dump) == 0)
return n;
dumpname = su_strdup(mr->mr_home, dump);
if (dumpname == NULL)
return n;
su_free(mr->mr_home, mr->mr_dump);
mr->mr_dump = dumpname;
if (mr->mr_dump_file && mr->mr_dump_file != stdout)
fclose(mr->mr_dump_file), mr->mr_dump_file = NULL;
if (strcmp(dumpname, "-"))
mr->mr_dump_file = fopen(dumpname, "ab"); /* XXX */
else
mr->mr_dump_file = stdout;
@ -126,6 +139,8 @@ void tport_open_log(tport_master_t *mr, tagi_t *tags)
fprintf(mr->mr_dump_file, "dump started at %s\n\n", ctime(&now));
}
}
return n;
}
/** Create log stamp */