[asterisk-commits] markster: branch markster/usersconf r38416 - in
/team/markster/usersconf: ./ ...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Jul 28 10:03:04 MST 2006
Author: markster
Date: Fri Jul 28 12:03:03 2006
New Revision: 38416
URL: http://svn.digium.com/view/asterisk?rev=38416&view=rev
Log:
Initial changes to support users.conf...
Modified:
team/markster/usersconf/ (props changed)
team/markster/usersconf/apps/app_directory.c
team/markster/usersconf/apps/app_voicemail.c
team/markster/usersconf/channels/chan_iax2.c
team/markster/usersconf/channels/chan_sip.c
team/markster/usersconf/channels/chan_zap.c
team/markster/usersconf/config.c
team/markster/usersconf/configs/extensions.conf.sample
team/markster/usersconf/configs/voicemail.conf.sample
team/markster/usersconf/include/asterisk/config.h
team/markster/usersconf/include/asterisk/pbx.h
team/markster/usersconf/manager.c
team/markster/usersconf/pbx.c
team/markster/usersconf/pbx/pbx_config.c
Propchange: team/markster/usersconf/
------------------------------------------------------------------------------
automerge = *
Propchange: team/markster/usersconf/
------------------------------------------------------------------------------
automerge-email = markster at digium.com
Propchange: team/markster/usersconf/
------------------------------------------------------------------------------
svnmerge-integrated = /trunk:1-38414
Modified: team/markster/usersconf/apps/app_directory.c
URL: http://svn.digium.com/view/asterisk/team/markster/usersconf/apps/app_directory.c?rev=38416&r1=38415&r2=38416&view=diff
==============================================================================
--- team/markster/usersconf/apps/app_directory.c (original)
+++ team/markster/usersconf/apps/app_directory.c Fri Jul 28 12:03:03 2006
@@ -388,10 +388,10 @@
return cfg;
}
-static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit, int last, int readext)
+static int do_directory(struct ast_channel *chan, struct ast_config *cfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int last, int readext)
{
/* Read in the first three digits.. "digit" is the first digit, already read */
- char ext[NUMDIGITS + 1];
+ char ext[NUMDIGITS + 1], *cat;
char name[80] = "";
struct ast_variable *v;
int res;
@@ -494,6 +494,58 @@
}
}
+ if (!res && ucfg) {
+ /* Search users.conf for all names which start with those digits */
+ for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) {
+ if (!strcasecmp(cat, "general"))
+ continue;
+ if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
+ continue;
+
+ /* Find all candidate extensions */
+ if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) {
+ ast_copy_string(name, pos, sizeof(name));
+ /* Grab the last name */
+ if (last && strrchr(pos,' '))
+ pos = strrchr(pos, ' ') + 1;
+ conv = convert(pos);
+ if (conv) {
+ if (!strcmp(conv, ext)) {
+ /* Match! */
+ found++;
+ /* We have a match -- play a greeting if they have it */
+ res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext);
+ switch (res) {
+ case -1:
+ /* user pressed '1' but extension does not exist, or
+ * user hungup
+ */
+ lastuserchoice = 0;
+ break;
+ case '1':
+ /* user pressed '1' and extensions exists;
+ play_mailbox_owner will already have done
+ a goto() on the channel
+ */
+ lastuserchoice = res;
+ break;
+ case '*':
+ /* user pressed '*' to skip something found */
+ lastuserchoice = res;
+ res = 0;
+ break;
+ default:
+ break;
+ }
+ free(conv);
+ break;
+ }
+ free(conv);
+ }
+ }
+ }
+ }
+
if (lastuserchoice != '1') {
res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language);
if (!res)
@@ -509,7 +561,7 @@
{
int res = 0;
struct localuser *u;
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
int last = 1;
int readext = 0;
char *dirintro, *parse;
@@ -546,6 +598,8 @@
LOCAL_USER_REMOVE(u);
return -1;
}
+
+ ucfg = ast_config_load("users.conf");
dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
if (ast_strlen_zero(dirintro))
@@ -563,7 +617,7 @@
if (!res)
res = ast_waitfordigit(chan, 5000);
if (res > 0) {
- res = do_directory(chan, cfg, args.vmcontext, args.dialcontext, res, last, readext);
+ res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, last, readext);
if (res > 0) {
res = ast_waitstream(chan, AST_DIGIT_ANY);
ast_stopstream(chan);
@@ -573,6 +627,8 @@
}
break;
}
+ if (ucfg)
+ ast_config_destroy(ucfg);
ast_config_destroy(cfg);
LOCAL_USER_REMOVE(u);
return res;
Modified: team/markster/usersconf/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/markster/usersconf/apps/app_voicemail.c?rev=38416&r1=38415&r2=38416&view=diff
==============================================================================
--- team/markster/usersconf/apps/app_voicemail.c (original)
+++ team/markster/usersconf/apps/app_voicemail.c Fri Jul 28 12:03:03 2006
@@ -330,6 +330,8 @@
static char VM_SPOOL_DIR[PATH_MAX];
static char ext_pass_cmd[128];
+
+static char userscontext[AST_MAX_EXTENSION] = "default";
static char *tdesc = "Comedian Mail (Voicemail System)";
@@ -563,9 +565,32 @@
}
}
+static void apply_options_full(struct ast_vm_user *retval, struct ast_variable *var)
+{
+ struct ast_variable *tmp;
+ tmp = var;
+ while (tmp) {
+ if (!strcasecmp(tmp->name, "password")) {
+ ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
+ } else if (!strcasecmp(tmp->name, "uniqueid")) {
+ ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
+ } else if (!strcasecmp(tmp->name, "pager")) {
+ ast_copy_string(retval->pager, tmp->value, sizeof(retval->pager));
+ } else if (!strcasecmp(tmp->name, "email")) {
+ ast_copy_string(retval->email, tmp->value, sizeof(retval->email));
+ } else if (!strcasecmp(tmp->name, "fullname")) {
+ ast_copy_string(retval->fullname, tmp->value, sizeof(retval->fullname));
+ } else if (!strcasecmp(tmp->name, "context")) {
+ ast_copy_string(retval->context, tmp->value, sizeof(retval->context));
+ } else
+ apply_option(retval, tmp->name, tmp->value);
+ tmp = tmp->next;
+ }
+}
+
static struct ast_vm_user *find_user_realtime(struct ast_vm_user *ivm, const char *context, const char *mailbox)
{
- struct ast_variable *var, *tmp;
+ struct ast_variable *var;
struct ast_vm_user *retval;
if ((retval = (ivm ? ivm : ast_calloc(1, sizeof(*retval))))) {
@@ -581,25 +606,7 @@
else
var = ast_load_realtime("voicemail", "mailbox", mailbox, "context", context, NULL);
if (var) {
- tmp = var;
- while (tmp) {
- printf("%s => %s\n", tmp->name, tmp->value);
- if (!strcasecmp(tmp->name, "password")) {
- ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
- } else if (!strcasecmp(tmp->name, "uniqueid")) {
- ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
- } else if (!strcasecmp(tmp->name, "pager")) {
- ast_copy_string(retval->pager, tmp->value, sizeof(retval->pager));
- } else if (!strcasecmp(tmp->name, "email")) {
- ast_copy_string(retval->email, tmp->value, sizeof(retval->email));
- } else if (!strcasecmp(tmp->name, "fullname")) {
- ast_copy_string(retval->fullname, tmp->value, sizeof(retval->fullname));
- } else if (!strcasecmp(tmp->name, "context")) {
- ast_copy_string(retval->context, tmp->value, sizeof(retval->context));
- } else
- apply_option(retval, tmp->name, tmp->value);
- tmp = tmp->next;
- }
+ apply_options_full(retval, var);
ast_variables_destroy(var);
} else {
if (!ivm)
@@ -5911,6 +5918,26 @@
return res;
}
+static struct ast_vm_user *find_or_create(char *context, char *mbox)
+{
+ struct ast_vm_user *vmu;
+ AST_LIST_TRAVERSE(&users, vmu, list) {
+ if (ast_test_flag((&globalflags), VM_SEARCH) && !strcasecmp(mbox, vmu->mailbox))
+ break;
+ if (context && (!strcasecmp(context, vmu->context)) && (!strcasecmp(mbox, vmu->mailbox)))
+ break;
+ }
+
+ if (!vmu) {
+ if ((vmu = ast_calloc(1, sizeof(*vmu)))) {
+ ast_copy_string(vmu->context, context, sizeof(vmu->context));
+ ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox));
+ AST_LIST_INSERT_TAIL(&users, vmu, list);
+ }
+ }
+ return vmu;
+}
+
static int append_mailbox(char *context, char *mbox, char *data)
{
/* Assumes lock is already held */
@@ -5920,10 +5947,7 @@
struct ast_vm_user *vmu;
ast_copy_string(tmp, data, sizeof(tmp));
- if ((vmu = ast_calloc(1, sizeof(*vmu)))) {
- ast_copy_string(vmu->context, context, sizeof(vmu->context));
- ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox));
-
+ if ((vmu = find_or_create(context, mbox))) {
populate_defaults(vmu);
stringp = tmp;
@@ -5937,8 +5961,6 @@
ast_copy_string(vmu->pager, s, sizeof(vmu->pager));
if (stringp && (s = strsep(&stringp, ",")))
apply_options(vmu, s);
-
- AST_LIST_INSERT_TAIL(&users, vmu, list);
}
return 0;
}
@@ -6151,7 +6173,7 @@
{
struct ast_vm_user *cur;
struct vm_zone *zcur;
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
char *cat;
struct ast_variable *var;
char *notifystr = NULL;
@@ -6173,6 +6195,7 @@
char *thresholdstr;
char *fmt;
char *astemail;
+ char *ucontext;
char *astmailcmd = SENDMAIL;
char *astforcename;
char *astforcegreet;
@@ -6203,6 +6226,9 @@
if (cfg) {
/* General settings */
+ if (!(ucontext = ast_variable_retrieve(cfg, "general", "userscontext")))
+ ucontext = "default";
+ ast_copy_string(userscontext, ucontext, sizeof(userscontext));
/* Attach voice message to mail message ? */
if (!(astattach = ast_variable_retrieve(cfg, "general", "attach")))
astattach = "yes";
@@ -6450,6 +6476,17 @@
if (!(astdirfwd = ast_variable_retrieve(cfg, "general", "usedirectory")))
astdirfwd = "no";
ast_set2_flag((&globalflags), ast_true(astdirfwd), VM_DIRECFORWARD);
+ if ((ucfg = ast_config_load("users.conf"))) {
+ for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
+ if (!ast_true(ast_config_option(ucfg, cat, "hasvoicemail")))
+ continue;
+ if ((cur = find_or_create(userscontext, cat))) {
+ apply_options_full(cur, ast_variable_browse(ucfg, cat));
+ ast_copy_string(cur->context, userscontext, sizeof(cur->context));
+ }
+ }
+ ast_config_destroy(ucfg);
+ }
cat = ast_category_browse(cfg, NULL);
while (cat) {
if (strcasecmp(cat, "general")) {
Modified: team/markster/usersconf/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/markster/usersconf/channels/chan_iax2.c?rev=38416&r1=38415&r2=38416&view=diff
==============================================================================
--- team/markster/usersconf/channels/chan_iax2.c (original)
+++ team/markster/usersconf/channels/chan_iax2.c Fri Jul 28 12:03:03 2006
@@ -796,8 +796,8 @@
static int send_command_transfer(struct chan_iax2_pvt *, char, int, unsigned int, const unsigned char *, int);
static struct ast_channel *iax2_request(const char *type, int format, void *data, int *cause);
static struct ast_frame *iax2_read(struct ast_channel *c);
-static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, int temponly);
-static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly);
+static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly);
+static struct iax2_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly);
static void destroy_user(struct iax2_user *user);
static void prune_peers(void);
@@ -2447,7 +2447,7 @@
if (!var)
return NULL;
- peer = build_peer(peername, var, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
+ peer = build_peer(peername, var, NULL, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
if (!peer)
return NULL;
@@ -2534,7 +2534,7 @@
tmp = tmp->next;
}
- user = build_user(username, var, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
+ user = build_user(username, var, NULL, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
if (!user)
return NULL;
@@ -8204,17 +8204,20 @@
/*! \brief Create peer structure based on configuration */
-static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, int temponly)
+static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly)
{
struct iax2_peer *peer = NULL;
struct ast_ha *oldha = NULL;
int maskfound=0;
int found=0;
+ int firstpass=1;
AST_LIST_LOCK(&peers);
if (!temponly) {
AST_LIST_TRAVERSE(&peers, peer, entry) {
if (!strcmp(peer->name, name)) {
+ if (!ast_test_flag(peer, IAX_DELME))
+ firstpass = 0;
break;
}
}
@@ -8222,8 +8225,10 @@
peer = NULL;
if (peer) {
found++;
- oldha = peer->ha;
- peer->ha = NULL;
+ if (firstpass) {
+ oldha = peer->ha;
+ peer->ha = NULL;
+ }
AST_LIST_REMOVE(&peers, peer, entry);
AST_LIST_UNLOCK(&peers);
} else {
@@ -8235,22 +8240,28 @@
}
}
if (peer) {
- ast_copy_flags(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
- peer->encmethods = iax2_encryption;
- peer->adsi = adsi;
- peer->secret[0] = '\0';
- if (!found) {
- ast_copy_string(peer->name, name, sizeof(peer->name));
- peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
- peer->expiry = min_reg_expire;
- }
- peer->prefs = prefs;
- peer->capability = iax2_capability;
- peer->smoothing = 0;
- peer->pokefreqok = DEFAULT_FREQ_OK;
- peer->pokefreqnotok = DEFAULT_FREQ_NOTOK;
- peer->context[0] = '\0';
- peer->peercontext[0] = '\0';
+ if (firstpass) {
+ ast_copy_flags(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
+ peer->encmethods = iax2_encryption;
+ peer->adsi = adsi;
+ peer->secret[0] = '\0';
+ if (!found) {
+ ast_copy_string(peer->name, name, sizeof(peer->name));
+ peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
+ peer->expiry = min_reg_expire;
+ }
+ peer->prefs = prefs;
+ peer->capability = iax2_capability;
+ peer->smoothing = 0;
+ peer->pokefreqok = DEFAULT_FREQ_OK;
+ peer->pokefreqnotok = DEFAULT_FREQ_NOTOK;
+ peer->context[0] = '\0';
+ peer->peercontext[0] = '\0';
+ }
+ if (!v) {
+ v = alt;
+ alt = NULL;
+ }
while(v) {
if (!strcasecmp(v->name, "secret")) {
ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
@@ -8352,6 +8363,12 @@
ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name),
peer->cid_num, sizeof(peer->cid_num));
ast_set_flag(peer, IAX_HASCALLERID);
+ } else if (!strcasecmp(v->name, "fullname")) {
+ ast_copy_string(peer->cid_name, v->value, sizeof(peer->cid_name));
+ ast_set_flag(peer, IAX_HASCALLERID);
+ } else if (!strcasecmp(v->name, "number")) {
+ ast_copy_string(peer->cid_num, v->value, sizeof(peer->cid_num));
+ ast_set_flag(peer, IAX_HASCALLERID);
} else if (!strcasecmp(v->name, "sendani")) {
ast_set2_flag(peer, ast_true(v->value), IAX_SENDANI);
} else if (!strcasecmp(v->name, "inkeys")) {
@@ -8383,6 +8400,10 @@
peer->adsi = ast_true(v->value);
}/* else if (strcasecmp(v->name,"type")) */
/* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
+ if (!v) {
+ v = alt;
+ alt = NULL;
+ }
v=v->next;
}
if (!peer->authmethods)
@@ -8397,13 +8418,14 @@
}
/*! \brief Create in-memory user structure from configuration */
-static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly)
+static struct iax2_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly)
{
struct iax2_user *user = NULL;
struct iax2_context *con, *conl = NULL;
struct ast_ha *oldha = NULL;
struct iax2_context *oldcon = NULL;
int format;
+ int firstpass=1;
int oldcurauthreq = 0;
char *varname = NULL, *varval = NULL;
struct ast_variable *tmpvar = NULL;
@@ -8412,6 +8434,8 @@
if (!temponly) {
AST_LIST_TRAVERSE(&users, user, entry) {
if (!strcmp(user->name, name)) {
+ if (!ast_test_flag(user, IAX_DELME))
+ firstpass = 0;
break;
}
}
@@ -8419,11 +8443,13 @@
user = NULL;
if (user) {
- oldcurauthreq = user->curauthreq;
- oldha = user->ha;
- oldcon = user->contexts;
- user->ha = NULL;
- user->contexts = NULL;
+ if (firstpass) {
+ oldcurauthreq = user->curauthreq;
+ oldha = user->ha;
+ oldcon = user->contexts;
+ user->ha = NULL;
+ user->contexts = NULL;
+ }
/* Already in the list, remove it and it will be added back (or FREE'd) */
AST_LIST_REMOVE(&users, user, entry);
AST_LIST_UNLOCK(&users);
@@ -8434,16 +8460,22 @@
}
if (user) {
- memset(user, 0, sizeof(struct iax2_user));
- user->maxauthreq = maxauthreq;
- user->curauthreq = oldcurauthreq;
- user->prefs = prefs;
- user->capability = iax2_capability;
- user->encmethods = iax2_encryption;
- user->adsi = adsi;
- ast_copy_string(user->name, name, sizeof(user->name));
- ast_copy_string(user->language, language, sizeof(user->language));
- ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP);
+ if (firstpass) {
+ memset(user, 0, sizeof(struct iax2_user));
+ user->maxauthreq = maxauthreq;
+ user->curauthreq = oldcurauthreq;
+ user->prefs = prefs;
+ user->capability = iax2_capability;
+ user->encmethods = iax2_encryption;
+ user->adsi = adsi;
+ ast_copy_string(user->name, name, sizeof(user->name));
+ ast_copy_string(user->language, language, sizeof(user->language));
+ ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP);
+ }
+ if (!v) {
+ v = alt;
+ alt = NULL;
+ }
while(v) {
if (!strcasecmp(v->name, "context")) {
con = build_context(v->value);
@@ -8516,6 +8548,12 @@
} else if (!strcasecmp(v->name, "callerid")) {
ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
ast_set_flag(user, IAX_HASCALLERID);
+ } else if (!strcasecmp(v->name, "fullname")) {
+ ast_copy_string(user->cid_name, v->value, sizeof(user->cid_name));
+ ast_set_flag(user, IAX_HASCALLERID);
+ } else if (!strcasecmp(v->name, "number")) {
+ ast_copy_string(user->cid_num, v->value, sizeof(user->cid_num));
+ ast_set_flag(user, IAX_HASCALLERID);
} else if (!strcasecmp(v->name, "accountcode")) {
ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
} else if (!strcasecmp(v->name, "mohinterpret")) {
@@ -8542,6 +8580,10 @@
}/* else if (strcasecmp(v->name,"type")) */
/* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
v = v->next;
+ if (!v) {
+ v = alt;
+ alt = NULL;
+ }
}
if (!user->authmethods) {
if (!ast_strlen_zero(user->secret)) {
@@ -8686,7 +8728,7 @@
/*! \brief Load configuration */
static int set_config(char *config_file, int reload)
{
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
int capability=iax2_capability;
struct ast_variable *v;
char *cat;
@@ -8939,13 +8981,49 @@
min_reg_expire = max_reg_expire;
}
iax2_capability = capability;
+
+ ucfg = ast_config_load("users.conf");
+ if (ucfg) {
+ struct ast_variable *gen;
+ int genhasiax;
+ char *hasiax;
+
+ genhasiax = ast_true(ast_variable_retrieve(ucfg, "general", "hasiax"));
+ gen = ast_variable_browse(ucfg, "general");
+ cat = ast_category_browse(ucfg, NULL);
+ while (cat) {
+ if (strcasecmp(cat, "general")) {
+ hasiax = ast_variable_retrieve(ucfg, cat, "hasiax");
+ if (ast_true(hasiax) || (!hasiax && genhasiax)) {
+ /* Start with general parameters, then specific parameters, user and peer */
+ user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
+ if (user) {
+ AST_LIST_LOCK(&users);
+ AST_LIST_INSERT_HEAD(&users, user, entry);
+ AST_LIST_UNLOCK(&users);
+ }
+ peer = build_peer(cat, gen, ast_variable_browse(cfg, cat), 0);
+ if (peer) {
+ AST_LIST_LOCK(&peers);
+ AST_LIST_INSERT_HEAD(&peers, peer, entry);
+ AST_LIST_UNLOCK(&peers);
+ if (ast_test_flag(peer, IAX_DYNAMIC))
+ reg_source_db(peer);
+ }
+ }
+ }
+ cat = ast_category_browse(ucfg, cat);
+ }
+ ast_config_destroy(ucfg);
+ }
+
cat = ast_category_browse(cfg, NULL);
while(cat) {
if (strcasecmp(cat, "general")) {
utype = ast_variable_retrieve(cfg, cat, "type");
if (utype) {
if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend")) {
- user = build_user(cat, ast_variable_browse(cfg, cat), 0);
+ user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
if (user) {
AST_LIST_LOCK(&users);
AST_LIST_INSERT_HEAD(&users, user, entry);
@@ -8953,7 +9031,7 @@
}
}
if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat), 0);
+ peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
if (peer) {
AST_LIST_LOCK(&peers);
AST_LIST_INSERT_HEAD(&peers, peer, entry);
Modified: team/markster/usersconf/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/markster/usersconf/channels/chan_sip.c?rev=38416&r1=38415&r2=38416&view=diff
==============================================================================
--- team/markster/usersconf/channels/chan_sip.c (original)
+++ team/markster/usersconf/channels/chan_sip.c Fri Jul 28 12:03:03 2006
@@ -1353,7 +1353,7 @@
/*--- Device object handling */
static struct sip_peer *temp_peer(const char *name);
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime);
+static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime);
static int update_call_counter(struct sip_pvt *fup, int event);
static void sip_destroy_peer(struct sip_peer *peer);
@@ -2348,7 +2348,7 @@
}
/* Peer found in realtime, now build it in memory */
- peer = build_peer(newpeername, var, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS));
+ peer = build_peer(newpeername, var, NULL, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS));
if (!peer) {
ast_variables_destroy(var);
return NULL;
@@ -15008,6 +15008,10 @@
ast_copy_string(user->md5secret, v->value, sizeof(user->md5secret));
} else if (!strcasecmp(v->name, "callerid")) {
ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
+ } else if (!strcasecmp(v->name, "fullname")) {
+ ast_copy_string(user->cid_name, v->value, sizeof(user->cid_name));
+ } else if (!strcasecmp(v->name, "number")) {
+ ast_copy_string(user->cid_num, v->value, sizeof(user->cid_num));
} else if (!strcasecmp(v->name, "callgroup")) {
user->callgroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "pickupgroup")) {
@@ -15133,12 +15137,13 @@
}
/*! \brief Build peer from configuration (file or realtime static/dynamic) */
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime)
+static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
{
struct sip_peer *peer = NULL;
struct ast_ha *oldha = NULL;
int obproxyfound=0;
int found=0;
+ int firstpass=1;
int format=0; /* Ama flags */
time_t regseconds = 0;
char *varname = NULL, *varval = NULL;
@@ -15158,6 +15163,8 @@
if (peer) {
/* Already in the list, remove it and it will be added back (or FREE'd) */
found++;
+ if (!(peer->objflags & ASTOBJ_FLAG_MARKED))
+ firstpass = 0;
} else {
if (!(peer = ast_calloc(1, sizeof(*peer))))
return NULL;
@@ -15169,11 +15176,12 @@
ASTOBJ_INIT(peer);
}
/* Note that our peer HAS had its reference count incrased */
-
- peer->lastmsgssent = -1;
- oldha = peer->ha;
- peer->ha = NULL;
- set_peer_defaults(peer); /* Set peer defaults */
+ if (firstpass) {
+ peer->lastmsgssent = -1;
+ oldha = peer->ha;
+ peer->ha = NULL;
+ set_peer_defaults(peer); /* Set peer defaults */
+ }
if (!found && name)
ast_copy_string(peer->name, name, sizeof(peer->name));
@@ -15183,7 +15191,7 @@
peer->chanvars = NULL;
/* XXX should unregister ? */
}
- for (; v; v = v->next) {
+ for (; v || ((v = alt) && !(alt=NULL)); v = v->next) {
if (handle_common_options(&peerflags[0], &mask[0], v))
continue;
if (realtime && !strcasecmp(v->name, "regseconds")) {
@@ -15203,6 +15211,10 @@
peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno);
else if (!strcasecmp(v->name, "callerid")) {
ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num));
+ } else if (!strcasecmp(v->name, "fullname")) {
+ ast_copy_string(peer->cid_name, v->value, sizeof(peer->cid_name));
+ } else if (!strcasecmp(v->name, "number")) {
+ ast_copy_string(peer->cid_num, v->value, sizeof(peer->cid_num));
} else if (!strcasecmp(v->name, "context")) {
ast_copy_string(peer->context, v->value, sizeof(peer->context));
} else if (!strcasecmp(v->name, "subscribecontext")) {
@@ -15391,7 +15403,7 @@
*/
static int reload_config(enum channelreloadreason reason)
{
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
struct ast_variable *v;
struct sip_peer *peer;
struct sip_user *user;
@@ -15753,6 +15765,33 @@
authl = add_realm_authentication(authl, v->value, v->lineno);
}
+ ucfg = ast_config_load("users.conf");
+ if (ucfg) {
+ struct ast_variable *gen;
+ int genhassip;
+ char *hassip;
+
+ genhassip = ast_true(ast_variable_retrieve(ucfg, "general", "hassip"));
+ gen = ast_variable_browse(ucfg, "general");
+ cat = ast_category_browse(ucfg, NULL);
+ while (cat) {
+ if (strcasecmp(cat, "general")) {
+ hassip = ast_variable_retrieve(ucfg, cat, "hassip");
+ if (ast_true(hassip) || (!hassip && genhassip)) {
+ peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
+ if (peer) {
+ ASTOBJ_CONTAINER_LINK(&peerl,peer);
+ ASTOBJ_UNREF(peer, sip_destroy_peer);
+ peer_count++;
+ }
+ }
+ }
+ cat = ast_category_browse(ucfg, cat);
+ }
+ ast_config_destroy(ucfg);
+ }
+
+
/* Load peers, users and friends */
cat = NULL;
while ( (cat = ast_category_browse(cfg, cat)) ) {
@@ -15784,7 +15823,7 @@
}
}
if (is_peer) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat), 0);
+ peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
if (peer) {
ASTOBJ_CONTAINER_LINK(&peerl,peer);
ASTOBJ_UNREF(peer, sip_destroy_peer);
Modified: team/markster/usersconf/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/markster/usersconf/channels/chan_zap.c?rev=38416&r1=38415&r2=38416&view=diff
==============================================================================
--- team/markster/usersconf/channels/chan_zap.c (original)
+++ team/markster/usersconf/channels/chan_zap.c Fri Jul 28 12:03:03 2006
@@ -219,6 +219,7 @@
static int cid_signalling = CID_SIG_BELL;
static int cid_start = CID_START_RING;
static int zaptrcallerid = 0;
+static int cur_radio = 0;
static int cur_signalling = -1;
static int cur_outsignalling = -1;
@@ -10217,105 +10218,109 @@
#endif
return __unload_module();
}
-
-static int setup_zap(int reload)
-{
- struct ast_config *cfg;
- struct ast_variable *v;
- struct ast_variable *vjb;
+
+static int build_channels(int iscrv, char *value, int reload, int lineno, int *found_pseudo)
+{
+ char *c, *chan;
+ int x, y, start, finish;
struct zt_pvt *tmp;
- char *chan;
- char *c;
+#ifdef HAVE_PRI
+ struct zt_pri *pri;
+ int trunkgroup;
+#endif
+
+
+ if (reload == 0) {
+ if (cur_signalling < 0) {
+ ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
+ return -1;
+ }
+ }
+ c = value;
+
+#ifdef HAVE_PRI
+ pri = NULL;
+ if (iscrv) {
+ if (sscanf(c, "%d:%n", &trunkgroup, &y) != 1) {
+ ast_log(LOG_WARNING, "CRV must begin with trunkgroup followed by a colon at line %d\n", lineno);
+ return -1;
+ }
+ if (trunkgroup < 1) {
+ ast_log(LOG_WARNING, "CRV trunk group must be a postive number at line %d\n", lineno);
+ return -1;
+ }
+ c += y;
+ for (y = 0; y < NUM_SPANS; y++) {
+ if (pris[y].trunkgroup == trunkgroup) {
+ pri = pris + y;
+ break;
+ }
+ }
+ if (!pri) {
+ ast_log(LOG_WARNING, "No such trunk group %d at CRV declaration at line %d\n", trunkgroup, lineno);
+ return -1;
+ }
+ }
+#endif
+ chan = strsep(&c, ",");
+ while (chan) {
+ if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
+ /* Range */
+ } else if (sscanf(chan, "%d", &start)) {
+ /* Just one */
+ finish = start;
+ } else if (!strcasecmp(chan, "pseudo")) {
+ finish = start = CHAN_PSEUDO;
+ if (found_pseudo)
+ *found_pseudo = 1;
+ } else {
+ ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", value, chan);
+ return -1;
+ }
+ if (finish < start) {
+ ast_log(LOG_WARNING, "Sillyness: %d < %d\n", start, finish);
+ x = finish;
+ finish = start;
+ start = x;
+ }
+ if (cur_outsignalling < 0) cur_outsignalling = cur_signalling;
+ for (x = start; x <= finish; x++) {
+#ifdef HAVE_PRI
+ tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, pri, reload);
+#else
+ tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, NULL, reload);
+#endif
+
+ if (tmp) {
+ if (option_verbose > 2) {
+#ifdef HAVE_PRI
+ if (pri)
+ ast_verbose(VERBOSE_PREFIX_3 "%s CRV %d:%d, %s signalling\n", reload ? "Reconfigured" : "Registered", trunkgroup,x, sig2str(tmp->sig));
+ else
+#endif
+ ast_verbose(VERBOSE_PREFIX_3 "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig));
+ }
+ } else {
+ if (reload == 1)
+ ast_log(LOG_ERROR, "Unable to reconfigure channel '%s'\n", value);
+ else
+ ast_log(LOG_ERROR, "Unable to register channel '%s'\n", value);
+ return -1;
+ }
+ }
+ chan = strsep(&c, ",");
+ }
+ return 0;
+}
+
+static int process_zap(struct ast_variable *v, int reload, int skipchannels)
+{
+ struct zt_pvt *tmp;
char *ringc;
- int start, finish,x;
int y;
int found_pseudo = 0;
- int cur_radio = 0;
-#ifdef HAVE_PRI
- int spanno;
- int i;
- int logicalspan;
- int trunkgroup;
- int dchannels[NUM_DCHANS];
- struct zt_pri *pri;
-#endif
-
- cfg = ast_config_load(config);
-
- /* Error if we have no config file */
- if (!cfg) {
- ast_log(LOG_ERROR, "Unable to load config %s\n", config);
- return 0;
- }
-
- /* It's a little silly to lock it, but we mind as well just to be sure */
- ast_mutex_lock(&iflock);
-#ifdef HAVE_PRI
- if (!reload) {
- /* Process trunkgroups first */
- v = ast_variable_browse(cfg, "trunkgroups");
- while (v) {
- if (!strcasecmp(v->name, "trunkgroup")) {
- trunkgroup = atoi(v->value);
- if (trunkgroup > 0) {
- if ((c = strchr(v->value, ','))) {
- i = 0;
- memset(dchannels, 0, sizeof(dchannels));
- while (c && (i < NUM_DCHANS)) {
- dchannels[i] = atoi(c + 1);
- if (dchannels[i] < 0) {
- ast_log(LOG_WARNING, "D-channel for trunk group %d must be a postiive number at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- i++;
- c = strchr(c + 1, ',');
- }
- if (i) {
- if (pri_create_trunkgroup(trunkgroup, dchannels)) {
- ast_log(LOG_WARNING, "Unable to create trunk group %d with Primary D-channel %d at line %d of zapata.conf\n", trunkgroup, dchannels[0], v->lineno);
- } else if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Created trunk group %d with Primary D-channel %d and %d backup%s\n", trunkgroup, dchannels[0], i - 1, (i == 1) ? "" : "s");
- } else
- ast_log(LOG_WARNING, "Trunk group %d lacks any valid D-channels at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group %d lacks a primary D-channel at line %d of zapata.conf\n", trunkgroup, v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group identifier must be a positive integer at line %d of zapata.conf\n", v->lineno);
- } else if (!strcasecmp(v->name, "spanmap")) {
- spanno = atoi(v->value);
- if (spanno > 0) {
- if ((c = strchr(v->value, ','))) {
- trunkgroup = atoi(c + 1);
- if (trunkgroup > 0) {
- if ((c = strchr(c + 1, ',')))
- logicalspan = atoi(c + 1);
- else
- logicalspan = 0;
- if (logicalspan >= 0) {
- if (pri_create_spanmap(spanno - 1, trunkgroup, logicalspan)) {
- ast_log(LOG_WARNING, "Failed to map span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
- } else if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Mapped span %d to trunk group %d (logical span %d)\n", spanno, trunkgroup, logicalspan);
- } else
- ast_log(LOG_WARNING, "Logical span must be a postive number, or '0' (for unspecified) at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Trunk group must be a postive number at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Missing trunk group for span map at line %d of zapata.conf\n", v->lineno);
- } else
- ast_log(LOG_WARNING, "Span number must be a postive integer at line %d of zapata.conf\n", v->lineno);
- } else {
- ast_log(LOG_NOTICE, "Ignoring unknown keyword '%s' in trunkgroups\n", v->name);
- }
- v = v->next;
- }
- }
-#endif
- v = ast_variable_browse(cfg, "channels");
- /* Copy the default jb config over global_jbconf */
- memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
- /* Traverse all variables to handle jb conf */
- for (vjb = v; vjb; vjb = vjb->next)
- ast_jb_read_conf(&global_jbconf, vjb->name, vjb->value);
+ char *c;
+
while(v) {
/* Create the interface list */
if (!strcasecmp(v->name, "channel")
@@ -10323,96 +10328,9 @@
|| !strcasecmp(v->name, "crv")
#endif
) {
- if (reload == 0) {
- if (cur_signalling < 0) {
- ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
+ if (!skipchannels) {
+ if (build_channels(!strcasecmp(v->name, "crv"), v->value, reload, v->lineno, &found_pseudo))
return -1;
- }
- }
- c = v->value;
-
-#ifdef HAVE_PRI
- pri = NULL;
- if (!strcasecmp(v->name, "crv")) {
- if (sscanf(c, "%d:%n", &trunkgroup, &y) != 1) {
- ast_log(LOG_WARNING, "CRV must begin with trunkgroup followed by a colon at line %d\n", v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- if (trunkgroup < 1) {
- ast_log(LOG_WARNING, "CRV trunk group must be a postive number at line %d\n", v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- c += y;
- for (y = 0; y < NUM_SPANS; y++) {
- if (pris[y].trunkgroup == trunkgroup) {
- pri = pris + y;
- break;
- }
- }
- if (!pri) {
- ast_log(LOG_WARNING, "No such trunk group %d at CRV declaration at line %d\n", trunkgroup, v->lineno);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- }
-#endif
- chan = strsep(&c, ",");
- while (chan) {
- if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
- /* Range */
- } else if (sscanf(chan, "%d", &start)) {
- /* Just one */
- finish = start;
- } else if (!strcasecmp(chan, "pseudo")) {
- finish = start = CHAN_PSEUDO;
- found_pseudo = 1;
- } else {
- ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", v->value, chan);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- if (finish < start) {
- ast_log(LOG_WARNING, "Sillyness: %d < %d\n", start, finish);
- x = finish;
- finish = start;
- start = x;
- }
- if (cur_outsignalling < 0) cur_outsignalling = cur_signalling;
- for (x = start; x <= finish; x++) {
-#ifdef HAVE_PRI
- tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, pri, reload);
-#else
- tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, NULL, reload);
-#endif
-
- if (tmp) {
- if (option_verbose > 2) {
-#ifdef HAVE_PRI
- if (pri)
- ast_verbose(VERBOSE_PREFIX_3 "%s CRV %d:%d, %s signalling\n", reload ? "Reconfigured" : "Registered", trunkgroup,x, sig2str(tmp->sig));
- else
-#endif
- ast_verbose(VERBOSE_PREFIX_3 "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig));
- }
- } else {
- if (reload == 1)
- ast_log(LOG_ERROR, "Unable to reconfigure channel '%s'\n", v->value);
- else
- ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
- return -1;
- }
- }
- chan = strsep(&c, ",");
}
} else if (!strcasecmp(v->name, "usedistinctiveringdetection")) {
if (ast_true(v->value))
@@ -10580,7 +10498,11 @@
cid_name[0] = '\0';
} else {
ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
- }
+ }
+ } else if (!strcasecmp(v->name, "fullname")) {
+ ast_copy_string(cid_name, v->value, sizeof(cid_name));
+ } else if (!strcasecmp(v->name, "number")) {
+ ast_copy_string(cid_num, v->value, sizeof(cid_num));
} else if (!strcasecmp(v->name, "useincomingcalleridonzaptransfer")) {
zaptrcallerid = ast_true(v->value);
} else if (!strcasecmp(v->name, "restrictcid")) {
@@ -10805,8 +10727,6 @@
switchtype = PRI_SWITCH_QSIG;
else {
ast_log(LOG_ERROR, "Unknown switchtype '%s'\n", v->value);
- ast_config_destroy(cfg);
- ast_mutex_unlock(&iflock);
return -1;
}
} else if (!strcasecmp(v->name, "nsf")) {
@@ -11019,7 +10939,7 @@
} else if (!strcasecmp(v->name, "defaultozz")) {
ast_copy_string(defaultozz, v->value, sizeof(defaultozz));
}
- } else
+ } else if (!skipchannels)
ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
v = v->next;
}
@@ -11040,8 +10960,123 @@
ast_log(LOG_WARNING, "Unable to register pseudo channel!\n");
}
}
+ return 0;
+}
+
+static int setup_zap(int reload)
+{
+ int x;
+ struct ast_config *cfg;
+ struct ast_variable *v;
+ struct ast_variable *vjb;
+ char *c;
+ int res;
+
+#ifdef HAVE_PRI
+ int spanno;
+ int i;
+ int logicalspan;
+ int trunkgroup;
+ int dchannels[NUM_DCHANS];
+#endif
+
+ cfg = ast_config_load(config);
+
+ /* Error if we have no config file */
+ if (!cfg) {
+ ast_log(LOG_ERROR, "Unable to load config %s\n", config);
+ return 0;
+ }
+
+ /* It's a little silly to lock it, but we mind as well just to be sure */
+ ast_mutex_lock(&iflock);
+#ifdef HAVE_PRI
+ if (!reload) {
+ /* Process trunkgroups first */
+ v = ast_variable_browse(cfg, "trunkgroups");
+ while (v) {
+ if (!strcasecmp(v->name, "trunkgroup")) {
+ trunkgroup = atoi(v->value);
+ if (trunkgroup > 0) {
+ if ((c = strchr(v->value, ','))) {
+ i = 0;
+ memset(dchannels, 0, sizeof(dchannels));
+ while (c && (i < NUM_DCHANS)) {
+ dchannels[i] = atoi(c + 1);
+ if (dchannels[i] < 0) {
[... 618 lines stripped ...]
More information about the asterisk-commits
mailing list