static int sip_show_subscriptions(int fd, int argc, char *argv[]);
static char *complete_sipch(const char *line, const char *word, int pos, int state);
static char *complete_sip_peer(const char *word, int state, int flags2);
+static char *complete_sip_registered_peer(const char *word, int state, int flags2);
static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state);
+static char *complete_sip_unregister(const char *line, const char *word, int pos, int state);
static char *complete_sip_debug_peer(const char *line, const char *word, int pos, int state);
static char *complete_sip_user(const char *word, int state, int flags2);
static char *complete_sip_show_user(const char *line, const char *word, int pos, int state);
#undef FORMAT2
}
-/*! \brief Unregister (force expiration) a SIP peer in the registry via CLI */
+/*! \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.
+*/
static int sip_unregister(int fd, int argc, char *argv[])
{
struct sip_peer *peer;
expire_register(peer);
ast_cli(fd, "Unregistered peer \'%s\'\n\n", argv[2]);
} else {
- ast_cli(fd, "Attempted to unregister an unknown peer \'%s\' via CLI\n", argv[2]);
+ ast_cli(fd, "Peer unknown: \'%s\'. Not unregistered.\n", argv[2]);
}
return 0;
return result;
}
+/*! \brief Do completion on registered peer name */
+static char *complete_sip_registered_peer(const char *word, int state, int flags2)
+{
+ char *result = NULL;
+ int wordlen = strlen(word);
+ int which = 0;
+
+ ASTOBJ_CONTAINER_TRAVERSE(&peerl, !result, do {
+ ASTOBJ_WRLOCK(iterator);
+ if (!strncasecmp(word, iterator->name, wordlen) &&
+ (!flags2 || ast_test_flag(&iterator->flags[1], flags2)) &&
+ ++which > state && iterator->expire > 0)
+ result = ast_strdup(iterator->name);
+ ASTOBJ_UNLOCK(iterator);
+ } while(0) );
+ return result;
+}
+
/*! \brief Support routine for 'sip show peer' CLI */
static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state)
{
return NULL;
}
+/*! \brief Support routine for 'sip unregister' CLI */
+static char *complete_sip_unregister(const char *line, const char *word, int pos, int state)
+{
+ if (pos == 2)
+ return complete_sip_registered_peer(word, state, 0);
+
+ return NULL;
+}
+
/*! \brief Support routine for 'sip debug peer' CLI */
static char *complete_sip_debug_peer(const char *line, const char *word, int pos, int state)
{
{ { "sip", "unregister", NULL },
sip_unregister, "Unregister (force expiration) a SIP peer from the registery\n",
- sip_unregister_usage },
+ sip_unregister_usage, complete_sip_unregister },
{ { "sip", "show", "settings", NULL },
sip_show_settings, "Show SIP global settings",