]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 31 May 2007 03:04:26 +0000 (03:04 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 31 May 2007 03:04:26 +0000 (03:04 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@187 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/openzap/mod_openzap/mod_openzap.c
libs/openzap/src/include/openzap.h
libs/openzap/src/zap_analog.c
libs/openzap/src/zap_io.c

index 25612c196f7be23bdd274f8f3f5cf16be26caa1e..db17d6a95f5d4631a0819aeb4ce61a19e0ad3c97 100644 (file)
@@ -49,11 +49,10 @@ static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0};
 
 typedef enum {
        TFLAG_IO = (1 << 0),
-       TFLAG_OUTBOUND = (1 << 1),
-       TFLAG_DTMF = (1 << 2),
-       TFLAG_CODEC = (1 << 3),
-       TFLAG_BREAK = (1 << 4),
-       TFLAG_HOLD = (1 << 5)
+       TFLAG_DTMF = (1 << 1),
+       TFLAG_CODEC = (1 << 2),
+       TFLAG_BREAK = (1 << 3),
+       TFLAG_HOLD = (1 << 4)
 } TFLAGS;
 
 static struct {
@@ -540,6 +539,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
                                                                                                        switch_caller_profile_t *outbound_profile,
                                                                                                        switch_core_session_t **new_session, switch_memory_pool_t **pool)
 {
+
+       char *dest;
+       int span_id = 0;
+       zap_channel_t *zchan = NULL;
+       switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+       char name[128];
+
+       if (!outbound_profile) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n");
+               return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+       }
+
+       if ((dest = strchr('/', outbound_profile->destination_number))) {
+               dest++;
+               span_id = atoi(outbound_profile->destination_number);
+       }
+
+       if (!span_id) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n");
+               return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+       }
+       
+       if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n");
+               return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+       }
+
        if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
                private_t *tech_pvt;
                switch_channel_t *channel;
@@ -548,36 +574,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
                switch_core_session_add_stream(*new_session, NULL);
                if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
                        channel = switch_core_session_get_channel(*new_session);
-                       tech_init(tech_pvt, *new_session, NULL);
+                       tech_init(tech_pvt, *new_session, zchan);
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
                        switch_core_session_destroy(new_session);
-                       return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-               }
-
-               if (outbound_profile) {
-                       char name[128];
-
-                       snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff);
-                       switch_channel_set_name(channel, name);
-
-                       caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
-                       switch_channel_set_caller_profile(channel, caller_profile);
-                       tech_pvt->caller_profile = caller_profile;
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
-                       switch_core_session_destroy(new_session);
-                       return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                       cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                       goto fail;
                }
 
+               snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number);
+               switch_channel_set_name(channel, name);
+               
+               caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+               switch_channel_set_caller_profile(channel, caller_profile);
+               tech_pvt->caller_profile = caller_profile;
 
+               
                switch_channel_set_flag(channel, CF_OUTBOUND);
-               switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
                switch_channel_set_state(channel, CS_INIT);
                return SWITCH_CAUSE_SUCCESS;
        }
 
-       return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+
+ fail:
+       if (zchan) {
+               zap_channel_done(zchan);
+       }
+       return cause;
 
 }
 
index 0d43156956c84697bf3f3ee68f5e195c145a1b65..acddd89f23c151ef8f23fccdb7d72169acbaf8d6 100644 (file)
@@ -346,6 +346,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t
 zap_status_t zap_channel_open_chan(zap_channel_t *zchan);
 zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan);
 zap_status_t zap_channel_close(zap_channel_t **zchan);
+zap_status_t zap_channel_done(zap_channel_t *zchan);
+zap_status_t zap_channel_use(zap_channel_t *zchan);
 zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj);
 zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to);
 zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen);
index 55acc7814e9c8c1a4a45f436accc56d6a806fc6c..dd41ebe8fa8ce8c4601080fce4d56f9784e3399a 100644 (file)
@@ -167,6 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_DOWN:
                                {
+                                       zap_channel_done(chan);
                                        goto done;
                                }
                                break;
@@ -180,6 +181,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                        switch(chan->state) {
                        case ZAP_CHANNEL_STATE_UP:
                                {
+                                       zap_channel_use(chan);
                                        if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) {
                                                zap_clear_flag(chan, ZAP_CHANNEL_HOLD);
                                                sig.event_id = ZAP_SIGEVENT_FLASH;
@@ -193,6 +195,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_IDLE:
                                {
+                                       zap_channel_use(chan);
                                        sig.event_id = ZAP_SIGEVENT_START;
                                        zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis));
                                        data->sig_cb(&sig);
@@ -201,6 +204,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_DOWN:
                                {
+                                       zap_channel_done(chan);
                                        sig.event_id = ZAP_SIGEVENT_STOP;
                                        data->sig_cb(&sig);
                                        goto done;
@@ -208,6 +212,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_DIALTONE:
                                {
+                                       zap_channel_done(chan);
                                        *dtmf = '\0';
                                        dtmf_offset = 0;
                                        zap_buffer_zero(dt_buffer);
@@ -217,6 +222,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_RING:
                                {
+                                       zap_channel_done(chan);
                                        zap_buffer_zero(dt_buffer);
                                        teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]);
                                        indicate = 1;
@@ -224,6 +230,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_BUSY:
                                {
+                                       zap_channel_done(chan);
                                        zap_buffer_zero(dt_buffer);
                                        teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]);
                                        indicate = 1;
@@ -231,12 +238,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
                                break;
                        case ZAP_CHANNEL_STATE_ATTN:
                                {
+                                       zap_channel_done(chan);
                                        zap_buffer_zero(dt_buffer);
                                        teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]);
                                        indicate = 1;
                                }
                                break;
                        default:
+                               zap_channel_done(chan);
                                break;
                        }
                }
index 3154ac2c059b8fdc551197f0b06f3249de01ff66..813a263846495343f2ebf9d50b60cfc8f390d6b3 100644 (file)
@@ -644,6 +644,26 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t
        return status;
 }
 
+zap_status_t zap_channel_done(zap_channel_t *zchan)
+{
+
+       assert(zchan != NULL);
+
+       zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE);
+
+       return ZAP_SUCCESS;
+}
+
+zap_status_t zap_channel_use(zap_channel_t *zchan)
+{
+
+       assert(zchan != NULL);
+
+       zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE);
+
+       return ZAP_SUCCESS;
+}
+
 zap_status_t zap_channel_close(zap_channel_t **zchan)
 {
        zap_channel_t *check;