Skinny blob cleanup
authorDamien Wedhorn <voip@facts.com.au>
Sun, 6 Jan 2013 21:37:59 +0000 (21:37 +0000)
committerDamien Wedhorn <voip@facts.com.au>
Sun, 6 Jan 2013 21:37:59 +0000 (21:37 +0000)
Cleanup of red blobs in chan_skinny and possible other small formatting issues.

Review: https://reviewboard.asterisk.org/r/2262/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@378634 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_skinny.c

index e59a81d..4ca5fba 100644 (file)
@@ -1306,9 +1306,9 @@ struct skinny_subchannel {
        char exten[AST_MAX_EXTENSION];                  \
        char context[AST_MAX_CONTEXT];                  \
        char language[MAX_LANGUAGE];                    \
-       char cid_num[AST_MAX_EXTENSION];                \
-       char cid_name[AST_MAX_EXTENSION];               \
-       char lastcallerid[AST_MAX_EXTENSION];           \
+       char cid_num[AST_MAX_EXTENSION];                \
+       char cid_name[AST_MAX_EXTENSION];               \
+       char lastcallerid[AST_MAX_EXTENSION];           \
        int cfwdtype;                                   \
        char call_forward_all[AST_MAX_EXTENSION];       \
        char call_forward_busy[AST_MAX_EXTENSION];      \
@@ -1366,15 +1366,15 @@ struct skinny_line {
 static struct skinny_line_options{
        SKINNY_LINE_OPTIONS
 } default_line_struct = {
-       .callwaiting = 1,
+       .callwaiting = 1,
        .transfer = 1,
-       .mwiblink = 0,
-       .dnd = 0,
-       .hidecallerid = 0,
+       .mwiblink = 0,
+       .dnd = 0,
+       .hidecallerid = 0,
        .amaflags = 0,
-       .instance = 0,
-       .directmedia = 0,
-       .nat = 0,
+       .instance = 0,
+       .directmedia = 0,
+       .nat = 0,
        .getforward = 0,
        .prune = 0,
 };
@@ -1474,15 +1474,15 @@ static struct skinny_device_options {
        SKINNY_DEVICE_OPTIONS
 } default_device_struct = {
        .transfer = 1,
-       .earlyrtp = 1,
-       .callwaiting = 1,
-       .mwiblink = 0,
-       .dnd = 0,
+       .earlyrtp = 1,
+       .callwaiting = 1,
+       .mwiblink = 0,
+       .dnd = 0,
        .prune = 0,
        .hookstate = SKINNY_ONHOOK,
 };
 static struct skinny_device_options *default_device = &default_device_struct;
-       
+
 static AST_LIST_HEAD_STATIC(devices, skinny_device);
 
 struct skinnysession {
@@ -1534,7 +1534,7 @@ static struct ast_channel_tech skinny_tech = {
        .fixup = skinny_fixup,
        .send_digit_begin = skinny_senddigit_begin,
        .send_digit_end = skinny_senddigit_end,
-       .bridge = ast_rtp_instance_bridge, 
+       .bridge = ast_rtp_instance_bridge,
 };
 
 static int skinny_extensionstate_cb(char *context, char *id, struct ast_state_cb_info *info, void *data);
@@ -1613,7 +1613,7 @@ static void *get_button_template(struct skinnysession *s, struct button_definiti
                                (btn++)->buttonDefinition = BT_NONE;
                        for (i = 0; i < 13; i++)
                                (btn++)->buttonDefinition = BT_SPEEDDIAL;
-                       
+
                        break;
                case SKINNY_DEVICE_12SPPLUS:
                case SKINNY_DEVICE_12SP:
@@ -1840,7 +1840,7 @@ static struct skinny_subline *find_subline_by_callid(struct skinny_device *d, in
 {
        struct skinny_subline *subline;
        struct skinny_line *l;
-       
+
        AST_LIST_TRAVERSE(&d->lines, l, list){
                AST_LIST_TRAVERSE(&l->sublines, subline, list){
                        if (subline->callid == callid) {
@@ -2052,7 +2052,7 @@ static void cleanup_stale_contexts(char *new, char *old)
                        } else if (strcmp(newcontext, oldcontext)) {
                                stalecontext = oldcontext;
                        }
-                       
+
                }
                if (stalecontext)
                        ast_context_destroy(ast_context_find(stalecontext), "Skinny");
@@ -2360,11 +2360,11 @@ static void send_callinfo(struct skinny_subchannel *sub)
        if (!sub || !sub->owner || !sub->line || !sub->line->device) {
                return;
        }
-       
+
        ast = sub->owner;
        l = sub->line;
        d = l->device;
-       
+
        if (sub->calldirection == SKINNY_INCOMING) {
                fromname = S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, "");
                fromnum = S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, "");
@@ -2395,11 +2395,11 @@ static void push_callinfo(struct skinny_subline *subline, struct skinny_subchann
        if (!sub || !sub->owner || !sub->line || !sub->line->device) {
                return;
        }
-       
+
        ast = sub->owner;
        l = sub->line;
        d = l->device;
-       
+
        if (sub->calldirection == SKINNY_INCOMING) {
                fromname = S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, "");
                fromnum = S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, "");
@@ -2917,10 +2917,10 @@ static void transmit_softkeytemplateres(struct skinny_device *d)
 static void transmit_reset(struct skinny_device *d, int fullrestart)
 {
        struct skinny_req *req;
-  
+
        if (!(req = req_alloc(sizeof(struct reset_message), RESET_MESSAGE)))
                return;
-  
+
        if (fullrestart)
                req->data.reset.resetType = 2;
        else
@@ -3152,7 +3152,7 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata)
        struct skinny_device *d = l->device;
        struct skinny_line *l2;
        int dev_msgs = 0;
-       
+
        if (!d || !d->session) {
                return;
        }
@@ -3242,7 +3242,7 @@ static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp_instance *r
        struct sockaddr_in them = { 0, };
        struct ast_sockaddr them_tmp;
        struct ast_sockaddr us_tmp;
-       
+
        sub = ast_channel_tech_pvt(c);
 
        if (ast_channel_state(c) != AST_STATE_UP)
@@ -3441,7 +3441,7 @@ static char *handle_skinny_reload(struct ast_cli_entry *e, int cmd, struct ast_c
        case CLI_GENERATE:
                return NULL;
        }
-       
+
        if (a->argc != e->args)
                return CLI_SHOWUSAGE;
 
@@ -3483,7 +3483,7 @@ static char *complete_skinny_show_line(const char *line, const char *word, int p
 
        if (pos != 3)
                return NULL;
-       
+
        AST_LIST_TRAVERSE(&devices, d, list) {
                AST_LIST_TRAVERSE(&d->lines, l, list) {
                        if (!strncasecmp(word, l->name, wordlen) && ++which > state)
@@ -3521,7 +3521,7 @@ static char *handle_skinny_reset(struct ast_cli_entry *e, int cmd, struct ast_cl
 
                        if (a->argc == 4 && !strcasecmp(a->argv[3], "restart"))
                                fullrestart = 1;
-                       
+
                        transmit_reset(d, fullrestart);
                }
        }
@@ -3702,7 +3702,7 @@ static char *_skinny_show_devices(int fd, int *total, struct mansession *s, cons
 
        if (total)
                *total = total_devices;
-       
+
        return CLI_SUCCESS;
 }
 
@@ -3797,7 +3797,7 @@ static char *_skinny_show_device(int type, int fd, struct mansession *s, const s
                                }
                                AST_LIST_TRAVERSE(&d->addons, sa, list) {
                                        numaddons++;
-                               }       
+                               }
                                ast_cli(fd, "Addons:      %d\n", numaddons);
                                AST_LIST_TRAVERSE(&d->addons, sa, list) {
                                        ast_cli(fd, "  %s\n", sa->type);
@@ -3908,7 +3908,7 @@ static char *_skinny_show_lines(int fd, int *total, struct mansession *s, const
        }
 
        if (!s) {
-               ast_cli(fd, "Name                 Device Name          Instance Label               \n");
+               ast_cli(fd, "Name                 Device Name          Instance Label               \n");
                ast_cli(fd, "-------------------- -------------------- -------- --------------------\n");
        }
        AST_LIST_LOCK(&lines);
@@ -4150,7 +4150,7 @@ static char *_skinny_show_line(int type, int fd, struct mansession *s, const str
                        }
                }
        }
-       
+
        AST_LIST_UNLOCK(&devices);
        return CLI_SUCCESS;
 }
@@ -4204,7 +4204,7 @@ static char *handle_skinny_show_settings(struct ast_cli_entry *e, int cmd, struc
                return NULL;
        case CLI_GENERATE:
                return NULL;
-       }       
+       }
 
        if (a->argc != 3)
                return CLI_SHOWUSAGE;
@@ -4890,7 +4890,7 @@ static struct ast_channel *skinny_new(struct skinny_line *l, struct skinny_subli
                        } else {
                                sub->subline = NULL;
                        }
-                       
+
                        AST_LIST_INSERT_HEAD(&l->sub, sub, list);
                        //l->activesub = sub;
                }
@@ -5125,7 +5125,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                        }
                        sub->substate = SUBSTATE_CONNECTED;
                        l->activesub = sub;
-                       return; 
+                       return;
                case SUBSTATE_HOLD:
                        if (sub->substate != SUBSTATE_CONNECTED) {
                                ast_log(LOG_WARNING, "Cannot set substate to SUBSTATE_HOLD from %s (on call-%d)\n", substate2str(sub->substate), sub->callid);
@@ -5138,7 +5138,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                        transmit_callstate(d, l->instance, subline->callid, SKINNY_CALLREMOTEMULTILINE);
                        transmit_selectsoftkeys(d, l->instance, subline->callid, KEYDEF_SLACONNECTEDNOTACTIVE);
                        transmit_displaypromptstatus(d, "In Use", 0, l->instance, subline->callid);
-                       
+
                        sub->substate = SUBSTATE_HOLD;
 
                        ast_queue_control_data(sub->owner, AST_CONTROL_HOLD,
@@ -5195,7 +5195,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                        transmit_callstate(d, l->instance, sub->callid, SKINNY_ONHOOK);
                        transmit_clearpromptmessage(d, l->instance, sub->callid);
                        transmit_ringer_mode(d, SKINNY_RING_OFF);
-                       transmit_definetimedate(d); 
+                       transmit_definetimedate(d);
                        transmit_lamp_indication(d, STIMULUS_LINE, l->instance, SKINNY_LAMP_OFF);
                } else {
                        transmit_stop_tone(d, l->instance, sub->callid);
@@ -5252,9 +5252,9 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                        ast_channel_exten_set(c, sub->exten);
                        ast_copy_string(l->lastnumberdialed, sub->exten, sizeof(l->lastnumberdialed));
                }
-               
+
                sub->substate = SUBSTATE_DIALING;
-       
+
                if (ast_pthread_create(&t, NULL, skinny_newcall, c)) {
                        ast_log(LOG_WARNING, "Unable to create new call thread: %s\n", strerror(errno));
                        ast_hangup(c);
@@ -5265,7 +5265,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                        ast_log(LOG_WARNING, "Cannot set substate to SUBSTATE_RINGOUT from %s (on call-%d)\n", substate2str(sub->substate), sub->callid);
                        return;
                }
-       
+
                if (!d->earlyrtp) {
                        transmit_start_tone(d, SKINNY_ALERT, l->instance, sub->callid);
                }
@@ -5287,7 +5287,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                if (d->hookstate == SKINNY_ONHOOK) {
                        l->activesub = sub;
                }
-       
+
                if (sub->substate != SUBSTATE_RINGIN || sub->substate != SUBSTATE_CALLWAIT) {
                        ast_setstate(c, AST_STATE_RINGING);
                        ast_queue_control(c, AST_CONTROL_RINGING);
@@ -5302,7 +5302,7 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
                send_callinfo(sub);
                transmit_lamp_indication(d, STIMULUS_LINE, l->instance, SKINNY_LAMP_BLINK);
                transmit_start_tone(d, SKINNY_CALLWAITTONE, l->instance, sub->callid);
-       
+
                ast_setstate(c, AST_STATE_RINGING);
                ast_queue_control(c, AST_CONTROL_RINGING);
                sub->substate = SUBSTATE_CALLWAIT;
@@ -5421,7 +5421,7 @@ static void dumpsub(struct skinny_subchannel *sub, int forcehangup)
 
        if (sub == l->activesub) {
                d->hookstate = SKINNY_ONHOOK;
-               transmit_speaker_mode(d, SKINNY_SPEAKEROFF); 
+               transmit_speaker_mode(d, SKINNY_SPEAKEROFF);
                if (sub->related) {
                        activate_sub = sub->related;
                        setsubstate(sub, SUBSTATE_ONHOOK);
@@ -5826,12 +5826,12 @@ static int handle_stimulus_message(struct skinny_req *req, struct skinnysession
                } else {
                        c = sub->owner;
                }
-               
+
                if (!c) {
                        ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, d->name);
                        break;
                }
-               
+
                sub = ast_channel_tech_pvt(c);
                if (sub->substate == SUBSTATE_UNSET || sub->substate == SUBSTATE_OFFHOOK){
                        dialandactivatesub(sub, l->vmexten);
@@ -6082,13 +6082,13 @@ static int handle_onhook_message(struct skinny_req *req, struct skinnysession *s
                handle_transfer_button(sub);
                return 0;
        }
-       
+
        ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Skinny/%s", l->name);
-       
+
        dumpsub(sub, 0);
 
        d->hookstate = SKINNY_ONHOOK;
-       
+
        /* Not ideal, but let's send updated time at onhook and offhook, as it clears the display */
        transmit_definetimedate(d);
 
@@ -6384,11 +6384,10 @@ static int handle_enbloc_call_message(struct skinny_req *req, struct skinnysessi
                sub = ast_channel_tech_pvt(c);
                dialandactivatesub(sub, req->data.enbloccallmessage.calledParty);
        }
-       
+
        return 1;
 }
 
-
 static int handle_soft_key_event_message(struct skinny_req *req, struct skinnysession *s)
 {
        struct skinny_device *d = s->device;
@@ -6586,7 +6585,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                        handle_transfer_button(sub);
                        return 0;
                }
-       
+
                ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Skinny/%s", l->name);
 
                if (sub) {
@@ -6599,7 +6598,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                }
 
                d->hookstate = SKINNY_ONHOOK;
-       
+
                /* Not ideal, but let's send updated time at onhook and offhook, as it clears the display */
                transmit_definetimedate(d);
 
@@ -6866,14 +6865,14 @@ static void destroy_session(struct skinnysession *s)
        AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, cur, list) {
                if (cur == s) {
                        AST_LIST_REMOVE_CURRENT(list);
-                       if (s->fd > -1) 
+                       if (s->fd > -1)
                                close(s->fd);
-                       
+
                        if (!s->device)
                                ast_atomic_fetchadd_int(&unauth_sessions, -1);
 
                        ast_mutex_destroy(&s->lock);
-                       
+
                        ast_free(s);
                }
        }
@@ -7150,45 +7149,45 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
        return tmpc;
 }
 
- #define TYPE_GENERAL  1
- #define TYPE_DEF_DEVICE 2
- #define TYPE_DEF_LINE         4
- #define TYPE_DEVICE   8
- #define TYPE_LINE     16
- #define CLINE_OPTS    ((struct skinny_line_options *)item)
- #define CLINE         ((struct skinny_line *)item)
- #define CDEV_OPTS     ((struct skinny_device_options *)item)
- #define CDEV          ((struct skinny_device *)item)
- static void config_parse_variables(int type, void *item, struct ast_variable *vptr)
- {
-       struct ast_variable *v;
-       int lineInstance = 1;
-       int speeddialInstance = 1;
-       
-       while(vptr) {
-               v = vptr;
-               vptr = vptr->next;
-               if (type & (TYPE_GENERAL)) {
-                       char newcontexts[AST_MAX_CONTEXT];
+#define TYPE_GENERAL   1
+#define TYPE_DEF_DEVICE 2
+#define TYPE_DEF_LINE  4
+#define TYPE_DEVICE    8
+#define TYPE_LINE      16
+
+#define CLINE_OPTS     ((struct skinny_line_options *)item)
+#define CLINE          ((struct skinny_line *)item)
+#define CDEV_OPTS      ((struct skinny_device_options *)item)
+#define CDEV           ((struct skinny_device *)item)
+
+static void config_parse_variables(int type, void *item, struct ast_variable *vptr)
+{
+       struct ast_variable *v;
+       int lineInstance = 1;
+       int speeddialInstance = 1;
+
+       while(vptr) {
+               v = vptr;
+               vptr = vptr->next;
+
+               if (type & (TYPE_GENERAL)) {
+                       char newcontexts[AST_MAX_CONTEXT];
                        char oldcontexts[AST_MAX_CONTEXT];
-                       char *stringp, *context, *oldregcontext;
-                       if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
-                               v = v->next;
-                               continue;
-                       }
-                       if (!strcasecmp(v->name, "bindaddr")) {
-                               if (!(hp = ast_gethostbyname(v->value, &ahp))) {
-                                       ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
-                               } else {
-                                       memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
-                               }
-                               continue;
-                       } else if (!strcasecmp(v->name, "keepalive")) {
-                               keep_alive = atoi(v->value);
-                               continue;
+                       char *stringp, *context, *oldregcontext;
+                       if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
+                               v = v->next;
+                               continue;
+                       }
+                       if (!strcasecmp(v->name, "bindaddr")) {
+                               if (!(hp = ast_gethostbyname(v->value, &ahp))) {
+                                       ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
+                               } else {
+                                       memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
+                               }
+                               continue;
+                       } else if (!strcasecmp(v->name, "keepalive")) {
+                               keep_alive = atoi(v->value);
+                               continue;
                        } else if (!strcasecmp(v->name, "authtimeout")) {
                                int timeout = atoi(v->value);
 
@@ -7209,174 +7208,174 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                                        auth_limit = limit;
                                }
                                continue;
-                       } else if (!strcasecmp(v->name, "regcontext")) {
-                               ast_copy_string(newcontexts, v->value, sizeof(newcontexts));
-                               stringp = newcontexts;
+                       } else if (!strcasecmp(v->name, "regcontext")) {
+                               ast_copy_string(newcontexts, v->value, sizeof(newcontexts));
+                               stringp = newcontexts;
                                /* Initialize copy of current global_regcontext for later use in removing stale contexts */
                                ast_copy_string(oldcontexts, regcontext, sizeof(oldcontexts));
                                oldregcontext = oldcontexts;
-                               /* Let's remove any contexts that are no longer defined in regcontext */
-                               cleanup_stale_contexts(stringp, oldregcontext);
-                               /* Create contexts if they don't exist already */
-                               while ((context = strsep(&stringp, "&"))) {
-                                       ast_copy_string(used_context, context, sizeof(used_context));
-                                       ast_context_find_or_create(NULL, NULL, context, "Skinny");
-                               }
-                               ast_copy_string(regcontext, v->value, sizeof(regcontext));
-                               continue;
-                       } else if (!strcasecmp(v->name, "vmexten")) {
-                               ast_copy_string(vmexten, v->value, sizeof(vmexten));
-                               continue;
-                       } else if (!strcasecmp(v->name, "dateformat")) {
-                               memcpy(date_format, v->value, sizeof(date_format));
-                               continue;
-                       } else if (!strcasecmp(v->name, "tos")) {
-                               if (ast_str2tos(v->value, &qos.tos))
-                                       ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "tos_audio")) {
-                               if (ast_str2tos(v->value, &qos.tos_audio))
-                                       ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "tos_video")) {
-                               if (ast_str2tos(v->value, &qos.tos_video))
-                                       ast_log(LOG_WARNING, "Invalid tos_video value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "cos")) {
-                               if (ast_str2cos(v->value, &qos.cos))
-                                       ast_log(LOG_WARNING, "Invalid cos value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "cos_audio")) {
-                               if (ast_str2cos(v->value, &qos.cos_audio))
-                                       ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "cos_video")) {
-                               if (ast_str2cos(v->value, &qos.cos_video))
-                                       ast_log(LOG_WARNING, "Invalid cos_video value at line %d, refer to QoS documentation\n", v->lineno);
-                               continue;
-                       } else if (!strcasecmp(v->name, "bindport")) {
-                               if (sscanf(v->value, "%5d", &ourport) == 1) {
-                                       bindaddr.sin_port = htons(ourport);
-                               } else {
-                                       ast_log(LOG_WARNING, "Invalid bindport '%s' at line %d of %s\n", v->value, v->lineno, config);
-                               }
-                               continue;
-                       } else if (!strcasecmp(v->name, "allow")) {
-                               ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 1);
-                               continue;
-                       } else if (!strcasecmp(v->name, "disallow")) {
-                               ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 0);
-                               continue;
-                       } 
-               }
-               if (!strcasecmp(v->name, "transfer")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               CDEV_OPTS->transfer = ast_true(v->value);
-                               continue;
-                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->transfer = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "callwaiting")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               CDEV_OPTS->callwaiting = ast_true(v->value);
-                               continue;
-                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->callwaiting = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "directmedia") || !strcasecmp(v->name, "canreinvite")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->directmedia = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "nat")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->nat = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "context")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->context, v->value, sizeof(CLINE_OPTS->context));
-                               continue;
-                       }
-               }else if (!strcasecmp(v->name, "vmexten")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               ast_copy_string(CDEV_OPTS->vmexten, v->value, sizeof(CDEV_OPTS->vmexten));
-                               continue;
-                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->vmexten, v->value, sizeof(CLINE_OPTS->vmexten));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "mwiblink")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               CDEV_OPTS->mwiblink = ast_true(v->value);
-                               continue;
-                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->mwiblink = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "linelabel")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->label, v->value, sizeof(CLINE_OPTS->label));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "callerid")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               if (!strcasecmp(v->value, "asreceived")) {
-                                       CLINE_OPTS->cid_num[0] = '\0';
-                                       CLINE_OPTS->cid_name[0] = '\0';
-                               } else {
-                                       ast_callerid_split(v->value, CLINE_OPTS->cid_name, sizeof(CLINE_OPTS->cid_name), CLINE_OPTS->cid_num, sizeof(CLINE_OPTS->cid_num));
-                               }
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "amaflags")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               int tempamaflags = ast_cdr_amaflags2int(v->value);
-                               if (tempamaflags < 0) {
-                                       ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
-                               } else {
-                                       CLINE_OPTS->amaflags = tempamaflags;
-                               }
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "regexten")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->regexten, v->value, sizeof(CLINE_OPTS->regexten));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "language")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->language, v->value, sizeof(CLINE_OPTS->language));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "accountcode")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->accountcode, v->value, sizeof(CLINE_OPTS->accountcode));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "mohinterpret") || !strcasecmp(v->name, "musiconhold")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->mohinterpret, v->value, sizeof(CLINE_OPTS->mohinterpret));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "mohsuggest")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->mohsuggest, v->value, sizeof(CLINE_OPTS->mohsuggest));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "callgroup")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->callgroup = ast_get_group(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "pickupgroup")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->pickupgroup = ast_get_group(v->value);
-                               continue;
-                       }
+                               /* Let's remove any contexts that are no longer defined in regcontext */
+                               cleanup_stale_contexts(stringp, oldregcontext);
+                               /* Create contexts if they don't exist already */
+                               while ((context = strsep(&stringp, "&"))) {
+                                       ast_copy_string(used_context, context, sizeof(used_context));
+                                       ast_context_find_or_create(NULL, NULL, context, "Skinny");
+                               }
+                               ast_copy_string(regcontext, v->value, sizeof(regcontext));
+                               continue;
+                       } else if (!strcasecmp(v->name, "vmexten")) {
+                               ast_copy_string(vmexten, v->value, sizeof(vmexten));
+                               continue;
+                       } else if (!strcasecmp(v->name, "dateformat")) {
+                               memcpy(date_format, v->value, sizeof(date_format));
+                               continue;
+                       } else if (!strcasecmp(v->name, "tos")) {
+                               if (ast_str2tos(v->value, &qos.tos))
+                                       ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "tos_audio")) {
+                               if (ast_str2tos(v->value, &qos.tos_audio))
+                                       ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "tos_video")) {
+                               if (ast_str2tos(v->value, &qos.tos_video))
+                                       ast_log(LOG_WARNING, "Invalid tos_video value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "cos")) {
+                               if (ast_str2cos(v->value, &qos.cos))
+                                       ast_log(LOG_WARNING, "Invalid cos value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "cos_audio")) {
+                               if (ast_str2cos(v->value, &qos.cos_audio))
+                                       ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "cos_video")) {
+                               if (ast_str2cos(v->value, &qos.cos_video))
+                                       ast_log(LOG_WARNING, "Invalid cos_video value at line %d, refer to QoS documentation\n", v->lineno);
+                               continue;
+                       } else if (!strcasecmp(v->name, "bindport")) {
+                               if (sscanf(v->value, "%5d", &ourport) == 1) {
+                                       bindaddr.sin_port = htons(ourport);
+                               } else {
+                                       ast_log(LOG_WARNING, "Invalid bindport '%s' at line %d of %s\n", v->value, v->lineno, config);
+                               }
+                               continue;
+                       } else if (!strcasecmp(v->name, "allow")) {
+                               ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 1);
+                               continue;
+                       } else if (!strcasecmp(v->name, "disallow")) {
+                               ast_parse_allow_disallow(&default_prefs, default_cap, v->value, 0);
+                               continue;
+                       } 
+               }
+
+               if (!strcasecmp(v->name, "transfer")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               CDEV_OPTS->transfer = ast_true(v->value);
+                               continue;
+                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->transfer = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "callwaiting")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               CDEV_OPTS->callwaiting = ast_true(v->value);
+                               continue;
+                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->callwaiting = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "directmedia") || !strcasecmp(v->name, "canreinvite")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->directmedia = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "nat")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->nat = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "context")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->context, v->value, sizeof(CLINE_OPTS->context));
+                               continue;
+                       }
+               }else if (!strcasecmp(v->name, "vmexten")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               ast_copy_string(CDEV_OPTS->vmexten, v->value, sizeof(CDEV_OPTS->vmexten));
+                               continue;
+                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->vmexten, v->value, sizeof(CLINE_OPTS->vmexten));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "mwiblink")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               CDEV_OPTS->mwiblink = ast_true(v->value);
+                               continue;
+                       } else if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->mwiblink = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "linelabel")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->label, v->value, sizeof(CLINE_OPTS->label));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "callerid")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               if (!strcasecmp(v->value, "asreceived")) {
+                                       CLINE_OPTS->cid_num[0] = '\0';
+                                       CLINE_OPTS->cid_name[0] = '\0';
+                               } else {
+                                       ast_callerid_split(v->value, CLINE_OPTS->cid_name, sizeof(CLINE_OPTS->cid_name), CLINE_OPTS->cid_num, sizeof(CLINE_OPTS->cid_num));
+                               }
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "amaflags")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               int tempamaflags = ast_cdr_amaflags2int(v->value);
+                               if (tempamaflags < 0) {
+                                       ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
+                               } else {
+                                       CLINE_OPTS->amaflags = tempamaflags;
+                               }
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "regexten")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->regexten, v->value, sizeof(CLINE_OPTS->regexten));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "language")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->language, v->value, sizeof(CLINE_OPTS->language));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "accountcode")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->accountcode, v->value, sizeof(CLINE_OPTS->accountcode));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "mohinterpret") || !strcasecmp(v->name, "musiconhold")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->mohinterpret, v->value, sizeof(CLINE_OPTS->mohinterpret));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "mohsuggest")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->mohsuggest, v->value, sizeof(CLINE_OPTS->mohsuggest));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "callgroup")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->callgroup = ast_get_group(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "pickupgroup")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->pickupgroup = ast_get_group(v->value);
+                               continue;
+                       }
                } else if (!strcasecmp(v->name, "namedcallgroup")) {
                        if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
                                CLINE_OPTS->named_callgroups = ast_get_namedgroups(v->value);
@@ -7387,103 +7386,103 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                                CLINE_OPTS->named_pickupgroups = ast_get_namedgroups(v->value);
                                continue;
                        }
