Merged revisions 45408 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r45408 | kpfleming | 2006-10-17 17:24:10 -0500 (Tue, 17 Oct 2006) | 3 lines

optimize the 'quick response' code a bit more... no more malloc() or memset() for each response
expand stringfields API a bit to allow reusing the stringfield pool on a structure when needed, and remove some unnecessary code when the structure was being freed

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45409 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Kevin P. Fleming 19 years ago
parent 17fabe225d
commit 696f9ed677

@ -1751,7 +1751,7 @@ retry:
iax2_frame_free(frame.data); iax2_frame_free(frame.data);
jb_destroy(pvt->jb); jb_destroy(pvt->jb);
/* gotta free up the stringfields */ /* gotta free up the stringfields */
ast_string_field_free_all(pvt); ast_string_field_free_pools(pvt);
free(pvt); free(pvt);
} }
} }
@ -8309,7 +8309,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
peer->expire = -1; peer->expire = -1;
ast_clear_flag(peer, IAX_DYNAMIC); ast_clear_flag(peer, IAX_DYNAMIC);
if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) { if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) {
ast_string_field_free_all(peer); ast_string_field_free_pools(peer);
free(peer); free(peer);
return NULL; return NULL;
} }
@ -8320,7 +8320,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
inet_aton("255.255.255.255", &peer->mask); inet_aton("255.255.255.255", &peer->mask);
} else if (!strcasecmp(v->name, "defaultip")) { } else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&peer->defaddr, v->value)) { if (ast_get_ip(&peer->defaddr, v->value)) {
ast_string_field_free_all(peer); ast_string_field_free_pools(peer);
free(peer); free(peer);
return NULL; return NULL;
} }
@ -8456,7 +8456,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
if (user) { if (user) {
if (firstpass) { if (firstpass) {
ast_string_field_free_all(user); ast_string_field_free_pools(user);
memset(user, 0, sizeof(struct iax2_user)); memset(user, 0, sizeof(struct iax2_user));
if (ast_string_field_init(user, 32)) { if (ast_string_field_init(user, 32)) {
free(user); free(user);
@ -8654,7 +8654,7 @@ static void destroy_user(struct iax2_user *user)
ast_variables_destroy(user->vars); ast_variables_destroy(user->vars);
user->vars = NULL; user->vars = NULL;
} }
ast_string_field_free_all(user); ast_string_field_free_pools(user);
free(user); free(user);
} }
@ -8695,7 +8695,7 @@ static void destroy_peer(struct iax2_peer *peer)
register_peer_exten(peer, 0); register_peer_exten(peer, 0);
if (peer->dnsmgr) if (peer->dnsmgr)
ast_dnsmgr_release(peer->dnsmgr); ast_dnsmgr_release(peer->dnsmgr);
ast_string_field_free_all(peer); ast_string_field_free_pools(peer);
free(peer); free(peer);
} }

