diff -NaurbB old/chan_sip.c new/chan_sip.c --- old/chan_sip.c 2009-01-21 17:00:22.000000000 +0000 +++ new/chan_sip.c 2009-01-22 16:14:37.000000000 +0000 @@ -1614,6 +1614,7 @@ ); enum sip_transport transport; /*!< Transport for this registration UDP, TCP or TLS */ int portno; /*!< Optional port override */ + int id; /*!< Identifier (ordered as registration strings appear in sip.conf) */ int expire; /*!< Sched ID of expiration */ int expiry; /*!< Value to use for the Expires header */ int regattempts; /*!< Number of attempts (since the last success) */ @@ -2047,6 +2048,7 @@ static char *_sip_qualify_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]); static char *sip_qualify_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); +static char *sip_show_registration(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); static const char *subscription_type2str(enum subscriptiontype subtype) attribute_pure; @@ -6525,6 +6527,9 @@ ast_atomic_fetchadd_int(®objs, 1); ASTOBJ_INIT(reg); + + reg->id = regobjs; + ast_string_field_set(reg, callback, callback); if (!ast_strlen_zero(username)) ast_string_field_set(reg, username, username); @@ -12643,14 +12648,24 @@ ASTOBJ_RDLOCK(iterator); astman_append(s, "Event: RegistryEntry\r\n" + "ID: %d\r\n" "Host: %s\r\n" "Port: %d\r\n" "Username: %s\r\n" + "Exten: %s\r\n" "Refresh: %d\r\n" "State: %s\r\n" "RegistrationTime: %ld\r\n" - "\r\n", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT, - iterator->username, iterator->refresh, regstate2str(iterator->regstate), (long) iterator->regtime.tv_sec); + "\r\n", + iterator->id, + iterator->hostname, + iterator->portno ? iterator->portno : STANDARD_SIP_PORT, + iterator->username, + iterator->callback, + iterator->refresh, + regstate2str(iterator->regstate), + (long) iterator->regtime.tv_sec + ); ASTOBJ_UNLOCK(iterator); total++; } while(0)); @@ -13791,8 +13806,8 @@ /*! \brief Show SIP Registry (registrations with other SIP proxies */ static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { -#define FORMAT2 "%-30.30s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" -#define FORMAT "%-30.30s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" +#define FORMAT2 "%3.3s %-30.30s %-6.6s %-15.15s %-15.15s %8.8s %-20.20s %-25.25s\n" +#define FORMAT "%3d %-30.30s %-6.6s %-15.15s %-15.15s %8d %-20.20s %-25.25s\n" char host[80]; char tmpdat[256]; struct ast_tm tm; @@ -13811,7 +13826,7 @@ if (a->argc != 3) return CLI_SHOWUSAGE; - ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time"); + ast_cli(a->fd, FORMAT2, "ID", "Host", "dnsmgr", "Username", "Exten", "Refresh", "State", "Reg.Time"); ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { ASTOBJ_RDLOCK(iterator); @@ -13821,7 +13836,7 @@ ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); } else tmpdat[0] = '\0'; - ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat); + ast_cli(a->fd, FORMAT, iterator->id, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->callback, iterator->refresh, regstate2str(iterator->regstate), tmpdat); ASTOBJ_UNLOCK(iterator); counter++; } while(0)); @@ -13831,6 +13846,61 @@ #undef FORMAT2 } +/*! \brief Show SIP Registration (registration details with other SIP proxy */ +static char *sip_show_registration(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + int counter = 0; + int match = 0; + char tmpdat[256]; + struct ast_tm tm; + + switch (cmd) { + case CLI_INIT: + e->command = "sip show registration"; + e->usage = + "Usage: sip show registration \n" + " Shows details of registration request.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 4) + return CLI_SHOWUSAGE; + + ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { + ASTOBJ_RDLOCK(iterator); + if (iterator->id == atoi(a->argv[3])) { + match=1; + ast_cli(a->fd,"\n\n"); + ast_cli(a->fd,"* ID : %d\n",iterator->id); + ast_cli(a->fd,"Host : %s\n",iterator->hostname); + ast_cli(a->fd,"Port : %d\n",iterator->portno ? iterator->portno : STANDARD_SIP_PORT); + ast_cli(a->fd,"Username : %s\n",iterator->username); + ast_cli(a->fd,"Exten : %s\n",iterator->callback); + ast_cli(a->fd,"Refresh : %d\n",iterator->refresh); + ast_cli(a->fd,"State : %s\n",regstate2str(iterator->regstate)); + if (iterator->regtime.tv_sec) { + ast_localtime(&iterator->regtime, &tm, NULL); + ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); + } else { + tmpdat[0] = '\0'; + } + ast_cli(a->fd,"RegistrationTime: %s\n",tmpdat); + ast_cli(a->fd,"\n"); + + } + ASTOBJ_UNLOCK(iterator); + counter++; + } while(0)); + if (!match) { + ast_cli(a->fd, "Registration with ID %s not found.\n", a->argv[3]); + ast_cli(a->fd, "\n"); + } + return CLI_SUCCESS; +} + + /*! \brief Unregister (force expiration) a SIP peer in the registry via CLI \note This function does not tell the SIP device what's going on, so use it with great care. @@ -23252,6 +23322,7 @@ AST_CLI_DEFINE(sip_show_objects, "List all SIP object allocations"), AST_CLI_DEFINE(sip_show_peers, "List defined SIP peers"), AST_CLI_DEFINE(sip_show_registry, "List SIP registration status"), + AST_CLI_DEFINE(sip_show_registration, "Show details on specific SIP registration"), AST_CLI_DEFINE(sip_unregister, "Unregister (force expiration) a SIP peer from the registry"), AST_CLI_DEFINE(sip_show_settings, "Show SIP global settings"), AST_CLI_DEFINE(sip_cli_notify, "Send a notify packet to a SIP peer"),