diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/alsa-driver-1.0.20-dummy.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/alsa-driver-1.0.20-dummy.c new file mode 120000 index 0000000000..1635114f26 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/alsa-driver-1.0.20-dummy.c @@ -0,0 +1 @@ +./dummy.c \ No newline at end of file diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/dummy.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/dummy.c new file mode 100644 index 0000000000..69a2d4fa08 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/alsa/dummy.c @@ -0,0 +1,787 @@ +/* + * Dummy soundcard + * Copyright (c) by Jaroslav Kysela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include //giova +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +MODULE_AUTHOR("Jaroslav Kysela "); +MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); +MODULE_LICENSE("GPL"); +MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); + +#define MAX_PCM_DEVICES 4 +#define MAX_PCM_SUBSTREAMS 128 +#define MAX_MIDI_DEVICES 2 + + +/* defaults */ +#ifndef MAX_BUFFER_SIZE +#define MAX_BUFFER_SIZE (64*1024) +#endif +#ifndef MAX_PERIOD_SIZE +#define MAX_PERIOD_SIZE MAX_BUFFER_SIZE +#endif +#ifndef USE_FORMATS +#define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) +#endif +#ifndef USE_RATE +#define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 +#define USE_RATE_MIN 5500 +#define USE_RATE_MAX 48000 +#endif +#ifndef USE_CHANNELS_MIN +#define USE_CHANNELS_MIN 1 +#endif +#ifndef USE_CHANNELS_MAX +#define USE_CHANNELS_MAX 2 +#endif +#ifndef USE_PERIODS_MIN +#define USE_PERIODS_MIN 1 +#endif +#ifndef USE_PERIODS_MAX +#define USE_PERIODS_MAX 1024 +#endif +#ifndef add_playback_constraints +#define add_playback_constraints(x) 0 +#endif +#ifndef add_capture_constraints +#define add_capture_constraints(x) 0 +#endif + +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ +static int enable[SNDRV_CARDS] = { 1,[1 ... (SNDRV_CARDS - 1)] = 0 }; +static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1 }; +static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 128 }; + + +module_param_array(index, int, NULL, 0444); +MODULE_PARM_DESC(index, "Index value for dummy soundcard."); +module_param_array(id, charp, NULL, 0444); +MODULE_PARM_DESC(id, "ID string for dummy soundcard."); +module_param_array(enable, bool, NULL, 0444); +MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); +module_param_array(pcm_devs, int, NULL, 0444); +MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); +module_param_array(pcm_substreams, int, NULL, 0444); +MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-64) for dummy driver."); + +static struct platform_device *devices[SNDRV_CARDS]; +static struct timer_list giovatimer; +static int giovastarted = 0; +static int giovaindex = 0; +static spinlock_t giovalock; +struct giovadpcm { + struct snd_pcm_substream *substream; + struct snd_dummy_pcm *dpcm; + int started; +}; +static struct giovadpcm giovadpcms[MAX_PCM_SUBSTREAMS]; + +#define MIXER_ADDR_MASTER 0 +#define MIXER_ADDR_LINE 1 +#define MIXER_ADDR_MIC 2 +#define MIXER_ADDR_SYNTH 3 +#define MIXER_ADDR_CD 4 +#define MIXER_ADDR_LAST 4 + +static void snd_card_dummy_pcm_timer_function(unsigned long data); +struct snd_dummy { + struct snd_card *card; + struct snd_pcm *pcm; + spinlock_t mixer_lock; + int mixer_volume[MIXER_ADDR_LAST + 1][2]; + int capture_source[MIXER_ADDR_LAST + 1][2]; +}; + +struct snd_dummy_pcm { + struct snd_dummy *dummy; + spinlock_t lock; + struct timer_list timer; + unsigned int pcm_buffer_size; + unsigned int pcm_period_size; + unsigned int pcm_bps; /* bytes per second */ + unsigned int pcm_hz; /* HZ */ + unsigned int pcm_irq_pos; /* IRQ position */ + unsigned int pcm_buf_pos; /* position in buffer */ + struct snd_pcm_substream *substream; +}; + + +static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) +{ + int i; + int found = 0; + + for (i = 0; i < giovaindex + 1; i++) { + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm); + } + + if (giovadpcms[i].dpcm == dpcm) { + giovadpcms[i].started = 1; + found = 1; + } + } + if (!found) { + printk("skypopen: start, NOT found?\n"); + } +} + +static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) +{ + int i; + int found = 0; + + for (i = 0; i < giovaindex + 1; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm); + } + if (giovadpcms[i].dpcm == dpcm) { + giovadpcms[i].started = 0; + found = 1; + } + } + if (!found) { + } else { + } +} + +static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm = runtime->private_data; + int err = 0; + + spin_lock_bh(&giovalock); + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + snd_card_dummy_pcm_timer_start(dpcm); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + snd_card_dummy_pcm_timer_stop(dpcm); + break; + default: + err = -EINVAL; + break; + } + spin_unlock_bh(&giovalock); + return 0; +} + +static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm = runtime->private_data; + int bps; + + bps = snd_pcm_format_width(runtime->format) * runtime->rate * runtime->channels / 8; + + if (bps <= 0) + return -EINVAL; + + dpcm->pcm_bps = bps; + dpcm->pcm_hz = HZ; + dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream); + dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream); + dpcm->pcm_irq_pos = 0; + dpcm->pcm_buf_pos = 0; + snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes)); + + return 0; +} + +static void snd_card_dummy_pcm_timer_function(unsigned long data) +{ + struct snd_dummy_pcm *dpcm = NULL; + int i; + + + giovatimer.expires = 1 + jiffies; + add_timer(&giovatimer); + + for (i = 0; i < giovaindex + 1; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm); + } + if (giovadpcms[i].started != 1) + continue; + dpcm = giovadpcms[i].dpcm; + if (dpcm == NULL) { + printk("giova: timer_func %d %d NULL: continue\n", __LINE__, i); + continue; + } + spin_lock_bh(&dpcm->lock); + dpcm->pcm_irq_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz; + if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) { + dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz; + spin_unlock_bh(&dpcm->lock); + snd_pcm_period_elapsed(dpcm->substream); + } else { + spin_unlock_bh(&dpcm->lock); + } + } +} + +static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm = runtime->private_data; + + return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz); +} + +static struct snd_pcm_hardware snd_card_dummy_playback = { + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), + .formats = USE_FORMATS, + .rates = USE_RATE, + .rate_min = USE_RATE_MIN, + .rate_max = USE_RATE_MAX, + .channels_min = USE_CHANNELS_MIN, + .channels_max = USE_CHANNELS_MAX, + .buffer_bytes_max = MAX_BUFFER_SIZE, + .period_bytes_min = 64, + .period_bytes_max = MAX_PERIOD_SIZE, + .periods_min = USE_PERIODS_MIN, + .periods_max = USE_PERIODS_MAX, + .fifo_size = 0, +}; + +static struct snd_pcm_hardware snd_card_dummy_capture = { + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), + .formats = USE_FORMATS, + .rates = USE_RATE, + .rate_min = USE_RATE_MIN, + .rate_max = USE_RATE_MAX, + .channels_min = USE_CHANNELS_MIN, + .channels_max = USE_CHANNELS_MAX, + .buffer_bytes_max = MAX_BUFFER_SIZE, + .period_bytes_min = 64, + .period_bytes_max = MAX_PERIOD_SIZE, + .periods_min = USE_PERIODS_MIN, + .periods_max = USE_PERIODS_MAX, + .fifo_size = 0, +}; + +static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) +{ + int i; + + spin_lock_bh(&giovalock); + + for (i = 0; i < giovaindex; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex); + } + if ((giovadpcms[i].dpcm == runtime->private_data)) { + giovadpcms[i].started = 0; + } else { + } + } + + spin_unlock_bh(&giovalock); + kfree(runtime->private_data); +} + +static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) +{ + return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); +} + +static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) +{ + return snd_pcm_lib_free_pages(substream); +} + +static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) +{ + struct snd_dummy_pcm *dpcm; + int i; + int found = 0; + + dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); + if (!dpcm) { + printk("giova, %s:%d, giovaindex=%d NO MEMORY!!!!\n", __FILE__, __LINE__, giovaindex); + return dpcm; + } + init_timer(&dpcm->timer); + spin_lock_init(&dpcm->lock); + dpcm->substream = substream; + + spin_lock_bh(&giovalock); + for (i = 0; i < giovaindex; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm); + } + if ((giovadpcms[i].substream == substream)) { + found = 1; + break; + } + + } + + if (!found) { + + giovadpcms[giovaindex].substream = substream; + giovaindex++; + } + + + + found = 0; + for (i = 0; i < giovaindex; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm); + } + if (giovadpcms[i].substream == substream) { + giovadpcms[i].dpcm = dpcm; + giovadpcms[i].started = 0; + found = 1; + break; + } + + } + + spin_unlock_bh(&giovalock); + if (!found) { + printk("skypopen giovaindex=%d NOT found????\n", giovaindex); + } + return dpcm; +} + +static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm; + int err; + + if ((dpcm = new_pcm_stream(substream)) == NULL) + return -ENOMEM; + runtime->private_data = dpcm; + /* makes the infrastructure responsible for freeing dpcm */ + runtime->private_free = snd_card_dummy_runtime_free; + runtime->hw = snd_card_dummy_playback; + if (substream->pcm->device & 1) { + runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; + runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; + } + if (substream->pcm->device & 2) + runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID); + err = add_playback_constraints(runtime); + if (err < 0) + return err; + + return 0; +} + +static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm; + int err; + + if ((dpcm = new_pcm_stream(substream)) == NULL) + return -ENOMEM; + runtime->private_data = dpcm; + /* makes the infrastructure responsible for freeing dpcm */ + runtime->private_free = snd_card_dummy_runtime_free; + runtime->hw = snd_card_dummy_capture; + if (substream->pcm->device == 1) { + runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; + runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; + } + if (substream->pcm->device & 2) + runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID); + err = add_capture_constraints(runtime); + if (err < 0) + return err; + + return 0; +} + +static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) +{ + snd_card_dummy_pcm_timer_stop(substream->private_data); + return 0; +} + +static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) +{ + snd_card_dummy_pcm_timer_stop(substream->private_data); + return 0; +} + +static struct snd_pcm_ops snd_card_dummy_playback_ops = { + .open = snd_card_dummy_playback_open, + .close = snd_card_dummy_playback_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_card_dummy_hw_params, + .hw_free = snd_card_dummy_hw_free, + .prepare = snd_card_dummy_pcm_prepare, + .trigger = snd_card_dummy_pcm_trigger, + .pointer = snd_card_dummy_pcm_pointer, +}; + +static struct snd_pcm_ops snd_card_dummy_capture_ops = { + .open = snd_card_dummy_capture_open, + .close = snd_card_dummy_capture_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_card_dummy_hw_params, + .hw_free = snd_card_dummy_hw_free, + .prepare = snd_card_dummy_pcm_prepare, + .trigger = snd_card_dummy_pcm_trigger, + .pointer = snd_card_dummy_pcm_pointer, +}; + +static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams) +{ + struct snd_pcm *pcm; + int err; + + err = snd_pcm_new(dummy->card, "Dummy PCM", device, substreams, substreams, &pcm); + if (err < 0) + return err; + dummy->pcm = pcm; + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); + pcm->private_data = dummy; + pcm->info_flags = 0; + strcpy(pcm->name, "Dummy PCM"); + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, snd_dma_continuous_data(GFP_KERNEL), 128 * 1024, 1024 * 1024); + + return 0; +} + +#define DUMMY_VOLUME(xname, xindex, addr) \ +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ + .name = xname, .index = xindex, \ + .info = snd_dummy_volume_info, \ + .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ + .private_value = addr, \ + .tlv = { .p = db_scale_dummy } } + +static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = -50; + uinfo->value.integer.max = 100; + return 0; +} + +static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); + int addr = kcontrol->private_value; + + if (in_irq()) + printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__); + spin_lock_bh(&dummy->mixer_lock); + ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; + ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; + spin_unlock_bh(&dummy->mixer_lock); + return 0; +} + +static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); + int change, addr = kcontrol->private_value; + int left, right; + + if (in_irq()) + printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__); + left = ucontrol->value.integer.value[0]; + if (left < -50) + left = -50; + if (left > 100) + left = 100; + right = ucontrol->value.integer.value[1]; + if (right < -50) + right = -50; + if (right > 100) + right = 100; + spin_lock_bh(&dummy->mixer_lock); + change = dummy->mixer_volume[addr][0] != left || dummy->mixer_volume[addr][1] != right; + dummy->mixer_volume[addr][0] = left; + dummy->mixer_volume[addr][1] = right; + spin_unlock_bh(&dummy->mixer_lock); + return change; +} + +static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0); + +#define DUMMY_CAPSRC(xname, xindex, addr) \ +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ + .info = snd_dummy_capsrc_info, \ + .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ + .private_value = addr } + +#define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info + +static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); + int addr = kcontrol->private_value; + + if (in_irq()) + printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__); + spin_lock_bh(&dummy->mixer_lock); + ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; + ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; + spin_unlock_bh(&dummy->mixer_lock); + return 0; +} + +static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); + int change, addr = kcontrol->private_value; + int left, right; + + if (in_irq()) + printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__); + left = ucontrol->value.integer.value[0] & 1; + right = ucontrol->value.integer.value[1] & 1; + spin_lock_bh(&dummy->mixer_lock); + change = dummy->capture_source[addr][0] != left && dummy->capture_source[addr][1] != right; + dummy->capture_source[addr][0] = left; + dummy->capture_source[addr][1] = right; + spin_unlock_bh(&dummy->mixer_lock); + return change; +} + +static struct snd_kcontrol_new snd_dummy_controls[] = { + DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), + DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), + DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), + DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH), + DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), + DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), + DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), + DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC), + DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), + DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD) +}; + +static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy) +{ + struct snd_card *card = dummy->card; + unsigned int idx; + int err; + + spin_lock_init(&dummy->mixer_lock); + strcpy(card->mixername, "Dummy Mixer"); + return 0; //giova no mixer + + for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { + err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy)); + if (err < 0) + return err; + } + return 0; +} + +static int __devinit snd_dummy_probe(struct platform_device *devptr) +{ + struct snd_card *card; + struct snd_dummy *dummy; + int idx, err; + int dev = devptr->id; + + card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_dummy)); //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below + if (card == NULL) //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below + return -ENOMEM; //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below + + //giova err = snd_card_create(index[dev], id[dev], THIS_MODULE, + //giova sizeof(struct snd_dummy), &card); + //giova if (err < 0) + //giova return err; + + dummy = card->private_data; + dummy->card = card; + for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { + if (pcm_substreams[dev] < 1) + pcm_substreams[dev] = 1; + if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) + pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; + err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev]); + if (err < 0) + goto __nodev; + } + err = snd_card_dummy_new_mixer(dummy); + if (err < 0) + goto __nodev; + strcpy(card->driver, "Dummy"); + strcpy(card->shortname, "Dummy"); + sprintf(card->longname, "Dummy %i", dev + 1); + + snd_card_set_dev(card, &devptr->dev); + + err = snd_card_register(card); + if (err == 0) { + platform_set_drvdata(devptr, card); + return 0; + } + __nodev: + snd_card_free(card); + return err; +} + +static int __devexit snd_dummy_remove(struct platform_device *devptr) +{ + + del_timer(&giovatimer); + snd_card_free(platform_get_drvdata(devptr)); + platform_set_drvdata(devptr, NULL); + return 0; +} + +#ifdef CONFIG_PM +static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct snd_card *card = platform_get_drvdata(pdev); + struct snd_dummy *dummy = card->private_data; + + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + snd_pcm_suspend_all(dummy->pcm); + return 0; +} + +static int snd_dummy_resume(struct platform_device *pdev) +{ + struct snd_card *card = platform_get_drvdata(pdev); + + snd_power_change_state(card, SNDRV_CTL_POWER_D0); + return 0; +} +#endif + +#define SND_DUMMY_DRIVER "snd_dummy" + +static struct platform_driver snd_dummy_driver = { + .probe = snd_dummy_probe, + .remove = __devexit_p(snd_dummy_remove), +#ifdef CONFIG_PM + .suspend = snd_dummy_suspend, + .resume = snd_dummy_resume, +#endif + .driver = { + .name = SND_DUMMY_DRIVER}, +}; + +static void snd_dummy_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_dummy_driver); +} + +static int __init alsa_card_dummy_init(void) +{ + int i, cards, err; + + err = platform_driver_register(&snd_dummy_driver); + if (err < 0) + return err; + + if (!giovastarted) { + giovastarted = 1; + spin_lock_init(&giovalock); + + spin_lock_bh(&giovalock); + for (i = 0; i < MAX_PCM_SUBSTREAMS; i++) { + + if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { + printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex); + } + giovadpcms[i].substream = NULL; + giovadpcms[i].dpcm = NULL; + giovadpcms[i].started = 0; + } + init_timer(&giovatimer); + giovatimer.data = (unsigned long) &giovadpcms; + giovatimer.function = snd_card_dummy_pcm_timer_function; + giovatimer.expires = 1 + jiffies; + add_timer(&giovatimer); + printk("snd-dummy skypopen driver version: 3, %s:%d working on a machine with %dHZ kernel\n", __FILE__, __LINE__, HZ); + spin_unlock_bh(&giovalock); + } + + + cards = 0; + for (i = 0; i < SNDRV_CARDS; i++) { + struct platform_device *device; + if (!enable[i]) + continue; + device = platform_device_register_simple(SND_DUMMY_DRIVER, i, NULL, 0); + if (IS_ERR(device)) + continue; + if (!platform_get_drvdata(device)) { + platform_device_unregister(device); + continue; + } + devices[i] = device; + cards++; + } + if (!cards) { +#ifdef MODULE + printk(KERN_ERR "Dummy soundcard not found or device busy\n"); +#endif + snd_dummy_unregister_all(); + return -ENODEV; + } + return 0; +} + +static void __exit alsa_card_dummy_exit(void) +{ + del_timer(&giovatimer); + snd_dummy_unregister_all(); +} + +module_init(alsa_card_dummy_init) + module_exit(alsa_card_dummy_exit) diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/Makefile b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/Makefile new file mode 100644 index 0000000000..86aab9175e --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/Makefile @@ -0,0 +1,93 @@ +# +# Asterisk -- A telephony toolkit for Linux. +# +# Makefile for channel drivers +# +# Copyright (C) 1999-2005, Mark Spencer +# +# Mark Spencer +# +# Edited By Belgarath <> Aug 28 2004 +# Added bare bones ultrasparc-linux support. +# +# This program is free software, distributed under the terms of +# the GNU General Public License +# + +#ASTERISK INCLUDE FILES +#The directory that contains the Asterisk include files (eg: /usr/include or /usr/include/asterisk or /usr/src/asterisk/include or ...) +#AST_INCLUDE_DIR=/usr/src/asterisk/include +#AST_INCLUDE_DIR=/home/maruzz/devel/svn_asterisk_trunk/include +#AST_INCLUDE_DIR=/home/maruzz/devel/svn_asterisk_branches_160/include +#AST_INCLUDE_DIR=/home/maruzz/devel/svn_asterisk_branches_12/include +#AST_INCLUDE_DIR=/home/maruzz/devel/svn_asterisk_branches_14/include +#AST_INCLUDE_DIR=/home/maruzz/devel/svn_celliax_trunk/asterisk-1.2.rev137401/include +AST_INCLUDE_DIR=/home/user/devel/asterisk-1.4.23.1/include + +#ASTERISK +CFLAGS+=-DASTERISK + +#ASTERISK VERSION +#Uncomment one of the following lines to match your Asterisk series +CFLAGS+=-DASTERISK_VERSION_1_4 +#CFLAGS+=-DASTERISK_VERSION_1_6 +#CFLAGS+=-DASTERISK_VERSION_1_2 + +#LINUX SKYPE SUPPORT (Celliax for Cygwin always supports Skype) +SKYPE_LIB=-L/usr/X11R6/lib -lX11 + +CFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations +CFLAGS+=-g3 + + + +CFLAGS+=-I$(AST_INCLUDE_DIR) -I. +CFLAGS+=-D_REENTRANT -D_GNU_SOURCE +#CFLAGS+=-O6 +CFLAGS+=-march=i686 +CFLAGS+=-fomit-frame-pointer +ifeq ($(shell uname -m),x86_64) +CFLAGS+=-fPIC +endif + +SVNDEF := -D'SKYPIAX_SVN_VERSION="$(shell svnversion -n ..)"' +CFLAGS += $(SVNDEF) + + +SOLINK=-shared -Xlinker -x +CHANNEL_LIBS=chan_skypiax.so +CC=gcc + +OSARCH=$(shell uname -s) + +ifeq ($(findstring CYGWIN,$(OSARCH)),CYGWIN) +# definition of pthread_kill as a printf (or as a noop) is required for Asterisk (and skypiax) to run on Cygwin +# without it, each time (often) pthread_kill is called (by any thread, with any signal, URG included), bad things happen +CC=gcc -D pthread_kill=cyg_no_pthreadkill +AST_DLL_DIR=/home/maruzz/devel/svn_asterisk_branches_12 +CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols cyg_no_pthread_kill.o +CYGSOLIB=-L/usr/lib/w32api -lrpcrt4 -L/lib/mingw -lwinmm -L$(AST_DLL_DIR) -lasterisk.dll -L$(AST_DLL_DIR)/res -lres_features.so +SKYPE_LIB= +CHANNEL_LIBS=cyg_no_pthread_kill.o chan_skypiax.so +endif + +all: $(CHANNEL_LIBS) + +clean: + rm -f *.so *.o *.so.a + + +#chan_skypiax section begins + +#to debug threads and lock on 1.4 uncomment the following +#CFLAGS+=-include /usr/src/asterisk/include/asterisk/autoconfig.h + + +cyg_no_pthread_kill.o: cyg_no_pthread_kill.c + $(CC) $(CFLAGS) -c -o cyg_no_pthread_kill.o cyg_no_pthread_kill.c +chan_skypiax.o: chan_skypiax.c + $(CC) $(CFLAGS) -c -o chan_skypiax.o chan_skypiax.c +chan_skypiax.so: chan_skypiax.o skypiax_protocol.o + $(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_skypiax.o skypiax_protocol.o -lm -ldl $(SKYPE_LIB) ${CYGSOLIB} +#chan_skypiax section ends + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/README b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/README new file mode 100644 index 0000000000..a3d352e0c6 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/README @@ -0,0 +1 @@ +Skypopen for asterisk does not work yet. diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/chan_skypiax.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/chan_skypiax.c new file mode 100644 index 0000000000..1759ab0185 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/chan_skypiax.c @@ -0,0 +1,2315 @@ +//indent -gnu -ts4 -br -brs -cdw -lp -ce -nbfda -npcs -nprs -npsl -nbbo -saf -sai -saw -cs -bbo -nhnl -nut -sob -l90 +#include "skypiax.h" + +/* LOCKS */ +/*! \brief Protect the skypiax_usecnt */ +AST_MUTEX_DEFINE_STATIC(skypiax_usecnt_lock); +/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not + * when it's doing something critical. */ +AST_MUTEX_DEFINE_STATIC(skypiax_monlock); +/*! \brief Protect the interfaces list */ +AST_MUTEX_DEFINE_STATIC(skypiax_iflock); + +/* GLOBAL VARIABLES */ +int running = 1; +int skypiax_dir_entry_extension = 1; //FIXME one var for each interface! +char skypiax_console_active_array[50] = ""; +char *skypiax_console_active = skypiax_console_active_array; +/*! \brief Count of active channels for this module */ +int skypiax_usecnt = 0; +int skypiax_debug = 0; +/*! \brief This is the thread for the monitor which checks for input on the channels + * which are not currently in use. */ +pthread_t skypiax_monitor_thread = AST_PTHREADT_NULL; +pthread_t skypiax_monitor_audio_thread = AST_PTHREADT_NULL; + +/* CONSTANTS */ +/*! \brief Textual description for this module */ +const char skypiax_desc[] = "Skypiax, Skype Driver"; +/*! \brief Textual type for this module */ +const char skypiax_type[] = "Skypiax"; +/*! \brief Name of configuration file for this module */ +const char skypiax_config[] = "skypiax.conf"; + +char skypiax_console_skypiax_usage[] = + " \n" "chan_skypiax commands info\n" " \n" + " chan_skypiax adds to Asterisk the following CLI commands:\n" " \n" + " CLI COMMANDS:\n" " skypiax_hangup\n" " skypiax_dial\n" + " skypiax_console\n" " skypiax_playback_boost\n" + " skypiax_capture_boost\n" " skypiax_skype\n" + " skypiax_dir_import\n" "\n" " You can type 'help [command]' to obtain more specific info on usage.\n" " \n"; +char skypiax_console_hangup_usage[] = + "Usage: skypiax_hangup\n" + " Hangs up any call currently placed on the \"current\" skypiax_console (Skypiax) channel.\n" + " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; +char skypiax_console_playback_boost_usage[] = + "Usage: skypiax_playback_boost [value]\n" + " Shows or set the value of boost applied to the outgoing sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n" + " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; +char skypiax_console_capture_boost_usage[] = + "Usage: skypiax_capture_boost [value]\n" + " Shows or set the value of boost applied to the incoming sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n" + " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; + +char skypiax_console_dial_usage[] = + "Usage: skypiax_dial [DTMFs]\n" + " Dials a given DTMF string in the call currently placed on the\n" + " \"current\" skypiax_console (Skypiax) channel.\n" " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; + +char skypiax_console_skypiax_console_usage[] = + "Usage: skypiax_console [interface] | [show]\n" + " If used without a parameter, displays which interface is the \"current\"\n" + " skypiax_console. If a device is specified, the \"current\" skypiax_console is changed to\n" + " the interface specified.\n" " If the parameter is \"show\", the available interfaces are listed\n"; + +char skypiax_console_skype_usage[] = + "Usage: skypiax_skype [command string]\n" + " Send the 'command string' skype_msg to the Skype client connected to the \"current\" skypiax_console (Skypiax) channel.\n" + " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; + +char skypiax_console_skypiax_dir_import_usage[] = + "Usage: skypiax_dir_import [add | replace]\n" + " Write in the directoriax.conf config file all the entries found in 'Contacts' list of the Skype client connected to the \"current\" skypiax_console.\n" + " You can choose between 'add' to the end of the directoriax.conf file, or 'replace' the whole file with this new content.\n" + " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n"; + +/*! \brief Definition of this channel for PBX channel registration */ +const struct ast_channel_tech skypiax_tech = { + .type = skypiax_type, + .description = skypiax_desc, + .capabilities = AST_FORMAT_SLINEAR, + .requester = skypiax_request, + .hangup = skypiax_hangup, + .answer = skypiax_answer, + .read = skypiax_read, + .call = skypiax_originate_call, + .write = skypiax_write, + .indicate = skypiax_indicate, + .fixup = skypiax_fixup, + .devicestate = skypiax_devicestate, +#ifdef ASTERISK_VERSION_1_4 + .send_digit_begin = skypiax_digitsend_begin, + .send_digit_end = skypiax_digitsend_end, +#else /* ASTERISK_VERSION_1_4 */ + .send_digit = skypiax_digitsend, +#endif /* ASTERISK_VERSION_1_4 */ +}; + +/*! \brief fake skypiax_pvt structure values, + * just for logging purposes */ +struct skypiax_pvt skypiax_log_struct = { + .name = "none", +}; + +/*! \brief Default skypiax_pvt structure values, + * used by skypiax_mkif to initialize the interfaces */ +struct skypiax_pvt skypiax_default = { + .interface_state = SKYPIAX_STATE_DOWN, + .skype_callflow = 0, + .context = "default", + .language = "en", + .exten = "s", + .next = NULL, + .owner = NULL, + .controldev_thread = AST_PTHREADT_NULL, + .skypiax_sound_rate = 8000, + .skypiax_sound_capt_fd = -1, + .capture_boost = 0, + .playback_boost = 0, + .stripmsd = 0, + .skype = 0, + .skypiax_dir_entry_extension_prefix = 6, +}; + +/*! + * \brief PVT structure for a skypiax interface (channel), created by skypiax_mkif + */ +struct skypiax_pvt *skypiax_iflist = NULL; + +#ifdef ASTERISK_VERSION_1_6 +struct ast_cli_entry myclis[] = { +/* + * CLI do not works since some time on 1.6, they changed the CLI mechanism + */ +#if 0 + AST_CLI_DEFINE(skypiax_console_hangup, "Hangup a call on the console"), + AST_CLI_DEFINE(skypiax_console_dial, "Dial an extension on the console"), + AST_CLI_DEFINE(skypiax_console_playback_boost, "Sets/displays spk boost in dB"), + AST_CLI_DEFINE(skypiax_console_capture_boost, "Sets/displays mic boost in dB"), + AST_CLI_DEFINE(skypiax_console_set_active, "Sets/displays active console"), + AST_CLI_DEFINE(skypiax_console_skype, "Sends a Skype command"), + AST_CLI_DEFINE(skypiax_console_skypiax_dir_import, "imports entries from cellphone"), + AST_CLI_DEFINE(skypiax_console_skypiax, "all things skypiax"), +#endif +}; +#else +struct ast_cli_entry myclis[] = { + {{"skypiax_hangup", NULL}, skypiax_console_hangup, + "Hangup a call on the skypiax_console", + skypiax_console_hangup_usage}, + {{"skypiax_playback_boost", NULL}, skypiax_console_playback_boost, "playback boost", + skypiax_console_playback_boost_usage}, + {{"skypiax_capture_boost", NULL}, skypiax_console_capture_boost, "capture boost", + skypiax_console_capture_boost_usage}, + {{"skypiax_usage", NULL}, skypiax_console_skypiax, "chan_skypiax commands info", + skypiax_console_skypiax_usage}, + {{"skypiax_skype", NULL}, skypiax_console_skype, "Skype msg", + skypiax_console_skype_usage}, + {{"skypiax_dial", NULL}, skypiax_console_dial, + "Dial an extension on the skypiax_console", + skypiax_console_dial_usage}, + {{"skypiax_console", NULL}, skypiax_console_set_active, + "Sets/displays active skypiax_console", + skypiax_console_skypiax_console_usage}, + {{"skypiax_dir_import", NULL}, skypiax_console_skypiax_dir_import, + "Write the directoriax.conf file, used by directoriax app", + skypiax_console_skypiax_dir_import_usage}, +}; +#endif + +/* IMPLEMENTATION */ + +void skypiax_unlocka_log(void *x) +{ + ast_mutex_t *y; + y = x; + int i; + + for (i = 0; i < 5; i++) { //let's be generous + + ast_log(LOG_DEBUG, + SKYPIAX_SVN_VERSION + "[%-7lx] I'm a dying thread, and I'm to go unlocking mutex %p for the %dth time\n", (unsigned long int) pthread_self(), y, i); + + ast_mutex_unlock(y); + } + ast_log(LOG_DEBUG, SKYPIAX_SVN_VERSION "[%-7lx] I'm a dying thread, I've finished unlocking mutex %p\n", (unsigned long int) pthread_self(), y); +} + +int skypiax_queue_control(struct ast_channel *c, int control) +{ + struct skypiax_pvt *p = c->tech_pvt; + +/* queue the frame */ + if (p) + p->control_to_send = control; + else { + return 0; + } + DEBUGA_PBX("Queued CONTROL FRAME %d\n", SKYPIAX_P_LOG, control); + +/* wait for the frame to be sent */ + while (p->control_to_send) + usleep(1); + + return 0; +} + +int skypiax_devicestate(void *data) +{ + struct skypiax_pvt *p = NULL; + char *name = data; + int res = AST_DEVICE_INVALID; + + if (!data) { + ERRORA("Devicestate requested with no data\n", SKYPIAX_P_LOG); + return res; + } + + /* lock the interfaces' list */ + LOKKA(&skypiax_iflock); + /* make a pointer to the first interface in the interfaces list */ + p = skypiax_iflist; + /* Search for the requested interface and verify if is unowned */ + while (p) { + size_t length = strlen(p->name); + /* is this the requested interface? */ + if (strncmp(name, p->name, length) == 0) { + /* is this interface unowned? */ + if (!p->owner) { + res = AST_DEVICE_NOT_INUSE; + DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG); + } else { + /* interface owned by a channel */ + res = AST_DEVICE_INUSE; + DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG); + } + + /* we found the requested interface, bail out from the while loop */ + break; + } + /* not yet found, next please */ + p = p->next; + } + /* unlock the interfaces' list */ + UNLOCKA(&skypiax_iflock); + + if (res == AST_DEVICE_INVALID) { + ERRORA("Checking device state for interface [%s] returning AST_DEVICE_INVALID\n", SKYPIAX_P_LOG, name); + } + return res; +} + +#ifndef ASTERISK_VERSION_1_4 +int skypiax_indicate(struct ast_channel *c, int cond) +#else +int skypiax_indicate(struct ast_channel *c, int cond, const void *data, size_t datalen) +#endif +{ + struct skypiax_pvt *p = c->tech_pvt; + int res = 0; + + NOTICA("Let's INDICATE %d\n", SKYPIAX_P_LOG, cond); + + switch (cond) { + case AST_CONTROL_BUSY: + case AST_CONTROL_CONGESTION: + case AST_CONTROL_RINGING: + case -1: + res = -1; /* Ask for inband indications */ + break; + case AST_CONTROL_PROGRESS: + case AST_CONTROL_PROCEEDING: + case AST_CONTROL_VIDUPDATE: + case AST_CONTROL_HOLD: + case AST_CONTROL_UNHOLD: +#ifdef ASTERISK_VERSION_1_4 + case AST_CONTROL_SRCUPDATE: +#endif /* ASTERISK_VERSION_1_4 */ + break; + default: + WARNINGA("Don't know how to display condition %d on %s\n", SKYPIAX_P_LOG, cond, c->name); + /* The core will play inband indications for us if appropriate */ + res = -1; + } + + return res; +} + +/*! \brief PBX interface function -build skypiax pvt structure + * skypiax calls initiated by the PBX arrive here */ +struct ast_channel *skypiax_request(const char *type, int format, void *data, int *cause) +{ + struct skypiax_pvt *p = NULL; + struct ast_channel *tmp = NULL; + char *name = data; + int found = 0; + + DEBUGA_PBX("Try to request type: %s, name: %s, cause: %d," " format: %d\n", SKYPIAX_P_LOG, type, name, *cause, format); + + if (!data) { + ERRORA("Channel requested with no data\n", SKYPIAX_P_LOG); + return NULL; + } + + char interface[256]; + int i; + memset(interface, '\0', sizeof(interface)); + + for (i = 0; i < sizeof(interface); i++) { + if (name[i] == '/') + break; + interface[i] = name[i]; + } + /* lock the interfaces' list */ + LOKKA(&skypiax_iflock); + /* make a pointer to the first interface in the interfaces list */ + p = skypiax_iflist; + + if (strcmp("ANY", interface) == 0) { + /* we've been asked for the "ANY" interface, let's find the first idle interface */ + DEBUGA_SKYPE("Finding one available skype interface\n", SKYPIAX_P_LOG); + p = find_available_skypiax_interface(); + if (p) { + found = 1; + + /* create a new channel owning this interface */ + tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context); + if (!tmp) { + /* the channel was not created, probable memory allocation error */ + *cause = AST_CAUSE_SWITCH_CONGESTION; + } + + } + + } + + /* Search for the requested interface and verify if is unowned and format compatible */ + while (p && !found) { + //size_t length = strlen(p->name); + /* is this the requested interface? */ + if (strcmp(interface, p->name) == 0) { + /* is the requested format supported by this interface? */ + if ((format & AST_FORMAT_SLINEAR) != 0) { + /* is this interface unowned? */ + if (!p->owner) { + DEBUGA_PBX("Requesting: %s, name: %s, format: %d\n", SKYPIAX_P_LOG, type, name, format); + /* create a new channel owning this interface */ + tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context); + if (!tmp) { + /* the channel was not created, probable memory allocation error */ + *cause = AST_CAUSE_SWITCH_CONGESTION; + } + } else { + /* interface owned by another channel */ + WARNINGA("owned by another channel\n", SKYPIAX_P_LOG); + *cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL; + } + } else { + /* requested format not supported */ + WARNINGA("format %d not supported\n", SKYPIAX_P_LOG, format); + *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; + } + /* we found the requested interface, bail out from the while loop */ + break; + } + /* not yet found, next please */ + p = p->next; + } + /* unlock the interfaces' list */ + UNLOCKA(&skypiax_iflock); + /* restart the monitor so it will watch only the remaining unowned interfaces */ + skypiax_restart_monitor(); + if (tmp == NULL) { + /* new channel was not created */ + WARNINGA("Unable to create new Skypiax channel %s\n", SKYPIAX_P_LOG, name); + } + /* return the newly created channel */ + return tmp; +} + +/*! \brief Hangup skypiax call + * Part of PBX interface, called from ast_hangup */ + +int skypiax_hangup(struct ast_channel *c) +{ + struct skypiax_pvt *p; + + /* get our skypiax pvt interface from channel */ + p = c->tech_pvt; + /* if there is not skypiax pvt why we are here ? */ + if (!p) { + ERRORA("Asked to hangup channel not connected\n", SKYPIAX_P_LOG); + return 0; + } + + if (p->skype && p->interface_state != SKYPIAX_STATE_DOWN) { + char msg_to_skype[1024]; + p->interface_state = SKYPIAX_STATE_HANGUP_REQUESTED; + DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id); + //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id); + sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id); + skypiax_signaling_write(p, msg_to_skype); + } + + while (p->interface_state != SKYPIAX_STATE_DOWN) { + usleep(10000); + } + DEBUGA_SKYPE("Now is really DOWN\n", SKYPIAX_P_LOG); + /* shutdown the serial monitoring thread */ + if (p->controldev_thread && (p->controldev_thread != AST_PTHREADT_NULL) + && (p->controldev_thread != AST_PTHREADT_STOP)) { + if (pthread_cancel(p->controldev_thread)) { + ERRORA("controldev_thread pthread_cancel failed, maybe he killed himself?\n", SKYPIAX_P_LOG); + } + /* push it, maybe is stuck in a select or so */ + if (pthread_kill(p->controldev_thread, SIGURG)) { + DEBUGA_SERIAL("controldev_thread pthread_kill failed, no problem\n", SKYPIAX_P_LOG); + } +#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */ + /* wait for it to die */ + if (pthread_join(p->controldev_thread, NULL)) { + ERRORA("controldev_thread pthread_join failed, BAD\n", SKYPIAX_P_LOG); + } +#else /* __CYGWIN__ */ +/* allow the serial thread to die */ + usleep(300000); //300msecs +#endif /* __CYGWIN__ */ + } + p->controldev_thread = AST_PTHREADT_NULL; + + p->interface_state = SKYPIAX_STATE_DOWN; + p->skype_callflow = CALLFLOW_CALL_IDLE; + + DEBUGA_PBX("I'll send AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG); + ast_queue_control(p->owner, AST_CONTROL_HANGUP); + DEBUGA_PBX("I've sent AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG); + + /* subtract one to the usage count of Skypiax-type channels */ + LOKKA(&skypiax_usecnt_lock); + skypiax_usecnt--; + if (skypiax_usecnt < 0) + ERRORA("Usecnt < 0???\n", SKYPIAX_P_LOG); + UNLOCKA(&skypiax_usecnt_lock); + ast_update_use_count(); + + /* our skypiax pvt interface is no more part of a channel */ + p->owner = NULL; + /* our channel has no more this skypiax pvt interface to manage */ + c->tech_pvt = NULL; + /* set the channel state to DOWN, eg. available, not in active use */ + if (ast_setstate(c, SKYPIAX_STATE_DOWN)) { + ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG); + return -1; + } + + /* restart the monitor thread, so it can recheck which interfaces it have to watch during its loop (the interfaces that are not owned by channels) */ + if (skypiax_restart_monitor()) { + ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG); + return -1; + } + + return 0; +} + +/*! \brief Answer incoming call, + * Part of PBX interface */ +int skypiax_answer(struct ast_channel *c) +{ + struct skypiax_pvt *p = c->tech_pvt; + int res; + + /* whle ringing, we just wait, the skype thread will answer */ + while (p->interface_state == SKYPIAX_STATE_RING) { + usleep(10000); //10msec + } + if (p->interface_state != SKYPIAX_STATE_UP) { + ERRORA("call answering failed, we want it to be into interface_state=%d, got %d\n", SKYPIAX_P_LOG, SKYPIAX_STATE_UP, p->interface_state); + res = -1; + } else { + DEBUGA_PBX("call answered\n", SKYPIAX_P_LOG); + res = 0; + } + return res; +} + +#ifdef ASTERISK_VERSION_1_4 +int skypiax_digitsend_begin(struct ast_channel *c, char digit) +{ + struct skypiax_pvt *p = c->tech_pvt; + + DEBUGA_PBX("DIGIT BEGIN received: %c\n", SKYPIAX_P_LOG, digit); + + return 0; +} + +int skypiax_digitsend_end(struct ast_channel *c, char digit, unsigned int duration) +{ + struct skypiax_pvt *p = c->tech_pvt; + char msg_to_skype[1024]; + + NOTICA("DIGIT END received: %c %d\n", SKYPIAX_P_LOG, digit, duration); + + sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit); + + skypiax_signaling_write(p, msg_to_skype); + + return 0; +} +#else /* ASTERISK_VERSION_1_4 */ +int skypiax_digitsend(struct ast_channel *c, char digit) +{ + struct skypiax_pvt *p = c->tech_pvt; + char msg_to_skype[1024]; + + NOTICA("DIGIT received: %c\n", SKYPIAX_P_LOG, digit); + + sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit); + + skypiax_signaling_write(p, msg_to_skype); + + return 0; +} + +#endif /* ASTERISK_VERSION_1_4 */ +//struct ast_frame *skypiax_audio_read(struct skypiax_pvt *p) +//#define SAMPLES_PER_FRAME 160 +/*! \brief Read audio frames from channel */ +struct ast_frame *skypiax_read(struct ast_channel *c) +{ + struct skypiax_pvt *p = c->tech_pvt; + static struct ast_frame f; + static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2]; + short *buf; + int samples; + +/* if there are control frames queued to be sent by skypiax_queue_control, send it the first */ +//TODO maybe better a real queue? + if (p && p->owner && p->control_to_send) { + ast_queue_control(p->owner, p->control_to_send); + DEBUGA_PBX("Sent CONTROL FRAME %d\n", SKYPIAX_P_LOG, p->control_to_send); + p->control_to_send = 0; + } + + memset(__buf, '\0', (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2)); + + buf = __buf + AST_FRIENDLY_OFFSET / 2; + + f.frametype = AST_FRAME_NULL; + f.subclass = 0; + f.samples = 0; + f.datalen = 0; + f.data = NULL; + f.offset = 0; + f.src = skypiax_type; + f.mallocd = 0; + f.delivery.tv_sec = 0; + f.delivery.tv_usec = 0; + +/* if the call is not active (ie: answered), do not send audio frames, they would pile up in a lag queue */ + if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) { + return &f; + } + + if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) { + DEBUGA_SOUND("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, SAMPLES_PER_FRAME * sizeof(short)); + usleep(100); + //do nothing + } else { + //DEBUGA_SOUND("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples); + /* A real frame */ + f.frametype = AST_FRAME_VOICE; + f.subclass = AST_FORMAT_SLINEAR; + f.samples = SKYPIAX_FRAME_SIZE; + f.datalen = SKYPIAX_FRAME_SIZE * 2; + f.data = buf; + f.offset = AST_FRIENDLY_OFFSET; + f.src = skypiax_type; + f.mallocd = 0; + + if (p->capture_boost) + skypiax_sound_boost(&f, p->capture_boost); + } + + return &f; +} + +/*! \brief Initiate skypiax call from PBX + * used from the dial() application + */ +int skypiax_originate_call(struct ast_channel *c, char *idest, int timeout) +{ + struct skypiax_pvt *p = NULL; + p = c->tech_pvt; + char rdest[80], *where, dstr[100] = ""; + char *stringp = NULL; + int status; + + if ((c->_state != SKYPIAX_STATE_DOWN) + && (c->_state != SKYPIAX_STATE_RESERVED)) { + ERRORA("skypiax_originate_call called on %s, neither down nor reserved\n", SKYPIAX_P_LOG, c->name); + return -1; + } + + DEBUGA_PBX("skypiax_originate_call to call idest: %s, timeout: %d!\n", SKYPIAX_P_LOG, idest, timeout); + + strncpy(rdest, idest, sizeof(rdest) - 1); + stringp = rdest; + strsep(&stringp, "/"); + where = strsep(&stringp, "/"); + if (!where) { + ERRORA("Destination %s requires an actual destination (Skypiax/device/destination)\n", SKYPIAX_P_LOG, idest); + return -1; + } + + strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1); + DEBUGA_PBX("skypiax_originate_call dialing idest: %s, timeout: %d, dstr: %s!\n", SKYPIAX_P_LOG, idest, timeout, dstr); + + strcpy(p->session_uuid_str, "dialing"); + status = skypiax_call(p, dstr, timeout); + if (status) { + WARNINGA("skypiax_originate_call dialing failed: %d!\n", SKYPIAX_P_LOG, status); + return -1; + } + + DEBUGA_PBX("skypiax_originate_call dialed idest: %s, timeout: %d, dstr: %s!\n", SKYPIAX_P_LOG, idest, timeout, dstr); + + ast_setstate(p->owner, SKYPIAX_STATE_DIALING); + return 0; +} + +int skypiax_sound_boost(struct ast_frame *f, double boost) +{ +/* LUIGI RIZZO's magic */ + if (boost != 0) { /* scale and clip values */ + int i, x; + int16_t *ptr = (int16_t *) f->data; + for (i = 0; i < f->samples; i++) { + x = (ptr[i] * boost) / BOOST_SCALE; + if (x > 32767) { + x = 32767; + } else if (x < -32768) { + x = -32768; + } + ptr[i] = x; + } + } + return 0; +} + +/*! \brief Send audio frame to channel */ +int skypiax_write(struct ast_channel *c, struct ast_frame *f) +{ + struct skypiax_pvt *p = c->tech_pvt; + int sent; + + if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) { + return 0; + } + if (p->playback_boost) + skypiax_sound_boost(f, p->playback_boost); + + sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen); + //skypiax_sound_write(p, f); + + return 0; +} + +/*! \brief Fix up a channel: If a channel is consumed, this is called. + * Basically update any ->owner links */ +int skypiax_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) +{ + struct skypiax_pvt *p = newchan->tech_pvt; + + if (!p) { + ERRORA("No pvt after masquerade. Strange things may happen\n", SKYPIAX_P_LOG); + return -1; + } + + if (p->owner != oldchan) { + ERRORA("old channel wasn't %p but was %p\n", SKYPIAX_P_LOG, oldchan, p->owner); + return -1; + } + + p->owner = newchan; + return 0; +} + +struct ast_channel *skypiax_new(struct skypiax_pvt *p, int state, char *context) +{ + struct ast_channel *tmp; + + /* alloc a generic channel struct */ +#ifndef ASTERISK_VERSION_1_4 + tmp = ast_channel_alloc(1); +#else + //tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, ""); + //tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "Skypiax/%s", p->name); + tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "Skypiax/%s", p->name); + +#endif /* ASTERISK_VERSION_1_4 */ + if (tmp) { + + /* give a name to the newly created channel */ +#ifndef ASTERISK_VERSION_1_4 + snprintf(tmp->name, sizeof(tmp->name), "Skypiax/%s", p->name); + tmp->type = skypiax_type; +#else /* ASTERISK_VERSION_1_4 */ + ast_string_field_build(tmp, name, "Skypiax/%s", p->name); +#endif /* ASTERISK_VERSION_1_4 */ + + DEBUGA_PBX("new channel: name=%s requested_state=%d\n", SKYPIAX_P_LOG, tmp->name, state); + + /* fd for the channel to poll for incoming audio */ + tmp->fds[0] = p->skypiax_sound_capt_fd; + + /* audio formats managed */ + tmp->nativeformats = AST_FORMAT_SLINEAR; + tmp->readformat = AST_FORMAT_SLINEAR; + tmp->writeformat = AST_FORMAT_SLINEAR; + /* the technology description (eg. the interface type) of the newly created channel is the Skypiax's one */ + tmp->tech = &skypiax_tech; + /* the technology pvt (eg. the interface) of the newly created channel is this interface pvt */ + tmp->tech_pvt = p; + + /* copy this interface default context, extension, language to the newly created channel */ + if (strlen(p->context)) + strncpy(tmp->context, p->context, sizeof(tmp->context) - 1); + if (strlen(p->exten)) + strncpy(tmp->exten, p->exten, sizeof(tmp->exten) - 1); +#ifndef ASTERISK_VERSION_1_4 + if (strlen(p->language)) + strncpy(tmp->language, p->language, sizeof(tmp->language) - 1); +#else + if (strlen(p->language)) + ast_string_field_set(tmp, language, p->language); +#endif /* ASTERISK_VERSION_1_4 */ + /* copy the requested context (not necessarily the interface default) to the newly created channel */ + if (strlen(context)) + strncpy(tmp->context, context, sizeof(tmp->context) - 1); + + /* copy this interface default callerid in the newly created channel */ + ast_set_callerid(tmp, !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL, + !ast_strlen_zero(p->callid_name) ? p->callid_name : NULL, !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL); + + DEBUGA_PBX("callid_number=%s, callid_name=%s\n", SKYPIAX_P_LOG, p->callid_number, p->callid_name); + + /* the owner of this interface pvt is the newly created channel */ + p->owner = tmp; + /* set the newly created channel state to the requested state */ + if (ast_setstate(tmp, state)) { + ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG); + //ast_dsp_free(p->dsp); + ast_channel_free(tmp); + return NULL; + } + /* if the requested state is different from DOWN, let the pbx manage this interface (now part of the newly created channel) */ + if (state != SKYPIAX_STATE_DOWN) { + DEBUGA_PBX("Try to start PBX on %s, state=%d\n", SKYPIAX_P_LOG, tmp->name, state); + if (ast_pbx_start(tmp)) { + ERRORA("Unable to start PBX on %s\n", SKYPIAX_P_LOG, tmp->name); + ast_channel_free(tmp); + return NULL; + } + } + /* let's start the serial monitoring thread too, so we can have serial signaling */ + if (ast_pthread_create(&p->controldev_thread, NULL, skypiax_do_controldev_thread, p) < 0) { + ERRORA("Unable to start controldev thread.\n", SKYPIAX_P_LOG); + ast_channel_free(tmp); + tmp = NULL; + } + DEBUGA_SERIAL("STARTED controldev_thread=%lu STOP=%lu NULL=%lu\n", SKYPIAX_P_LOG, + (unsigned long) p->controldev_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL); + + /* add one to the usage count of Skypiax-type channels */ + LOKKA(&skypiax_usecnt_lock); + skypiax_usecnt++; + UNLOCKA(&skypiax_usecnt_lock); + ast_update_use_count(); + + /* return the newly created channel */ + return tmp; + } + ERRORA("failed memory allocation for Skypiax channel\n", SKYPIAX_P_LOG); + return NULL; +} + +/*! + * \brief Load the module into Asterisk and start its threads + * + * This function register the module into Asterisk, + * create the interfaces for the channels, + * start the auxiliary threads for the interfaces, + * then start a monitor thread. The monitor thread + * will signal Asterisk when an interface receive a call. + * + * + * \return zero on success, -1 on error. + */ +int load_module(void) +{ + int i; + struct ast_config *cfg; + struct skypiax_pvt *tmp; + struct skypiax_pvt *p = NULL; + struct skypiax_pvt *p2 = NULL; +#ifdef ASTERISK_VERSION_1_6 + struct ast_flags config_flags = { 0 }; +#endif /* ASTERISK_VERSION_1_6 */ + +#if defined(WANT_SKYPE_X11) || defined(__CYGWIN__) +#ifndef __CYGWIN__ + if (!XInitThreads()) + ast_log(LOG_ERROR, "Not initialized XInitThreads!\n"); +#endif /* __CYGWIN__ */ +#if 0 + ast_register_atexit(skypiax_disconnect); + ast_register_application(skype2skypiaxapp, skype2skypiax, skype2skypiaxsynopsis, skype2skypiaxdescrip); + ast_register_application(skypiax2skypeapp, skypiax2skype, skypiax2skypesynopsis, skypiax2skypedescrip); +#endif +#endif /* defined(WANT_SKYPE_X11) || defined(__CYGWIN__) */ + + /* make sure we can register our channel type with Asterisk */ + i = ast_channel_register(&skypiax_tech); + if (i < 0) { + ERRORA("Unable to register channel type '%s'\n", SKYPIAX_P_LOG, skypiax_type); + return -1; + } + /* load skypiax.conf config file */ +#ifdef ASTERISK_VERSION_1_6 + cfg = ast_config_load(skypiax_config, config_flags); +#else + cfg = ast_config_load(skypiax_config); +#endif /* ASTERISK_VERSION_1_6 */ + if (cfg != NULL) { + char *ctg = NULL; + int is_first_category = 1; + while ((ctg = ast_category_browse(cfg, ctg)) != NULL) { + /* create one interface for each category in skypiax.conf config file, first one set the defaults */ + tmp = skypiax_mkif(cfg, ctg, is_first_category); + if (tmp) { + DEBUGA_PBX("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'" "\n", SKYPIAX_P_LOG, ctg, tmp->name); + /* add interface to skypiax_iflist */ + tmp->next = skypiax_iflist; + skypiax_iflist = tmp; + /* next one will not be the first ;) */ + if (is_first_category == 1) { + is_first_category = 0; + skypiax_console_active = tmp->name; + } + } else { + ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n", SKYPIAX_P_LOG, ctg); + /* if error, unload config from memory and return */ + ast_config_destroy(cfg); + ast_channel_unregister(&skypiax_tech); + return -1; + } + /* do it for each category described in config */ + } + + /* we finished, unload config from memory */ + ast_config_destroy(cfg); + } else { + ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG); + ast_channel_unregister(&skypiax_tech); + return -1; + } +#ifndef ASTERISK_VERSION_1_6 + ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry)); +#endif /* ASTERISK_VERSION_1_6 */ + /* start to monitor the interfaces (skypiax_iflist) for the first time */ + if (skypiax_restart_monitor()) { + ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG); + return -1; + } + /* go through the interfaces list (skypiax_iflist) WITHOUT locking */ + p = skypiax_iflist; + while (p) { + int i; + /* for each interface in list */ + p2 = p->next; + NOTICA("STARTING interface %s, please be patient\n", SKYPIAX_P_LOG, p->name); + i = 0; + while (p->SkypiaxHandles.api_connected == 0 && running && i < 60000) { // 60sec FIXME + usleep(1000); + i++; + } + if (p->SkypiaxHandles.api_connected) { + NOTICA("STARTED interface %s\n", SKYPIAX_P_LOG, p->name); + } else { + ERRORA("Interface %s FAILED to start\n", SKYPIAX_P_LOG, p->name); + running = 0; + return -1; + } + /* next one, please */ + p = p2; + } + return 0; +} + +/*! + * \brief Unload the module from Asterisk and shutdown its threads + * + * This function unregister the module from Asterisk, + * destroy the interfaces for the channels, + * shutdown the auxiliary threads for the interfaces, + * then shutdown its monitor thread. + * + * \return zero on success, -1 on error. + */ +int unload_module(void) +{ + struct skypiax_pvt *p = NULL, *p2 = NULL; + int res; + + /* unregister our channel type with Asterisk */ + ast_channel_unregister(&skypiax_tech); + ast_cli_unregister_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry)); + +#if defined(WANT_SKYPE_X11) || defined(__CYGWIN__) +#ifndef __CYGWIN__ + //FIXME what to do? if (!XInitThreads()) + //FIXME what to do? ast_log(LOG_ERROR, "Not initialized XInitThreads!\n"); +#endif /* __CYGWIN__ */ +#if 0 + ast_unregister_atexit(skypiax_disconnect); + ast_unregister_application(skype2skypiaxapp); + ast_unregister_application(skypiax2skypeapp); +#endif +#endif /* defined(WANT_SKYPE_X11) || defined(__CYGWIN__) */ + + /* lock the skypiax_monlock, kill the monitor thread, unlock the skypiax_monlock */ + LOKKA(&skypiax_monlock); + if (skypiax_monitor_thread && (skypiax_monitor_thread != AST_PTHREADT_NULL) + && (skypiax_monitor_thread != AST_PTHREADT_STOP)) { + if (pthread_cancel(skypiax_monitor_thread)) { + ERRORA("pthread_cancel failed, BAD\n", SKYPIAX_P_LOG); + return -1; + } + if (pthread_kill(skypiax_monitor_thread, SIGURG)) { + DEBUGA_PBX("pthread_kill failed\n", SKYPIAX_P_LOG); //maybe it just died + } +#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */ + if (pthread_join(skypiax_monitor_thread, NULL)) { + ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG); + return -1; + } +#endif /* __CYGWIN__ */ + } + skypiax_monitor_thread = AST_PTHREADT_STOP; + UNLOCKA(&skypiax_monlock); + + if (skypiax_monitor_audio_thread && (skypiax_monitor_audio_thread != AST_PTHREADT_NULL) + && (skypiax_monitor_audio_thread != AST_PTHREADT_STOP)) { + + if (pthread_cancel(skypiax_monitor_audio_thread)) { + ERRORA("pthread_cancel skypiax_monitor_audio_thread failed, BAD\n", SKYPIAX_P_LOG); + } + if (pthread_kill(skypiax_monitor_audio_thread, SIGURG)) { + DEBUGA_PBX("pthread_kill skypiax_monitor_audio_thread failed, no problem\n", SKYPIAX_P_LOG); //maybe it just died + } + + if (pthread_join(skypiax_monitor_audio_thread, NULL)) { + ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG); + } + } + /* lock the skypiax_iflock, and go through the interfaces list (skypiax_iflist) */ + LOKKA(&skypiax_iflock); + p = skypiax_iflist; + while (p) { + /* for each interface in list */ + p2 = p->next; + /* shutdown the sound system, close sound fds, and if exist shutdown the sound managing threads */ + DEBUGA_SOUND("shutting down sound\n", SKYPIAX_P_LOG); + res = skypiax_sound_shutdown(p); + if (res == -1) { + ERRORA("Failed to shutdown sound\n", SKYPIAX_P_LOG); + } +#if 0 + /* if a dsp struct has been allocated, free it */ + if (p->dsp) { + ast_dsp_free(p->dsp); + p->dsp = NULL; + } +#endif + DEBUGA_PBX("freeing PVT\n", SKYPIAX_P_LOG); + /* free the pvt allocated memory */ + free(p); + /* next one, please */ + p = p2; + } + /* finished with the interfaces list, unlock the skypiax_iflock */ + UNLOCKA(&skypiax_iflock); + +#ifdef __CYGWIN__ + NOTICA("Sleping 5 secs, please wait...\n", SKYPIAX_P_LOG); + sleep(5); /* without this pause, for some unknown (to me) reason it crashes on cygwin */ +#endif /* __CYGWIN__ */ + NOTICA("Unloaded Skypiax Module\n", SKYPIAX_P_LOG); + return 0; +} + +/*! + * \brief Return the count of active channels for this module + * + * \return the count of active channels for this module + */ +int usecount() +{ + int res; + static struct skypiax_pvt *p = &skypiax_log_struct; +/* lock the skypiax_usecnt lock */ + LOKKA(&skypiax_usecnt_lock); + /* retrieve the skypiax_usecnt */ + res = skypiax_usecnt; +/* unlock the skypiax_usecnt lock */ + UNLOCKA(&skypiax_usecnt_lock); + /* return the skypiax_usecnt */ + return res; +} + +/*! + * \brief Return the textual description of the module + * + * \return the textual description of the module + */ +char *description() +{ + return (char *) skypiax_desc; +} + +/*! + * \brief Return the ASTERISK_GPL_KEY + * + * \return the ASTERISK_GPL_KEY + */ +char *key() +{ + struct skypiax_pvt *p = NULL; + + NOTICA("Returning Key\n", SKYPIAX_P_LOG); + + return ASTERISK_GPL_KEY; +} + +/*! + * \brief Create and initialize one interface for the module + * \param cfg pointer to configuration data from skypiax.conf + * \param ctg pointer to a category name to be found in cfg + * \param is_first_category is this the first category in cfg + * + * This function create and initialize one interface for the module + * + * \return a pointer to the PVT structure of interface on success, NULL on error. + */ +struct skypiax_pvt *skypiax_mkif(struct ast_config *cfg, char *ctg, int is_first_category) +{ + struct skypiax_pvt *tmp; + struct ast_variable *v; + int res; + + int debug_all = 0; + int debug_at = 0; + int debug_fbus2 = 0; + int debug_serial = 0; + int debug_sound = 0; + int debug_pbx = 0; + int debug_skype = 0; + int debug_call = 0; + int debug_locks = 0; + int debug_monitorlocks = 0; + + ast_log(LOG_DEBUG, "ENTERING FUNC\n"); + /* alloc memory for PVT */ + tmp = malloc(sizeof(struct skypiax_pvt)); + if (tmp == NULL) { /* fail */ + return NULL; + } + /* clear memory for PVT */ + memset(tmp, 0, sizeof(struct skypiax_pvt)); + + /* if we are reading the "first" category of the config file, take SELECTED values as defaults, overriding the values in skypiax_default */ + if (is_first_category == 1) { + /* for each variable in category, copy it in the skypiax_default struct */ + for (v = ast_variable_browse(cfg, ctg); v; v = v->next) { + M_START(v->name, v->value); + + M_STR("context", skypiax_default.context) + M_STR("language", skypiax_default.language) + M_STR("extension", skypiax_default.exten) + M_F("playback_boost", skypiax_store_boost(v->value, &skypiax_default.playback_boost)) + M_F("capture_boost", skypiax_store_boost(v->value, &skypiax_default.capture_boost)) + M_UINT("skypiax_dir_entry_extension_prefix", skypiax_default.skypiax_dir_entry_extension_prefix) + M_END(; + ); + } + } + + /* initialize the newly created PVT from the skypiax_default values */ + *tmp = skypiax_default; + + /* the category name becomes the interface name */ + tmp->name = strdup(ctg); + + /* for each category in config file, "first" included, read in ALL the values */ + for (v = ast_variable_browse(cfg, ctg); v; v = v->next) { + M_START(v->name, v->value); + + M_BOOL("debug_all", debug_all) + M_BOOL("debug_at", debug_at) + M_BOOL("debug_fbus2", debug_fbus2) + M_BOOL("debug_serial", debug_serial) + M_BOOL("debug_sound", debug_sound) + M_BOOL("debug_pbx", debug_pbx) + M_BOOL("debug_skype", debug_skype) + M_BOOL("debug_call", debug_call) + M_BOOL("debug_locks", debug_locks) + M_BOOL("debug_monitorlocks", debug_monitorlocks) + M_BOOL("skype", tmp->skype) + M_STR("context", tmp->context) + M_STR("language", tmp->language) + M_STR("extension", tmp->exten) + M_STR("X11_display", tmp->X11_display) + M_UINT("tcp_cli_port", tmp->tcp_cli_port) + M_UINT("tcp_srv_port", tmp->tcp_srv_port) + M_F("playback_boost", skypiax_store_boost(v->value, &tmp->playback_boost)) + M_F("capture_boost", skypiax_store_boost(v->value, &tmp->capture_boost)) + M_STR("skype_user", tmp->skype_user) + M_UINT("skypiax_dir_entry_extension_prefix", tmp->skypiax_dir_entry_extension_prefix) + M_END(; + ); + } + + if (debug_all) { + skypiax_debug = skypiax_debug | DEBUG_ALL; + if (!option_debug) { + WARNINGA + ("DEBUG_ALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_ALL debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_ALL activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_fbus2) { + skypiax_debug = skypiax_debug | DEBUG_FBUS2; + if (!option_debug) { + WARNINGA + ("DEBUG_FBUS2 activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_FBUS2 debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_FBUS2 activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_serial) { + skypiax_debug = skypiax_debug | DEBUG_SERIAL; + if (!option_debug) { + WARNINGA + ("DEBUG_SERIAL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SERIAL debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_SERIAL activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_sound) { + skypiax_debug = skypiax_debug | DEBUG_SOUND; + if (!option_debug) { + WARNINGA + ("DEBUG_SOUND activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SOUND debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_SOUND activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_pbx) { + skypiax_debug = skypiax_debug | DEBUG_PBX; + if (!option_debug) { + WARNINGA + ("DEBUG_PBX activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_PBX debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_PBX activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_skype) { + skypiax_debug = skypiax_debug | DEBUG_SKYPE; + if (!option_debug) { + WARNINGA + ("DEBUG_SKYPE activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SKYPE debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_SKYPE activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_call) { + skypiax_debug = skypiax_debug | DEBUG_CALL; + if (!option_debug) { + WARNINGA + ("DEBUG_CALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_CALL debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_CALL activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_locks) { + skypiax_debug = skypiax_debug | DEBUG_LOCKS; + if (!option_debug) { + WARNINGA + ("DEBUG_LOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_LOCKS debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_LOCKS activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (debug_monitorlocks) { + skypiax_debug = skypiax_debug | DEBUG_MONITORLOCKS; + if (!option_debug) { + WARNINGA + ("DEBUG_MONITORLOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_MONITORLOCKS debugging output.\n", + SKYPIAX_TMP_LOG); + } else { + NOTICA("DEBUG_MONITORLOCKS activated. \n", SKYPIAX_TMP_LOG); + } + } + + if (option_debug > 1) { + DEBUGA_SOUND("playback_boost is %f\n", SKYPIAX_TMP_LOG, tmp->playback_boost); + DEBUGA_SOUND("capture_boost is %f\n", SKYPIAX_TMP_LOG, tmp->capture_boost); + } +/* initialize the soundcard channels (input and output) used by this interface (a multichannel soundcard can be used by multiple interfaces), optionally starting the sound managing threads */ + res = skypiax_sound_init(tmp); + if (res == -1) { + ERRORA("Failed initializing sound device\n", SKYPIAX_TMP_LOG); + /* we failed, free the PVT */ + free(tmp); + return NULL; + } + /* + res = pipe(tmp->SkypiaxHandles.fdesc); + if (res) { + ast_log(LOG_ERROR, "Unable to create skype pipe\n"); + if (option_debug > 10) { + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG); + } + free(tmp); + return NULL; + } + fcntl(tmp->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK); + fcntl(tmp->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK); + */ + tmp->skype_thread = AST_PTHREADT_NULL; + + if (tmp->skype) { + ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n", + (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL); +#ifdef __CYGWIN__ + if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + free(tmp); + return NULL; + } +#else /* __CYGWIN__ */ +#ifdef WANT_SKYPE_X11 + ast_log(LOG_DEBUG, "AsteriskHandlesfd: %d\n", tmp->SkypiaxHandles.fdesc[1]); + if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + free(tmp); + return NULL; + } +#endif /* WANT_SKYPE_X11 */ +#endif /* __CYGWIN__ */ + usleep(100000); //0.1 sec + if (tmp->skype_thread == AST_PTHREADT_NULL) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + free(tmp); + return NULL; + } + ast_log(LOG_DEBUG, "STARTED skype_thread=%lu STOP=%lu NULL=%lu\n", + (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL); + } +#if 0 + if (tmp->skype) { +#if 0 + if (option_debug > 1) + ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n", + (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL); +#endif +#ifdef __CYGWIN__ + if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->SkypiaxHandles) < 0) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + if (option_debug > 10) { + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG); + } + free(tmp); + return NULL; + } +#else /* __CYGWIN__ */ +#ifdef WANT_SKYPE_X11 + if (ast_pthread_create(&tmp->signaling_thread, NULL, do_signaling_thread_fnc, tmp) < 0) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + if (option_debug > 10) { + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG); + } + free(tmp); + return NULL; + } +#endif /* WANT_SKYPE_X11 */ +#endif /* __CYGWIN__ */ + usleep(100000); //0.1 sec + if (tmp->skype_thread == AST_PTHREADT_NULL) { + ast_log(LOG_ERROR, "Unable to start skype_main thread.\n"); + if (option_debug > 10) { + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG); + } + free(tmp); + return NULL; + } + if (option_debug > 1) + ast_log(LOG_DEBUG, "STARTED signaling_thread=%lu STOP=%lu NULL=%lu\n", + (unsigned long) tmp->signaling_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL); + } +#endif + + /* return the newly created skypiax_pvt */ + return tmp; +} + +/*! \brief (Re)Start the module main monitor thread, watching for incoming calls on the interfaces */ +int skypiax_restart_monitor(void) +{ + static struct skypiax_pvt *p = &skypiax_log_struct; + + /* If we're supposed to be stopped -- stay stopped */ + if (skypiax_monitor_thread == AST_PTHREADT_STOP) { + return 0; + } + LOKKA(&skypiax_monlock); + /* Do not seems possible to me that this function can be called by the very same monitor thread, but let's be paranoid */ + if (skypiax_monitor_thread == pthread_self()) { + UNLOCKA(&skypiax_monlock); + ERRORA("Cannot kill myself\n", SKYPIAX_P_LOG); + return -1; + } + /* if the monitor thread exists */ + if (skypiax_monitor_thread != AST_PTHREADT_NULL) { + /* Wake up the thread, it can be stuck waiting in a select or so */ + pthread_kill(skypiax_monitor_thread, SIGURG); + } else { + /* the monitor thread does not exists, start a new monitor */ + if (ast_pthread_create(&skypiax_monitor_thread, NULL, skypiax_do_monitor, NULL) < 0) { + UNLOCKA(&skypiax_monlock); + ERRORA("Unable to start monitor thread.\n", SKYPIAX_P_LOG); + return -1; + } + } + UNLOCKA(&skypiax_monlock); + return 0; +} + +/*! \brief The skypiax monitoring thread + * \note This thread monitors all the skypiax interfaces that are not in a call + * (and thus do not have a separate thread) indefinitely + * */ +void *skypiax_do_monitor(void *data) +{ + fd_set rfds; + int res; + struct skypiax_pvt *p = NULL; + int max = -1; + struct timeval to; + time_t now_timestamp; + + if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) { + ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG); + return NULL; + } + + for (;;) { + pthread_testcancel(); + /* Don't let anybody kill us right away. Nobody should lock the interface list + and wait for the monitor list, but the other way around is okay. */ + PUSHA_UNLOCKA(&skypiax_monlock); + MONITORLOKKA(&skypiax_monlock); + /* Lock the interface list */ + PUSHA_UNLOCKA(&skypiax_iflock); + MONITORLOKKA(&skypiax_iflock); + /* Build the stuff we're going to select on, that is the skypiax_serial_fd of every + skypiax_pvt that does not have an associated owner channel. In the case of FBUS2 3310 + and in the case of PROTOCOL_NO_SERIAL we add the audio_fd as well, because there is not serial signaling of incoming calls */ + FD_ZERO(&rfds); + + time(&now_timestamp); + p = skypiax_iflist; + while (p) { + if (!p->owner) { + /* This interface needs to be watched, as it lacks an owner */ + + if (p->skype) { + if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds)) + ERRORA("Descriptor %d (SkypiaxHandles.fdesc[0]) appears twice ?\n", SKYPIAX_P_LOG, p->SkypiaxHandles.fdesc[0]); + + if (p->SkypiaxHandles.fdesc[0] > 0) { + FD_SET(p->SkypiaxHandles.fdesc[0], &rfds); + if (p->SkypiaxHandles.fdesc[0] > max) + max = p->SkypiaxHandles.fdesc[0]; + + } + } + + } + /* next interface, please */ + p = p->next; + } + /* Okay, now that we know what to do, release the interface lock */ + MONITORUNLOCKA(&skypiax_iflock); + POPPA_UNLOCKA(&skypiax_iflock); + /* And from now on, we're okay to be killed, so release the monitor lock as well */ + MONITORUNLOCKA(&skypiax_monlock); + POPPA_UNLOCKA(&skypiax_monlock); + + /* you want me to die? */ + pthread_testcancel(); + + /* Wait for something to happen */ + to.tv_sec = 0; + to.tv_usec = 500000; /* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */ + res = ast_select(max + 1, &rfds, NULL, NULL, &to); + + /* you want me to die? */ + pthread_testcancel(); + + /* Okay, select has finished. Let's see what happened. */ + + /* If there are errors... */ + if (res < 0) { + if (errno == EINTR) /* EINTR is just the select + being interrupted by a SIGURG, or so */ + continue; + else { + ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, res, strerror(errno)); + return NULL; + } + } + + /* must not be killed while skypiax_iflist is locked */ + PUSHA_UNLOCKA(&skypiax_monlock); + MONITORLOKKA(&skypiax_monlock); + /* Alright, lock the interface list again, and let's look and see what has + happened */ + PUSHA_UNLOCKA(&skypiax_iflock); + MONITORLOKKA(&skypiax_iflock); + + p = skypiax_iflist; + for (; p; p = p->next) { + + if (p->skype) { + if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds)) { + res = skypiax_signaling_read(p); + if (res == CALLFLOW_INCOMING_CALLID || res == CALLFLOW_INCOMING_RING) { + //ast_log(LOG_NOTICE, "CALLFLOW_INCOMING_RING SKYPE\n"); + DEBUGA_SKYPE("CALLFLOW_INCOMING_RING\n", SKYPIAX_P_LOG); + skypiax_new(p, SKYPIAX_STATE_RING, p->context /* p->context */ ); + } + } + } + + } + MONITORUNLOCKA(&skypiax_iflock); + POPPA_UNLOCKA(&skypiax_iflock); + MONITORUNLOCKA(&skypiax_monlock); + POPPA_UNLOCKA(&skypiax_monlock); + pthread_testcancel(); + } +/* Never reached */ + return NULL; + +} + +/*! + * \brief Initialize the soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces) + * \param p the skypiax_pvt of the interface + * + * This function initialize the soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces). It simply pass its parameters to the right function for the sound system for which has been compiled, eg. alsa_init for ALSA, oss_init for OSS, winmm_init for Windows Multimedia, etc and return the result + * + * \return zero on success, -1 on error. + */ + +int skypiax_sound_init(struct skypiax_pvt *p) +{ + return skypiax_audio_init(p); +} + +/*! + * \brief Shutdown the soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces) + * \param p the skypiax_pvt of the interface + * + * This function shutdown the soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces). It simply pass its parameters to the right function for the sound system for which has been compiled, eg. alsa_shutdown for ALSA, oss_shutdown for OSS, winmm_shutdown for Windows Multimedia, etc and return the result + * + * \return zero on success, -1 on error. + */ + +int skypiax_sound_shutdown(struct skypiax_pvt *p) +{ + + //return skypiax_portaudio_shutdown(p); + + return -1; +} + +/*! \brief Read audio frames from interface */ +struct ast_frame *skypiax_sound_read(struct skypiax_pvt *p) +{ + struct ast_frame *f = NULL; + int res; + + res = skypiax_audio_read(p); + f = &p->read_frame; + return f; +} + +/*! \brief Send audio frame to interface */ +int skypiax_sound_write(struct skypiax_pvt *p, struct ast_frame *f) +{ + int ret = -1; + + ret = skypiax_audio_write(p, f); + return ret; +} + +/*! + * \brief This thread runs during a call, and monitor the interface serial port for signaling, like hangup, caller id, etc + * + */ +void *skypiax_do_controldev_thread(void *data) +{ + struct skypiax_pvt *p = data; + int res; + + DEBUGA_SERIAL("In skypiax_do_controldev_thread: started, p=%p\n", SKYPIAX_P_LOG, p); + + if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) { + ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG); + return NULL; + } + + while (1) { + usleep(1000); + pthread_testcancel(); + if (p->skype) { + res = skypiax_signaling_read(p); + if (res == CALLFLOW_INCOMING_HANGUP) { + DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG); + if (p->owner) { + pthread_testcancel(); + ast_queue_control(p->owner, AST_CONTROL_HANGUP); + } + } + } + } + + return NULL; + +} + +/************************************************/ + +/* LUIGI RIZZO's magic */ +/* + * store the boost factor + */ +#ifdef ASTERISK_VERSION_1_6 +void skypiax_store_boost(const char *s, double *boost) +#else +void skypiax_store_boost(char *s, double *boost) +#endif /* ASTERISK_VERSION_1_6 */ +{ + struct skypiax_pvt *p = NULL; + + if (sscanf(s, "%lf", boost) != 1) { + ERRORA("invalid boost <%s>\n", SKYPIAX_P_LOG, s); + return; + } + if (*boost < -BOOST_MAX) { + WARNINGA("boost %s too small, using %d\n", SKYPIAX_P_LOG, s, -BOOST_MAX); + *boost = -BOOST_MAX; + } else if (*boost > BOOST_MAX) { + WARNINGA("boost %s too large, using %d\n", SKYPIAX_P_LOG, s, BOOST_MAX); + *boost = BOOST_MAX; + } + *boost = exp(log(10) * *boost / 20) * BOOST_SCALE; + DEBUGA_SOUND("setting boost %s to %f\n", SKYPIAX_P_LOG, s, *boost); +} + +/* + * returns a pointer to the descriptor with the given name + */ +struct skypiax_pvt *skypiax_console_find_desc(char *dev) +{ + struct skypiax_pvt *p = NULL; + + for (p = skypiax_iflist; p && strcmp(p->name, dev) != 0; p = p->next); + if (p == NULL) + WARNINGA("could not find <%s>\n", SKYPIAX_P_LOG, dev); + + return p; +} +int skypiax_console_playback_boost(int fd, int argc, char *argv[]) +{ + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + + if (argc > 2) { + return RESULT_SHOWUSAGE; + } + if (!p) { + ast_cli(fd, "No \"current\" skypiax_console for playback_boost, please enter 'help skypiax_console'\n"); + return RESULT_SUCCESS; + } + + if (argc == 1) { + ast_cli(fd, "playback_boost on the active skypiax_console, that is [%s], is: %5.1f\n", + skypiax_console_active, 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE))); + } else if (argc == 2) { + skypiax_store_boost(argv[1], &p->playback_boost); + + ast_cli(fd, + "playback_boost on the active skypiax_console, that is [%s], is now: %5.1f\n", + skypiax_console_active, 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE))); + } + + return RESULT_SUCCESS; +} +int skypiax_console_capture_boost(int fd, int argc, char *argv[]) +{ + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + + if (argc > 2) { + return RESULT_SHOWUSAGE; + } + if (!p) { + ast_cli(fd, "No \"current\" skypiax_console for capture_boost, please enter 'help skypiax_console'\n"); + return RESULT_SUCCESS; + } + + if (argc == 1) { + ast_cli(fd, "capture_boost on the active skypiax_console, that is [%s], is: %5.1f\n", + skypiax_console_active, 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE))); + } else if (argc == 2) { + skypiax_store_boost(argv[1], &p->capture_boost); + + ast_cli(fd, + "capture_boost on the active skypiax_console, that is [%s], is now: %5.1f\n", + skypiax_console_active, 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE))); + } + + return RESULT_SUCCESS; +} + +int skypiax_console_hangup(int fd, int argc, char *argv[]) +{ + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + + if (argc != 1) { + return RESULT_SHOWUSAGE; + } + if (!p) { + ast_cli(fd, "No \"current\" skypiax_console for hanging up, please enter 'help skypiax_console'\n"); + return RESULT_SUCCESS; + } + if (!p->owner) { + ast_cli(fd, "No call to hangup on the active skypiax_console, that is [%s]\n", skypiax_console_active); + return RESULT_FAILURE; + } + if (p->owner) + ast_queue_hangup(p->owner); + return RESULT_SUCCESS; +} + +int skypiax_console_dial(int fd, int argc, char *argv[]) +{ + char *s = NULL; + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + + if (argc != 2) { + return RESULT_SHOWUSAGE; + } + if (!p) { + ast_cli(fd, "No \"current\" skypiax_console for dialing, please enter 'help skypiax_console'\n"); + return RESULT_SUCCESS; + } + + if (p->owner) { /* already in a call */ + int i; + struct ast_frame f = { AST_FRAME_DTMF, 0 }; + + s = argv[1]; + /* send the string one char at a time */ + for (i = 0; i < strlen(s); i++) { + f.subclass = s[i]; + ast_queue_frame(p->owner, &f); + } + return RESULT_SUCCESS; + } else + ast_cli(fd, "No call in which to dial on the \"current\" skypiax_console, that is [%s]\n", skypiax_console_active); + if (s) + free(s); + return RESULT_SUCCESS; +} +int skypiax_console_set_active(int fd, int argc, char *argv[]) +{ + if (argc == 1) + ast_cli(fd, + "\"current\" skypiax_console is [%s]\n Enter 'skypiax_console show' to see the available interfaces.\n Enter 'skypiax_console interfacename' to change the \"current\" skypiax_console.\n", + skypiax_console_active); + else if (argc != 2) { + return RESULT_SHOWUSAGE; + } else { + struct skypiax_pvt *p; + if (strcmp(argv[1], "show") == 0) { + ast_cli(fd, "Available interfaces:\n"); + for (p = skypiax_iflist; p; p = p->next) + ast_cli(fd, " [%s]\n", p->name); + return RESULT_SUCCESS; + } + p = skypiax_console_find_desc(argv[1]); + if (p == NULL) + ast_cli(fd, "Interface [%s] do not exists!\n", argv[1]); + else { + skypiax_console_active = p->name; + ast_cli(fd, "\"current\" skypiax_console is now: [%s]\n", argv[1]); + } + } + return RESULT_SUCCESS; +} + +int skypiax_console_skypiax(int fd, int argc, char *argv[]) +{ + return RESULT_SHOWUSAGE; +} + +void *do_skypeapi_thread(void *obj) +{ + return skypiax_do_skypeapi_thread_func(obj); +} + +int dtmf_received(private_t * p, char *value) +{ + + struct ast_frame f2 = { AST_FRAME_DTMF, value[0], }; + DEBUGA_SKYPE("Received DTMF: %s\n", SKYPIAX_P_LOG, value); + ast_queue_frame(p->owner, &f2); + + return 0; + +} + +int start_audio_threads(private_t * p) +{ + //if (!p->tcp_srv_thread) { + if (ast_pthread_create(&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) { + ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG); + return -1; + } else { + DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG); + } + //} + //if (!p->tcp_cli_thread) { + if (ast_pthread_create(&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) { + ERRORA("Unable to start tcp_cli_thread thread.\n", SKYPIAX_P_LOG); + return -1; + } else { + DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG); + } + //} + +#ifdef NOTDEF + switch_threadattr_t *thd_attr = NULL; + + switch_threadattr_create(&thd_attr, skypiax_module_pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&tech_pvt->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, tech_pvt, skypiax_module_pool); + DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG); + + switch_threadattr_create(&thd_attr, skypiax_module_pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&tech_pvt->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, tech_pvt, skypiax_module_pool); + DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG); + switch_sleep(100000); + +#endif + + return 0; +} + +int new_inbound_channel(private_t * p) +{ + +#ifdef NOTDEF + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + + if ((session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) { + switch_core_session_add_stream(session, NULL); + channel = switch_core_session_get_channel(session); + skypiax_tech_init(tech_pvt, session); + + if ((tech_pvt->caller_profile = + switch_caller_profile_new(switch_core_session_get_pool(session), "skypiax", + tech_pvt->dialplan, tech_pvt->callid_name, + tech_pvt->callid_number, NULL, NULL, NULL, NULL, "mod_skypiax", tech_pvt->context, tech_pvt->destination)) != 0) { + char name[128]; + //switch_snprintf(name, sizeof(name), "skypiax/%s/%s", tech_pvt->name, tech_pvt->caller_profile->destination_number); + switch_snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + } + switch_channel_set_state(channel, CS_INIT); + if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { + ERRORA("Error spawning thread\n", SKYPIAX_P_LOG); + switch_core_session_destroy(&session); + } + } + switch_channel_mark_answered(channel); + +#endif + return 0; +} + +int remote_party_is_ringing(private_t * p) +{ + if (p->owner) { + ast_queue_control(p->owner, AST_CONTROL_RINGING); + } + + return 0; +} + +int remote_party_is_early_media(private_t * p) +{ + if (p->owner) { + ast_queue_control(p->owner, AST_CONTROL_RINGING); + } + + return 0; +} + +int outbound_channel_answered(private_t * p) +{ + + if (p->owner) { + ast_queue_control(p->owner, AST_CONTROL_ANSWER); + } + + return 0; +} +void *skypiax_do_tcp_srv_thread(void *obj) +{ + return skypiax_do_tcp_srv_thread_func(obj); +} +void *skypiax_do_tcp_cli_thread(void *obj) +{ + return skypiax_do_tcp_cli_thread_func(obj); +} + +int skypiax_audio_write(struct skypiax_pvt *p, struct ast_frame *f) +{ + int sent; + + sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen); + + return 0; +} +int skypiax_console_skype(int fd, int argc, char *argv[]) +{ + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + char skype_msg[1024]; + int i, a, c; + + if (argc == 1) { + return RESULT_SHOWUSAGE; + } + if (!p) { + ast_cli(fd, "No \"current\" console for skypiax_, please enter 'help console'\n"); + return RESULT_SUCCESS; + } + if (!p->skype) { + ast_cli(fd, "The \"current\" console is not connected to a Skype client'\n"); + return RESULT_SUCCESS; + } + + memset(skype_msg, 0, sizeof(skype_msg)); + c = 0; + for (i = 1; i < argc; i++) { + for (a = 0; a < strlen(argv[i]); a++) { + skype_msg[c] = argv[i][a]; + c++; + if (c == 1022) + break; + } + if (i != argc - 1) { + skype_msg[c] = ' '; + c++; + } + if (c == 1023) + break; + } + skypiax_signaling_write(p, skype_msg); + return RESULT_SUCCESS; +} + +int skypiax_console_skypiax_dir_import(int fd, int argc, char *argv[]) +{ + //int res; + struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active); + //char list_command[64]; + char fn[256]; + char date[256] = ""; + time_t t; + char *configfile = SKYPIAX_DIR_CONFIG; + int add_to_skypiax_dir_conf = 1; + //int fromskype = 0; + //int fromcell = 0; + +#if 0 + if (directoriax_entry_extension) { + skypiax_dir_entry_extension = directoriax_entry_extension; + } else { + ast_cli(fd, "No 'directoriax_entry_extension', you MUST have loaded directoriax.so\n"); + return RESULT_SUCCESS; + } +#endif + + if (argc != 2) + return RESULT_SHOWUSAGE; + if (!p) { + ast_cli(fd, "No \"current\" console ???, please enter 'help skypiax_console'\n"); + return RESULT_SUCCESS; + } + + if (!strcasecmp(argv[1], "add")) + add_to_skypiax_dir_conf = 1; + else if (!strcasecmp(argv[1], "replace")) + add_to_skypiax_dir_conf = 0; + else { + ast_cli(fd, "\n\nYou have neither specified 'add' nor 'replace'\n\n"); + return RESULT_SHOWUSAGE; + } + +#if 0 + if (!strcasecmp(argv[2], "fromskype")) + fromskype = 1; + else if (!strcasecmp(argv[2], "fromcell")) + fromcell = 1; + else { + ast_cli(fd, "\n\nYou have neither specified 'fromskype' nor 'fromcell'\n\n"); + return RESULT_SHOWUSAGE; + } + + if (fromcell) { + ast_cli(fd, "Importing from cellphone is currently supported only on \"AT\" cellphones :( !\n"); + //fclose(p->phonebook_writing_fp); + //skypiax_dir_create_extensions(); + return RESULT_SUCCESS; + } + + if (fromskype) + if (!p->skype) { + ast_cli(fd, "Importing from skype is supported by skypiax_dir on chan_skypiax!\n"); + //fclose(p->phonebook_writing_fp); + //skypiax_dir_create_extensions(); + return RESULT_SUCCESS; + } + + if (fromcell || fromskype) + if (argc != 3) { + ast_cli(fd, "\n\nYou don't have to specify a filename with 'fromcell' or with 'fromskype'\n\n"); + return RESULT_SHOWUSAGE; + } +#endif + + /*******************************************************************************************/ + + if (configfile[0] == '/') { + ast_copy_string(fn, configfile, sizeof(fn)); + } else { + snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile); + } + NOTICA("Opening '%s'\n", SKYPIAX_P_LOG, fn); + time(&t); + ast_copy_string(date, ctime(&t), sizeof(date)); + + if (add_to_skypiax_dir_conf) + p->phonebook_writing_fp = fopen(fn, "a+"); + else + p->phonebook_writing_fp = fopen(fn, "w+"); + + if (p->phonebook_writing_fp) { + if (add_to_skypiax_dir_conf) { + NOTICA("Opened '%s' for appending \n", SKYPIAX_P_LOG, fn); + fprintf(p->phonebook_writing_fp, ";!\n"); + fprintf(p->phonebook_writing_fp, ";! Update Date: %s", date); + fprintf(p->phonebook_writing_fp, ";! Updated by: %s, %d\n", __FILE__, __LINE__); + fprintf(p->phonebook_writing_fp, ";!\n"); + } else { + NOTICA("Opened '%s' for writing \n", SKYPIAX_P_LOG, fn); + fprintf(p->phonebook_writing_fp, ";!\n"); + fprintf(p->phonebook_writing_fp, ";! Automatically generated configuration file\n"); + fprintf(p->phonebook_writing_fp, ";! Filename: %s (%s)\n", configfile, fn); + fprintf(p->phonebook_writing_fp, ";! Creation Date: %s", date); + fprintf(p->phonebook_writing_fp, ";! Generated by: %s, %d\n", __FILE__, __LINE__); + fprintf(p->phonebook_writing_fp, ";!\n"); + fprintf(p->phonebook_writing_fp, "[general]\n\n"); + fprintf(p->phonebook_writing_fp, "[default]\n"); + } + + /*******************************************************************************************/ + //if (fromskype) { + if (p->skype) { + WARNINGA("About to querying the Skype client 'Contacts', it may take some moments... Don't worry.\n", SKYPIAX_P_LOG); + if (p->skype_thread != AST_PTHREADT_NULL) { + char msg_to_skype[1024]; + + p->skype_friends[0] = '\0'; + sprintf(msg_to_skype, "#333 SEARCH FRIENDS"); + if (skypiax_signaling_write(p, msg_to_skype) < 0) { + return -1; + } + + int friends_count = 0; + while (p->skype_friends[0] == '\0') { + /* FIXME needs a timeout, can't wait forever! + * eg. when skype is running but not connected! */ + usleep(100); + friends_count++; + if (friends_count > 20000) { + return -1; /* FIXME */ + } + } + + } + + if (p->skype_thread != AST_PTHREADT_NULL) { + char msg_to_skype[1024]; + + if (p->skype_friends[0] != '\0') { + char *buf, *where; + char **stringp; + int skype_dir_file_written = 0; + + buf = p->skype_friends; + stringp = &buf; + where = strsep(stringp, ", "); + while (where) { + if (where[0] != '\0') { + /* + * So, we have the Skype username (the HANDLE, I think is called). + * But we want to call the names we see in the Skype contact list + * So, let's check the DISPLAYNAME (the end user modified contact name) + * Then, we check the FULLNAME (that appears as it was the DISPLAYNAME + * if the end user has not modify it) + * If we still have neither DISPLAYNAME nor FULLNAME, we'll use the + * Skipe username (the HANDLE) + */ + + p->skype_displayname[0] = '\0'; + sprintf(msg_to_skype, "#765 GET USER %s DISPLAYNAME", where); + skypiax_signaling_write(p, msg_to_skype); + int displayname_count = 0; + while (p->skype_displayname[0] == '\0') { + /* FIXME needs a timeout, can't wait forever! + * eg. when skype is running but not connected! */ + usleep(100); + displayname_count++; + if (displayname_count > 20000) + return -1; /* FIXME */ + } + if (p->skype_displayname[0] != '\0') { + char *where2; + char sanitized[300]; + + sanitized[0] = '\0'; + + where2 = strstr(p->skype_displayname, "DISPLAYNAME "); + if (where2) { + + /* there can be some *smart* that makes a displayname + * that is different than firstlast, */ + /* maybe initials, simbols, slashes, + * something smartish... let's check */ + + if (where2[12] != '\0') { + int i = 12; + int x = 0; + int spaces = 0; + int last_char_was_space = 0; + + for (i = 12; i < strlen(where2) && x < 299; i++) { + if (!isalnum(where2[i])) { + if (!isblank(where2[i])) { + /* bad char */ + continue; + } + /* is a space */ + if (last_char_was_space == 1) /* do not write 2 consecutive spaces */ + continue; + last_char_was_space = 1; + sanitized[x] = ' '; + x++; + continue; + } + /* is alphanum */ + last_char_was_space = 0; + sanitized[x] = where2[i]; + x++; + continue; + } + + sanitized[x] = '\0'; + if (spaces == 0) { + } + DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n", SKYPIAX_P_LOG, sanitized, where, &where2[12]); + } + + if (where2[12] != '\0') { + skypiax_dir_entry_extension++; + if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, sanitized, "no", + p->skypiax_dir_entry_extension_prefix, "2", skypiax_dir_entry_extension, "yes", "not_specified"); + } else { /* is a skype name */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, sanitized, "no", + p->skypiax_dir_entry_extension_prefix, "1", skypiax_dir_entry_extension, "yes", "not_specified"); + } + skype_dir_file_written = 1; + + } + } + } + p->skype_displayname[0] = '\0'; + + p->skype_fullname[0] = '\0'; + sprintf(msg_to_skype, "#222 GET USER %s FULLNAME", where); + skypiax_signaling_write(p, msg_to_skype); + int fullname_count = 0; + while (p->skype_fullname[0] == '\0') { + /* FIXME needs a timeout, can't wait forever! + * eg. when skype is running but not connected! */ + usleep(100); + fullname_count++; + if (fullname_count > 20000) + return -1; /* FIXME */ + } + if (p->skype_fullname[0] != '\0') { + char *where2; + char sanitized[300]; + + where2 = strstr(p->skype_fullname, "FULLNAME "); + if (where2) { + + /* there can be some *smart* that makes a fullname + * that is different than firstlast, */ + /* maybe initials, simbols, slashes, + * something smartish... let's check */ + + if (where2[9] != '\0') { + int i = 9; + int x = 0; + int spaces = 0; + int last_char_was_space = 0; + + for (i = 9; i < strlen(where2) && x < 299; i++) { + if (!isalnum(where2[i])) { + if (!isblank(where2[i])) { + /* bad char */ + continue; + } + /* is a space */ + if (last_char_was_space == 1) /* do not write 2 consecutive spaces */ + continue; + last_char_was_space = 1; + sanitized[x] = ' '; + x++; + continue; + } + /* alphanum */ + last_char_was_space = 0; + sanitized[x] = where2[i]; + x++; + continue; + } + + sanitized[x] = '\0'; + if (spaces == 0) { + } + DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n", SKYPIAX_P_LOG, sanitized, where, &where2[9]); + } + + if (skype_dir_file_written == 0) { + skypiax_dir_entry_extension++; + if (where2[9] != '\0') { + if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, sanitized, "no", + p->skypiax_dir_entry_extension_prefix, "2", skypiax_dir_entry_extension, "yes", "not_specified"); + } else { /* is a skype name */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, sanitized, "no", + p->skypiax_dir_entry_extension_prefix, "1", skypiax_dir_entry_extension, "yes", "not_specified"); + + } + + } else { + if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, where, "no", p->skypiax_dir_entry_extension_prefix, + "2", skypiax_dir_entry_extension, "yes", "not_specified"); + } else { /* is a skype name */ + fprintf(p->phonebook_writing_fp, + "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n", + where, where, "no", p->skypiax_dir_entry_extension_prefix, + "1", skypiax_dir_entry_extension, "yes", "not_specified"); + + } + } + } + + skype_dir_file_written = 0; + + } + + } + p->skype_fullname[0] = '\0'; + + } + where = strsep(stringp, ", "); + } + + p->skype_friends[0] = '\0'; + } + } + } else { + + ast_cli(fd, "Skype not configured on the 'current' console, not importing from Skype client!\n"); + } + //} + /*******************************************************************************************/ + /*******************************************************************************************/ + } else { + ast_cli(fd, "\n\nfailed to open the skypiax_dir.conf configuration file: %s\n", fn); + ERRORA("failed to open the skypiax_dir.conf configuration file: %s\n", SKYPIAX_P_LOG, fn); + return RESULT_FAILURE; + } + + fclose(p->phonebook_writing_fp); + //skypiax_dir_create_extensions(); + + return RESULT_SUCCESS; +} + +private_t *find_available_skypiax_interface(void) +{ + private_t *p; + int found = 0; + + /* lock the interfaces' list */ + LOKKA(&skypiax_iflock); + /* make a pointer to the first interface in the interfaces list */ + p = skypiax_iflist; + /* Search for the requested interface and verify if is unowned */ + while (p) { + if (!p->owner) { + DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG); + found = 1; + /* we found the requested interface, bail out from the while loop */ + break; + } else { + /* interface owned by a channel */ + DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG); + } + /* not yet found, next please */ + p = p->next; + } + + /* lock the interfaces' list */ + UNLOCKA(&skypiax_iflock); + + if (found) + return p; + else + return NULL; +} + +/************************************************/ +#ifdef ASTERISK_VERSION_1_4 +#ifndef AST_MODULE +#define AST_MODULE "chan_skypiax" +#endif +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skypiax, Audio-Serial Driver"); +#endif /* ASTERISK_VERSION_1_4 */ + +/* rewriting end */ +/*******************************************************************************/ diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/cyg_no_pthread_kill.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/cyg_no_pthread_kill.c new file mode 100644 index 0000000000..df2da1868a --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/cyg_no_pthread_kill.c @@ -0,0 +1,17 @@ +#include +#define PRINTMSGCYG + +extern int option_debug; +int cyg_no_pthreadkill(int thread, int sig); + +int cyg_no_pthreadkill(int thread, int sig) +{ +#ifdef PRINTMSGCYG + if (option_debug) { + printf + ("\n\nHere there would have been a pthread_kill() on thread [%-7lx], with sig=%d, but it has been substituted by this printf in file cyg_no_pthread_kill.c because CYGWIN does not support sending a signal to a one only thread :-(\n\n", + (unsigned long int) thread, sig); + } +#endif // PRINTMSGCYG + return 0; +} diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.conf b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.conf new file mode 100644 index 0000000000..445c65536a --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.conf @@ -0,0 +1,207 @@ +;;;;;;;; +;;;;;;;; +;;;;;;; Skypiax Asterisk Driver +;;;;;;; +;;;;;;; Configuration file +;;;;;;; lines beginning with semicolon (" are ignored (commented out) +;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; +;;;;;;; The first interface (named skypeclient) +;;;;;;[skypeclient] +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; general settings, valid on all platforms +;;;;;;; +;;;;;;; +;;;;;;; Default language +;;;;;;; +;;;;;;language=en +;;;;;;; +;;;;;;; Default context (in extensions.conf, can be overridden with @context syntax) +;;;;;;; +;;;;;;context=default +;;;;;;; +;;;;;;; Default extension (in extensions.conf) where incoming calls land +;;;;;;; +;;;;;;extension=s +;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; Debugging settings, valid globally for all interfaces on all platforms +;;;;;;; +;;;;;;; the debug values are global for all the interfaces. +;;;;;;; +;;;;;;; default is no skypiax debugging output, you **have** to activate debugging here to obtain debugging from skypiax +;;;;;;; +;;;;;;; To see the debugging output you have to "set debug 100" from the Asterisk CLI or launch +;;;;;;; Asterisk with -ddddddddddd option, and have the logger.conf file activating debug info for console and messages +;;;;;;; +;;;;;;; You can activate each of the following separately, but you can't disactivate. Eg: debug_at=no does not subtract debug_at from debug_all +;;;;;;; debug_all activate all possible debugging info +;;;;;;; +;;;;;;;debug_all=yes +;;;;;;debug_skype=yes +;;;;;;debug_pbx=yes +;;;;;;;debug_sound=yes +;;;;;;;debug_locks=yes +;;;;;;;debug_monitorlocks=yes +;;;;;; +;;;;;;skype=yes ; legacy setting, leave it to yes +;;;;;;X11_display=:101 +;;;;;;tcp_cli_port=11234 +;;;;;;tcp_srv_port=11235 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; audio boost settings, valid for all platforms, to compensate for different input/output audio signal levels +;;;;;;; tweak it if you get horrible (or not hearable) sound +;;;;;;; +;;;;;;;boost can be positive or negative (-40 to +40) in db +;;;;;;;experiment to find which values are best for your computer +;;;;;;playback_boost=0 ; +;;;;;;capture_boost=0 ; +;;;;;; +;;; [skypiax1] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:101 +;;; tcp_cli_port=15576 +;;; tcp_srv_port=15577 +;;; skype_user=skypiax1 +;;; +;;; [skypiax2] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:102 +;;; tcp_cli_port=15578 +;;; tcp_srv_port=15579 +;;; skype_user=skypiax2 +;;; +;;; [skypiax3] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:103 +;;; tcp_cli_port=15580 +;;; tcp_srv_port=15581 +;;; skype_user=skypiax3 +;;; +[skypiax4] +language=en +context=default +extension=s +debug_skype=yes +debug_pbx=yes +skype=yes ; legacy setting, leave it to yes +playback_boost=0 ; +capture_boost=0 ; +X11_display=:104 +tcp_cli_port=15582 +tcp_srv_port=15583 +skype_user=skypiax4 + +[skypiax5] +language=en +context=default +extension=s +debug_skype=yes +debug_pbx=yes +skype=yes ; legacy setting, leave it to yes +playback_boost=0 ; +capture_boost=0 ; +X11_display=:105 +tcp_cli_port=15584 +tcp_srv_port=15585 +skype_user=skypiax5 + +[skypiax6] +language=en +context=default +extension=s +debug_skype=yes +debug_pbx=yes +skype=yes ; legacy setting, leave it to yes +playback_boost=0 ; +capture_boost=0 ; +X11_display=:106 +tcp_cli_port=15586 +tcp_srv_port=16586 +skype_user=skypiax6 + +;;; [skypiax17] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:117 +;;; tcp_cli_port=15587 +;;; tcp_srv_port=15588 +;;; skype_user=skypiax17 +;;; +;;; [skypiax18] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:118 +;;; tcp_cli_port=15589 +;;; tcp_srv_port=15590 +;;; skype_user=skypiax18 +;;; +;;; [skypiax19] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:119 +;;; tcp_cli_port=15591 +;;; tcp_srv_port=15592 +;;; skype_user=skypiax19 +;;; +;;; [skypiax20] +;;; language=en +;;; context=default +;;; extension=s +;;; debug_skype=yes +;;; debug_pbx=yes +;;; skype=yes ; legacy setting, leave it to yes +;;; playback_boost=0 ; +;;; capture_boost=0 ; +;;; X11_display=:120 +;;; tcp_cli_port=15593 +;;; tcp_srv_port=15594 +;;; skype_user=skypiax20 +;;; +;;; +;;; diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.h b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.h new file mode 100644 index 0000000000..e16edc9f11 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/asterisk/skypiax.h @@ -0,0 +1,427 @@ +//indent -gnu -ts4 -br -brs -cdw -lp -ce -nbfda -npcs -nprs -npsl -nbbo -saf -sai -saw -cs -bbo -nhnl -nut -sob -l90 +#ifndef _SKYPIAX_H_ +#define _SKYPIAX_H_ + +#ifndef SKYPIAX_SVN_VERSION +#define SKYPIAX_SVN_VERSION "????NO_REVISION???" +#endif + +#include /* needed here for conditional compilation on version.h */ + /* the following #defs are for LINUX */ +#ifndef __CYGWIN__ +#ifndef ASTERISK_VERSION_1_6 +#ifndef ASTERISK_VERSION_1_4 +#ifndef ASTERISK_VERSION_1_2 +#define ASTERISK_VERSION_1_4 +#if(ASTERISK_VERSION_NUM == 999999) +#undef ASTERISK_VERSION_1_4 +#elif(ASTERISK_VERSION_NUM < 10400) +#undef ASTERISK_VERSION_1_4 +#endif /* ASTERISK_VERSION_NUM == 999999 || ASTERISK_VERSION_NUM < 10400 */ +#endif /* ASTERISK_VERSION_1_2 */ +#endif /* ASTERISK_VERSION_1_4 */ +#endif /* ASTERISK_VERSION_1_6 */ +#ifdef ASTERISK_VERSION_1_2 +#undef ASTERISK_VERSION_1_4 +#endif /* ASTERISK_VERSION_1_2 */ +#ifdef ASTERISK_VERSION_1_6 +#define ASTERISK_VERSION_1_4 +#endif /* ASTERISK_VERSION_1_6 */ +#define SKYPIAX_SKYPE +#define WANT_SKYPE_X11 +#endif /* NOT __CYGWIN__ */ + /* the following #defs are for WINDOWS */ +#ifdef __CYGWIN__ +#undef ASTERISK_VERSION_1_4 +#undef ASTERISK_VERSION_1_6 +#define SKYPIAX_SKYPE +#undef WANT_SKYPE_X11 +#endif /* __CYGWIN__ */ + +/* INCLUDES */ +#ifdef ASTERISK_VERSION_1_6 +#include /* some asterisk-devel package do not contains asterisk.h, but seems that is needed for the 1.6 series, at least from trunk */ +#endif /* ASTERISK_VERSION_1_6 */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef ASTERISK_VERSION_1_4 +#include +#include +#endif /* ASTERISK_VERSION_1_4 */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef ASTERISK_VERSION_1_6 +#include +#include +#endif /* ASTERISK_VERSION_1_6 */ +#ifdef ASTERISK_VERSION_1_4 +#include +#include +#include +#include +#endif /* ASTERISK_VERSION_1_4 */ +#ifdef ASTERISK_VERSION_1_2 +#include +#include +#endif /* ASTERISK_VERSION_1_2 */ +#ifdef HAVE_CONFIG_H +#include +#endif +//#include "skypiax_spandsp.h" +#ifdef __CYGWIN__ +#include +#endif /* __CYGWIN__ */ +#ifdef WANT_SKYPE_X11 +#include +#include +#include +#endif /* WANT_SKYPE_X11 */ +#ifndef AST_DIGIT_ANYDIG +#define AST_DIGIT_ANYDIG "0123456789*#" +#else +#warning Please review Skypiax AST_DIGIT_ANYDIG +#endif +#ifndef _ASTERISK_H +#define AST_CONFIG_MAX_PATH 255 /* defined in asterisk.h, but some asterisk-devel package do not contains asterisk.h */ +extern char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH]; +int ast_register_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */ +void ast_unregister_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */ +#endif + +/* DEFINITIONS */ +#define SAMPLERATE_SKYPIAX 8000 +#define SAMPLES_PER_FRAME SAMPLERATE_SKYPIAX/50 +#define SKYPIAX_DIR_CONFIG "directoriax.conf" + +/* LUIGI RIZZO's magic */ +/* boost support. BOOST_SCALE * 10 ^(BOOST_MAX/20) must + * be representable in 16 bits to avoid overflows. + */ +#define BOOST_SCALE (1<<9) +#define BOOST_MAX 40 /* slightly less than 7 bits */ +/* call flow from the device */ +#define CALLFLOW_CALL_IDLE AST_STATE_DOWN +#define CALLFLOW_INCOMING_RING AST_STATE_RING +#define CALLFLOW_CALL_DIALING AST_STATE_DIALING +#define CALLFLOW_CALL_LINEBUSY AST_STATE_BUSY +#define CALLFLOW_CALL_ACTIVE 300 +#define CALLFLOW_INCOMING_HANGUP 100 +#define CALLFLOW_CALL_RELEASED 101 +#define CALLFLOW_CALL_NOCARRIER 102 +#define CALLFLOW_CALL_INFLUX 103 +#define CALLFLOW_CALL_INCOMING 104 +#define CALLFLOW_CALL_FAILED 105 +#define CALLFLOW_CALL_NOSERVICE 106 +#define CALLFLOW_CALL_OUTGOINGRESTRICTED 107 +#define CALLFLOW_CALL_SECURITYFAIL 108 +#define CALLFLOW_CALL_NOANSWER 109 +#define CALLFLOW_STATUS_FINISHED 110 +#define CALLFLOW_STATUS_CANCELLED 111 +#define CALLFLOW_STATUS_FAILED 112 +#define CALLFLOW_STATUS_REFUSED 113 +#define CALLFLOW_STATUS_RINGING 114 +#define CALLFLOW_STATUS_INPROGRESS 115 +#define CALLFLOW_STATUS_UNPLACED 116 +#define CALLFLOW_STATUS_ROUTING 117 +#define CALLFLOW_STATUS_EARLYMEDIA 118 +#define AST_STATE_HANGUP_REQUESTED 200 + //FIXME CALLFLOW_INCOMING_CALLID to be removed +#define CALLFLOW_INCOMING_CALLID 1019 +/* debugging bitmask */ +#define DEBUG_SOUND 1 +#define DEBUG_SERIAL 2 +#define DEBUG_SKYPE 4 +#define DEBUG_AT 8 +#define DEBUG_FBUS2 16 +#define DEBUG_CALL 32 +#define DEBUG_LOCKS 64 +#define DEBUG_PBX 128 +#define DEBUG_MONITORLOCKS 256 +#define DEBUG_ALL DEBUG_SOUND|DEBUG_SERIAL|DEBUG_SKYPE|DEBUG_AT|DEBUG_FBUS2|DEBUG_CALL|DEBUG_PBX|DEBUG_LOCKS|DEBUG_MONITORLOCKS +/* wrappers for ast_log */ +#define DEBUGA_SOUND(...) if (skypiax_debug & DEBUG_SOUND) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SOUND %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_SERIAL(...) if (skypiax_debug & DEBUG_SERIAL) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SERIAL %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_SKYPE(...) if (skypiax_debug & DEBUG_SKYPE) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SKYPE %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_AT(...) if (skypiax_debug & DEBUG_AT) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_AT %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_FBUS2(...) if (skypiax_debug & DEBUG_FBUS2) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_FBUS2 %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_CALL(...) if (skypiax_debug & DEBUG_CALL) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_CALL %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define DEBUGA_PBX(...) if (skypiax_debug & DEBUG_PBX) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_PBX %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define ERRORA(...) ast_log(LOG_ERROR, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][ERROR %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define NOTICA(...) ast_log(LOG_NOTICE, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][NOTICE %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +#define WARNINGA(...) ast_log(LOG_WARNING, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][WARNING %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); +/* macros for logging */ +#define SKYPIAX_P_LOG p ? p->owner : NULL, (unsigned long)pthread_self(), __LINE__, p ? p->name ? p->name : "none" : "none", p ? p->owner ? p->owner->_state : -1 : -1, p ? p->interface_state : -1, p ? p->skype_callflow : -1 +#define SKYPIAX_TMP_LOG tmp ? tmp->owner : NULL, (unsigned long)pthread_self(), __LINE__, tmp ? tmp->name ? tmp->name : "none" : "none", tmp ? tmp->owner ? tmp->owner->_state : -1 : -1, tmp ? tmp->interface_state : -1, tmp ? tmp->skype_callflow : -1 +/* logging wrappers for ast_mutex_lock and ast_mutex_unlock */ +#define LOKKA(x) if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] going to lock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_lock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] locked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); +#define UNLOCKA(x) if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] going to unlock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_unlock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] unlocked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); +#define PUSHA_UNLOCKA(x) pthread_cleanup_push(skypiax_unlocka_log, (void *) x); +#define POPPA_UNLOCKA(x) pthread_cleanup_pop(0); +#define MONITORLOKKA(x) if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] going to lock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_lock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] locked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); +#define MONITORUNLOCKA(x) if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] going to unlock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_unlock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] unlocked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); +/* macros used for config file parsing (luigi rizzo)*/ +#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) ) +#define M_END(x) x; +#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else +#ifdef ASTERISK_VERSION_1_6 +#define M_START(var, val) const char *__s = var; const char *__val = val; +#else +#define M_START(var, val) char *__s = var; char *__val = val; +#endif /* ASTERISK_VERSION_1_6 */ +#define M_STR(tag, dst) M_F(tag, ast_copy_string(dst, __val, sizeof(dst))) +#define M_UINT(tag, dst) M_F(tag, (dst) = strtoul(__val, NULL, 0) ) + +#define SKYPIAX_FRAME_SIZE 160 + +/* SKYPIAX INTERNAL STRUCTS */ +/*! + * \brief structure for exchanging messages with the skype client + */ +#ifdef WANT_SKYPE_X11 +struct AsteriskHandles { + Window skype_win; + Display *disp; + Window win; + int fdesc[2]; +}; +#else /* WANT_SKYPE_X11 */ +struct AsteriskHandles { + HWND win32_hInit_MainWindowHandle; + HWND win32_hGlobal_SkypeAPIWindowHandle; + int fdesc[2]; +}; +#endif /* WANT_SKYPE_X11 */ + +#ifndef WIN32 +struct SkypiaxHandles { + Window skype_win; + Display *disp; + Window win; + int api_connected; + int fdesc[2]; +}; +#else //WIN32 + +struct SkypiaxHandles { + HWND win32_hInit_MainWindowHandle; + HWND win32_hGlobal_SkypeAPIWindowHandle; + HINSTANCE win32_hInit_ProcessHandle; + char win32_acInit_WindowClassName[128]; + UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach; + UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover; + int api_connected; + int fdesc[2]; +}; + +#endif //WIN32 + +/*! + * \brief PVT structure for a skypiax interface (channel), created by skypiax_mkif + */ +struct skypiax_pvt { + char *name; /*!< \brief 'name' of the interface (channel) */ + int interface_state; /*!< \brief 'state' of the interface (channel) */ + struct ast_channel *owner; /*!< \brief channel we belong to, possibly NULL */ + struct skypiax_pvt *next; /*!< \brief Next interface (channel) in list */ + char context[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan context for this interface */ + char language[MAX_LANGUAGE]; /*!< \brief default Asterisk dialplan language for this interface */ + char exten[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan extension for this interface */ + int skypiax_sound_rate; /*!< \brief rate of the sound device, in Hz, eg: 8000 */ + int skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */ + char callid_name[50]; + char callid_number[50]; + pthread_t controldev_thread; /*!< \brief serial control thread for this interface, running during the call */ + double playback_boost; + double capture_boost; + int stripmsd; + pthread_t skype_thread; + struct AsteriskHandles AsteriskHandlesAst; + struct SkypiaxHandles SkypiaxHandles; + char skype_call_id[512]; + int skype_call_ongoing; + char skype_friends[4096]; + char skype_fullname[512]; + char skype_displayname[512]; + int skype_callflow; /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */ + int skype; /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */ + int control_to_send; + int audiopipe[2]; + int audioskypepipe[2]; + pthread_t tcp_srv_thread; + pthread_t tcp_cli_thread; + short audiobuf[160]; + int audiobuf_is_loaded; + + //int phonebook_listing; + //int phonebook_querying; + //int phonebook_listing_received_calls; + + //int phonebook_first_entry; + //int phonebook_last_entry; + //int phonebook_number_lenght; + //int phonebook_text_lenght; + FILE *phonebook_writing_fp; + int skypiax_dir_entry_extension_prefix; +#ifdef WIN32 + unsigned short tcp_cli_port; + unsigned short tcp_srv_port; +#else + int tcp_cli_port; + int tcp_srv_port; +#endif + char X11_display[256]; + + struct ast_frame read_frame; + + char skype_user[256]; + char skype_password[256]; + char destination[256]; + char session_uuid_str[512 + 1]; + pthread_t signaling_thread; +}; + +typedef struct skypiax_pvt private_t; +/* FUNCTIONS */ + +/* module helpers functions */ +int load_module(void); +int unload_module(void); +int usecount(void); +char *description(void); +char *key(void); + +/* chan_skypiax internal functions */ +void skypiax_unlocka_log(void *x); + +void *do_skypeapi_thread(void *data); +//int skypiax2skype(struct ast_channel *c, void *data); +//int skype2skypiax(struct ast_channel *c, void *data); +//void skypiax_disconnect(void); +int skypiax_signaling_write(struct skypiax_pvt *p, char *msg_to_skype); +int skypiax_signaling_read(struct skypiax_pvt *p); +int skypiax_console_skype(int fd, int argc, char *argv[]); +#ifdef WANT_SKYPE_X11 +int X11_errors_handler(Display * dpy, XErrorEvent * err); +int skypiax_send_message(struct SkypiaxHandles *SkypiaxHandles, const char *message_P); +int skypiax_present(struct SkypiaxHandles *SkypiaxHandles); +void skypiax_clean_disp(void *data); +#endif /* WANT_SKYPE_X11 */ +#ifdef __CYGWIN__ + +int win32_Initialize_CreateWindowClass(private_t * tech_pvt); +void win32_DeInitialize_DestroyWindowClass(private_t * tech_pvt); +int win32_Initialize_CreateMainWindow(private_t * tech_pvt); +void win32_DeInitialize_DestroyMainWindow(private_t * tech_pvt); +#endif /* __CYGWIN__ */ + +/* CHAN_SKYPIAX.C */ +int skypiax_queue_control(struct ast_channel *chan, int control); +struct skypiax_pvt *skypiax_console_find_desc(char *dev); +int skypiax_serial_call(struct skypiax_pvt *p, char *dstr); + +/* FUNCTIONS */ +/* PBX interface functions */ +struct ast_channel *skypiax_request(const char *type, int format, void *data, int *cause); +int skypiax_answer(struct ast_channel *c); +int skypiax_hangup(struct ast_channel *c); +int skypiax_originate_call(struct ast_channel *c, char *idest, int timeout); +struct ast_frame *skypiax_read(struct ast_channel *chan); +int skypiax_write(struct ast_channel *c, struct ast_frame *f); +int skypiax_fixup(struct ast_channel *oldchan, struct ast_channel *newchan); +#ifndef ASTERISK_VERSION_1_4 +int skypiax_indicate(struct ast_channel *c, int cond); +#else +int skypiax_indicate(struct ast_channel *c, int cond, const void *data, size_t datalen); +#endif +int skypiax_devicestate(void *data); +#ifdef ASTERISK_VERSION_1_4 +int skypiax_digitsend_begin(struct ast_channel *ast, char digit); +int skypiax_digitsend_end(struct ast_channel *ast, char digit, unsigned int duration); +#else /* ASTERISK_VERSION_1_4 */ +int skypiax_digitsend(struct ast_channel *ast, char digit); +#endif /* ASTERISK_VERSION_1_4 */ + +/* chan_skypiax internal functions */ + +struct skypiax_pvt *skypiax_mkif(struct ast_config *cfg, char *ctg, int is_first_category); +struct ast_channel *skypiax_new(struct skypiax_pvt *p, int state, char *context); +int skypiax_restart_monitor(void); +void *skypiax_do_monitor(void *data); +int skypiax_sound_boost(struct ast_frame *f, double boost); +int skypiax_sound_init(struct skypiax_pvt *p); +int skypiax_sound_shutdown(struct skypiax_pvt *p); +struct ast_frame *skypiax_sound_read(struct skypiax_pvt *p); +int skypiax_sound_write(struct skypiax_pvt *p, struct ast_frame *f); +void *skypiax_do_controldev_thread(void *data); +#ifdef ASTERISK_VERSION_1_6 +void skypiax_store_boost(const char *s, double *boost); +#else +void skypiax_store_boost(char *s, double *boost); +#endif /* ASTERISK_VERSION_1_6 */ +int skypiax_console_set_active(int fd, int argc, char *argv[]); +int skypiax_console_hangup(int fd, int argc, char *argv[]); +int skypiax_console_playback_boost(int fd, int argc, char *argv[]); +int skypiax_console_capture_boost(int fd, int argc, char *argv[]); +int skypiax_console_skypiax(int fd, int argc, char *argv[]); +int skypiax_console_dial(int fd, int argc, char *argv[]); +int skypiax_audio_init(struct skypiax_pvt *p); +//struct ast_frame *skypiax_audio_read(struct skypiax_pvt *p); +int skypiax_audio_read(struct skypiax_pvt *p); +void *skypiax_do_tcp_srv_thread(void *data); +int skypiax_audio_write(struct skypiax_pvt *p, struct ast_frame *f); +void *skypiax_do_tcp_cli_thread(void *data); +int skypiax_call(struct skypiax_pvt *p, char *idest, int timeout); +int skypiax_console_skypiax_dir_import(int fd, int argc, char *argv[]); + +void *skypiax_do_tcp_srv_thread_func(void *obj); +void *skypiax_do_tcp_cli_thread_func(void *obj); +void *skypiax_do_skypeapi_thread_func(void *obj); +int dtmf_received(private_t * tech_pvt, char *value); +int start_audio_threads(private_t * tech_pvt); +int new_inbound_channel(private_t * tech_pvt); +int outbound_channel_answered(private_t * tech_pvt); +int skypiax_senddigit(struct skypiax_pvt *p, char digit); +int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype); +#if defined(WIN32) && !defined(__CYGWIN__) +int skypiax_pipe_read(switch_file_t * pipe, short *buf, int howmany); +int skypiax_pipe_write(switch_file_t * pipe, short *buf, int howmany); +/* Visual C do not have strsep ? */ +char *strsep(char **stringp, const char *delim); +#else +int skypiax_pipe_read(int pipe, short *buf, int howmany); +int skypiax_pipe_write(int pipe, short *buf, int howmany); +#endif /* WIN32 */ +int skypiax_close_socket(unsigned int fd); +private_t *find_available_skypiax_interface(void); +int remote_party_is_ringing(private_t * tech_pvt); +int remote_party_is_early_media(private_t * tech_pvt); +#define SKYPIAX_STATE_DOWN AST_STATE_DOWN +#define SKYPIAX_STATE_RING AST_STATE_RING +#define SKYPIAX_STATE_DIALING AST_STATE_DIALING +#define SKYPIAX_STATE_BUSY AST_STATE_BUSY +#define SKYPIAX_STATE_UP AST_STATE_UP +#define SKYPIAX_STATE_RINGING AST_STATE_RINGING +#define SKYPIAX_STATE_PRERING AST_STATE_PRERING +#define SKYPIAX_STATE_RESERVED AST_STATE_RESERVED +#define SKYPIAX_STATE_HANGUP_REQUESTED 200 +#endif /* _SKYPIAX_H_ */ diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/README.skypopen_auth b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/README.skypopen_auth new file mode 100644 index 0000000000..c59122e952 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/README.skypopen_auth @@ -0,0 +1,57 @@ +####################################### +HOW TO USE SKYPOPEN_AUTH +####################################### + +You will use skypopen_auth only at the setup moment, to force the Skype client to ask you to authorize "skypopen" to connect to it. + +Then you copy the .Skype configuration directory of the user that has launched Skype (eg: /home/maruzz/.Skype if you are maruzz) on the home directory of the user that will start Skype on the server (eg: root). + +Compile skypopen_auth: +$ gcc -Wall -ggdb skypopen_auth.c -o skypopen_auth -lX11 + +Then: + +1) on a Linux desktop machine, rmmod all the snd* modules +2) on the desktop machine, modprobe snd-dummy +3) on the desktop machine, logout from your autologin username if any, launch the Skype client and login as the username you'll use on server +4) on the desktop machine, set the desktop client to use the "hw:dummy" audio device, to not update, to not make "events", etc etc... Make and receive a couple of test calls. Please note that you (and the remote party) will hear nothing (you're using the snd-dummy "fake" audio driver), that's ok. +3) on the desktop machine, when satisfied of the Skype client setup, use skypopen_auth (that simulates FS-skypopen connecting to the Skype client). The Skype client will ask you to be authorized to let "skypopen" connect. +4) Give the authorization and check the "not ask me again" option. +5) Close (Quit) the Skype client from the tray icon, so it saves its config. +6) Then, relaunch the Skype client and use skypopen_auth again, just to be sure it now succeed. +7) Close (Quit) the Skype client from the tray icon, so it saves its config. + +*** Do the steps 1-7 for all Skype usernames you will want to use on the server (eg: one Skype username per channel) + +When finished with all the Skype usernames: +Copy or targzip the .Skype directory and all its content on the home directory of the server user that will launch the Skype client(s). + +############################ +first time you use skypopen_auth +############################ +$ ./skypopen_auth +Skype instance found with id #27263062 +RECEIVED==> ERROR 68 +RECEIVED==> OK + +############################ +Give the auth to the Skype client, and tell him not to ask again +Then Ctrl-C to exit from skypopen_auth +############################ + + +Close (Quit) the Skype client from the tray icon, so it saves its config. +Then, relaunch the Skype client + +############################ +you use skypopen_auth again +############################ +$ ./skypopen_auth +Skype instance found with id #27263062 +RECEIVED==> OK +RECEIVED==> PROTOCOL 6 +RECEIVED==> CONNSTATUS ONLINE +RECEIVED==> CURRENTUSERHANDLE gmaruzz3 +RECEIVED==> USERSTATUS INVISIBLE + + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/client.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/client.c new file mode 100644 index 0000000000..87c4c6c422 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/client.c @@ -0,0 +1,297 @@ +//gcc -Wall -ggdb client.c -o client -lX11 -lpthread +/* + + Interactive client for the Skype API + +USAGE: client [Xserver instance] + +# ./client :103 + +*/ + +#include +#include +#include +#include +#include +#include + +Display *disp = NULL; + +struct SkypopenHandles { + Window skype_win; + Display *disp; + Window win; + int api_connected; + int fdesc[2]; +}; + +XErrorHandler old_handler = 0; +int xerror = 0; +char *dispname; + +int X11_errors_handler(Display * dpy, XErrorEvent * err) +{ + (void) dpy; + + xerror = err->error_code; + printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror, dispname); + return 0; /* ignore the error */ +} + +static void X11_errors_trap(void) +{ + xerror = 0; + old_handler = XSetErrorHandler(X11_errors_handler); +} + +static int X11_errors_untrap(void) +{ + XSetErrorHandler(old_handler); + return (xerror != BadValue) && (xerror != BadWindow); +} + +int skypopen_send_message(struct SkypopenHandles *SkypopenHandles, const char *message_P) +{ + + Window w_P; + Display *disp; + Window handle_P; + int ok; + + w_P = SkypopenHandles->skype_win; + disp = SkypopenHandles->disp; + handle_P = SkypopenHandles->win; + + Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); + Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False); + unsigned int pos = 0; + unsigned int len = strlen(message_P); + XEvent e; + + memset(&e, 0, sizeof(e)); + e.xclient.type = ClientMessage; + e.xclient.message_type = atom1; /* leading message */ + e.xclient.display = disp; + e.xclient.window = handle_P; + e.xclient.format = 8; + + X11_errors_trap(); + do { + unsigned int i; + for (i = 0; i < 20 && i + pos <= len; ++i) + e.xclient.data.b[i] = message_P[i + pos]; + XSendEvent(disp, w_P, False, 0, &e); + + e.xclient.message_type = atom2; /* following messages */ + pos += i; + } while (pos <= len); + + XSync(disp, False); + ok = X11_errors_untrap(); + + if (!ok) + printf("Sending message failed with status %d\n", xerror); + + return 1; +} + +int skypopen_present(struct SkypopenHandles *SkypopenHandles) +{ + Atom skype_inst = XInternAtom(SkypopenHandles->disp, "_SKYPE_INSTANCE", True); + + Atom type_ret; + int format_ret; + unsigned long nitems_ret; + unsigned long bytes_after_ret; + unsigned char *prop; + int status; + + X11_errors_trap(); + status = + XGetWindowProperty(SkypopenHandles->disp, DefaultRootWindow(SkypopenHandles->disp), + skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop); + + X11_errors_untrap(); + /* sanity check */ + if (status != Success || format_ret != 32 || nitems_ret != 1) { + SkypopenHandles->skype_win = (Window) - 1; + printf("Skype instance not found on display '%s'\n", dispname); + return 0; + } + + SkypopenHandles->skype_win = *(const unsigned long *) prop & 0xffffffff; + //printf("Skype instance found on display '%s', with id #%d\n", dispname, (unsigned int) SkypopenHandles->skype_win); + return 1; +} + +void skypopen_clean_disp(void *data) +{ + + int *dispptr; + int disp; + + dispptr = data; + disp = *dispptr; + + if (disp) { + close(disp); + } else { + } + usleep(1000); +} + +typedef struct { + int value; + char string[128]; +} thread_parm_t; + +void *threadfunc(void *parm) +{ //child + thread_parm_t *p = (thread_parm_t *) parm; + //printf("%s, parm = %d\n", p->string, p->value); + free(p); + + /* perform an events loop */ + XEvent an_event; + char buf[21]; /* can't be longer */ + char buffer[17000]; + char *b; + int i; + + b = buffer; + + while (1) { + + XNextEvent(disp, &an_event); + switch (an_event.type) { + case ClientMessage: + + if (an_event.xclient.format != 8) + break; + + for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i) + buf[i] = an_event.xclient.data.b[i]; + + buf[i] = '\0'; + + strcat(buffer, buf); + + if (i < 20) { /* last fragment */ + unsigned int howmany; + + howmany = strlen(b) + 1; + + //printf("\tRECEIVED\t==>\t%s\n", b); + printf("%s\n", b); + fflush(stdout); + memset(buffer, '\0', 17000); + } + + break; + default: + break; + } + + } + return NULL; +} + +int main(int argc, char *argv[]) +{ + + struct SkypopenHandles SkypopenHandles; + char buf[512]; + //Display *disp = NULL; + Window root = -1; + Window win = -1; + + if (argc == 2) + dispname = argv[1]; + else + dispname = ":0.0"; + + + if (!XInitThreads()) { + printf("Not initialized XInitThreads!\n"); + } else { + printf("Initialized XInitThreads!\n"); + } + + + + + + disp = XOpenDisplay(dispname); + if (!disp) { + printf("Cannot open X Display '%s', exiting\n", dispname); + return -1; + } + + int xfd; + xfd = XConnectionNumber(disp); + + SkypopenHandles.disp = disp; + + if (skypopen_present(&SkypopenHandles)) { + root = DefaultRootWindow(disp); + win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp))); + + SkypopenHandles.win = win; + + snprintf(buf, 512, "NAME skypopen"); + + if (!skypopen_send_message(&SkypopenHandles, buf)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + + snprintf(buf, 512, "PROTOCOL 7"); + if (!skypopen_send_message(&SkypopenHandles, buf)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + + snprintf(buf, 512, "#ciapalino PING"); + if (!skypopen_send_message(&SkypopenHandles, buf)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + + pthread_t thread; + int rc = 0; + pthread_attr_t pta; + thread_parm_t *parm = NULL; + + rc = pthread_attr_init(&pta); + + parm = malloc(sizeof(thread_parm_t)); + parm->value = 5; + rc = pthread_create(&thread, NULL, threadfunc, (void *) parm); + + while (1) { + char s[512]; + + memset(s, '\0', 512); + fgets(s, sizeof(s) - 1, stdin); + s[strlen(s) - 1] = '\0'; + + //printf("\tSENT\t\t==>\t%s\n", s); + + if (!strncmp(s, "#output", 7)) { + + system("/bin/nc -l -p 15557 0/tmp/back2 &"); + system("/bin/nc -l -p 15556 0/tmp/back1 &"); + } + if (!skypopen_send_message(&SkypopenHandles, s)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + } + } else { + printf("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypopen_auth again\n\n\n", dispname); + return -1; + } + return 0; + +} diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/copy b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/copy new file mode 100644 index 0000000000..59400bf1ff --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/copy @@ -0,0 +1,39 @@ +cp -a skypopen101/* skypopen102/ +cp -a skypopen101/* skypopen103/ +cp -a skypopen101/* skypopen104/ +cp -a skypopen101/* skypopen105/ +cp -a skypopen101/* skypopen106/ +cp -a skypopen101/* skypopen107/ +cp -a skypopen101/* skypopen108/ +cp -a skypopen101/* skypopen109/ +cp -a skypopen101/* skypopen110/ +cp -a skypopen101/* skypopen111/ +cp -a skypopen101/* skypopen112/ +cp -a skypopen101/* skypopen113/ +cp -a skypopen101/* skypopen114/ +cp -a skypopen101/* skypopen115/ +cp -a skypopen101/* skypopen116/ +cp -a skypopen101/* skypopen117/ +cp -a skypopen101/* skypopen118/ +cp -a skypopen101/* skypopen119/ +cp -a skypopen101/* skypopen120/ +cp -a skypopen101/* skypopen121/ +cp -a skypopen101/* skypopen122/ +cp -a skypopen101/* skypopen123/ +cp -a skypopen101/* skypopen124/ +cp -a skypopen101/* skypopen125/ +cp -a skypopen101/* skypopen126/ +cp -a skypopen101/* skypopen127/ +cp -a skypopen101/* skypopen128/ +cp -a skypopen101/* skypopen129/ +cp -a skypopen101/* skypopen130/ +cp -a skypopen101/* skypopen131/ +cp -a skypopen101/* skypopen132/ +cp -a skypopen101/* skypopen133/ +cp -a skypopen101/* skypopen134/ +cp -a skypopen101/* skypopen135/ +cp -a skypopen101/* skypopen136/ +cp -a skypopen101/* skypopen137/ +cp -a skypopen101/* skypopen138/ +cp -a skypopen101/* skypopen139/ +cp -a skypopen101/* skypopen140/ diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/create b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/create new file mode 100644 index 0000000000..fd2c9e0229 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/create @@ -0,0 +1,40 @@ +mkdir skypopen101 +mkdir skypopen102 +mkdir skypopen103 +mkdir skypopen104 +mkdir skypopen105 +mkdir skypopen106 +mkdir skypopen107 +mkdir skypopen108 +mkdir skypopen109 +mkdir skypopen110 +mkdir skypopen111 +mkdir skypopen112 +mkdir skypopen113 +mkdir skypopen114 +mkdir skypopen115 +mkdir skypopen116 +mkdir skypopen117 +mkdir skypopen118 +mkdir skypopen119 +mkdir skypopen120 +mkdir skypopen121 +mkdir skypopen122 +mkdir skypopen123 +mkdir skypopen124 +mkdir skypopen125 +mkdir skypopen126 +mkdir skypopen127 +mkdir skypopen128 +mkdir skypopen129 +mkdir skypopen130 +mkdir skypopen131 +mkdir skypopen132 +mkdir skypopen133 +mkdir skypopen134 +mkdir skypopen135 +mkdir skypopen136 +mkdir skypopen137 +mkdir skypopen138 +mkdir skypopen139 +mkdir skypopen140 diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/README b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/README new file mode 100644 index 0000000000..3de4125e12 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/README @@ -0,0 +1,4 @@ +# just execute the file + +sh ./multi.sh + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/multi.sh b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/multi.sh new file mode 100644 index 0000000000..792e330a44 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/multi.sh @@ -0,0 +1,152 @@ +#!/bin/bash +# remember to add here the removing of all the installed snd-* modules, so you're sure only the snd-dummy driver will be around +rmmod snd_hda_intel +rmmod snd-dummy # enable=1,1,1 + +# you need three dummy soundcard for 20 Skype client instances, because each dummy soundcard can handle a max of 8 Skype instances +# the enable= module parameter tells how many cards to start. For each additional card, add a comma and a 1 +# manually configure the first 8 Skype client instances to use the hw:Dummy_0, the next 8 instances to use hw:Dummy_1, etc for all three devices (Play, Capture, Ring) +modprobe snd-dummy +#modprobe snd-aloop enable=1,1,1 +sleep 3 + +#start the fake X server on a given port + /usr/bin/Xvfb :101 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +# start a Skype client instance that will connect to the X server above, and will login to the Skype network using the 'username password' you send to it on stdin. Here passwd5 would be the password and user5 the username +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:101 /usr/bin/skype --dbpath=/root/multi/skypopen101 --pipelogin &" + + +sleep 7 + + + /usr/bin/Xvfb :102 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:102 /usr/bin/skype --dbpath=/root/multi/skypopen102 --pipelogin &" + +sleep 7 + +exit 0 + +################################################################# +# Following X server and Skype client instances are commented out +################################################################# + /usr/bin/Xvfb :103 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:103 /usr/bin/skype --dbpath=/root/multi/skypopen103 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :104 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:104 /usr/bin/skype --dbpath=/root/multi/skypopen104 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :105 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:105 /usr/bin/skype --dbpath=/root/multi/skypopen105 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :106 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:106 /usr/bin/skype --dbpath=/root/multi/skypopen106 --pipelogin &" + + +sleep 7 + /usr/bin/Xvfb :107 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:107 /usr/bin/skype --dbpath=/root/multi/skypopen107 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :108 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:108 /usr/bin/skype --dbpath=/root/multi/skypopen108 --pipelogin &" + +sleep 7 + + + /usr/bin/Xvfb :109 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:109 /usr/bin/skype --dbpath=/root/multi/skypopen109 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :110 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:110 /usr/bin/skype --dbpath=/root/multi/skypopen110 --pipelogin &" + +sleep 7 + + + /usr/bin/Xvfb :111 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:111 /usr/bin/skype --dbpath=/root/multi/skypopen111 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :112 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:112 /usr/bin/skype --dbpath=/root/multi/skypopen112 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :113 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:113 /usr/bin/skype --dbpath=/root/multi/skypopen113 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :114 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:114 /usr/bin/skype --dbpath=/root/multi/skypopen114 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :115 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:115 /usr/bin/skype --dbpath=/root/multi/skypopen115 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :116 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:116 /usr/bin/skype --dbpath=/root/multi/skypopen116 --pipelogin &" + +sleep 7 + + + /usr/bin/Xvfb :117 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:117 /usr/bin/skype --dbpath=/root/multi/skypopen117 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :118 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:118 /usr/bin/skype --dbpath=/root/multi/skypopen118 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :119 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:119 /usr/bin/skype --dbpath=/root/multi/skypopen119 --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :120 -screen 0 800x600x16 -nolisten tcp -ac & +sleep 3 + +su root -c "/bin/echo 'user5 passwd5'| DISPLAY=:120 /usr/bin/skype --dbpath=/root/multi/skypopen120 --pipelogin &" + +sleep 7 + +exit 0 diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/skypopen.conf.xml b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/skypopen.conf.xml new file mode 100644 index 0000000000..037a26255b --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/multiple-instance-same-skype-username/skypopen.conf.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen.conf.xml b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen.conf.xml new file mode 100644 index 0000000000..f4e1c0ec5a --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen.conf.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen_auth.c b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen_auth.c new file mode 100644 index 0000000000..f886834fe0 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/skypopen_auth.c @@ -0,0 +1,219 @@ +//gcc -Wall -ggdb skypopen_auth.c -o skypopen_auth -lX11 +#include +#include +#include +#include +#include + +struct SkypopenHandles { + Window skype_win; + Display *disp; + Window win; + int api_connected; + int fdesc[2]; +}; + +XErrorHandler old_handler = 0; +int xerror = 0; +char *dispname; + +int X11_errors_handler(Display * dpy, XErrorEvent * err) +{ + (void) dpy; + + xerror = err->error_code; + printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror, dispname); + return 0; /* ignore the error */ +} + +static void X11_errors_trap(void) +{ + xerror = 0; + old_handler = XSetErrorHandler(X11_errors_handler); +} + +static int X11_errors_untrap(void) +{ + XSetErrorHandler(old_handler); + return (xerror != BadValue) && (xerror != BadWindow); +} + +int skypopen_send_message(struct SkypopenHandles *SkypopenHandles, const char *message_P) +{ + + Window w_P; + Display *disp; + Window handle_P; + int ok; + + w_P = SkypopenHandles->skype_win; + disp = SkypopenHandles->disp; + handle_P = SkypopenHandles->win; + + Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); + Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False); + unsigned int pos = 0; + unsigned int len = strlen(message_P); + XEvent e; + + memset(&e, 0, sizeof(e)); + e.xclient.type = ClientMessage; + e.xclient.message_type = atom1; /* leading message */ + e.xclient.display = disp; + e.xclient.window = handle_P; + e.xclient.format = 8; + + X11_errors_trap(); + do { + unsigned int i; + for (i = 0; i < 20 && i + pos <= len; ++i) + e.xclient.data.b[i] = message_P[i + pos]; + XSendEvent(disp, w_P, False, 0, &e); + + e.xclient.message_type = atom2; /* following messages */ + pos += i; + } while (pos <= len); + + XSync(disp, False); + ok = X11_errors_untrap(); + + if (!ok) + printf("Sending message failed with status %d\n", xerror); + + return 1; +} + +int skypopen_present(struct SkypopenHandles *SkypopenHandles) +{ + Atom skype_inst = XInternAtom(SkypopenHandles->disp, "_SKYPE_INSTANCE", True); + + Atom type_ret; + int format_ret; + unsigned long nitems_ret; + unsigned long bytes_after_ret; + unsigned char *prop; + int status; + + X11_errors_trap(); + status = + XGetWindowProperty(SkypopenHandles->disp, DefaultRootWindow(SkypopenHandles->disp), + skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop); + + X11_errors_untrap(); + /* sanity check */ + if (status != Success || format_ret != 32 || nitems_ret != 1) { + SkypopenHandles->skype_win = (Window) - 1; + printf("Skype instance not found on display '%s'\n", dispname); + return 0; + } + + SkypopenHandles->skype_win = *(const unsigned long *) prop & 0xffffffff; + printf("Skype instance found on display '%s', with id #%d\n", dispname, (unsigned int) SkypopenHandles->skype_win); + return 1; +} + +void skypopen_clean_disp(void *data) +{ + + int *dispptr; + int disp; + + dispptr = data; + disp = *dispptr; + + if (disp) { + close(disp); + } else { + } + usleep(1000); +} + +int main(int argc, char *argv[]) +{ + + struct SkypopenHandles SkypopenHandles; + char buf[512]; + Display *disp = NULL; + Window root = -1; + Window win = -1; + + if (argc == 2) + dispname = argv[1]; + else + dispname = ":0.0"; + + disp = XOpenDisplay(dispname); + if (!disp) { + printf("Cannot open X Display '%s', exiting\n", dispname); + return -1; + } + + int xfd; + xfd = XConnectionNumber(disp); + + SkypopenHandles.disp = disp; + + if (skypopen_present(&SkypopenHandles)) { + root = DefaultRootWindow(disp); + win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp))); + + SkypopenHandles.win = win; + + snprintf(buf, 512, "NAME skypopen"); + + if (!skypopen_send_message(&SkypopenHandles, buf)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + + snprintf(buf, 512, "PROTOCOL 6"); + if (!skypopen_send_message(&SkypopenHandles, buf)) { + printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypopen_auth again\n"); + return -1; + } + + /* perform an events loop */ + XEvent an_event; + char buf[21]; /* can't be longer */ + char buffer[17000]; + char *b; + int i; + + b = buffer; + + while (1) { + XNextEvent(disp, &an_event); + switch (an_event.type) { + case ClientMessage: + + if (an_event.xclient.format != 8) + break; + + for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i) + buf[i] = an_event.xclient.data.b[i]; + + buf[i] = '\0'; + + strcat(buffer, buf); + + if (i < 20) { /* last fragment */ + unsigned int howmany; + + howmany = strlen(b) + 1; + + printf("RECEIVED==> %s\n", b); + memset(buffer, '\0', 17000); + } + + break; + default: + break; + } + } + } else { + printf("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypopen_auth again\n\n\n", dispname); + return -1; + } + return 0; + +} diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.bat b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.bat new file mode 100644 index 0000000000..5624b02af4 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.bat @@ -0,0 +1,52 @@ +echo off +REM +REM you MUST use the new Skype (4.x) for Windows, older versions (3.x) cannot be started this way +REM +REM you have to adjust PATH to where the Skype executable is +set PATH=%PATH%;C:\Program Files\Skype\Phone\ + +echo %PATH% + +REM start a Skype client instance that will login to the Skype network using the "username password" you give to it. Here xxx would be the password and user1 the username +start Skype.exe /secondary /username:user1 /password:xxx +call wait 7 +start Skype.exe /secondary /username:user2 /password:xxx +call wait 7 +REM +REM Following Skype client instances are commented out +REM +REM start Skype.exe /secondary /username:user3 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user4 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user5 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user6 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user7 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user8 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user9 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user10 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user11 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user12 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user13 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user14 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user15 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user16 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user17 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user18 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user19 /password:xxx +REM call wait 7 +REM start Skype.exe /secondary /username:user20 /password:xxx diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.sh b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.sh new file mode 100755 index 0000000000..8e030ec2f3 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/startskype.sh @@ -0,0 +1,143 @@ +# remember to add here the removing of all the installed snd-* modules, so you're sure only the snd-dummy driver will be around +rmmod snd_hda_intel +rmmod snd-dummy + +# if you DO NOT USE the custom ALSA device we provide, you need three "standard" dummy soundcard for 20 Skype client instances, because each "standard" dummy soundcard can handle a max of 8 Skype instances +# the enable= module parameter tells how many cards to start. For each additional card, add a comma and a 1 +# manually configure the first 8 Skype client instances to use the hw:Dummy_0, the next 8 instances to use hw:Dummy_1, etc for all three devices (Play, Capture, Ring) +modprobe snd-dummy # enable=1,1,1 +sleep 3 + +#start the fake X server on a given port + /usr/bin/Xvfb :101 -ac & +sleep 3 + +# start a Skype client instance that will connect to the X server above, and will login to the Skype network using the 'username password' you send to it on stdin. Here xxxx would be the password and user1 the username +su root -c "/bin/echo 'user1 xxxx'| DISPLAY=:101 /usr/bin/skype --pipelogin &" + + +sleep 7 + + + /usr/bin/Xvfb :102 -ac & +sleep 3 + +su root -c "/bin/echo 'user2 xxxx'| DISPLAY=:102 /usr/bin/skype --pipelogin &" + +sleep 7 + +exit 0 + +################################################################################## +# Following X server and Skype client instances are NOT LAUNCHED (see line before) +################################################################################## + + /usr/bin/Xvfb :103 -ac & +sleep 3 + +su root -c "/bin/echo 'user3 xxxx'| DISPLAY=:103 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :104 -ac & +sleep 3 + +su root -c "/bin/echo 'user4 xxxx'| DISPLAY=:104 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :105 -ac & +sleep 3 + +su root -c "/bin/echo 'user5 xxxx'| DISPLAY=:105 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :106 -ac & +sleep 3 + +su root -c "/bin/echo 'user6 xxxx'| DISPLAY=:106 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :107 -ac & +sleep 3 + +su root -c "/bin/echo 'user7 xxxx'| DISPLAY=:107 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :108 -ac & +sleep 3 + +su root -c "/bin/echo 'user8 xxxx'| DISPLAY=:108 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :109 -ac & +sleep 3 + +su root -c "/bin/echo 'user9 xxxx'| DISPLAY=:109 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :110 -ac & +sleep 3 + +su root -c "/bin/echo 'user10 xxxx'| DISPLAY=:110 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :111 -ac & +sleep 3 + +su root -c "/bin/echo 'user11 xxxx'| DISPLAY=:111 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :112 -ac & +sleep 3 + +su root -c "/bin/echo 'user12 xxxx'| DISPLAY=:112 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :113 -ac & +sleep 3 + +su root -c "/bin/echo 'user13 xxxx'| DISPLAY=:113 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :114 -ac & +sleep 3 + +su root -c "/bin/echo 'user14 xxxx'| DISPLAY=:114 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :115 -ac & +sleep 3 + +su root -c "/bin/echo 'user15 xxxx'| DISPLAY=:115 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :116 -ac & +sleep 3 + +su root -c "/bin/echo 'user16 xxxx'| DISPLAY=:116 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :117 -ac & +sleep 3 + +su root -c "/bin/echo 'user17 xxxx'| DISPLAY=:117 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :118 -ac & +sleep 3 + +su root -c "/bin/echo 'user18 xxxx'| DISPLAY=:118 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :119 -ac & +sleep 3 + +su root -c "/bin/echo 'user19 xxxx'| DISPLAY=:119 /usr/bin/skype --pipelogin &" + +sleep 7 + /usr/bin/Xvfb :120 -ac & +sleep 3 + +su root -c "/bin/echo 'user20 xxxx'| DISPLAY=:120 /usr/bin/skype --pipelogin &" + +sleep 7 + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/wait.bat b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/wait.bat new file mode 100644 index 0000000000..8381230f47 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/wait.bat @@ -0,0 +1,4 @@ +REM would you believe there is no sleep() in standard windows batchfiles? +@ping 127.0.0.1 -n 2 -w 1000 > nul +@ping 127.0.0.1 -n %1% -w 1000> nul + diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/startskype.cmd b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/startskype.cmd new file mode 100644 index 0000000000..505a36c4b5 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/startskype.cmd @@ -0,0 +1,61 @@ +echo off + +REM +REM you MUST use the new Skype (4.x) for Windows, older versions (3.x) cannot be started this way +REM +REM you have to adjust PATH to where the Skype executable is +set PATH=%PATH%;C:\Program Files\Skype\Phone\ + +REM echo %PATH% + +REM start a Skype client instance that will login to the Skype network using the "username password" you give to it. +REM Here xxxx would be the password and user20 the username + +start Skype.exe /secondary /username:user20 /password:xxxx +call C:\wait.cmd 20 + +start Skype.exe /secondary /username:user19 /password:xxxx +call C:\wait.cmd 5 + +REM +REM Following Skype client instances are commented out +REM + +REM start Skype.exe /secondary /username:user18 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user17 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user16 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user15 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user14 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user13 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user12 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user11 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user10 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user9 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user8 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user7 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user6 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user5 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user4 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user3 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user2 /password:xxxx +REM call C:\wait.cmd 5 +REM start Skype.exe /secondary /username:user1 /password:xxxx +call C:\wait.cmd 120 +NET start AICCU2 +pause diff --git a/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/wait.cmd b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/wait.cmd new file mode 100644 index 0000000000..8381230f47 --- /dev/null +++ b/src/mod/endpoints/mod_skypiax/mod_skypopen/configs/windows-service/wait.cmd @@ -0,0 +1,4 @@ +REM would you believe there is no sleep() in standard windows batchfiles? +@ping 127.0.0.1 -n 2 -w 1000 > nul +@ping 127.0.0.1 -n %1% -w 1000> nul +