@ -4243,45 +4243,46 @@ static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *si
static int sip_register ( char * value , int lineno )
static int sip_register ( char * value , int lineno )
{
{
struct sip_registry * reg ;
struct sip_registry * reg ;
char copy [ 256 ] ;
int portnum = 0 ;
char * username = NULL , * hostname = NULL , * secret = NULL , * authuser = NULL ;
char username [ 256 ] = " " ;
char * hostname = NULL , * secret = NULL , * authuser = NULL ;
char * porta = NULL ;
char * porta = NULL ;
char * contact = NULL ;
char * contact = NULL ;
char * stringp = NULL ;
if ( ! value )
if ( ! value )
return - 1 ;
return - 1 ;
ast_copy_string ( copy , value , sizeof ( copy ) ) ;
ast_copy_string ( username , value , sizeof ( username ) ) ;
stringp = copy ;
/* First split around the last '@' then parse the two components. */
username = stringp ;
hostname = strrchr ( username , ' @ ' ) ; /* allow @ in the first part */
hostname = strrchr ( stringp , ' @ ' ) ;
if ( hostname )
if ( hostname )
* hostname + + = ' \0 ' ;
* hostname + + = ' \0 ' ;
if ( ast_strlen_zero ( username ) | | ast_strlen_zero ( hostname ) ) {
if ( ast_strlen_zero ( username ) | | ast_strlen_zero ( hostname ) ) {
ast_log ( LOG_WARNING , " Format for registration is user[:secret[:authuser]]@host[:port][/contact] at line %d \n " , lineno ) ;
ast_log ( LOG_WARNING , " Format for registration is user[:secret[:authuser]]@host[:port][/contact] at line %d \n " , lineno ) ;
return - 1 ;
return - 1 ;
}
}
stringp = username ;
/* split user[:secret[:authuser]] */
username = strsep ( & stringp , " : " ) ;
secret = strchr ( username , ' : ' ) ;
if ( username ) {
if ( secret ) {
secret = strsep ( & stringp , " : " ) ;
* secret + + = ' \0 ' ;
if ( secret )
authuser = strchr ( secret , ' : ' ) ;
authuser = strsep ( & stringp , " : " ) ;
if ( authuser )
* authuser + + = ' \0 ' ;
}
}
stringp = hostname ;
/* split host[:port][/contact] */
hostname = strsep ( & stringp , " / " ) ;
contact = strchr ( hostname , ' / ' ) ;
if ( hostname)
if ( contact)
contact = strsep ( & stringp , " / " ) ;
* contact + + = ' \0 ' ;
if ( ast_strlen_zero ( contact ) )
if ( ast_strlen_zero ( contact ) )
contact = " s " ;
contact = " s " ;
stringp= hostname ;
porta = strchr ( hostname , ' : ' ) ;
hostname = strsep ( & stringp , " : " ) ;
if ( porta ) {
porta = strsep ( & stringp , " : " ) ;
* porta + + = ' \0 ' ;
portnum = atoi ( porta ) ;
if ( porta & & ! atoi ( porta ) ) {
if ( portnum = = 0 ) {
ast_log ( LOG_WARNING , " %s is not a valid port number at line %d \n " , porta , lineno ) ;
ast_log ( LOG_WARNING , " %s is not a valid port number at line %d \n " , porta , lineno ) ;
return - 1 ;
return - 1 ;
}
}
}
if ( ! ( reg = ast_calloc ( 1 , sizeof ( * reg ) ) ) ) {
if ( ! ( reg = ast_calloc ( 1 , sizeof ( * reg ) ) ) ) {
ast_log ( LOG_ERROR , " Out of memory. Can't allocate SIP registry entry \n " ) ;
ast_log ( LOG_ERROR , " Out of memory. Can't allocate SIP registry entry \n " ) ;
return - 1 ;
return - 1 ;
@ -4307,7 +4308,7 @@ static int sip_register(char *value, int lineno)
reg - > expire = - 1 ;
reg - > expire = - 1 ;
reg - > timeout = - 1 ;
reg - > timeout = - 1 ;
reg - > refresh = default_expiry ;
reg - > refresh = default_expiry ;
reg - > portno = port a ? atoi ( porta ) : 0 ;
reg - > portno = port num ;
reg - > callid_valid = FALSE ;
reg - > callid_valid = FALSE ;
reg - > ocseq = INITIAL_CSEQ ;
reg - > ocseq = INITIAL_CSEQ ;
ASTOBJ_CONTAINER_LINK ( & regl , reg ) ; /* Add the new registry entry to the list */
ASTOBJ_CONTAINER_LINK ( & regl , reg ) ; /* Add the new registry entry to the list */
@ -15368,6 +15369,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
struct ast_variable * tmpvar = NULL ;
struct ast_variable * tmpvar = NULL ;
struct ast_flags peerflags [ 2 ] = { { ( 0 ) } } ;
struct ast_flags peerflags [ 2 ] = { { ( 0 ) } } ;
struct ast_flags mask [ 2 ] = { { ( 0 ) } } ;
struct ast_flags mask [ 2 ] = { { ( 0 ) } } ;
char contact [ 256 ] = " " ;
if ( ! realtime )
if ( ! realtime )
@ -15503,6 +15505,8 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_copy_string ( peer - > language , v - > value , sizeof ( peer - > language ) ) ;
ast_copy_string ( peer - > language , v - > value , sizeof ( peer - > language ) ) ;
} else if ( ! strcasecmp ( v - > name , " regexten " ) ) {
} else if ( ! strcasecmp ( v - > name , " regexten " ) ) {
ast_copy_string ( peer - > regexten , v - > value , sizeof ( peer - > regexten ) ) ;
ast_copy_string ( peer - > regexten , v - > value , sizeof ( peer - > regexten ) ) ;
} else if ( ! strcasecmp ( v - > name , " contact " ) ) {
ast_copy_string ( contact , v - > value , sizeof ( contact ) ) ;
} else if ( ! strcasecmp ( v - > name , " call-limit " ) ) {
} else if ( ! strcasecmp ( v - > name , " call-limit " ) ) {
peer - > call_limit = atoi ( v - > value ) ;
peer - > call_limit = atoi ( v - > value ) ;
if ( peer - > call_limit < 0 )
if ( peer - > call_limit < 0 )
@ -15612,6 +15616,15 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
reg_source_db ( peer ) ;
reg_source_db ( peer ) ;
ASTOBJ_UNMARK ( peer ) ;
ASTOBJ_UNMARK ( peer ) ;
ast_free_ha ( oldha ) ;
ast_free_ha ( oldha ) ;
if ( ! ast_strlen_zero ( contact ) ) { /* build string from peer info */
char * reg_string ;
asprintf ( & reg_string , " %s:%s@%s/%s " , peer - > username , peer - > secret , peer - > tohost , contact ) ;
if ( reg_string ) {
sip_register ( reg_string , 0 ) ; /* XXX TODO: count in registry_count */
free ( reg_string ) ;
}
}
return peer ;
return peer ;
}
}