-               } else if (!strcasecmp(v->name, "immediate")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE | TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->immediate = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "cancallforward")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->cancallforward = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "mailbox")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->mailbox, v->value, sizeof(CLINE_OPTS->mailbox));
-                               continue;
-                       }
-               } else if ( !strcasecmp(v->name, "parkinglot")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->parkinglot, v->value, sizeof(CLINE_OPTS->parkinglot));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "hasvoicemail")) {
-                       if (type & (TYPE_LINE)) {
-                               if (ast_true(v->value) && ast_strlen_zero(CLINE->mailbox)) {
-                                       ast_copy_string(CLINE->mailbox, CLINE->name, sizeof(CLINE->mailbox));
-                               }
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "threewaycalling")) {
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               CLINE_OPTS->threewaycalling = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "setvar")) {
-                       if (type & (TYPE_LINE)) {
-                               CLINE->chanvars = add_var(v->value, CLINE->chanvars);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "earlyrtp")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               CDEV_OPTS->earlyrtp = ast_true(v->value);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "host")) {
-                       if (type & (TYPE_DEVICE)) {
+               } else if (!strcasecmp(v->name, "immediate")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE | TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->immediate = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "cancallforward")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->cancallforward = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "mailbox")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->mailbox, v->value, sizeof(CLINE_OPTS->mailbox));
+                               continue;
+                       }
+               } else if ( !strcasecmp(v->name, "parkinglot")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->parkinglot, v->value, sizeof(CLINE_OPTS->parkinglot));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "hasvoicemail")) {
+                       if (type & (TYPE_LINE)) {
+                               if (ast_true(v->value) && ast_strlen_zero(CLINE->mailbox)) {
+                                       ast_copy_string(CLINE->mailbox, CLINE->name, sizeof(CLINE->mailbox));
+                               }
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "threewaycalling")) {
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               CLINE_OPTS->threewaycalling = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "setvar")) {
+                       if (type & (TYPE_LINE)) {
+                               CLINE->chanvars = add_var(v->value, CLINE->chanvars);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "earlyrtp")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               CDEV_OPTS->earlyrtp = ast_true(v->value);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "host")) {
+                       if (type & (TYPE_DEVICE)) {
                                struct ast_sockaddr CDEV_addr_tmp;
 
                                CDEV_addr_tmp.ss.ss_family = AF_INET;
                                if (ast_get_ip(&CDEV_addr_tmp, v->value)) {
-                                       ast_log(LOG_WARNING, "Bad IP '%s' at line %d.\n", v->value, v->lineno);
-                               }
+                                       ast_log(LOG_WARNING, "Bad IP '%s' at line %d.\n", v->value, v->lineno);
+                               }
                                ast_sockaddr_to_sin(&CDEV_addr_tmp,
                                                    &CDEV->addr);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "port")) {
-                       if (type & (TYPE_DEF_DEVICE)) {
-                               CDEV->addr.sin_port = htons(atoi(v->value));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "device")) {
-                       if (type & (TYPE_DEVICE)) {
-                               ast_copy_string(CDEV_OPTS->id, v->value, sizeof(CDEV_OPTS->id));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
-                       if (type & (TYPE_DEVICE)) {
-                               CDEV->ha = ast_append_ha(v->name, v->value, CDEV->ha, NULL);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "allow")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 1);
-                               continue;
-                       }
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 1);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "disallow")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 0);
-                               continue;
-                       }
-                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
-                               ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 0);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "version")) {
-                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
-                               ast_copy_string(CDEV_OPTS->version_id, v->value, sizeof(CDEV_OPTS->version_id));
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "line")) {
-                       if (type & (TYPE_DEVICE)) {
-                               struct skinny_line *l;
-                               AST_LIST_TRAVERSE(&lines, l, all) {
-                                       if (!strcasecmp(v->value, l->name) && !l->prune) {
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "port")) {
+                       if (type & (TYPE_DEF_DEVICE)) {
+                               CDEV->addr.sin_port = htons(atoi(v->value));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "device")) {
+                       if (type & (TYPE_DEVICE)) {
+                               ast_copy_string(CDEV_OPTS->id, v->value, sizeof(CDEV_OPTS->id));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
+                       if (type & (TYPE_DEVICE)) {
+                               CDEV->ha = ast_append_ha(v->name, v->value, CDEV->ha, NULL);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "allow")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 1);
+                               continue;
+                       }
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 1);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "disallow")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               ast_parse_allow_disallow(&CDEV->confprefs, CDEV->confcap, v->value, 0);
+                               continue;
+                       }
+                       if (type & (TYPE_DEF_LINE | TYPE_LINE)) {
+                               ast_parse_allow_disallow(&CLINE->confprefs, CLINE->confcap, v->value, 0);
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "version")) {
+                       if (type & (TYPE_DEF_DEVICE | TYPE_DEVICE)) {
+                               ast_copy_string(CDEV_OPTS->version_id, v->value, sizeof(CDEV_OPTS->version_id));
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "line")) {
+                       if (type & (TYPE_DEVICE)) {
+                               struct skinny_line *l;
+                               AST_LIST_TRAVERSE(&lines, l, all) {
+                                       if (!strcasecmp(v->value, l->name) && !l->prune) {
 
                                                /* FIXME: temp solution about line conflicts */
                                                struct skinny_device *d;
@@ -7505,28 +7504,28 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                                                        AST_LIST_INSERT_HEAD(&CDEV->lines, l, list);
                                                        l->device = CDEV;
                                                }
-                                               break;
-                                       }
-                               }
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "subline")) {
-                       if (type & (TYPE_LINE)) {
-                               struct skinny_subline *subline;
-                               struct skinny_container *container;
+                                               break;
+                                       }
+                               }
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "subline")) {
+                       if (type & (TYPE_LINE)) {
+                               struct skinny_subline *subline;
+                               struct skinny_container *container;
                                char buf[256];
                                char *stringp = buf, *exten, *stname, *context;
 
-                               if (!(subline = ast_calloc(1, sizeof(*subline)))) {
-                                       ast_log(LOG_WARNING, "Unable to allocate memory for subline %s. Ignoring subline.\n", v->value);
-                                       continue;
-                               }
-                               if (!(container = ast_calloc(1, sizeof(*container)))) {
-                                       ast_log(LOG_WARNING, "Unable to allocate memory for subline %s container. Ignoring subline.\n", v->value);
+                               if (!(subline = ast_calloc(1, sizeof(*subline)))) {
+                                       ast_log(LOG_WARNING, "Unable to allocate memory for subline %s. Ignoring subline.\n", v->value);
+                                       continue;
+                               }
+                               if (!(container = ast_calloc(1, sizeof(*container)))) {
+                                       ast_log(LOG_WARNING, "Unable to allocate memory for subline %s container. Ignoring subline.\n", v->value);
                                        ast_free(subline);
-                                       continue;
-                               }
-                               
+                                       continue;
+                               }
+
                                ast_copy_string(buf, v->value, sizeof(buf));
                                exten = strsep(&stringp, "@");
                                ast_copy_string(subline->exten, ast_strip(exten), sizeof(subline->exten));
@@ -7544,34 +7543,34 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                                container->data = subline;
                                subline->container = container;
                                AST_LIST_INSERT_HEAD(&CLINE->sublines, subline, list);
-                               continue;
+                               continue;
                        }
-               } else if (!strcasecmp(v->name, "dialoutcontext")) {
-                       if (type & (TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->dialoutcontext, v->value, sizeof(CLINE_OPTS->dialoutcontext));
+               } else if (!strcasecmp(v->name, "dialoutcontext")) {
+                       if (type & (TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->dialoutcontext, v->value, sizeof(CLINE_OPTS->dialoutcontext));
                                continue;
                        }
-               } else if (!strcasecmp(v->name, "dialoutexten")) {
-                       if (type & (TYPE_LINE)) {
-                               ast_copy_string(CLINE_OPTS->dialoutexten, v->value, sizeof(CLINE_OPTS->dialoutexten));
+               } else if (!strcasecmp(v->name, "dialoutexten")) {
+                       if (type & (TYPE_LINE)) {
+                               ast_copy_string(CLINE_OPTS->dialoutexten, v->value, sizeof(CLINE_OPTS->dialoutexten));
                                continue;
                        }
-               } else if (!strcasecmp(v->name, "speeddial")) {
-                       if (type & (TYPE_DEVICE)) {
-                               struct skinny_speeddial *sd;
-                               struct skinny_container *container;
+               } else if (!strcasecmp(v->name, "speeddial")) {
+                       if (type & (TYPE_DEVICE)) {
+                               struct skinny_speeddial *sd;
+                               struct skinny_container *container;
                                char buf[256];
                                char *stringp = buf, *exten, *context, *label;
 
-                               if (!(sd = ast_calloc(1, sizeof(*sd)))) {
-                                       ast_log(LOG_WARNING, "Unable to allocate memory for speeddial %s. Ignoring speeddial.\n", v->name);
-                                       continue;
-                               }
-                               if (!(container = ast_calloc(1, sizeof(*container)))) {
-                                       ast_log(LOG_WARNING, "Unable to allocate memory for speeddial %s container. Ignoring speeddial.\n", v->name);
+                               if (!(sd = ast_calloc(1, sizeof(*sd)))) {
+                                       ast_log(LOG_WARNING, "Unable to allocate memory for speeddial %s. Ignoring speeddial.\n", v->name);
+                                       continue;
+                               }
+                               if (!(container = ast_calloc(1, sizeof(*container)))) {
+                                       ast_log(LOG_WARNING, "Unable to allocate memory for speeddial %s container. Ignoring speeddial.\n", v->name);
                                        ast_free(sd);
-                                       continue;
-                               }
+                                       continue;
+                               }
 
                                ast_copy_string(buf, v->value, sizeof(buf));
                                exten = strsep(&stringp, ",");
@@ -7596,146 +7595,146 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                                container->data = sd;
                                sd->container = container;
                                AST_LIST_INSERT_HEAD(&CDEV->speeddials, sd, list);
-                               continue;
-                       }
-               } else if (!strcasecmp(v->name, "addon")) {
-                       if (type & (TYPE_DEVICE)) {
-                               struct skinny_addon *a;
-                               if (!(a = ast_calloc(1, sizeof(*a)))) {
-                                       ast_log(LOG_WARNING, "Unable to allocate memory for addon %s. Ignoring addon.\n", v->name);
-                                       continue;
-                               } else {
-                                       ast_mutex_init(&a->lock);
-                                       ast_copy_string(a->type, v->value, sizeof(a->type));
-                                       AST_LIST_INSERT_HEAD(&CDEV->addons, a, list);
-                               }
-                               continue;
-                       }
-
-               } else {
-                       ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
-                       continue;
-               }
-               ast_log(LOG_WARNING, "Invalid category used: %s at line %d\n", v->name, v->lineno);
-       }
- }
- static struct skinny_line *config_line(const char *lname, struct ast_variable *v)
- {
-       struct skinny_line *l, *temp;
+                               continue;
+                       }
+               } else if (!strcasecmp(v->name, "addon")) {
+                       if (type & (TYPE_DEVICE)) {
+                               struct skinny_addon *a;
+                               if (!(a = ast_calloc(1, sizeof(*a)))) {
+                                       ast_log(LOG_WARNING, "Unable to allocate memory for addon %s. Ignoring addon.\n", v->name);
+                                       continue;
+                               } else {
+                                       ast_mutex_init(&a->lock);
+                                       ast_copy_string(a->type, v->value, sizeof(a->type));
+                                       AST_LIST_INSERT_HEAD(&CDEV->addons, a, list);
+                               }
+                               continue;
+                       }
+
+               } else {
+                       ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
+                       continue;
+               }
+               ast_log(LOG_WARNING, "Invalid category used: %s at line %d\n", v->name, v->lineno);
+       }
+}
+
+static struct skinny_line *config_line(const char *lname, struct ast_variable *v)
+{
+       struct skinny_line *l, *temp;
        int update = 0;
        struct skinny_container *container;
-       ast_log(LOG_NOTICE, "Configuring skinny line %s.\n", lname);
+
+       ast_log(LOG_NOTICE, "Configuring skinny line %s.\n", lname);
 
        /* We find the old line and remove it just before the new
           line is created */
-       AST_LIST_LOCK(&lines);
-       AST_LIST_TRAVERSE(&lines, temp, all) {
-               if (!strcasecmp(lname, temp->name) && temp->prune) {
+       AST_LIST_LOCK(&lines);
+       AST_LIST_TRAVERSE(&lines, temp, all) {
+               if (!strcasecmp(lname, temp->name) && temp->prune) {
                        update = 1;
-                       break;
-               }
-       }
-
-       if (!(l = skinny_line_alloc())) {
-               ast_verb(1, "Unable to allocate memory for line %s.\n", lname);
-               AST_LIST_UNLOCK(&lines);
-               return NULL;
-       }
+                       break;
+               }
+       }
+
+       if (!(l = skinny_line_alloc())) {
+               ast_verb(1, "Unable to allocate memory for line %s.\n", lname);
+               AST_LIST_UNLOCK(&lines);
+               return NULL;
+       }
        if (!(container = ast_calloc(1, sizeof(*container)))) {
                ast_log(LOG_WARNING, "Unable to allocate memory for line %s container.\n", lname);
                skinny_line_destroy(l);
-               AST_LIST_UNLOCK(&lines);
-               return NULL;
+               AST_LIST_UNLOCK(&lines);
+               return NULL;
        }
 
        container->type = SKINNY_LINECONTAINER;
        container->data = l;
        l->container = container;
-       
-       memcpy(l, default_line, sizeof(*default_line));
-       ast_mutex_init(&l->lock);
-       ast_copy_string(l->name, lname, sizeof(l->name));
+
+       memcpy(l, default_line, sizeof(*default_line));
+       ast_mutex_init(&l->lock);
+       ast_copy_string(l->name, lname, sizeof(l->name));
        ast_format_cap_copy(l->confcap, default_cap);
-       AST_LIST_INSERT_TAIL(&lines, l, all);
-
-       ast_mutex_lock(&l->lock);
-       AST_LIST_UNLOCK(&lines);
-
-       config_parse_variables(TYPE_LINE, l, v);
-                       
-       if (!ast_strlen_zero(l->mailbox)) {
-               char *cfg_mailbox, *cfg_context;
-               cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
-               ast_verb(3, "Setting mailbox '%s' on line %s\n", cfg_mailbox, l->name);
-               strsep(&cfg_context, "@");
-               if (ast_strlen_zero(cfg_context))
-                        cfg_context = "default";
+       AST_LIST_INSERT_TAIL(&lines, l, all);
+
+       ast_mutex_lock(&l->lock);
+       AST_LIST_UNLOCK(&lines);
+
+       config_parse_variables(TYPE_LINE, l, v);
+
+       if (!ast_strlen_zero(l->mailbox)) {
+               char *cfg_mailbox, *cfg_context;
+               cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
+               ast_verb(3, "Setting mailbox '%s' on line %s\n", cfg_mailbox, l->name);
+               strsep(&cfg_context, "@");
+               if (ast_strlen_zero(cfg_context))
+                        cfg_context = "default";
                l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "skinny MWI subsciption", l,
-                       AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
-                       AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
-                       AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-                       AST_EVENT_IE_END);
-       }
+                       AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
+                       AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
+                       AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+                       AST_EVENT_IE_END);
+       }
 
        if (!ast_strlen_zero(vmexten) && ast_strlen_zero(l->vmexten)) {
                ast_copy_string(l->vmexten, vmexten, sizeof(l->vmexten));
        }
