Module: sip-router Branch: admorten/sca Commit: 36b6571500880d046064ed05a22ce225bf45e9db URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=36b65715...
Author: Andrew Mortensen admorten@isc.upenn.edu Committer: Andrew Mortensen admorten@isc.upenn.edu Date: Sun Mar 3 16:59:23 2013 -0500
sca: make sca_reply a generic reply function.
- take a pre-filled extra_headers parameter instead, add with add_lump_rpl.
---
modules/sca/sca_reply.c | 55 ++++++----------------------------------------- modules/sca/sca_reply.h | 5 +-- 2 files changed, 9 insertions(+), 51 deletions(-)
diff --git a/modules/sca/sca_reply.c b/modules/sca/sca_reply.c index 8da3a6e..3e2f910 100644 --- a/modules/sca/sca_reply.c +++ b/modules/sca/sca_reply.c @@ -31,63 +31,22 @@
int sca_reply( sca_mod *scam, int status_code, char *status_msg, - int event_type, int expires, sip_msg_t *msg ) + str *extra_headers, sip_msg_t *msg ) { str status_str = STR_NULL; - str extra_headers = STR_NULL; - char hdr_buf[ 1024 ]; - int len;
assert( scam != NULL && scam->sl_api != NULL ); assert( msg != NULL );
- if ( event_type != SCA_EVENT_TYPE_CALL_INFO && - event_type != SCA_EVENT_TYPE_LINE_SEIZE ) { - LM_ERR( "Unrecognized event type %d", event_type ); - return( -1 ); - } - status_str.s = status_msg; status_str.len = strlen( status_msg );
- if ( status_code < 300 ) { - /* Add Event, Contact, Allow-Events and Expires headers */ - extra_headers.s = hdr_buf; - len = snprintf( extra_headers.s, sizeof( hdr_buf ), - "Event: %s%s", sca_event_name_from_type( event_type ), CRLF ); - extra_headers.len = len; - - SCA_STR_APPEND_CSTR( &extra_headers, "Contact: " ); - SCA_STR_APPEND( &extra_headers, &REQ_LINE( msg ).uri ); - SCA_STR_APPEND_CSTR( &extra_headers, CRLF ); - - SCA_STR_COPY_CSTR( &extra_headers, - "Allow-Events: call-info, line-seize" CRLF ); - - SCA_STR_COPY_CSTR( &extra_headers, "Expires: " ); - - len = snprintf( extra_headers.s + extra_headers.len, - sizeof( hdr_buf ) - extra_headers.len, - "%d%s", expires, CRLF ); - extra_headers.len += len; - - if ( add_lump_rpl( msg, extra_headers.s, extra_headers.len, - LUMP_RPL_HDR ) == NULL ) { - LM_ERR( "Failed to add Allow-Events and Expires headers" ); - return( -1 ); - } - } else if ( status_code == 480 ) { - /* tell loser of line-seize SUBSCRIBE race to try again shortly */ - extra_headers.s = hdr_buf; - len = snprintf( extra_headers.s, sizeof( hdr_buf ), - "Retry-After: %d%s", 1, CRLF ); - extra_headers.len = len; - - if ( add_lump_rpl( msg, extra_headers.s, extra_headers.len, - LUMP_RPL_HDR ) == NULL ) { - LM_ERR( "sca_reply: failed to add Retry-After header" ); - return( -1 ); - } + if ( extra_headers && extra_headers->len ) { + if ( add_lump_rpl( msg, extra_headers->s, extra_headers->len, + LUMP_RPL_HDR ) == NULL ) { + LM_ERR("sca_subscription_reply: failed to add Retry-After header"); + return( -1 ); + } }
if ( scam->sl_api->freply( msg, status_code, &status_str ) < 0 ) { diff --git a/modules/sca/sca_reply.h b/modules/sca/sca_reply.h index a8b1131..e2c5d1a 100644 --- a/modules/sca/sca_reply.h +++ b/modules/sca/sca_reply.h @@ -28,9 +28,8 @@ #include "sca.h"
#define SCA_REPLY_ERROR( mod, scode, smsg, sreply ) \ - sca_reply((mod), (scode), (smsg), SCA_EVENT_TYPE_CALL_INFO, -1, \ - (sreply)) + sca_reply((mod), (scode), (smsg), NULL, (sreply))
-int sca_reply( sca_mod *, int, char *, int, int, sip_msg_t * ); +int sca_reply( sca_mod *, int, char *, str *, sip_msg_t * );
#endif /* SCA_REPLY_H */