fix gatekeeper logic
[asterisk/asterisk.git] / channels / h323 / chan_h323.c
index 7ba3515..f992e91 100755 (executable)
@@ -70,7 +70,6 @@ static char default_context[AST_MAX_EXTENSION];
 static char gatekeeper[100];
 static int     gatekeeper_disable = 1;
 static int     gatekeeper_discover = 0;
-static int  manual = 0;
 static int  usingGk;
 static int     port = 1720;
 static int     jitter;
@@ -256,6 +255,8 @@ static struct oh323_user *build_user(char *name, struct ast_variable *v)
                                        free(user);
                                        return NULL;
                                } 
+                               /* Let us know we need to use ip authentication */
+                               user->host = 1;
                        } else if (!strcasecmp(v->name, "amaflags")) {
                                format = ast_cdr_amaflags2int(v->value);
                                if (format < 0) {
@@ -957,9 +958,11 @@ int setup_incoming_call(call_details_t cd)
                        strncpy(p->context, default_context, sizeof(p->context)-1);
                        ast_log(LOG_DEBUG, "Sending %s to context [%s]\n", cd.call_source_aliases, p->context);
                } else {
-                       if (strcasecmp(cd.sourceIp, inet_ntoa(user->addr.sin_addr))){
-                               ast_log(LOG_ERROR, "Call from user '%s' rejected due to non-matching IP address: '%s'\n", user->name, cd.sourceIp);
-                                return 0;
+                       if (user->host) {
+                               if (strcasecmp(cd.sourceIp, inet_ntoa(user->addr.sin_addr))){
+                                       ast_log(LOG_ERROR, "Call from user '%s' rejected due to non-matching IP address of '%s'\n", user->name, cd.sourceIp);
+                                       return 0;
+                               }
                        }
                        if (user->incominglimit > 0) {
                                if (user->inUse >= user->incominglimit) {
@@ -1241,7 +1244,7 @@ static int h323_gk_cycle(int fd, int argc, char *argv[])
        h323_gk_urq();
        
        /* Possibly register with a GK */
-       if (!gatekeeper_disable) {
+       if (gatekeeper_disable == 0) {
                if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
                        ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
                        h323_end_process();
@@ -1383,8 +1386,6 @@ int reload_config()
                } else if (!strcasecmp(v->name, "context")) {
                        strncpy(default_context, v->value, sizeof(default_context)-1);
                        printf("  == Setting default context to %s\n", default_context);        
-               } else if (!strcasecmp(v->name, "manual")) {
-                               manual = ast_true(v->value);
                } else if (!strcasecmp(v->name, "dtmfmode")) {
                        if (!strcasecmp(v->value, "inband"))
                                dtmfmode=H323_DTMF_INBAND;
@@ -1530,7 +1531,7 @@ int reload(void)
        reload_config();
 
        /* Possibly register with a GK */
-       if (!gatekeeper_disable) {
+       if (gatekeeper_disable == 0) {
                if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
                        ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
                        h323_end_process();
@@ -1633,7 +1634,7 @@ int load_module()
                }
 
                /* Possibly register with a GK */
-               if (!gatekeeper_disable) {
+               if (gatekeeper_disable == 0) {
                        if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
                                ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
                                h323_end_process();