-       ast_mutex_unlock(&l->lock);
-       
+
+       ast_mutex_unlock(&l->lock);
+
        /* We do not want to unlink or free the line yet, it needs
           to be available to detect a device reconfig when we load the
           devices.  Old lines will be pruned after the reload completes */
 
        ast_verb(3, "%s config for line '%s'\n", update ? "Updated" : (skinnyreload ? "Reloaded" : "Created"), l->name);
 
-       return l;
- }
- static struct skinny_device *config_device(const char *dname, struct ast_variable *v)
- {
-       struct skinny_device *d, *temp;
-       struct skinny_line *l, *ltemp;
+       return l;
+}
+
+static struct skinny_device *config_device(const char *dname, struct ast_variable *v)
+{
+       struct skinny_device *d, *temp;
+       struct skinny_line *l, *ltemp;
        struct skinny_subchannel *sub;
        int update = 0;
-       ast_log(LOG_NOTICE, "Configuring skinny device %s.\n", dname);
 
-       AST_LIST_LOCK(&devices);
-       AST_LIST_TRAVERSE(&devices, temp, list) {
-               if (!strcasecmp(dname, temp->name) && temp->prune) {
+       ast_log(LOG_NOTICE, "Configuring skinny device %s.\n", dname);
+
+       AST_LIST_LOCK(&devices);
+       AST_LIST_TRAVERSE(&devices, temp, list) {
+               if (!strcasecmp(dname, temp->name) && temp->prune) {
                        update = 1;
-                       break;
-               }
-       }
-
-       if (!(d = skinny_device_alloc())) {
-               ast_verb(1, "Unable to allocate memory for device %s.\n", dname);
-               AST_LIST_UNLOCK(&devices);
-               return NULL;
-       }
-       memcpy(d, default_device, sizeof(*default_device));
-       ast_mutex_init(&d->lock);
-       ast_copy_string(d->name, dname, sizeof(d->name));
+                       break;
+               }
+       }
+
+       if (!(d = skinny_device_alloc())) {
+               ast_verb(1, "Unable to allocate memory for device %s.\n", dname);
+               AST_LIST_UNLOCK(&devices);
+               return NULL;
+       }
+       memcpy(d, default_device, sizeof(*default_device));
+       ast_mutex_init(&d->lock);
+       ast_copy_string(d->name, dname, sizeof(d->name));
        ast_format_cap_copy(d->confcap, default_cap);
-       AST_LIST_INSERT_TAIL(&devices, d, list);
-
-       ast_mutex_lock(&d->lock);
-       AST_LIST_UNLOCK(&devices);
-       config_parse_variables(TYPE_DEVICE, d, v);
-       if (!AST_LIST_FIRST(&d->lines)) {
-               ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
-               ast_mutex_unlock(&d->lock);
-               return NULL;
-       }
-       if (/*d->addr.sin_addr.s_addr && */!ntohs(d->addr.sin_port)) {
-               d->addr.sin_port = htons(DEFAULT_SKINNY_PORT);
-       }
+       AST_LIST_INSERT_TAIL(&devices, d, list);
+
+       ast_mutex_lock(&d->lock);
+       AST_LIST_UNLOCK(&devices);
+
+       config_parse_variables(TYPE_DEVICE, d, v);
+
+       if (!AST_LIST_FIRST(&d->lines)) {
+               ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
+               ast_mutex_unlock(&d->lock);
+               return NULL;
+       }
+       if (/*d->addr.sin_addr.s_addr && */!ntohs(d->addr.sin_port)) {
+               d->addr.sin_port = htons(DEFAULT_SKINNY_PORT);
+       }
+
        if (skinnyreload){
                AST_LIST_LOCK(&devices);
                AST_LIST_TRAVERSE(&devices, temp, list) {
@@ -7775,35 +7774,35 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                AST_LIST_UNLOCK(&devices);
        }
 
-       ast_mutex_unlock(&d->lock);
+       ast_mutex_unlock(&d->lock);
 
        ast_verb(3, "%s config for device '%s'\n", update ? "Updated" : (skinnyreload ? "Reloaded" : "Created"), d->name);
-       
+
        return d;
 
- }
- static int config_load(void)
- {
-       int on = 1;
-       struct ast_config *cfg;
-       char *cat;
-       int oldport = ntohs(bindaddr.sin_port);
-       struct ast_flags config_flags = { 0 };
-       
-       ast_log(LOG_NOTICE, "Configuring skinny from %s\n", config);
-  
-       if (gethostname(ourhost, sizeof(ourhost))) {
-               ast_log(LOG_WARNING, "Unable to get hostname, Skinny disabled.\n");
-               return 0;
-       }
-       cfg = ast_config_load(config, config_flags);
-  
-       /* We *must* have a config file otherwise stop immediately */
-       if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
-               ast_log(LOG_NOTICE, "Unable to load config %s, Skinny disabled.\n", config);
-               return -1;
-       }
+}
+
+static int config_load(void)
+{
+       int on = 1;
+       struct ast_config *cfg;
+       char *cat;
+       int oldport = ntohs(bindaddr.sin_port);
+       struct ast_flags config_flags = { 0 };
+
+       ast_log(LOG_NOTICE, "Configuring skinny from %s\n", config);
+
+       if (gethostname(ourhost, sizeof(ourhost))) {
+               ast_log(LOG_WARNING, "Unable to get hostname, Skinny disabled.\n");
+               return 0;
+       }
+       cfg = ast_config_load(config, config_flags);
+
+       /* We *must* have a config file otherwise stop immediately */
+       if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
+               ast_log(LOG_NOTICE, "Unable to load config %s, Skinny disabled.\n", config);
+               return -1;
+       }
        memset(&bindaddr, 0, sizeof(bindaddr));
        memset(&default_prefs, 0, sizeof(default_prefs));
 
