]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
lock sooner, fix some formatting (bug #3207)
authorRussell Bryant <russell@russellbryant.com>
Tue, 4 Jan 2005 05:47:49 +0000 (05:47 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 4 Jan 2005 05:47:49 +0000 (05:47 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@4652 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_mgcp.c

index 65dd124e35357b789adfbe5f8adc8f246a45a74b..102c28b1469fea91e2c3a778c97a64ed9f8fb5a9 100755 (executable)
@@ -686,8 +686,7 @@ static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
        if (gettimeofday(&tv, NULL) < 0) {
                /* This shouldn't ever happen, but let's be sure */
                ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
-       }
-    else {
+       } else {
         msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
 
         if (gw->retransid == -1)
@@ -862,8 +861,9 @@ static int mgcp_hangup(struct ast_channel *ast)
        struct mgcp_subchannel *sub = ast->pvt->pvt;
        struct mgcp_endpoint *p = sub->parent;
 
-       if (option_debug)
+       if (option_debug) {
                ast_log(LOG_DEBUG, "mgcp_hangup(%s)\n", ast->name);
+       }
        if (!ast->pvt->pvt) {
                ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
                return 0;
@@ -872,14 +872,14 @@ static int mgcp_hangup(struct ast_channel *ast)
                ast_log(LOG_DEBUG, "Invalid magic. MGCP subchannel freed up already.\n");
                return 0;
     }
+       ast_mutex_lock(&sub->lock);
     if (mgcpdebug) {
         ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name);
     }
 
-       if ((p->dtmfmode & MGCP_DTMF_INBAND) && (p->dsp != NULL)){
+       if ((p->dtmfmode & MGCP_DTMF_INBAND) && p->dsp) {
         /* SC: check whether other channel is active. */
-        if (!sub->next->owner)
-        {
+               if (!sub->next->owner) {
             if (mgcpdebug) {
                 ast_verbose(VERBOSE_PREFIX_2 "MGCP free dsp on %s@%s\n", p->name, p->parent->name);
             }
@@ -887,7 +887,6 @@ static int mgcp_hangup(struct ast_channel *ast)
             p->dsp = NULL;
         }
     }
-       ast_mutex_lock(&sub->lock);
 
        sub->owner = NULL;
        if (strlen(sub->cxident)) {
@@ -967,7 +966,7 @@ static int mgcp_show_endpoints(int fd, int argc, char *argv[])
                e = g->endpoints;
                ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), g->addr.sin_addr) : ast_inet_ntoa(iabuf, sizeof(iabuf), g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static");
                while(e) {
-                       // JS: Don't show wilcard endpoint
+                       /* JS: Don't show wilcard endpoint */
                        if (strcmp(e->name, g->wcardep) !=0)
                                ast_cli(fd, "   -- '%s@%s in '%s' is %s\n", e->name, g->name, e->context, e->sub->owner ? "active" : "idle");
                        hasendpoints = 1;
@@ -1311,7 +1310,8 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
        return tmp;
 }
 
-static char* get_sdp_by_line(char* line, char *name, int nameLen) {
+static char* get_sdp_by_line(char* line, char *name, int nameLen)
+{
   if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') {
     char* r = line + nameLen + 1;
     while (*r && (*r < 33)) ++r;
@@ -1321,7 +1321,8 @@ static char* get_sdp_by_line(char* line, char *name, int nameLen) {
   return "";
 }
 
-static char *get_sdp(struct mgcp_request *req, char *name) {
+static char *get_sdp(struct mgcp_request *req, char *name)
+{
   int x;
   int len = strlen(name);
   char *r;
@@ -1333,12 +1334,13 @@ static char *get_sdp(struct mgcp_request *req, char *name) {
   return "";
 }
 
-static void sdpLineNum_iterator_init(int* iterator) {
+static void sdpLineNum_iterator_init(int* iterator)
+{
   *iterator = 0;
 }
 
-static char* get_sdp_iterate(int* iterator,
-                            struct mgcp_request *req, char *name) {
+static char* get_sdp_iterate(int* iterator, struct mgcp_request *req, char *name)
+{
   int len = strlen(name);
   char *r;
   while (*iterator < req->lines) {
@@ -1656,7 +1658,7 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
 #if 0
        printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
 #endif 
-       // Scan through the RTP payload types specified in a "m=" line:
+       /* Scan through the RTP payload types specified in a "m=" line: */
     ast_rtp_pt_clear(sub->rtp);
        codecs = m + len;
        while(strlen(codecs)) {
@@ -1668,18 +1670,18 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
                codecs += len;
        }
 
-        // Next, scan through each "a=rtpmap:" line, noting each
-        // specified RTP payload type (with corresponding MIME subtype):
+        /* Next, scan through each "a=rtpmap:" line, noting each
+         specified RTP payload type (with corresponding MIME subtype): */
         sdpLineNum_iterator_init(&iterator);
         while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
           char* mimeSubtype = strdup(a); // ensures we have enough space
           if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) continue;
-          // Note: should really look at the 'freq' and '#chans' params too
+          /* Note: should really look at the 'freq' and '#chans' params too */
           ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype);
          free(mimeSubtype);
         }
 
-        // Now gather all of the codecs that were asked for:
+        /* Now gather all of the codecs that were asked for: */
         ast_rtp_get_current_formats(sub->rtp,
                                 &peercapability, &peerNonCodecCapability);
        p->capability = capability & peercapability;
@@ -1694,7 +1696,6 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
                return -1;
        }
        return 0;
-       
 }
 
 static int add_header(struct mgcp_request *req, char *var, char *value)
@@ -1710,9 +1711,9 @@ static int add_header(struct mgcp_request *req, char *var, char *value)
        req->header[req->headers] = req->data + req->len;
        snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s: %s\r\n", var, value);
        req->len += strlen(req->header[req->headers]);
-       if (req->headers < MGCP_MAX_HEADERS)
+       if (req->headers < MGCP_MAX_HEADERS) {
                req->headers++;
-       else {
+       else {
                ast_log(LOG_WARNING, "Out of header space\n");
                return -1;
        }
@@ -1733,9 +1734,9 @@ static int add_line(struct mgcp_request *req, char *line)
        req->line[req->lines] = req->data + req->len;
        snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
        req->len += strlen(req->line[req->lines]);
-       if (req->lines < MGCP_MAX_LINES)
+       if (req->lines < MGCP_MAX_LINES) {
                req->lines++;
-       else {
+       else {
                ast_log(LOG_WARNING, "Out of line space\n");
                return -1;
        }
@@ -2113,7 +2114,7 @@ static int transmit_audit_endpoint(struct mgcp_endpoint *p)
        struct mgcp_request resp;
        reqprep(&resp, p, "AUEP");
     /* SC: removed unknown param VS */
-       //add_header(&resp, "F", "A,R,D,S,X,N,I,T,O,ES,E,MD,M");
+       /*add_header(&resp, "F", "A,R,D,S,X,N,I,T,O,ES,E,MD,M");*/
        add_header(&resp, "F", "A");
     /* SC: fill in new fields */
     resp.cmd = MGCP_CMD_AUEP;
@@ -2858,7 +2859,7 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
                        if (option_verbose > 2 && (strcmp(p->name, p->parent->wcardep) != 0)) {
                                        ast_verbose(VERBOSE_PREFIX_3 "Resetting interface %s@%s\n", p->name, p->parent->name);
                        }
-                       // JS: For RSIP on wildcard we reset all endpoints
+                       /* JS: For RSIP on wildcard we reset all endpoints */
                        if (!strcmp(p->name, p->parent->wcardep)) {
                                /* Reset all endpoints */
                                struct mgcp_endpoint *tmp_ep;
@@ -2866,7 +2867,7 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
                                g = p->parent;
                                tmp_ep = g->endpoints;
                                while (tmp_ep) {
-                                       //if ((strcmp(tmp_ep->name, "*") != 0) && (strcmp(tmp_ep->name, "aaln/*") != 0)) {
+                                       /*if ((strcmp(tmp_ep->name, "*") != 0) && (strcmp(tmp_ep->name, "aaln/" "*") != 0)) {*/
                                        if (strcmp(tmp_ep->name, g->wcardep) != 0) {
                                                struct mgcp_subchannel *tmp_sub, *first_sub;
                                                if (option_verbose > 2) {
@@ -2926,7 +2927,9 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
                 return -1;
             }
                    /* do not let * confrnce two down channels */  
-                   if( sub->owner && sub->owner->_state == AST_STATE_DOWN && !sub->next->owner) return -1;
+                       if( sub->owner && sub->owner->_state == AST_STATE_DOWN && !sub->next->owner) {
+                               return -1;
+                       }
 
             if (p->callwaiting || p->transfer || p->threewaycalling) {
                 if (option_verbose > 2) {
@@ -3083,11 +3086,9 @@ static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req,
             if (strstr(p->curtone, "wt") && (ev[0] == 'A')) {
                 memset(p->curtone, 0, sizeof(p->curtone));
             }
-               }
-       else if (!strcasecmp(ev, "T")) {
+               } else if (!strcasecmp(ev, "T")) {
                        /* Digit timeout -- unimportant */
-       }
-       else if (!strcasecmp(ev, "ping")) {
+               } else if (!strcasecmp(ev, "ping")) {
                        /* ping -- unimportant */
                } else {
                        ast_log(LOG_NOTICE, "Received unknown event '%s' from %s@%s\n", ev, p->name, p->parent->name);
@@ -3259,10 +3260,10 @@ static void *do_monitor(void *data)
                /* Lock the network interface */
                ast_mutex_lock(&netlock);
 
+#if 0
         /* XXX THIS IS COMPLETELY HOSED */
         /* The gateway goes into a state of panic */
         /* If the vmwi indicator is sent while it is reseting interfaces */
-#if 0
         lastpass = thispass;
         thispass = time(NULL);
         g = gateways;
@@ -3387,8 +3388,9 @@ static struct ast_channel *mgcp_request(char *type, int format, void *data)
                return NULL;
     }
        tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN);
-       if (!tmpc)
+       if (!tmpc) {
                ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp);
+       }
        restart_monitor();
        return tmpc;
 }
@@ -3555,7 +3557,7 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
                         e->needaudit = 1;
                     }
                     strncpy(gw->wcardep, v->value, sizeof(gw->wcardep)-1);
-                                       //strncpy(e->name, "aaln/*", sizeof(e->name) - 1);
+                                       /*strncpy(e->name, "aaln/" "*", sizeof(e->name) - 1);*/
                                        /* XXX Should we really check for uniqueness?? XXX */
                                        strncpy(e->context, context, sizeof(e->context) - 1);
                                        strncpy(e->callerid, callerid, sizeof(e->callerid) - 1);
@@ -4228,4 +4230,3 @@ char *description()
 {
        return desc;
 }
-