Prefer ast_set_qos() over ast_netsock_set_qos()
[asterisk/asterisk.git] / channels / chan_mgcp.c
index 9df36eb..9a49d00 100644 (file)
@@ -69,7 +69,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/app.h"
 #include "asterisk/musiconhold.h"
 #include "asterisk/utils.h"
-#include "asterisk/netsock.h"
+#include "asterisk/netsock2.h"
 #include "asterisk/causes.h"
 #include "asterisk/dsp.h"
 #include "asterisk/devicestate.h"
@@ -441,8 +441,8 @@ static void dump_cmd_queues(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
 static char *mgcp_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static int reload_config(int reload);
 
-static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
-static int mgcp_call(struct ast_channel *ast, char *dest, int timeout);
+static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *dest, int *cause);
+static int mgcp_call(struct ast_channel *ast, const char *dest, int timeout);
 static int mgcp_hangup(struct ast_channel *ast);
 static int mgcp_answer(struct ast_channel *ast);
 static struct ast_frame *mgcp_read(struct ast_channel *ast);
@@ -451,7 +451,7 @@ static int mgcp_indicate(struct ast_channel *ast, int ind, const void *data, siz
 static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 static int mgcp_senddigit_begin(struct ast_channel *ast, char digit);
 static int mgcp_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
-static int mgcp_devicestate(void *data);
+static int mgcp_devicestate(const char *data);
 static void add_header_offhook(struct mgcp_subchannel *sub, struct mgcp_request *resp, char *tone);
 static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp);
 static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v);
@@ -832,7 +832,7 @@ static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
        return res;
 }
 
-static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
+static int mgcp_call(struct ast_channel *ast, const char *dest, int timeout)
 {
        int res;
        struct mgcp_endpoint *p;
@@ -842,8 +842,8 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
        struct varshead *headp;
        struct ast_var_t *current;
 
-       ast_debug(3, "MGCP mgcp_call(%s)\n", ast->name);
-       sub = ast->tech_pvt;
+       ast_debug(3, "MGCP mgcp_call(%s)\n", ast_channel_name(ast));
+       sub = ast_channel_tech_pvt(ast);
        p = sub->parent;
        headp = &ast->varshead;
        AST_LIST_TRAVERSE(headp,current,entries) {
@@ -876,8 +876,8 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
                break;
        }
 
-       if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
-               ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast->name);
+       if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) {
+               ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
                ast_mutex_unlock(&sub->lock);
                return -1;
        }
@@ -919,12 +919,12 @@ static int mgcp_call(struct ast_channel *ast, char *dest, int timeout)
 
 static int mgcp_hangup(struct ast_channel *ast)
 {
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        struct mgcp_endpoint *p = sub->parent;
        struct ast_channel *bridged;
 
-       ast_debug(1, "mgcp_hangup(%s)\n", ast->name);
-       if (!ast->tech_pvt) {
+       ast_debug(1, "mgcp_hangup(%s)\n", ast_channel_name(ast));
+       if (!ast_channel_tech_pvt(ast)) {
                ast_debug(1, "Asked to hangup channel not connected\n");
                return 0;
        }
@@ -933,7 +933,7 @@ static int mgcp_hangup(struct ast_channel *ast)
                return 0;
        }
        ast_mutex_lock(&sub->lock);
-       ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name);
+       ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s\n", ast_channel_name(ast), p->name, p->parent->name);
 
        if ((p->dtmfmode & MGCP_DTMF_INBAND) && p->dsp) {
                /* check whether other channel is active. */
@@ -997,7 +997,7 @@ static int mgcp_hangup(struct ast_channel *ast)
                transmit_notify_request(sub, "");
        }
 
-       ast->tech_pvt = NULL;
+       ast_channel_tech_pvt_set(ast, NULL);
        sub->alreadygone = 0;
        sub->outgoing = 0;
        sub->cxmode = MGCP_CX_INACTIVE;