@@ -7838,7 +7837,7 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
                config_line(cat, ast_variable_browse(cfg, cat));
                cat = ast_category_browse(cfg, cat);
        }
-               
+
        /* load the devices sections */
        default_device->confprefs = default_prefs;
        config_parse_variables(TYPE_DEF_DEVICE, default_device, ast_variable_browse(cfg, "devices"));
@@ -7964,7 +7963,7 @@ int skinny_reload(void)
                        continue;
                }
                ast_verb(3, "Removing device '%s'\n", d->name);
-               /* Delete all lines for this device. 
+               /* Delete all lines for this device.
                   We do not want to free the line here, that
                   will happen below. */
                while ((l = AST_LIST_REMOVE_HEAD(&d->lines, list))) {
@@ -7983,7 +7982,7 @@ int skinny_reload(void)
        AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&devices);
 
-       AST_LIST_LOCK(&lines);  
+       AST_LIST_LOCK(&lines);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&lines, l, all) {
                if (l->prune) {
                        AST_LIST_REMOVE_CURRENT(all);
@@ -7991,7 +7990,7 @@ int skinny_reload(void)
                }
        }
        AST_LIST_TRAVERSE_SAFE_END;
-       AST_LIST_UNLOCK(&lines);  
+       AST_LIST_UNLOCK(&lines);
 
        AST_LIST_TRAVERSE(&devices, d, list) {
                /* Do a soft reset to re-register the devices after
@@ -8012,8 +8011,8 @@ int skinny_reload(void)
  * Module loading including tests for configuration or dependencies.
  * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
- * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the 
- * configuration file or other non-critical problem return 
+ * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
+ * configuration file or other non-critical problem return
  * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  */
 static int load_module(void)
@@ -8084,7 +8083,7 @@ static int unload_module(void)
        ast_manager_unregister("SKINNYshowdevice");
        ast_manager_unregister("SKINNYlines");
        ast_manager_unregister("SKINNYshowline");
-       
+
        AST_LIST_LOCK(&sessions);
        /* Destroy all the interfaces and free their memory */
        while((s = AST_LIST_REMOVE_HEAD(&sessions, list))) {