@ -716,7 +716,7 @@ struct sip_auth {
#define SIP_PROG_INBAND_NEVER (0 << 25) #define SIP_PROG_INBAND_NEVER (0 << 25)
#define SIP_PROG_INBAND_NO (1 << 25) #define SIP_PROG_INBAND_NO (1 << 25)
#define SIP_PROG_INBAND_YES (2 << 25) #define SIP_PROG_INBAND_YES (2 << 25)
#define SIP_FREE_BIT (1 << 27) /*!< Undefined bit - not in use */ #define SIP_NO_HISTORY (1 << 27) /*!< Suppress recording request/response history */
#define SIP_CALL_LIMIT (1 << 28) /*!< Call limit enforced for this call */ #define SIP_CALL_LIMIT (1 << 28) /*!< Call limit enforced for this call */
#define SIP_SENDRPID (1 << 29) /*!< Remote Party-ID Support */ #define SIP_SENDRPID (1 << 29) /*!< Remote Party-ID Support */
#define SIP_INC_COUNT (1 << 30) /*!< Did this connection increment the counter of in-use calls? */ #define SIP_INC_COUNT (1 << 30) /*!< Did this connection increment the counter of in-use calls? */
@ -1790,7 +1790,7 @@ static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
{ {
va_list ap; va_list ap;
if (!recordhistory || !p) if (!p)
return; return;
va_start(ap, fmt); va_start(ap, fmt);
append_history_va(p, fmt, ap); append_history_va(p, fmt, ap);
@ -1977,7 +1977,7 @@ static void sip_scheddestroy(struct sip_pvt *p, int ms)
} }
if (sip_debug_test_pvt(p)) if (sip_debug_test_pvt(p))
ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text); ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text);
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "SchedDestroy", "%d ms", ms); append_history(p, "SchedDestroy", "%d ms", ms);
if (p->autokillid > -1) if (p->autokillid > -1)
@ -2111,7 +2111,7 @@ static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmitty
ast_inet_ntoa(dst->sin_addr), ast_inet_ntoa(dst->sin_addr),
ntohs(dst->sin_port), req->data); ntohs(dst->sin_port), req->data);
} }
if (recordhistory) { if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
struct sip_request tmp; struct sip_request tmp;
parse_copy(&tmp, req); parse_copy(&tmp, req);
append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"),
@ -2137,7 +2137,7 @@ static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittyp
else else
ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data); ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
} }
if (recordhistory) { if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
struct sip_request tmp; struct sip_request tmp;
parse_copy(&tmp, req); parse_copy(&tmp, req);
append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text); append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text);
@ -2805,7 +2805,7 @@ static void sip_registry_destroy(struct sip_registry *reg)
ast_sched_del(sched, reg->expire); ast_sched_del(sched, reg->expire);
if (reg->timeout > -1) if (reg->timeout > -1)
ast_sched_del(sched, reg->timeout); ast_sched_del(sched, reg->timeout);
ast_string_field_free_all(reg); ast_string_field_free_pools(reg);
regobjs--; regobjs--;
free(reg); free(reg);
@ -2898,7 +2898,7 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner)
} }
ast_mutex_destroy(&p->lock); ast_mutex_destroy(&p->lock);
ast_string_field_free_all(p); ast_string_field_free_pools(p);
free(p); free(p);
} }
@ -3313,7 +3313,7 @@ static int sip_hangup(struct ast_channel *ast)
transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
/* Get RTCP quality before end of call */ /* Get RTCP quality before end of call */
if (recordhistory) { if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
if (p->rtp) if (p->rtp)
append_history(p, "RTCPaudio", "Quality:%s", audioqos); append_history(p, "RTCPaudio", "Quality:%s", audioqos);
if (p->vrtp) if (p->vrtp)
@ -3804,7 +3804,7 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
for (v = i->chanvars ; v ; v = v->next) for (v = i->chanvars ; v ; v = v->next)
pbx_builtin_setvar_helper(tmp,v->name,v->value); pbx_builtin_setvar_helper(tmp,v->name,v->value);
if (recordhistory) if (!ast_test_flag(&i->flags[0], SIP_NO_HISTORY))
append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid); append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
return tmp; return tmp;
@ -4112,6 +4112,8 @@ static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *si
ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
ast_set2_flag(&p->flags[0], !recordhistory, SIP_NO_HISTORY);
p->branch = ast_random(); p->branch = ast_random();
make_our_tag(p->tag, sizeof(p->tag)); make_our_tag(p->tag, sizeof(p->tag));
p->ocseq = INITIAL_CSEQ; p->ocseq = INITIAL_CSEQ;
@ -5543,12 +5545,14 @@ static int transmit_response_using_temp(ast_string_field callid, struct sockaddr
return -1; return -1;
} }
memset(p, 0, sizeof(*p)); /* if the structure was just allocated, initialize it */
if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
/* Initialize the bare minimum */ ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
if (ast_string_field_init(p, 512)) if (ast_string_field_init(p, 512))
return -1; return -1;
}
/* Initialize the bare minimum */
p->method = intended_method; p->method = intended_method;
if (sin) { if (sin) {
@ -5575,7 +5579,7 @@ static int transmit_response_using_temp(ast_string_field callid, struct sockaddr
/* Use this temporary pvt structure to send the message */ /* Use this temporary pvt structure to send the message */
__transmit_response(p, msg, req, XMIT_UNRELIABLE); __transmit_response(p, msg, req, XMIT_UNRELIABLE);
/* Now do a simple destruction */ /* Free the string fields, but not the pool space */
ast_string_field_free_all(p); ast_string_field_free_all(p);
return 0; return 0;
@ -6286,7 +6290,7 @@ static int transmit_reinvite_with_sdp(struct sip_pvt *p)
add_header(&req, "Supported", SUPPORTED_EXTENSIONS); add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
if (sipdebug) if (sipdebug)
add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)"); add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)");
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "ReInv", "Re-invite sent"); append_history(p, "ReInv", "Re-invite sent");
add_sdp(&req, p); add_sdp(&req, p);
/* Use this as the basis */ /* Use this as the basis */
@ -6911,7 +6915,7 @@ static int sip_reregister(void *data)
if (!r) if (!r)
return 0; return 0;
if (r->call && recordhistory) if (r->call && !ast_test_flag(&r->call->flags[0], SIP_NO_HISTORY))
append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname); append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname);
/* Since registry's are only added/removed by the the monitor thread, this /* Since registry's are only added/removed by the the monitor thread, this
may be overkill to reference/dereference at all here */ may be overkill to reference/dereference at all here */
@ -7011,7 +7015,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n"); ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n");
return 0; return 0;
} }
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname); append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
/* Find address to hostname */ /* Find address to hostname */
if (create_addr(p, r->hostname)) { if (create_addr(p, r->hostname)) {
@ -10818,7 +10822,7 @@ static int do_register_auth(struct sip_pvt *p, struct sip_request *req, enum sip
/* No old challenge */ /* No old challenge */
return -1; return -1;
} }
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "RegistryAuth", "Try: %d", p->authtries); append_history(p, "RegistryAuth", "Try: %d", p->authtries);
if (sip_debug_test_pvt(p) && p->registry) if (sip_debug_test_pvt(p) && p->registry)
ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname); ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname);
@ -13037,7 +13041,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n"); ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n");
} }
if (recordhistory) /* This is a response, note what it was for */ if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a response, note what it was for */
append_history(p, "ReInv", "Re-invite received"); append_history(p, "ReInv", "Re-invite received");
} }
} else if (debug) } else if (debug)
@ -13836,18 +13840,18 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
ast_set_flag(&p->flags[0], SIP_ALREADYGONE); ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
/* Get RTCP quality before end of call */ /* Get RTCP quality before end of call */
if (recordhistory || p->owner) { if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY) || p->owner) {
char *audioqos, *videoqos; char *audioqos, *videoqos;
if (p->rtp) { if (p->rtp) {
audioqos = ast_rtp_get_quality(p->rtp); audioqos = ast_rtp_get_quality(p->rtp);
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "RTCPaudio", "Quality:%s", audioqos); append_history(p, "RTCPaudio", "Quality:%s", audioqos);
if (p->owner) if (p->owner)
pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", audioqos); pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", audioqos);
} }
if (p->vrtp) { if (p->vrtp) {
videoqos = ast_rtp_get_quality(p->vrtp); videoqos = ast_rtp_get_quality(p->vrtp);
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "RTCPvideo", "Quality:%s", videoqos); append_history(p, "RTCPvideo", "Quality:%s", videoqos);
if (p->owner) if (p->owner)
pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos); pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
@ -14469,7 +14473,7 @@ static int sipsock_read(int *id, int fd, short events, void *ignore)
} }
p->recv = sin; p->recv = sin;
if (recordhistory) /* This is a request or response, note what it was for */ if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a request or response, note what it was for */
append_history(p, "Rx", "%s / %s / %s", req.data, get_header(&req, "CSeq"), req.rlPart2); append_history(p, "Rx", "%s / %s / %s", req.data, get_header(&req, "CSeq"), req.rlPart2);
if (!lockretry) { if (!lockretry) {
@ -16465,7 +16469,7 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struc
} }
if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) { if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
if (chan->_state != AST_STATE_UP) { /* We are in early state */ if (chan->_state != AST_STATE_UP) { /* We are in early state */
if (recordhistory) if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal."); append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip)); ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip));

@ -248,6 +248,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
} \ } \
} while (0) } while (0)
#endif #endif
/*! /*!
\brief Set a field to a simple string value \brief Set a field to a simple string value
\param x Pointer to a structure containing fields \param x Pointer to a structure containing fields
@ -262,6 +263,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
#define ast_string_field_logset(x, field, data, logstr) \ #define ast_string_field_logset(x, field, data, logstr) \
ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr) ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr)
#endif #endif
/*! /*!
\brief Set a field to a complex (built) value \brief Set a field to a complex (built) value
\param x Pointer to a structure containing fields \param x Pointer to a structure containing fields
@ -312,7 +314,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
ast_string_field_index_free(x, ast_string_field_index(x, field)) ast_string_field_index_free(x, ast_string_field_index(x, field))
/*! /*!
\brief Free all fields (and the storage pool) in a structure \brief Free the stringfield storage pools attached to a structure
\param x Pointer to a structure containing fields \param x Pointer to a structure containing fields
\return nothing \return nothing
@ -320,15 +322,29 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
structure; it should only be called immediately before freeing structure; it should only be called immediately before freeing
the structure itself. the structure itself.
*/ */
#define ast_string_field_free_all(x) do { \ #define ast_string_field_free_pools(x) do { \
int index; \
struct ast_string_field_pool *this, *prev; \ struct ast_string_field_pool *this, *prev; \
for (index = 0; index < ast_string_field_count(x); index ++) \
ast_string_field_index_free(x, index); \
for (this = (x)->__field_mgr.pool; this; this = prev) { \ for (this = (x)->__field_mgr.pool; this; this = prev) { \
prev = this->prev; \ prev = this->prev; \
free(this); \ free(this); \
} \ } \
} while(0) } while(0)
/*!
\brief Free the stringfields in a structure
\param x Pointer to a structure containing fields
\return nothing
After calling this macro, the most recently allocated pool
attached to the structure will be available for use by
stringfields again.
*/
#define ast_string_field_free_all(x) do { \
int index; \
for (index = 0; index < ast_string_field_count(x); index++) \
ast_string_field_index_free(x, index); \
(x)->__field_mgr.used = 0; \
(x)->__field_mgr.space = (x)->__field_mgr.size; \
} while(0)
#endif /* _ASTERISK_STRINGFIELDS_H */ #endif /* _ASTERISK_STRINGFIELDS_H */

@ -142,7 +142,7 @@
#include "asterisk.h" #include "asterisk.h"
#ifndef STANDALONE #ifndef STANDALONE
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40546 $") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#endif #endif
#include <sys/types.h> #include <sys/types.h>

@ -654,7 +654,7 @@ struct ast_channel *ast_channel_alloc(int needqueue)
if (needqueue) { if (needqueue) {
if (pipe(tmp->alertpipe)) { if (pipe(tmp->alertpipe)) {
ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n"); ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
ast_string_field_free_all(tmp); ast_string_field_free_pools(tmp);
free(tmp); free(tmp);
return NULL; return NULL;
} else { } else {
@ -1055,7 +1055,7 @@ void ast_channel_free(struct ast_channel *chan)
/* Destroy the jitterbuffer */ /* Destroy the jitterbuffer */
ast_jb_destroy(chan); ast_jb_destroy(chan);
ast_string_field_free_all(chan); ast_string_field_free_pools(chan);
free(chan); free(chan);
AST_LIST_UNLOCK(&channels); AST_LIST_UNLOCK(&channels);

Loading…
Cancel
Save