@@ -1017,16 +1017,16 @@ static int mgcp_hangup(struct ast_channel *ast)
        if ((p->hookstate == MGCP_ONHOOK) && (!sub->next->rtp)) {
                p->hidecallerid = 0;
                if (p->hascallwaiting && !p->callwaiting) {
-                       ast_verb(3, "Enabling call waiting on %s\n", ast->name);
+                       ast_verb(3, "Enabling call waiting on %s\n", ast_channel_name(ast));
                        p->callwaiting = -1;
                }
                if (has_voicemail(p)) {
                        ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(+)\n",
-                               ast->name, p->name, p->parent->name);
+                               ast_channel_name(ast), p->name, p->parent->name);
                        transmit_notify_request(sub, "L/vmwi(+)");
                } else {
                        ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(-)\n",
-                               ast->name, p->name, p->parent->name);
+                               ast_channel_name(ast), p->name, p->parent->name);
                        transmit_notify_request(sub, "L/vmwi(-)");
                }
        }
@@ -1175,7 +1175,7 @@ static struct ast_cli_entry cli_mgcp[] = {
 static int mgcp_answer(struct ast_channel *ast)
 {
        int res = 0;
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        struct mgcp_endpoint *p = sub->parent;
 
        ast_mutex_lock(&sub->lock);
@@ -1186,10 +1186,10 @@ static int mgcp_answer(struct ast_channel *ast)
                transmit_modify_request(sub);
        }
        ast_verb(3, "MGCP mgcp_answer(%s) on %s@%s-%d\n",
-                       ast->name, p->name, p->parent->name, sub->id);
-       if (ast->_state != AST_STATE_UP) {
+                       ast_channel_name(ast), p->name, p->parent->name, sub->id);
+       if (ast_channel_state(ast) != AST_STATE_UP) {
                ast_setstate(ast, AST_STATE_UP);
-               ast_debug(1, "mgcp_answer(%s)\n", ast->name);
+               ast_debug(1, "mgcp_answer(%s)\n", ast_channel_name(ast));
                transmit_notify_request(sub, "");
                transmit_modify_request(sub);
        }
@@ -1209,11 +1209,11 @@ static struct ast_frame *mgcp_rtp_read(struct mgcp_subchannel *sub)
        if (sub->owner) {
                /* We already hold the channel lock */
                if (f->frametype == AST_FRAME_VOICE) {
-                       if (!ast_format_cap_iscompatible(sub->owner->nativeformats, &f->subclass.format)) {
+                       if (!ast_format_cap_iscompatible(ast_channel_nativeformats(sub->owner), &f->subclass.format)) {
                                ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
-                               ast_format_cap_set(sub->owner->nativeformats, &f->subclass.format);
-                               ast_set_read_format(sub->owner, &sub->owner->readformat);
-                               ast_set_write_format(sub->owner, &sub->owner->writeformat);
+                               ast_format_cap_set(ast_channel_nativeformats(sub->owner), &f->subclass.format);
+                               ast_set_read_format(sub->owner, ast_channel_readformat(sub->owner));
+                               ast_set_write_format(sub->owner, ast_channel_writeformat(sub->owner));
                        }
                        /* Courtesy fearnor aka alex@pilosoft.com */
                        if ((sub->parent->dtmfmode & MGCP_DTMF_INBAND) && (sub->parent->dsp)) {
@@ -1231,7 +1231,7 @@ static struct ast_frame *mgcp_rtp_read(struct mgcp_subchannel *sub)
 static struct ast_frame *mgcp_read(struct ast_channel *ast)
 {
        struct ast_frame *f;
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        ast_mutex_lock(&sub->lock);
        f = mgcp_rtp_read(sub);
        ast_mutex_unlock(&sub->lock);
@@ -1240,7 +1240,7 @@ static struct ast_frame *mgcp_read(struct ast_channel *ast)
 
 static int mgcp_write(struct ast_channel *ast, struct ast_frame *frame)
 {
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        int res = 0;
        char buf[256];
 
@@ -1252,12 +1252,12 @@ static int mgcp_write(struct ast_channel *ast, struct ast_frame *frame)
                        return 0;
                }
        } else {
-               if (!(ast_format_cap_iscompatible(ast->nativeformats, &frame->subclass.format))) {
+               if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
                        ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
                                ast_getformatname(&frame->subclass.format),
-                               ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
-                               ast_getformatname(&ast->readformat),
-                               ast_getformatname(&ast->writeformat));
+                               ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
+                               ast_getformatname(ast_channel_readformat(ast)),
+                               ast_getformatname(ast_channel_writeformat(ast)));
                        /* return -1; */
                }
        }
@@ -1281,10 +1281,10 @@ static int mgcp_write(struct ast_channel *ast, struct ast_frame *frame)
 
 static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
 {
-       struct mgcp_subchannel *sub = newchan->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(newchan);
 
        ast_mutex_lock(&sub->lock);
-       ast_log(LOG_NOTICE, "mgcp_fixup(%s, %s)\n", oldchan->name, newchan->name);
+       ast_log(LOG_NOTICE, "mgcp_fixup(%s, %s)\n", ast_channel_name(oldchan), ast_channel_name(newchan));
        if (sub->owner != oldchan) {
                ast_mutex_unlock(&sub->lock);
                ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, sub->owner);
@@ -1297,7 +1297,7 @@ static int mgcp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
 
 static int mgcp_senddigit_begin(struct ast_channel *ast, char digit)
 {
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        struct mgcp_endpoint *p = sub->parent;
        int res = 0;
 
@@ -1318,7 +1318,7 @@ static int mgcp_senddigit_begin(struct ast_channel *ast, char digit)
 
 static int mgcp_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration)
 {
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        struct mgcp_endpoint *p = sub->parent;
        int res = 0;
        char tmp[4];
@@ -1357,7 +1357,7 @@ static int mgcp_senddigit_end(struct ast_channel *ast, char digit, unsigned int
  *
  *  \return device status result (from devicestate.h) AST_DEVICE_INVALID (not available) or AST_DEVICE_UNKNOWN (available but unknown state)
  */
-static int mgcp_devicestate(void *data)
+static int mgcp_devicestate(const char *data)
 {
        struct mgcp_gateway  *g;
        struct mgcp_endpoint *e = NULL;
@@ -1437,11 +1437,11 @@ static char *control2str(int ind) {
 
 static int mgcp_indicate(struct ast_channel *ast, int ind, const void *data, size_t datalen)
 {
-       struct mgcp_subchannel *sub = ast->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        int res = 0;
 
        ast_debug(3, "MGCP asked to indicate %d '%s' condition on channel %s\n",
-               ind, control2str(ind), ast->name);
+               ind, control2str(ind), ast_channel_name(ast));
        ast_mutex_lock(&sub->lock);
        switch(ind) {
        case AST_CONTROL_RINGING:
@@ -1498,10 +1498,10 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state, cons
 
        tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, linkedid, i->accountcode, i->exten, i->context, i->amaflags, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
        if (tmp) {
-               tmp->tech = &mgcp_tech;
-               ast_format_cap_copy(tmp->nativeformats, i->cap);
-               if (ast_format_cap_is_empty(tmp->nativeformats)) {
-                       ast_format_cap_copy(tmp->nativeformats, global_capability);
+               ast_channel_tech_set(tmp, &mgcp_tech);
+               ast_format_cap_copy(ast_channel_nativeformats(tmp), i->cap);
+               if (ast_format_cap_is_empty(ast_channel_nativeformats(tmp))) {
+                       ast_format_cap_copy(ast_channel_nativeformats(tmp), global_capability);
                }
                if (sub->rtp) {
                        ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
@@ -1515,27 +1515,27 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state, cons
                        i->dsp = NULL;
                }
                if (state == AST_STATE_RING)
-                       tmp->rings = 1;
-
-               ast_best_codec(tmp->nativeformats, &tmpfmt);
-               ast_format_copy(&tmp->writeformat, &tmpfmt);
-               ast_format_copy(&tmp->rawwriteformat, &tmpfmt);
-               ast_format_copy(&tmp->readformat, &tmpfmt);
-               ast_format_copy(&tmp->rawreadformat, &tmpfmt);
-               tmp->tech_pvt = sub;
+                       ast_channel_rings_set(tmp, 1);
+
+               ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
+               ast_format_copy(ast_channel_writeformat(tmp), &tmpfmt);
+               ast_format_copy(ast_channel_rawwriteformat(tmp), &tmpfmt);
+               ast_format_copy(ast_channel_readformat(tmp), &tmpfmt);
+               ast_format_copy(ast_channel_rawreadformat(tmp), &tmpfmt);
+               ast_channel_tech_pvt_set(tmp, sub);
                if (!ast_strlen_zero(i->language))
-                       ast_string_field_set(tmp, language, i->language);
+                       ast_channel_language_set(tmp, i->language);
                if (!ast_strlen_zero(i->accountcode))
-                       ast_string_field_set(tmp, accountcode, i->accountcode);
+                       ast_channel_accountcode_set(tmp, i->accountcode);
                if (i->amaflags)
-                       tmp->amaflags = i->amaflags;
+                       ast_channel_amaflags_set(tmp, i->amaflags);
                sub->owner = tmp;
                ast_module_ref(ast_module_info->self);
                tmp->callgroup = i->callgroup;
                tmp->pickupgroup = i->pickupgroup;
-               ast_string_field_set(tmp, call_forward, i->call_forward);
-               ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
-               ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
+               ast_channel_call_forward_set(tmp, i->call_forward);
+               ast_channel_context_set(tmp, i->context);
+               ast_channel_exten_set(tmp, i->exten);
 
                /* Don't use ast_set_callerid() here because it will
                 * generate a needless NewCallerID event */
@@ -1545,9 +1545,9 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state, cons
                }
 
                if (!i->adsi) {
-                       tmp->adsicpe = AST_ADSI_UNAVAILABLE;
+                       ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
                }
-               tmp->priority = 1;
+               ast_channel_priority_set(tmp, 1);
 
                /* Set channel variables for this call from configuration */
                for (v = i->chanvars ; v ; v = v->next) {
@@ -1560,13 +1560,13 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state, cons
                }
                if (state != AST_STATE_DOWN) {
                        if (ast_pbx_start(tmp)) {
-                               ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
+                               ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
                                ast_hangup(tmp);
                                tmp = NULL;
                        }
                }
                ast_verb(3, "MGCP mgcp_new(%s) created in state: %s\n",
-                               tmp->name, ast_state2str(state));
+                               ast_channel_name(tmp), ast_state2str(state));
        } else {
                ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
        }
@@ -2624,7 +2624,7 @@ static void add_header_offhook(struct mgcp_subchannel *sub, struct mgcp_request
        }
 
        if (p && p->sub && p->sub->owner &&
-                       p->sub->owner->_state >= AST_STATE_RINGING &&
+                       ast_channel_state(p->sub->owner) >= AST_STATE_RINGING &&
                        (p->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID))) {
            add_header(resp, "R", "L/hu(N),L/hf(N)");
 
@@ -2829,7 +2829,7 @@ static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
                if (result == 200 && (req->cmd == MGCP_CMD_CRCX || req->cmd == MGCP_CMD_MDCX)) {
                                if (sub) {
                                        transmit_response(sub, "000", resp, "OK");
-                                       if (sub->owner && sub->owner->_state == AST_STATE_RINGING) {
+                                       if (sub->owner && ast_channel_state(sub->owner) == AST_STATE_RINGING) {
                                                ast_queue_control(sub->owner, AST_CONTROL_RINGING);
                                        }
                                }
@@ -2963,7 +2963,7 @@ static void start_rtp(struct mgcp_subchannel *sub)
 static void *mgcp_ss(void *data)
 {
        struct ast_channel *chan = data;
-       struct mgcp_subchannel *sub = chan->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(chan);
        struct mgcp_endpoint *p = sub->parent;
        /* char exten[AST_MAX_EXTENSION] = ""; */
        int len = 0;
@@ -2990,7 +2990,7 @@ static void *mgcp_ss(void *data)
                timeout = 0;
                len = strlen(p->dtmf_buf);
 
-               if (!ast_ignore_pattern(chan->context, p->dtmf_buf)) {
+               if (!ast_ignore_pattern(ast_channel_context(chan), p->dtmf_buf)) {
                        /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
                        ast_indicate(chan, -1);
                } else {
@@ -2998,13 +2998,13 @@ static void *mgcp_ss(void *data)
                        /*tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALTONE);*/
                        transmit_notify_request(sub, "L/dl");
                }
-               if (ast_exists_extension(chan, chan->context, p->dtmf_buf, 1, p->cid_num)) {
-                       if (!res || !ast_matchmore_extension(chan, chan->context, p->dtmf_buf, 1, p->cid_num)) {
+               if (ast_exists_extension(chan, ast_channel_context(chan), p->dtmf_buf, 1, p->cid_num)) {
+                       if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), p->dtmf_buf, 1, p->cid_num)) {
                                if (getforward) {
                                        /* Record this as the forwarding extension */
                                        ast_copy_string(p->call_forward, p->dtmf_buf, sizeof(p->call_forward));
                                        ast_verb(3, "Setting call forward to '%s' on channel %s\n",
-                                                       p->call_forward, chan->name);
+                                                       p->call_forward, ast_channel_name(chan));
                                        /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
                                        transmit_notify_request(sub, "L/sl");
                                        if (res)
@@ -3021,7 +3021,7 @@ static void *mgcp_ss(void *data)
                                } else {
                                        /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
                                        ast_indicate(chan, -1);
-                                       ast_copy_string(chan->exten, p->dtmf_buf, sizeof(chan->exten));
+                                       ast_channel_exten_set(chan, p->dtmf_buf);
                                        chan->dialed.number.str = ast_strdup(p->dtmf_buf);
                                        memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
                                        ast_set_callerid(chan,
@@ -3057,7 +3057,7 @@ static void *mgcp_ss(void *data)
                        memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
                        return NULL;
                } else if (p->hascallwaiting && p->callwaiting && !strcmp(p->dtmf_buf, "*70")) {
-                       ast_verb(3, "Disabling call waiting on %s\n", chan->name);
+                       ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
                        /* Disable call waiting if enabled */
                        p->callwaiting = 0;
                        /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
@@ -3079,7 +3079,7 @@ static void *mgcp_ss(void *data)
                        ast_hangup(chan);
                        return NULL;
                } else if (!p->hidecallerid && !strcmp(p->dtmf_buf, "*67")) {
-                       ast_verb(3, "Disabling Caller*ID on %s\n", chan->name);
+                       ast_verb(3, "Disabling Caller*ID on %s\n", ast_channel_name(chan));
                        /* Disable Caller*ID if enabled */
                        p->hidecallerid = 1;
                        ast_set_callerid(chan, "", "", NULL);
@@ -3091,7 +3091,7 @@ static void *mgcp_ss(void *data)
                } else if (p->callreturn && !strcmp(p->dtmf_buf, "*69")) {
                        res = 0;
                        if (!ast_strlen_zero(p->lastcallerid)) {
-                               res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language);
+                               res = ast_say_digit_str(chan, p->lastcallerid, "", ast_channel_language(chan));
                        }
                        if (!res)
                                /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
@@ -3099,7 +3099,7 @@ static void *mgcp_ss(void *data)
                        break;
                } else if (!strcmp(p->dtmf_buf, "*78")) {
                        /* Do not disturb */
-                       ast_verb(3, "Enabled DND on channel %s\n", chan->name);
+                       ast_verb(3, "Enabled DND on channel %s\n", ast_channel_name(chan));
                        /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
                        transmit_notify_request(sub, "L/sl");
                        p->dnd = 1;
@@ -3108,7 +3108,7 @@ static void *mgcp_ss(void *data)
                        len = 0;
                } else if (!strcmp(p->dtmf_buf, "*79")) {
                        /* Do not disturb */
-                       ast_verb(3, "Disabled DND on channel %s\n", chan->name);
+                       ast_verb(3, "Disabled DND on channel %s\n", ast_channel_name(chan));
                        /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
                        transmit_notify_request(sub, "L/sl");
                        p->dnd = 0;
@@ -3122,20 +3122,20 @@ static void *mgcp_ss(void *data)
                        memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
                        len = 0;
                } else if (p->cancallforward && !strcmp(p->dtmf_buf, "*73")) {
-                       ast_verb(3, "Cancelling call forwarding on channel %s\n", chan->name);
+                       ast_verb(3, "Cancelling call forwarding on channel %s\n", ast_channel_name(chan));
                        /*res = tone_zone_play_tone(p->subs[index].zfd, DAHDI_TONE_DIALRECALL);*/
                        transmit_notify_request(sub, "L/sl");
                        memset(p->call_forward, 0, sizeof(p->call_forward));
                        getforward = 0;
                        memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
                        len = 0;
-               } else if (ast_parking_ext_valid(p->dtmf_buf, chan, chan->context) &&
+               } else if (ast_parking_ext_valid(p->dtmf_buf, chan, ast_channel_context(chan)) &&
                        sub->next->owner && ast_bridged_channel(sub->next->owner)) {
                        /* This is a three way call, the main call being a real channel,
                           and we're parking the first call. */
                        ast_masq_park_call_exten(ast_bridged_channel(sub->next->owner), chan,
-                               p->dtmf_buf, chan->context, 0, NULL);
-                       ast_verb(3, "Parking call to '%s'\n", chan->name);
+                               p->dtmf_buf, ast_channel_context(chan), 0, NULL);
+                       ast_verb(3, "Parking call to '%s'\n", ast_channel_name(chan));
                        break;
                } else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(p->dtmf_buf, "*60")) {
                        ast_verb(3, "Blacklisting number %s\n", p->lastcallerid);
@@ -3147,7 +3147,7 @@ static void *mgcp_ss(void *data)
                                len = 0;
                        }
                } else if (p->hidecallerid && !strcmp(p->dtmf_buf, "*82")) {
-                       ast_verb(3, "Enabling Caller*ID on %s\n", chan->name);
+                       ast_verb(3, "Enabling Caller*ID on %s\n", ast_channel_name(chan));
                        /* Enable Caller*ID if enabled */
                        p->hidecallerid = 0;
                        ast_set_callerid(chan, p->cid_num, p->cid_name, NULL);
@@ -3156,17 +3156,17 @@ static void *mgcp_ss(void *data)
                        len = 0;
                        memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
                        timeout = firstdigittimeout;
-               } else if (!ast_canmatch_extension(chan, chan->context, p->dtmf_buf, 1,
+               } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), p->dtmf_buf, 1,
                        S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))
                        && ((p->dtmf_buf[0] != '*') || (strlen(p->dtmf_buf) > 2))) {
                        ast_debug(1, "Can't match %s from '%s' in context %s\n", p->dtmf_buf,
                                S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, "<Unknown Caller>"),
-                               chan->context);
+                               ast_channel_context(chan));
                        break;
                }
                if (!timeout)
                        timeout = gendigittimeout;
-               if (len && !ast_ignore_pattern(chan->context, p->dtmf_buf))
+               if (len && !ast_ignore_pattern(ast_channel_context(chan), p->dtmf_buf))
                        /*tone_zone_play_tone(p->subs[index].zfd, -1);*/
                        ast_indicate(chan, -1);
        }
@@ -3229,24 +3229,24 @@ static int attempt_transfer(struct mgcp_endpoint *p)
                   stop if now if appropriate */
                if (ast_bridged_channel(p->sub->next->owner))
                        ast_queue_control(p->sub->next->owner, AST_CONTROL_UNHOLD);
-               if (p->sub->owner->_state == AST_STATE_RINGING) {
+               if (ast_channel_state(p->sub->owner) == AST_STATE_RINGING) {
                        ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING);
                }
                if (ast_channel_masquerade(p->sub->next->owner, ast_bridged_channel(p->sub->owner))) {
                        ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
-                               ast_bridged_channel(p->sub->owner)->name, p->sub->next->owner->name);
+                               ast_channel_name(ast_bridged_channel(p->sub->owner)), ast_channel_name(p->sub->next->owner));
                        return -1;
                }
                /* Orphan the channel */
                unalloc_sub(p->sub->next);
        } else if (ast_bridged_channel(p->sub->next->owner)) {
-               if (p->sub->owner->_state == AST_STATE_RINGING) {
+               if (ast_channel_state(p->sub->owner) == AST_STATE_RINGING) {
                        ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING);
                }
                ast_queue_control(p->sub->next->owner, AST_CONTROL_UNHOLD);
                if (ast_channel_masquerade(p->sub->owner, ast_bridged_channel(p->sub->next->owner))) {
                        ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
-                               ast_bridged_channel(p->sub->next->owner)->name, p->sub->owner->name);
+                               ast_channel_name(ast_bridged_channel(p->sub->next->owner)), ast_channel_name(p->sub->owner));
                        return -1;
                }
                /*swap_subs(p, SUB_THREEWAY, SUB_REAL);*/
@@ -3257,7 +3257,7 @@ static int attempt_transfer(struct mgcp_endpoint *p)
                return 1;
        } else {
                ast_debug(1, "Neither %s nor %s are in a bridge, nothing to transfer\n",
-                       p->sub->owner->name, p->sub->next->owner->name);
+                       ast_channel_name(p->sub->owner), ast_channel_name(p->sub->next->owner));
                p->sub->next->owner->_softhangup |= AST_SOFTHANGUP_DEV;
                if (p->sub->next->owner) {
                        p->sub->next->alreadygone = 1;
@@ -3439,7 +3439,7 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
                                return -1;
                        }
                        /* do not let * conference two down channels */
-                       if (sub->owner && sub->owner->_state == AST_STATE_DOWN && !sub->next->owner)
+                       if (sub->owner && ast_channel_state(sub->owner) == AST_STATE_DOWN && !sub->next->owner)
                                return -1;
 
                        if (p->callwaiting || p->transfer || p->threewaycalling) {
@@ -3563,7 +3563,7 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
                                (((ev[0] >= '0') && (ev[0] <= '9')) ||
                                 ((ev[0] >= 'A') && (ev[0] <= 'D')) ||
                                  (ev[0] == '*') || (ev[0] == '#'))) {
-                       if (sub && sub->owner && (sub->owner->_state >=  AST_STATE_UP)) {
+                       if (sub && sub->owner && (ast_channel_state(sub->owner) >=  AST_STATE_UP)) {
                                f.frametype = AST_FRAME_DTMF;
                                f.subclass.integer = ev[0];
                                f.src = "mgcp";
@@ -3920,12 +3920,11 @@ static int restart_monitor(void)
        return 0;
 }
 
-static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *dest, int *cause)
 {
        struct mgcp_subchannel *sub;
        struct ast_channel *tmpc = NULL;
        char tmp[256];
-       char *dest = data;
 
        if (!(ast_format_cap_has_joint(cap, global_capability))) {
                ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
@@ -3960,7 +3959,7 @@ static struct ast_channel *mgcp_request(const char *type, struct ast_format_cap
                ast_mutex_unlock(&sub->lock);
                return NULL;
        }
-       tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL);
+       tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN, requestor ? ast_channel_linkedid(requestor) : NULL);
        ast_mutex_unlock(&sub->lock);
        if (!tmpc)
                ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
@@ -4419,7 +4418,7 @@ static enum ast_rtp_glue_result mgcp_get_rtp_peer(struct ast_channel *chan, stru
 {
        struct mgcp_subchannel *sub = NULL;
 
-       if (!(sub = chan->tech_pvt) || !(sub->rtp))
+       if (!(sub = ast_channel_tech_pvt(chan)) || !(sub->rtp))
                return AST_RTP_GLUE_RESULT_FORBID;
 
        *instance = sub->rtp ? ao2_ref(sub->rtp, +1), sub->rtp : NULL;
@@ -4434,7 +4433,7 @@ static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *
 {
        /* XXX Is there such thing as video support with MGCP? XXX */
        struct mgcp_subchannel *sub;
-       sub = chan->tech_pvt;
+       sub = ast_channel_tech_pvt(chan);
        if (sub && !sub->alreadygone) {
                transmit_modify_with_sdp(sub, rtp, cap);
                return 0;
@@ -4444,7 +4443,7 @@ static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *
 
 static void mgcp_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
 {
-       struct mgcp_subchannel *sub = chan->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(chan);
        struct mgcp_endpoint *p = sub->parent;
        ast_format_cap_copy(result, p->cap);
 }
@@ -4459,11 +4458,11 @@ static struct ast_rtp_glue mgcp_rtp_glue = {
 
 static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen)
 {
-       struct mgcp_subchannel *sub = chan->tech_pvt;
+       struct mgcp_subchannel *sub = ast_channel_tech_pvt(chan);
        int res = 0;
 
        /* Sanity check */
-       if (!chan || chan->tech != &mgcp_tech) {
+       if (!chan || ast_channel_tech(chan) != &mgcp_tech) {
                ast_log(LOG_ERROR, "This function requires a valid MGCP channel\n");
                return -1;
        }
@@ -4776,7 +4775,7 @@ static int reload_config(int reload)
                } else {
                        ast_verb(2, "MGCP Listening on %s:%d\n",
                                        ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-                       ast_netsock_set_qos(mgcpsock, qos.tos, qos.cos, "MGCP");
+                       ast_set_qos(mgcpsock, qos.tos, qos.cos, "MGCP");
                }
        }
        ast_mutex_unlock(&netlock);