diff options
Diffstat (limited to '1.2-netsec/utils')
-rw-r--r-- | 1.2-netsec/utils/Makefile | 80 | ||||
-rw-r--r-- | 1.2-netsec/utils/astman.1 | 102 | ||||
-rw-r--r-- | 1.2-netsec/utils/astman.c | 720 | ||||
-rw-r--r-- | 1.2-netsec/utils/check_expr.c | 324 | ||||
-rw-r--r-- | 1.2-netsec/utils/frame.c | 1034 | ||||
-rw-r--r-- | 1.2-netsec/utils/frame.h | 300 | ||||
-rw-r--r-- | 1.2-netsec/utils/smsq.c | 763 | ||||
-rw-r--r-- | 1.2-netsec/utils/stereorize.c | 159 | ||||
-rw-r--r-- | 1.2-netsec/utils/streamplayer.c | 103 |
9 files changed, 0 insertions, 3585 deletions
diff --git a/1.2-netsec/utils/Makefile b/1.2-netsec/utils/Makefile deleted file mode 100644 index a07a39da7..000000000 --- a/1.2-netsec/utils/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -# -# Asterisk -- A telephony toolkit for Linux. -# -# Various utilities -# -# Copyright (C) 1999-2005, Digium -# -# Mark Spencer <markster@digium.com> -# -# This program is free software, distributed under the terms of -# the GNU General Public License -# - -# -# Don't use ast mm routines -# -CFLAGS+=-DNO_AST_MM - -ifeq ($(findstring BSD,${OSARCH}),BSD) - CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib -endif - -TARGET=stereorize streamplayer - -ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/popt.h)$(wildcard -f $(CROSS_COMPILE_TARGET)/usr/local/include/popt.h),) - TARGET+=smsq -endif - -ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/newt.h)$(wildcard -f $(CROSS_COMPILE_TARGET)/usr/local/include/newt.h),) - TARGET+=astman -endif - -ifeq (${OSARCH},SunOS) - SOL=../strcompat.o - SOLLIBS=-lsocket -lnsl -endif - -all: depend $(TARGET) - -install: - for x in $(TARGET); do \ - if [ "$$x" != "none" ]; then \ - $(INSTALL) -m 755 $$x $(DESTDIR)$(ASTSBINDIR)/$$x; \ - fi; \ - done - -clean: - rm -f *.o astman smsq stereorize streamplayer check_expr .depend - rm -f ast_expr2.o ast_expr2f.o - -astman: astman.o ../md5.o - $(CC) $(CFLAGS) -o astman astman.o ../md5.o -lnewt - -stereorize: stereorize.o frame.o - $(CC) $(CFLAGS) -o stereorize stereorize.o frame.o -lm - -ast_expr2.o: ../ast_expr2.c - gcc -g -c -o $@ $< - -ast_expr2f.o: ../ast_expr2f.c - gcc -g -c -DSTANDALONE -o $@ $< - -check_expr: check_expr.c ast_expr2.o ast_expr2f.o - $(CC) $(CFLAGS) -o $@ $^ - -smsq: smsq.o - $(CC) $(CFLAGS) -o smsq ${SOL} smsq.o -lpopt - -streamplayer: streamplayer.o - $(CC) $(CFLAGS) -o streamplayer ${SOL} streamplayer.o ${SOLLIBS} - -ifneq ($(wildcard .depend),) - include .depend -endif - -depend: .depend - -.depend: - ../build_tools/mkdep $(CFLAGS) `ls *.c` - diff --git a/1.2-netsec/utils/astman.1 b/1.2-netsec/utils/astman.1 deleted file mode 100644 index 6a36ca4da..000000000 --- a/1.2-netsec/utils/astman.1 +++ /dev/null @@ -1,102 +0,0 @@ -.\" $Header$ -.\" -.\" transcript compatibility for postscript use. -.\" -.\" synopsis: .P! <file.ps> -.\" -.de P! -.fl -\!!1 setgray -.fl -\\&.\" -.fl -\!!0 setgray -.fl \" force out current output buffer -\!!save /psv exch def currentpoint translate 0 0 moveto -\!!/showpage{}def -.fl \" prolog -.sy sed \-e 's/^/!/' \\$1\" bring in postscript file -\!!psv restore -. -.de pF -.ie \\*(f1 .ds f1 \\n(.f -.el .ie \\*(f2 .ds f2 \\n(.f -.el .ie \\*(f3 .ds f3 \\n(.f -.el .ie \\*(f4 .ds f4 \\n(.f -.el .tm ? font overflow -.ft \\$1 -.. -.de fP -.ie !\\*(f4 \{\ -. ft \\*(f4 -. ds f4\" -' br \} -.el .ie !\\*(f3 \{\ -. ft \\*(f3 -. ds f3\" -' br \} -.el .ie !\\*(f2 \{\ -. ft \\*(f2 -. ds f2\" -' br \} -.el .ie !\\*(f1 \{\ -. ft \\*(f1 -. ds f1\" -' br \} -.el .tm ? font underflow -.. -.ds f1\" -.ds f2\" -.ds f3\" -.ds f4\" -'\" t -.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n -.TH ASTMAN 1 "Jun 12th, 2005" "astman" "Linux Programmer's Manual" -.SH NAME -.B astman --- a client to asterisk's manager interface -.SH SYNOPSIS -.PP -.B astman -.I hostname - -.SH DESCRIPTION -.B astman -This program is a full-screen (terminal) client for Asterisk's manager -interface. - -.SH OPTIONS -.B hostname - -The host name or IP address to connect to (TCP port 5038). If astman -fails to connect it will exit immidiately. - -.SH USAGE -If \fBastman\fR has successfully cunnected to the manager port it will -prompt the user for a username and a secret (password) for the manager -interface on the remote Asterisk manager interface. It will then be able -to report existing channels (calls). You will then be able to redirect -calls to or terminate them. - -.SH "SEE ALSO" -asterisk(8) - -http://www.voip-info.org/wiki-Asterisk+astman - -.SH BUGS -The hostname does not default to localhost. - -Impossible to use a port other than 5038. - -The username and password cannot be defined from the command-line. - -I mean, what's the point in a man page if the syntax is so simple? - -.SH "AUTHOR" -This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com> -Permission is granted to copy, distribute and/or modify this document under -the terms of the GNU General Public License, Version 2 any -later version published by the Free Software Foundation. - -On Debian systems, the complete text of the GNU General Public -License can be found in /usr/share/common-licenses/GPL. diff --git a/1.2-netsec/utils/astman.c b/1.2-netsec/utils/astman.c deleted file mode 100644 index 1cb2ebab7..000000000 --- a/1.2-netsec/utils/astman.c +++ /dev/null @@ -1,720 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2005, Digium, Inc. - * - * Mark Spencer <markster@digium.com> - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -/* - * - * ASTerisk MANager - * - */ - -#include <newt.h> -#include <stdio.h> -#include <sys/time.h> -#include <netdb.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <sys/socket.h> -#include <sys/select.h> -#include <fcntl.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include <stdlib.h> - -#include "asterisk/md5.h" -#include "asterisk/manager.h" - -#undef gethostbyname - -#define MAX_HEADERS 80 -#define MAX_LEN 256 - -/* - * 2005.05.27 - different versions of newt define the type of the buffer - * for the 5th argument to newtEntry() as char ** or const char ** . To - * let the code compile cleanly with -Werror, we cast it to void * through - * _NEWT_CAST. - */ -#define _NEWT_CAST (void *) - -static struct ast_mansession { - struct sockaddr_in sin; - int fd; - char inbuf[MAX_LEN]; - int inlen; -} session; - -static struct ast_chan { - char name[80]; - char exten[20]; - char context[20]; - char priority[20]; - char callerid[40]; - char state[10]; - struct ast_chan *next; -} *chans; - -/* dummy functions to be compatible with the Asterisk core for md5.c */ -void ast_register_file_version(const char *file, const char *version); -void ast_register_file_version(const char *file, const char *version) -{ -} - -void ast_unregister_file_version(const char *file); -void ast_unregister_file_version(const char *file) -{ -} - -static struct ast_chan *find_chan(char *name) -{ - struct ast_chan *prev = NULL, *chan = chans; - while(chan) { - if (!strcmp(name, chan->name)) - return chan; - prev = chan; - chan = chan->next; - } - chan = malloc(sizeof(struct ast_chan)); - if (chan) { - memset(chan, 0, sizeof(struct ast_chan)); - strncpy(chan->name, name, sizeof(chan->name) - 1); - if (prev) - prev->next = chan; - else - chans = chan; - } - return chan; -} - -static void del_chan(char *name) -{ - struct ast_chan *prev = NULL, *chan = chans; - while(chan) { - if (!strcmp(name, chan->name)) { - if (prev) - prev->next = chan->next; - else - chans = chan->next; - free(chan); - return; - } - prev = chan; - chan = chan->next; - } -} - -static void fdprintf(int fd, char *fmt, ...) -{ - char stuff[4096]; - va_list ap; - va_start(ap, fmt); - vsnprintf(stuff, sizeof(stuff), fmt, ap); - va_end(ap); - write(fd, stuff, strlen(stuff)); -} - -static char *get_header(struct message *m, char *var) -{ - char cmp[80]; - int x; - snprintf(cmp, sizeof(cmp), "%s: ", var); - for (x=0;x<m->hdrcount;x++) - if (!strncasecmp(cmp, m->headers[x], strlen(cmp))) - return m->headers[x] + strlen(cmp); - return ""; -} - -static int event_newstate(struct ast_mansession *s, struct message *m) -{ - struct ast_chan *chan; - chan = find_chan(get_header(m, "Channel")); - strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1); - return 0; -} - -static int event_newexten(struct ast_mansession *s, struct message *m) -{ - struct ast_chan *chan; - chan = find_chan(get_header(m, "Channel")); - strncpy(chan->exten, get_header(m, "Extension"), sizeof(chan->exten) - 1); - strncpy(chan->context, get_header(m, "Context"), sizeof(chan->context) - 1); - strncpy(chan->priority, get_header(m, "Priority"), sizeof(chan->priority) - 1); - return 0; -} - -static int event_newchannel(struct ast_mansession *s, struct message *m) -{ - struct ast_chan *chan; - chan = find_chan(get_header(m, "Channel")); - strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1); - strncpy(chan->callerid, get_header(m, "Callerid"), sizeof(chan->callerid) - 1); - return 0; -} - -static int event_status(struct ast_mansession *s, struct message *m) -{ - struct ast_chan *chan; - chan = find_chan(get_header(m, "Channel")); - strncpy(chan->state, get_header(m, "State"), sizeof(chan->state) - 1); - strncpy(chan->callerid, get_header(m, "Callerid"), sizeof(chan->callerid) - 1); - strncpy(chan->exten, get_header(m, "Extension"), sizeof(chan->exten) - 1); - strncpy(chan->context, get_header(m, "Context"), sizeof(chan->context) - 1); - strncpy(chan->priority, get_header(m, "Priority"), sizeof(chan->priority) - 1); - return 0; -} - -static int event_hangup(struct ast_mansession *s, struct message *m) -{ - del_chan(get_header(m, "Channel")); - return 0; -} - -static int event_ignore(struct ast_mansession *s, struct message *m) -{ - return 0; -} - -static int event_rename(struct ast_mansession *s, struct message *m) -{ - struct ast_chan *chan; - chan = find_chan(get_header(m, "Oldname")); - strncpy(chan->name, get_header(m, "Newname"), sizeof(chan->name) - 1); - return 0; -} -static struct event { - char *event; - int (*func)(struct ast_mansession *s, struct message *m); -} events[] = { - { "Newstate", event_newstate }, - { "Newchannel", event_newchannel }, - { "Newexten", event_newexten }, - { "Hangup", event_hangup }, - { "Rename", event_rename }, - { "Status", event_status }, - { "Link", event_ignore }, - { "Unlink", event_ignore }, - { "StatusComplete", event_ignore } -}; - -static int process_message(struct ast_mansession *s, struct message *m) -{ - int x; - char event[80] = ""; - strncpy(event, get_header(m, "Event"), sizeof(event) - 1); - if (!strlen(event)) { - fprintf(stderr, "Missing event in request"); - return 0; - } - for (x=0;x<sizeof(events) / sizeof(events[0]);x++) { - if (!strcasecmp(event, events[x].event)) { - if (events[x].func(s, m)) - return -1; - break; - } - } - if (x >= sizeof(events) / sizeof(events[0])) - fprintf(stderr, "Ignoring unknown event '%s'", event); -#if 0 - for (x=0;x<m->hdrcount;x++) { - printf("Header: %s\n", m->headers[x]); - } -#endif - return 0; -} - -static void rebuild_channels(newtComponent c) -{ - void *prev = NULL; - struct ast_chan *chan; - char tmpn[42]; - char tmp[256]; - int x=0; - prev = newtListboxGetCurrent(c); - newtListboxClear(c); - chan = chans; - while(chan) { - snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid); - if (strlen(chan->exten)) - snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s", - tmpn, chan->state, - chan->exten, chan->context, chan->priority); - else - snprintf(tmp, sizeof(tmp), "%-30s %8s", - tmpn, chan->state); - newtListboxAppendEntry(c, tmp, chan); - x++; - chan = chan->next; - } - if (!x) - newtListboxAppendEntry(c, " << No Active Channels >> ", NULL); - newtListboxSetCurrentByKey(c, prev); -} - -static int has_input(struct ast_mansession *s) -{ - int x; - for (x=1;x<s->inlen;x++) - if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) - return 1; - return 0; -} - -static int get_input(struct ast_mansession *s, char *output) -{ - /* output must have at least sizeof(s->inbuf) space */ - int res; - int x; - struct timeval tv = {0, 0}; - fd_set fds; - for (x=1;x<s->inlen;x++) { - if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) { - /* Copy output data up to and including \r\n */ - memcpy(output, s->inbuf, x + 1); - /* Add trailing \0 */ - output[x+1] = '\0'; - /* Move remaining data back to the front */ - memmove(s->inbuf, s->inbuf + x + 1, s->inlen - x); - s->inlen -= (x + 1); - return 1; - } - } - if (s->inlen >= sizeof(s->inbuf) - 1) { - fprintf(stderr, "Dumping long line with no return from %s: %s\n", inet_ntoa(s->sin.sin_addr), s->inbuf); - s->inlen = 0; - } - FD_ZERO(&fds); - FD_SET(s->fd, &fds); - res = select(s->fd + 1, &fds, NULL, NULL, &tv); - if (res < 0) { - fprintf(stderr, "Select returned error: %s\n", strerror(errno)); - } else if (res > 0) { - res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen); - if (res < 1) - return -1; - s->inlen += res; - s->inbuf[s->inlen] = '\0'; - } else { - return 2; - } - return 0; -} - -static int input_check(struct ast_mansession *s, struct message **mout) -{ - static struct message m; - int res; - - if (mout) - *mout = NULL; - - for(;;) { - res = get_input(s, m.headers[m.hdrcount]); - if (res == 1) { -#if 0 - fprintf(stderr, "Got header: %s", m.headers[m.hdrcount]); - fgetc(stdin); -#endif - /* Strip trailing \r\n */ - if (strlen(m.headers[m.hdrcount]) < 2) - continue; - m.headers[m.hdrcount][strlen(m.headers[m.hdrcount]) - 2] = '\0'; - if (!strlen(m.headers[m.hdrcount])) { - if (mout && strlen(get_header(&m, "Response"))) { - *mout = &m; - return 0; - } - if (process_message(s, &m)) - break; - memset(&m, 0, sizeof(&m)); - } else if (m.hdrcount < MAX_HEADERS - 1) - m.hdrcount++; - } else if (res < 0) { - return -1; - } else if (res == 2) - return 0; - } - return -1; -} - -static struct message *wait_for_response(int timeout) -{ - struct message *m; - struct timeval tv; - int res; - fd_set fds; - for (;;) { - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - FD_SET(session.fd, &fds); - res = select(session.fd + 1, &fds, NULL, NULL, &tv); - if (res < 1) - break; - if (input_check(&session, &m) < 0) { - return NULL; - } - if (m) - return m; - } - return NULL; -} - -static int manager_action(char *action, char *fmt, ...) -{ - struct ast_mansession *s; - char tmp[4096]; - va_list ap; - - s = &session; - fdprintf(s->fd, "Action: %s\r\n", action); - va_start(ap, fmt); - vsnprintf(tmp, sizeof(tmp), fmt, ap); - va_end(ap); - write(s->fd, tmp, strlen(tmp)); - fdprintf(s->fd, "\r\n"); - return 0; -} - -static int show_message(char *title, char *msg) -{ - newtComponent form; - newtComponent label; - newtComponent ok; - struct newtExitStruct es; - - newtCenteredWindow(60,7, title); - - label = newtLabel(4,1,msg); - ok = newtButton(27, 3, "OK"); - form = newtForm(NULL, NULL, 0); - newtFormAddComponents(form, label, ok, NULL); - newtFormRun(form, &es); - newtPopWindow(); - newtFormDestroy(form); - return 0; -} - -static newtComponent showform; -static int show_doing(char *title, char *tmp) -{ - struct newtExitStruct es; - newtComponent label; - showform = newtForm(NULL, NULL, 0); - newtCenteredWindow(70,4, title); - label = newtLabel(3,1,tmp); - newtFormAddComponents(showform,label, NULL); - newtFormSetTimer(showform, 200); - newtFormRun(showform, &es); - return 0; -} - -static int hide_doing(void) -{ - newtPopWindow(); - newtFormDestroy(showform); - return 0; -} - -static void try_status(void) -{ - struct message *m; - manager_action("Status", ""); - m = wait_for_response(10000); - if (!m) { - show_message("Status Failed", "Timeout waiting for response"); - } else if (strcasecmp(get_header(m, "Response"), "Success")) { - show_message("Status Failed Failed", get_header(m, "Message")); - } -} - - -static void try_hangup(newtComponent c) -{ - struct ast_chan *chan; - struct message *m; - - chan = newtListboxGetCurrent(c); - if (chan) { - manager_action("Hangup", "Channel: %s\r\n", chan->name); - m = wait_for_response(10000); - if (!m) { - show_message("Hangup Failed", "Timeout waiting for response"); - } else if (strcasecmp(get_header(m, "Response"), "Success")) { - show_message("Hangup Failed", get_header(m, "Message")); - } - } - -} - -static int get_user_input(char *msg, char *buf, int buflen) -{ - newtComponent form; - newtComponent ok; - newtComponent cancel; - newtComponent inpfield; - const char *input; - int res = -1; - struct newtExitStruct es; - - newtCenteredWindow(60,7, msg); - - inpfield = newtEntry(5, 2, "", 50, _NEWT_CAST &input, 0); - ok = newtButton(22, 3, "OK"); - cancel = newtButton(32, 3, "Cancel"); - form = newtForm(NULL, NULL, 0); - newtFormAddComponents(form, inpfield, ok, cancel, NULL); - newtFormRun(form, &es); - strncpy(buf, input, buflen - 1); - if (es.u.co == ok) - res = 0; - else - res = -1; - newtPopWindow(); - newtFormDestroy(form); - return res; -} - -static void try_redirect(newtComponent c) -{ - struct ast_chan *chan; - char dest[256]; - struct message *m; - char channame[256]; - char tmp[80]; - char *context; - - chan = newtListboxGetCurrent(c); - if (chan) { - strncpy(channame, chan->name, sizeof(channame) - 1); - snprintf(tmp, sizeof(tmp), "Enter new extension for %s", channame); - if (get_user_input(tmp, dest, sizeof(dest))) - return; - if ((context = strchr(dest, '@'))) { - *context = '\0'; - context++; - manager_action("Redirect", "Channel: %s\r\nContext: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name,context,dest); - } else { - manager_action("Redirect", "Channel: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name, dest); - } - m = wait_for_response(10000); - if (!m) { - show_message("Hangup Failed", "Timeout waiting for response"); - } else if (strcasecmp(get_header(m, "Response"), "Success")) { - show_message("Hangup Failed", get_header(m, "Message")); - } - } - -} - -static int manage_calls(char *host) -{ - newtComponent form; - newtComponent quit; - newtComponent hangup; - newtComponent redirect; - newtComponent channels; - struct newtExitStruct es; - char tmp[80]; - - /* If there's one thing you learn from this code, it is this... - Never, ever fly Air France. Their customer service is absolutely - the worst. I've never heard the words "That's not my problem" as - many times as I have from their staff -- It should, without doubt - be their corporate motto if it isn't already. Don't bother giving - them business because you're just a pain in their side and they - will be sure to let you know the first time you speak to them. - - If you ever want to make me happy just tell me that you, too, will - never fly Air France again either (in spite of their excellent - cuisine). */ - snprintf(tmp, sizeof(tmp), "Asterisk Manager at %s", host); - newtCenteredWindow(74, 20, tmp); - form = newtForm(NULL, NULL, 0); - newtFormWatchFd(form, session.fd, NEWT_FD_READ); - newtFormSetTimer(form, 100); - quit = newtButton(62, 16, "Quit"); - redirect = newtButton(35, 16, "Redirect"); - hangup = newtButton(50, 16, "Hangup"); - channels = newtListbox(1,1,14, NEWT_FLAG_SCROLL); - newtFormAddComponents(form, channels, redirect, hangup, quit, NULL); - newtListboxSetWidth(channels, 72); - - show_doing("Getting Status", "Retrieving system status..."); - try_status(); - hide_doing(); - - for(;;) { - newtFormRun(form, &es); - if (has_input(&session) || (es.reason == NEWT_EXIT_FDREADY)) { - if (input_check(&session, NULL)) { - show_message("Disconnected", "Disconnected from remote host"); - break; - } - } else if (es.reason == NEWT_EXIT_COMPONENT) { - if (es.u.co == quit) - break; - if (es.u.co == hangup) { - try_hangup(channels); - } else if (es.u.co == redirect) { - try_redirect(channels); - } - } - rebuild_channels(channels); - } - newtFormDestroy(form); - return 0; -} - -static int login(char *hostname) -{ - newtComponent form; - newtComponent cancel; - newtComponent login; - newtComponent username; - newtComponent password; - newtComponent label; - newtComponent ulabel; - newtComponent plabel; - const char *user; - const char *pass; - struct message *m; - struct newtExitStruct es; - char tmp[55]; - struct hostent *hp; - int res = -1; - - session.fd = socket(AF_INET, SOCK_STREAM, 0); - if (session.fd < 0) { - snprintf(tmp, sizeof(tmp), "socket() failed: %s\n", strerror(errno)); - show_message("Socket failed", tmp); - return -1; - } - - snprintf(tmp, sizeof(tmp), "Looking up %s\n", hostname); - show_doing("Connecting....", tmp); - - - hp = gethostbyname(hostname); - if (!hp) { - snprintf(tmp, sizeof(tmp), "No such address: %s\n", hostname); - show_message("Host lookup failed", tmp); - return -1; - } - hide_doing(); - snprintf(tmp, sizeof(tmp), "Connecting to %s", hostname); - show_doing("Connecting...", tmp); - - session.sin.sin_family = AF_INET; - session.sin.sin_port = htons(DEFAULT_MANAGER_PORT); - memcpy(&session.sin.sin_addr, hp->h_addr, sizeof(session.sin.sin_addr)); - - if (connect(session.fd,(struct sockaddr*)&session.sin, sizeof(session.sin))) { - snprintf(tmp, sizeof(tmp), "%s failed: %s\n", hostname, strerror(errno)); - show_message("Connect Failed", tmp); - return -1; - } - - hide_doing(); - - login = newtButton(5, 6, "Login"); - cancel = newtButton(25, 6, "Cancel"); - newtCenteredWindow(40, 10, "Asterisk Manager Login"); - snprintf(tmp, sizeof(tmp), "Host: %s", hostname); - label = newtLabel(4,1, tmp); - - ulabel = newtLabel(4,2,"Username:"); - plabel = newtLabel(4,3,"Password:"); - - username = newtEntry(14, 2, "", 20, _NEWT_CAST &user, 0); - password = newtEntry(14, 3, "", 20, _NEWT_CAST &pass, NEWT_FLAG_HIDDEN); - - form = newtForm(NULL, NULL, 0); - newtFormAddComponents(form, username, password, login, cancel, label, ulabel, plabel,NULL); - newtFormRun(form, &es); - if (es.reason == NEWT_EXIT_COMPONENT) { - if (es.u.co == login) { - snprintf(tmp, sizeof(tmp), "Logging in '%s'...", user); - show_doing("Logging in", tmp); - /* Check to see if the remote host supports MD5 Authentication */ - manager_action("Challenge", "AuthType: MD5\r\n"); - m = wait_for_response(10000); - if (m && !strcasecmp(get_header(m, "Response"), "Success")) { - char *challenge = get_header(m, "Challenge"); - int x; - int len = 0; - char md5key[256] = ""; - struct MD5Context md5; - unsigned char digest[16]; - MD5Init(&md5); - MD5Update(&md5, (unsigned char *)challenge, strlen(challenge)); - MD5Update(&md5, (unsigned char *)pass, strlen(pass)); - MD5Final(digest, &md5); - for (x=0; x<16; x++) - len += sprintf(md5key + len, "%2.2x", digest[x]); - manager_action("Login", - "AuthType: MD5\r\n" - "Username: %s\r\n" - "Key: %s\r\n", - user, md5key); - m = wait_for_response(10000); - hide_doing(); - if (!strcasecmp(get_header(m, "Response"), "Success")) { - res = 0; - } else { - show_message("Login Failed", get_header(m, "Message")); - } - } else { - memset(m, 0, sizeof(m)); - manager_action("Login", - "Username: %s\r\n" - "Secret: %s\r\n", - user, pass); - m = wait_for_response(10000); - hide_doing(); - if (m) { - if (!strcasecmp(get_header(m, "Response"), "Success")) { - res = 0; - } else { - show_message("Login Failed", get_header(m, "Message")); - } - } - } - } - } - newtFormDestroy(form); - return res; -} - -int main(int argc, char *argv[]) -{ - if (argc < 2) { - fprintf(stderr, "Usage: astman <host>\n"); - exit(1); - } - newtInit(); - newtCls(); - newtDrawRootText(0, 0, "Asterisk Manager (C)2002, Linux Support Services, Inc."); - newtPushHelpLine("Welcome to the Asterisk Manager!"); - if (login(argv[1])) { - newtFinished(); - exit(1); - } - manage_calls(argv[1]); - newtFinished(); - return 0; -} diff --git a/1.2-netsec/utils/check_expr.c b/1.2-netsec/utils/check_expr.c deleted file mode 100644 index 531af49c0..000000000 --- a/1.2-netsec/utils/check_expr.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2005, Digium, Inc. - * - * Mark Spencer <markster@digium.com> - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -#include <stdio.h> -#include <stddef.h> -#include <stdarg.h> -#include <string.h> -#include <stdlib.h> -#include <../include/asterisk/ast_expr.h> - -int global_lineno = 1; -int global_expr_count = 0; -int global_expr_max_size = 0; -int global_expr_tot_size = 0; -int global_warn_count = 0; -int global_OK_count = 0; - -struct varz -{ - char varname[100]; /* a really ultra-simple, space-wasting linked list of var=val data */ - char varval[1000]; /* if any varname is bigger than 100 chars, or val greater than 1000, then **CRASH** */ - struct varz *next; -}; - -struct varz *global_varlist; - -/* Our own version of ast_log, since the expr parser uses it. */ - -void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6))); - -void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) -{ - va_list vars; - va_start(vars,fmt); - - printf("LOG: lev:%d file:%s line:%d func: %s ", - level, file, line, function); - vprintf(fmt, vars); - fflush(stdout); - va_end(vars); -} - -char *find_var(const char *varname) /* the list should be pretty short, if there's any list at all */ -{ - struct varz *t; - for (t= global_varlist; t; t = t->next) { - if (!strcmp(t->varname, varname)) { - return t->varval; - } - } - return 0; -} - -void set_var(const char *varname, const char *varval) -{ - struct varz *t = calloc(1,sizeof(struct varz)); - strcpy(t->varname, varname); - strcpy(t->varval, varval); - t->next = global_varlist; - global_varlist = t; -} - -int check_expr(char *buffer, char *error_report) -{ - char *cp; - int oplen = 0; - int warn_found = 0; - - error_report[0] = 0; - - for (cp=buffer;*cp;cp++) { - - if (*cp == '|' - || *cp == '&' - || *cp == '=' - || *cp == '>' - || *cp == '<' - || *cp == '+' - || *cp == '-' - || *cp == '*' - || *cp == '/' - || *cp == '%' - || *cp == '?' - || *cp == ':' - /* || *cp == '(' - || *cp == ')' These are pretty hard to track, as they are in funcalls, etc. */ - || *cp == '"') { - if (*cp == '"') { - /* skip to the other end */ - cp++; - while (*cp && *cp != '"') - cp++; - if (*cp == 0) { - fprintf(stderr,"Trouble? Unterminated double quote found at line %d\n", - global_lineno); - } - } - else { - if ((*cp == '>'||*cp == '<' ||*cp=='!') && (*(cp+1) == '=')) { - oplen = 2; - } - else { - oplen = 1; - } - - if ((cp > buffer && *(cp-1) != ' ') || *(cp+oplen) != ' ') { - char tbuf[1000]; - if (oplen == 1) - sprintf(tbuf,"WARNING: line %d, '%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n", - global_lineno, *cp); - else - sprintf(tbuf,"WARNING: line %d, '%c%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n", - global_lineno, *cp, *(cp+1)); - strcat(error_report,tbuf); - - global_warn_count++; - warn_found++; - } - } - } - } - return warn_found; -} - -int check_eval(char *buffer, char *error_report) -{ - char *cp, *ep, *xp; - char s[4096]; - char evalbuf[80000]; - int oplen = 0; - int warn_found = 0; - int result; - - error_report[0] = 0; - ep = evalbuf; - - for (cp=buffer;*cp;cp++) { - if (*cp == '$' && *(cp+1) == '{') { - int brack_lev = 1; - char *xp= cp+2; - - while (*xp) { - if (*xp == '{') - brack_lev++; - else if (*xp == '}') - brack_lev--; - - if (brack_lev == 0) - break; - xp++; - } - if (*xp == '}') { - char varname[200]; - char *val; - - strncpy(varname,cp+2, xp-cp-2); - varname[xp-cp-2] = 0; - cp = xp; - val = find_var(varname); - if (val) { - char *z = val; - while (*z) - *ep++ = *z++; - } - else { - *ep++ = '5'; /* why not */ - *ep++ = '5'; - *ep++ = '5'; - } - } - else { - printf("Unterminated variable reference at line %d\n", global_lineno); - *ep++ = *cp; - } - } - else if (*cp == '\\') { - /* braindead simple elim of backslash */ - cp++; - *ep++ = *cp; - } - else - *ep++ = *cp; - } - *ep++ = 0; - - /* now, run the test */ - result = ast_expr(evalbuf, s, sizeof(s)); - if (result) { - sprintf(error_report,"line %d, evaluation of $[ %s ] result: %s\n", global_lineno, evalbuf, s); - return 1; - } else { - sprintf(error_report,"line %d, evaluation of $[ %s ] result: ****SYNTAX ERROR****\n", global_lineno, evalbuf); - return 1; - } -} - - -void parse_file(const char *fname) -{ - FILE *f = fopen(fname,"r"); - FILE *l = fopen("expr2_log","w"); - int c1; - char last_char= 0; - char buffer[30000]; /* I sure hope no expr gets this big! */ - - if (!f) { - fprintf(stderr,"Couldn't open %s for reading... need an extensions.conf file to parse!\n"); - exit(20); - } - if (!l) { - fprintf(stderr,"Couldn't open 'expr2_log' file for writing... please fix and re-run!\n"); - exit(21); - } - - global_lineno = 1; - - while ((c1 = fgetc(f)) != EOF) { - if (c1 == '\n') - global_lineno++; - else if (c1 == '[') { - if (last_char == '$') { - /* bingo, an expr */ - int bracklev = 1; - int bufcount = 0; - int retval; - char error_report[30000]; - - while ((c1 = fgetc(f)) != EOF) { - if (c1 == '[') - bracklev++; - else if (c1 == ']') - bracklev--; - if (c1 == '\n') { - fprintf(l, "ERROR-- A newline in an expression? Weird! ...at line %d\n", global_lineno); - fclose(f); - fclose(l); - printf("--- ERROR --- A newline in the middle of an expression at line %d!\n", global_lineno); - } - - if (bracklev == 0) - break; - buffer[bufcount++] = c1; - } - if (c1 == EOF) { - fprintf(l, "ERROR-- End of File Reached in the middle of an Expr at line %d\n", global_lineno); - fclose(f); - fclose(l); - printf("--- ERROR --- EOF reached in middle of an expression at line %d!\n", global_lineno); - exit(22); - } - - buffer[bufcount] = 0; - /* update stats */ - global_expr_tot_size += bufcount; - global_expr_count++; - if (bufcount > global_expr_max_size) - global_expr_max_size = bufcount; - - retval = check_expr(buffer, error_report); /* check_expr should bump the warning counter */ - if (retval != 0) { - /* print error report */ - printf("Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n", - global_lineno, buffer); - fprintf(l, "%s", error_report); - } - else { - printf("OK -- $[%s] at line %d\n", buffer, global_lineno); - global_OK_count++; - } - error_report[0] = 0; - retval = check_eval(buffer, error_report); - fprintf(l, "%s", error_report); - } - } - last_char = c1; - } - printf("Summary:\n Expressions detected: %d\n Expressions OK: %d\n Total # Warnings: %d\n Longest Expr: %d chars\n Ave expr len: %d chars\n", - global_expr_count, - global_OK_count, - global_warn_count, - global_expr_max_size, - (global_expr_count) ? global_expr_tot_size/global_expr_count : 0); - - fclose(f); - fclose(l); -} - - -main(int argc,char **argv) -{ - int argc1; - char *eq; - - if (argc < 2) { - printf("Hey-- give me a path to an extensions.conf file!\n"); - exit(19); - } - global_varlist = 0; - for (argc1=2;argc1 < argc; argc1++) { - if ((eq = strchr(argv[argc1],'='))) { - *eq = 0; - set_var(argv[argc1],eq+1); - } - } - - /* parse command args for x=y and set varz */ - - parse_file(argv[1]); -} diff --git a/1.2-netsec/utils/frame.c b/1.2-netsec/utils/frame.c deleted file mode 100644 index 7fdb1637d..000000000 --- a/1.2-netsec/utils/frame.c +++ /dev/null @@ -1,1034 +0,0 @@ -/**************************************************************************** - * - * Programs for processing sound files in raw- or WAV-format. - * -- Useful functions for parsing command line options and - * issuing errors, warnings, and chit chat. - * - * Name: frame.c - * Version: see static char *standardversion, below. - * Author: Mark Roberts <mark@manumark.de> - * Michael Labuschke <michael@labuschke.de> sys_errlist fixes - * - ****************************************************************************/ -/**************************************************************************** - * These are useful functions that all DSP programs might find handy - ****************************************************************************/ - -#include <stdio.h> -#include <math.h> -#include <stdlib.h> /* for exit and malloc */ -#include <string.h> -#include <time.h> -#include <stdarg.h> -#include <errno.h> -#include <assert.h> -#include "frame.h" - -time_t stopwatch; /* will hold time at start of calculation */ -int samplefrequency; -unsigned short samplewidth; -unsigned short channels; -int wavout; /* TRUE iff out file should be a .WAV file */ -int iswav; /* TRUE iff in file was found to be a .WAV file */ -FILE *in, *out; -char *infilename, *outfilename; -int verboselevel; -char *version = ""; -char *usage = ""; -static int test_usage; - -static char *standardversion = "frame version 1.3, June 13th 2001"; -static char *standardusage = -"\nOptions common to all mark-dsp programs:\n" - -"-h \t\t create a WAV-header on output files.\n" -"-c#\t\t set number of channels to # (1 or 2). Default: like input.\n" -"-w#\t\t set number of bits per sample (width) to # (only 16)\n" -"-f#\t\t set sample frequency to #. Default: like input.\n" -"-V \t\t verbose: talk a lot.\n" -"-Q \t\t quiet: talk as little as possible.\n\n" -"In most cases, a filename of '-' means stdin or stdout.\n\n" -"Bug-reports: mark@manumark.de\n" -; - -/* ----------------------------------------------------------------------- - Writes the number of samples to result that are yet to be read from anyin. - Return values are TRUE on success, FALSE on failure. - -----------------------------------------------------------------------*/ -int getremainingfilelength( FILE *anyin, long *result) -{ - long i; - - i = ftell (anyin); - if (i == -1) return FALSE; - if (fseek (anyin, 0, SEEK_END) == -1) return FALSE; - *result = ftell (anyin); - if (*result == -1) return FALSE; - (*result) -= i; - (*result) /= samplewidth; - if (fseek (anyin, i, SEEK_SET) == -1) return FALSE; - return TRUE; -} - -/* ----------------------------------------------------------------------- - Read a .pk-header from 'anyin'. - -----------------------------------------------------------------------*/ -void readpkheader( FILE *anyin) -{ - unsigned short tempushort; - int tempint, i, x; - unsigned char blood[8]; - - for (i = 0; i < 11; i++) - { - fread( &tempint, 4, 1, anyin); - printf( "%d: %d, ", i, tempint); - } - printf( "\n"); - fread( blood, 1, 8, anyin); - for (i = 0; i < 8; i++) - printf( "%d ", blood[i]); - printf( "\n"); - for (i = 0; i < 8; i++) - { - for (x = 128; x > 0; x /= 2) - printf((blood[i] & x) == 0? "0 ":"1 "); - printf(i%4==3? "\n":"| "); - } - printf( "\n"); - for (i = 0; i < 2; i++) - { - fread( &tempint, 4, 1, anyin); - printf( "%d: %d, ", i, tempint); - } - printf( "\n"); - for (i = 0; i < 2; i++) - { - fread( &tempushort, 2, 1, anyin); - printf( "%d: %d, ", i, tempushort); - } - printf( "\n"); -} - - - -/* ----------------------------------------------------------------------- - Read a .WAV header from 'anyin'. See header for details. - -----------------------------------------------------------------------*/ -void readwavheader( FILE *anyin) -{ - unsigned int tempuint, sf; - unsigned short tempushort, cn; - char str[9]; - int nowav = FALSE; - - iswav = FALSE; - - if (ftell(anyin) == -1) /* If we cannot seek this file */ - { - nowav = TRUE; /* -> Pretend this is no wav-file */ - chat("File not seekable: not checking for WAV-header.\n"); - } - else - { - /* Expect four bytes "RIFF" and four bytes filelength */ - fread (str, 1, 8, anyin); /* 0 */ - str[4] = '\0'; - if (strcmp(str, "RIFF") != 0) nowav = TRUE; - /* Expect eight bytes "WAVEfmt " */ - fread (str, 1, 8, anyin); /* 8 */ - str[8] = '\0'; - if (strcmp(str, "WAVEfmt ") != 0) nowav = TRUE; - /* Expect length of fmt data, which should be 16 */ - fread (&tempuint, 4, 1, anyin); /* 16 */ - if (tempuint != 16) nowav = TRUE; - /* Expect format tag, which should be 1 for pcm */ - fread (&tempushort, 2, 1, anyin); /* 20 */ - if (tempushort != 1) - nowav = TRUE; - /* Expect number of channels */ - fread (&cn, 2, 1, anyin); /* 20 */ - if (cn != 1 && cn != 2) nowav = TRUE; - /* Read samplefrequency */ - fread (&sf, 4, 1, anyin); /* 24 */ - /* Read bytes per second: Should be samplefreq * channels * 2 */ - fread (&tempuint, 4, 1, anyin); /* 28 */ - if (tempuint != sf * cn * 2) nowav = TRUE; - /* read bytes per frame: Should be channels * 2 */ - fread (&tempushort, 2, 1, anyin); /* 32 */ - if (tempushort != cn * 2) nowav = TRUE; - /* Read bits per sample: Should be 16 */ - fread (&tempushort, 2, 1, anyin); /* 34 */ - if (tempushort != 16) nowav = TRUE; - fread (str, 4, 1, anyin); /* 36 */ - str[4] = '\0'; - if (strcmp(str, "data") != 0) nowav = TRUE; - fread (&tempuint, 4, 1, anyin); /* 40 */ - if (nowav) - { - fseek (anyin, 0, SEEK_SET); /* Back to beginning of file */ - chat("File has no WAV header.\n"); - } - else - { - samplefrequency = sf; - channels = cn; - chat ("Read WAV header: %d channels, samplefrequency %d.\n", - channels, samplefrequency); - iswav = TRUE; - } - } - return; -} - - - -/* ----------------------------------------------------------------------- - Write a .WAV header to 'out'. See header for details. - -----------------------------------------------------------------------*/ -void makewavheader( void) -{ - unsigned int tempuint, filelength; - unsigned short tempushort; - - /* If fseek fails, don't create the header. */ - if (fseek (out, 0, SEEK_END) != -1) - { - filelength = ftell (out); - chat ("filelength %d, ", filelength); - fseek (out, 0, SEEK_SET); - fwrite ("RIFF", 1, 4, out); /* 0 */ - tempuint = filelength - 8; fwrite (&tempuint, 4, 1, out); /* 4 */ - fwrite ("WAVEfmt ", 1, 8, out); /* 8 */ - /* length of fmt data 16 bytes */ - tempuint = 16; - fwrite (&tempuint, 4, 1, out); /* 16 */ - /* Format tag: 1 for pcm */ - tempushort = 1; - fwrite (&tempushort, 2, 1, out); /* 20 */ - chat ("%d channels\n", channels); - fwrite (&channels, 2, 1, out); - chat ("samplefrequency %d\n", samplefrequency); - fwrite (&samplefrequency, 4, 1, out); /* 24 */ - /* Bytes per second */ - tempuint = channels * samplefrequency * 2; - fwrite (&tempuint, 4, 1, out); /* 28 */ - /* Block align */ - tempushort = 2 * channels; - fwrite (&tempushort, 2, 1, out); /* 32 */ - /* Bits per sample */ - tempushort = 16; - fwrite (&tempushort, 2, 1, out); /* 34 */ - fwrite ("data", 4, 1, out); /* 36 */ - tempuint = filelength - 44; fwrite (&tempuint, 4, 1, out); /* 40 */ - } - return; -} - -/* ----------------------------------------------------------------------- - After all is read and done, inform the inclined user of the elapsed time - -----------------------------------------------------------------------*/ -static void statistics( void) -{ - int temp; - - temp = time(NULL) - stopwatch; - if (temp != 1) - { - inform ("\nTime: %d seconds\n", temp); - } - else - { - inform ("\nTime: 1 second\n"); - } - return; -} - - -/* ----------------------------------------------------------------------- - Start the stopwatch and make sure the user is informed at end of program. - -----------------------------------------------------------------------*/ -void startstopwatch(void) -{ - stopwatch = time(NULL); /* Remember time 'now' */ - atexit(statistics); /* Call function statistics() at exit. */ - - return; -} - -/* -------------------------------------------------------------------- - Tests the character 'coal' for being a command line option character, - momentarrily '-'. - -------------------------------------------------------------------- */ -int isoptionchar (char coal) -{ - return (coal =='-'); -} - -/* ----------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a time and passed - to *result, where the result is meant to mean 'number of samples' in - that time. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -int parsetimearg( int argcount, char *args[], char *string, int *result) -{ - int i; - - if ((i = findoption( argcount, args, string)) > 0) - { - if (parsetime(args[i] + 1 + strlen( string), result)) - return TRUE; - argerrornum(args[i]+1, ME_NOTIME); - } - return FALSE; -} - -/* ----------------------------------------------------------------------- - The string argument is read as a time and passed - to *result, where the result is meant to mean 'number of samples' in - that time. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -int parsetime(char *string, int *result) -{ - int k; - double temp; - char m, s, end; - - k = sscanf(string, "%lf%c%c%c", &temp, &m, &s, &end); - switch (k) - { - case 0: case EOF: case 4: - return FALSE; - case 1: - *result = temp; - break; - case 2: - if (m == 's') - *result = temp * samplefrequency; - else - return FALSE; - break; - case 3: - if (m == 'm' && s == 's') - *result = temp * samplefrequency / 1000; - else if (m == 'H' && s == 'z') - *result = samplefrequency / temp; - else - return FALSE; - break; - default: - argerrornum(NULL, ME_THISCANTHAPPEN); - } - return TRUE; -} - -/* ----------------------------------------------------------------------- - The string argument is read as a frequency and passed - to *result, where the result is meant to mean 'number of samples' in - one cycle of that frequency. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -int parsefreq(char *string, double *result) -{ - int k; - double temp; - char m, s, end; - - k = sscanf(string, "%lf%c%c%c", &temp, &m, &s, &end); - switch (k) - { - case 0: case EOF: case 2: case 4: - return FALSE; - case 1: - *result = temp; - break; - case 3: - if (m == 'H' && s == 'z') - *result = samplefrequency / temp; - else - return FALSE; - break; - default: - argerrornum(NULL, ME_THISCANTHAPPEN); - } - return TRUE; -} - -char *parsefilearg( int argcount, char *args[]) -{ - int i; - char *result = NULL; - - for (i = 1; i < argcount; i++) - { - if (args[i][0] != '\0' && - (!isoptionchar (args[i][0]) || args[i][1] == '\0' )) - { - /*---------------------------------------------* - * The argument is a filename: * - * it is either no dash followed by something, * - * or it is a dash following by nothing. * - *---------------------------------------------*/ - result = malloc( strlen( args[i]) + 1); - if (result == NULL) - fatalperror( "Couldn't allocate memory for filename\n"); - strcpy( result, args[i]); - args[i][0] = '\0'; /* Mark as used up */ - break; - } - } - return result; -} - -int parseswitch( char *found, char *wanted) -{ - if (strncmp( found, wanted, strlen( wanted)) == 0) - { - if (found[strlen( wanted)] == '\0') - return TRUE; - else - argerrornum( found, ME_NOSWITCH); - } - return FALSE; -} - -int parseswitcharg( int argcount, char *args[], char *string) -{ - int i; - - if ((i = findoption( argcount, args, string)) > 0) - { - if (args[i][strlen( string) + 1] == '\0') - return TRUE; - else - argerrornum( args[i] + 1, ME_NOSWITCH); - } - return FALSE; -} - -int parseintarg( int argcount, char *args[], char *string, int *result) -{ - int i, temp; - char c; - - if ((i = findoption( argcount, args, string)) > 0) - { - switch (sscanf(args[i] + 1 + strlen( string), - "%d%c", &temp, &c)) - { - case 0: case EOF: case 2: - argerrornum(args[i]+1, ME_NOINT); - return FALSE; - case 1: - *result = temp; - break; - default: - say("frame.c: This can't happen\n"); - } - return TRUE; - } - else - { - return FALSE; - } -} - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a double and - passed to *result. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -int parsedoublearg( int argcount, char *args[], char *string, double *result) -{ - int i; - double temp; - char end; - - if ((i = findoption( argcount, args, string)) > 0) - { - switch (sscanf(args[i] + 1 + strlen( string), "%lf%c", &temp, &end)) - { - case 0: case EOF: case 2: - argerrornum(args[i]+1, ME_NODOUBLE); - return FALSE; - case 1: - *result = temp; - break; - default: - say("frame.c: This can't happen\n"); - } - return TRUE; - } - else - { - return FALSE; - } -} - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a volume, i.e. - absolute, percent or db. The result is passed to *result. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -int parsevolarg( int argcount, char *args[], char *string, double *result) -{ - double vol = 1.0; - char sbd, sbb, end; - int i, weird = FALSE; - - if ((i = findoption( argcount, args, string)) > 0) - { - switch (sscanf(args[i] + 1 + strlen( string), - "%lf%c%c%c", &vol, &sbd, &sbb, &end)) - { - case 0: case EOF: case 4: - weird = TRUE; - break; /* No number: error */ - case 1: - *result = vol; - break; - case 2: - if (sbd == '%') - *result = vol / 100; - else - weird = TRUE; /* One char but no percent: error */ - break; - case 3: - if (sbd =='d' && sbb == 'b') - *result = pow(2, vol / 6.02); - else - weird = TRUE; /* Two chars but not db: error */ - break; - default: - say("frame.c: This can't happen.\n"); - } - if (weird) - argerrornum( args[i] + 1, ME_NOVOL); - /* ("Weird option: couldn't parse volume '%s'\n", args[i]+2); */ - return !weird; - } - else - { - return FALSE; - } -} - - -/* -------------------------------------------------------------------- - Reads the specified string 's' and interprets it as a volume. The string - would be of the form 1.8 or 180% or 5db. - On success, the return value TRUE and *result is given result - (i.e. the relative volume, i.e. 1.8). On failure, FALSE is returned and - result is given value 1.0. - -------------------------------------------------------------------- */ -int parsevolume(char *s, double *result) -{ - int k; - char sbd, sbb, end; - - *result = 1.0; - k = sscanf(s, "%lf%c%c%c", result, &sbd, &sbb, &end); - switch (k) - { - case 0: - case EOF: - case 4: - return FALSE; - case 1: - break; - case 2: - if (sbd != '%') - return FALSE; - (*result) /=100; - break; - case 3: - if (sbd !='d' || sbb != 'b') - return FALSE; - (*result) = pow(2, (*result) / 6.02); - break; - default: - say("parsevolume: This can't happen (%d).\n", k); - } - return TRUE; -} - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. - -------------------------------------------------------------------- */ -void argerror(char *s) -{ - error ("Error parsing command line. Unrecognized option:\n\t-%s\n", s); - fatalerror("\nTry --help for help.\n"); -} - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. 'code' indicates the type of error. - -------------------------------------------------------------------- */ -void argerrornum(char *s, Errornum code) -{ - char *message; - - if (code == ME_TOOMANYFILES) - { - error("Too many files on command line: '%s'.\n", s); - } - else - { - if (s != NULL) - error ("Error parsing option -%s:\n\t", s); - switch( code) - { - case ME_NOINT: - message = "Integer expected"; - break; - case ME_NODOUBLE: - message = "Floating point number expected"; - break; - case ME_NOTIME: - message = "Time argument expected"; - break; - case ME_NOVOL: - message = "Volume argument expected"; - break; - case ME_NOSWITCH: - message = "Garbage after switch-type option"; - break; - case ME_HEADERONTEXTFILE: - message = "Option -h is not useful for text-output"; - break; - case ME_NOINFILE: - message = "No input file specified"; - break; - case ME_NOOUTFILE: - message = "No output file specified"; - break; - case ME_NOIOFILE: - message = "No input/output file specified"; - break; - case ME_NOSTDIN: - message = "Standard in not supported here"; - break; - case ME_NOSTDOUT: - message = "Standard out not supported here"; - break; - case ME_NOSTDIO: - message = "Standard in/out not supported here"; - break; - case ME_NOTENOUGHFILES: - message = "Not enough files specified"; - break; - case ME_THISCANTHAPPEN: - fatalerror("\nThis can't happen. Report this as a bug\n"); - /* fatalerror does not return */ - default: - error("Error code %d not implemented. Fix me!\n", code); - message = "Error message not implemented. Fix me!"; - } - error("%s\n", message); - } - fatalerror("\nTry --help for help.\n"); -} - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. 'message' explains the type of error. - -------------------------------------------------------------------- */ -void argerrortxt(char *s, char *message) -{ - if (s != NULL) - error ("Error parsing option -%s:\n\t", s); - else - error ("Error parsing command line:\n\t"); - error ("%s\n", message); - fatalerror("\nTry --help for help.\n"); -} - -/* -------------------------------------------------------------------- - Check for any remaining arguments and complain about their existence - -------------------------------------------------------------------- */ -void checknoargs( int argcount, char *args[]) -{ - int i, errorcount = 0; - - for (i = 1; i < argcount; i++) - { - if (args[i][0] != '\0') /* An unused argument! */ - { - errorcount++; - if (errorcount == 1) - error("The following arguments were not recognized:\n"); - error("\t%s\n", args[i]); - } - } - if (errorcount > 0) /* Errors are fatal */ - fatalerror("\nTry --help for help.\n"); - - return; /* No errors? Return. */ -} - -/* -------------------------------------------------------------------- - Parses the command line arguments as represented by the function - arguments. Sets the global variables 'in', 'out', 'samplefrequency' - and 'samplewidth' accordingly. Also verboselevel. - The files 'in' and 'out' are even opened according to 'fileswitch'. - See headerfile for details - -------------------------------------------------------------------- */ -void parseargs( int argcount, char *args[], int fileswitch) -{ - char *filename; - int tempint; - - if ((fileswitch & 1) != 0) /* If getting infile */ - in = NULL; - if ((fileswitch & 4) != 0) /* If getting outfile */ - out = NULL; - wavout = FALSE; - verboselevel = 5; - samplefrequency = DEFAULTFREQ; - samplewidth = 2; - channels = 1; - - /*-----------------------------------------------* - * First first check testcase, usage and version * - *-----------------------------------------------*/ - test_usage = parseswitcharg( argcount, args, "-test-usage"); - if (parseswitcharg( argcount, args, "-help")) - { - printf("%s%s", usage, standardusage); - exit(0); - } - if (parseswitcharg( argcount, args, "-version")) - { - printf("%s\n(%s)\n", version, standardversion); - exit(0); - } - /*--------------------------------------* - * Set verboselevel * - *--------------------------------------*/ - while (parseswitcharg( argcount, args, "V")) - verboselevel = 10; - while (parseswitcharg( argcount, args, "Q")) - verboselevel = 1; - /*-------------------------------------------------* - * Get filenames and open files * - *-------------------------------------------------*/ - if ((fileswitch & 1) != 0) /* Infile wanted */ - { - infilename = parsefilearg( argcount, args); - if (infilename == NULL) - argerrornum( NULL, ME_NOINFILE); - if (strcmp( infilename, "-") == 0) - { - infilename = "<stdin>"; - in = stdin; - if ((fileswitch & 2) != 0) /* Binfile wanted */ - readwavheader( in); - } - else - { - if ((fileswitch & 2) == 0) /* Textfile wanted */ - in = fopen(infilename, "rt"); - else /* Binfile wanted */ - if ((in = fopen(infilename, "rb")) != NULL) - readwavheader( in); - } - if (in == NULL) - fatalerror("Error opening input file '%s': %s\n", infilename,strerror(errno)); - else - inform("Using file '%s' as input\n", infilename); - } - if ((fileswitch & 4) != 0) /* Outfile wanted */ - { - outfilename = parsefilearg( argcount, args); - if (outfilename == NULL) - argerrornum( NULL, ME_NOOUTFILE); - if (strcmp( outfilename, "-") == 0) - { - outfilename = "<stdout>"; - out = stdout; - } - else - { - - if ((fileswitch & 8) == 0) /* Textfile wanted */ - out = fopen(outfilename, "wt"); - else /* Binfile wanted */ - out = fopen(outfilename, "wb"); - } - if (out == NULL) - fatalerror("Error opening output file '%s': %s\n", outfilename,strerror(errno)); - else - inform("Using file '%s' as output\n", outfilename); - } - if ((fileswitch & 32) != 0) /* In-/Outfile wanted */ - { - assert (in == NULL && out == NULL); - infilename = outfilename = parsefilearg( argcount, args); - if (outfilename == NULL) - argerrornum( NULL, ME_NOIOFILE); - if (strcmp( infilename, "-") == 0) - argerrornum( infilename, ME_NOSTDIN); - inform("Using file '%s' as input/output\n", outfilename); - in = out = fopen(outfilename, "r+"); - if (out == NULL) - fatalerror("Error opening input/output file '%s': %s\n", outfilename,strerror(errno)); - - readwavheader( in); - } - if ((fileswitch & 16) == 0) /* No additional files wanted */ - { - if ((filename = parsefilearg( argcount, args)) != NULL) - argerrornum( filename, ME_TOOMANYFILES); - } - - /*-------------------------------------------------* - * Set samplefrequency, width, wavout, - *-------------------------------------------------*/ - parseintarg( argcount, args, "f", &samplefrequency); - wavout = parseswitcharg( argcount, args, "h"); - if (parseintarg( argcount, args, "w", &tempint)) - { - if (tempint != 16) - argerrortxt(NULL, "Option -w is only valid " - "with value 16. Sorry."); - else - samplewidth = tempint; - } - if (parseintarg( argcount, args, "c", &tempint)) - { - if (tempint != 1 && tempint != 2) - argerrortxt(NULL, "Option -c is only valid " - "with values 1 or 2. Sorry."); - else - channels = tempint; - } - /*-------------------------------------------------* - * Create WAV-header on output if wanted. * - *-------------------------------------------------*/ - if (wavout) - switch (fileswitch & (12)) - { - case 4: /* User wants header on textfile */ - argerrornum( NULL, ME_HEADERONTEXTFILE); - case 12: /* User wants header on binfile */ - makewavheader(); - break; - case 0: /* User wants header, but there is no outfile */ - /* Problem: what about i/o-file, 32? You might want a header - on that? Better ignore this case. */ - break; - case 8: /* An application musn't ask for this */ - default: /* This can't happen */ - assert( FALSE); - } - return; -} - -/* -------------------------------------------------------------------- - Returns the index 'i' of the first argument that IS an option, and - which begins with the label 's'. If there is none, -1. - We also mark that option as done with, i.e. we cross it out. - -------------------------------------------------------------------- */ -int findoption( int argcount, char *args[], char *s) -{ - int i; - - if (test_usage) - printf("Checking for option -%s\n", s); - - for (i=1; i<argcount; i++) - { - if (isoptionchar (args[i][0]) && - strncmp( args[i] + 1, s, strlen( s)) == 0) - { - args[i][0] = '\0'; - return i; - } - } - return -1; -} - -/* -------------------------------------------------------------------- - Finishes off the .WAV header (if any) and exits correctly and formerly. - -------------------------------------------------------------------- */ -int myexit (int value) -{ - switch (value) - { - case 0: - if (wavout) - makewavheader(); /* Writes a fully informed .WAV header */ - chat ("Success!\n"); - break; - default: - chat ("Failure.\n"); - break; - } - exit (value); -} - -/* -------------------------------------------------------------------- - Reads the stated input file bufferwise, calls the function 'work' - with the proper values, and writes the result to the stated output file. - Return value: TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -int workloop( FILE *theinfile, FILE *theoutfile, - int (*work)( short *buffer, int length) ) -{ - short *buffer; - int length, nowlength; - - length = BUFFSIZE; - if ((buffer = malloc( sizeof(short) * length)) == NULL) - fatalperror (""); - while (TRUE) - { - nowlength = fread(buffer, sizeof(short), length, theinfile); - if (ferror( theinfile) != 0) - fatalperror("Error reading input file"); - if (nowlength == 0) /* Reached end of input file */ - break; - /* Call the routine that does the work */ - if (!work (buffer, nowlength)) /* On error, stop. */ - return FALSE; - fwrite(buffer, sizeof(short), nowlength, theoutfile); - if (ferror( theoutfile) != 0) - fatalperror("Error writing to output file"); - } - return TRUE; /* Input file done with, no errors. */ -} - -int chat( const char *format, ...) -{ - va_list ap; - int result = 0; - - if (verboselevel > 5) - { - va_start( ap, format); - result = vfprintf( stderr, format, ap); - va_end( ap); - } - return result; -} - - -int inform( const char *format, ...) -{ - va_list ap; - int result = 0; - - if (verboselevel > 1) - { - va_start( ap, format); - result = vfprintf( stderr, format, ap); - va_end( ap); - } - return result; -} - -int error( const char *format, ...) -{ - va_list ap; - int result; - - va_start( ap, format); - result = vfprintf( stderr, format, ap); - va_end( ap); - return result; -} - -void fatalerror( const char *format, ...) -{ - va_list ap; - - va_start( ap, format); - vfprintf( stderr, format, ap); - va_end( ap); - myexit(1); -} - -void fatalperror( const char *string) -{ - perror( string); - myexit( 1); -} - -int say( const char *format, ...) -{ - va_list ap; - int result; - - va_start( ap, format); - result = vfprintf( stdout, format, ap); - va_end( ap); - return result; -} - - -char *malloccopy( char *string) -{ - char *result; - - result = malloc( strlen( string) + 1); - if (result != NULL) - strcpy( result, string); - return result; -} - - -char *mallocconcat( char *one, char *two) -{ - char *result; - - result = malloc( strlen( one) + strlen( two) + 1); - if (result != NULL) - { - strcpy( result, one); - strcat( result, two); - } - return result; -} - -double double2db( double value) -{ - if (value < 0) - value = -value; - return 6.0 * log( value / 32767) / log( 2); -} - -void readawaysamples( FILE *in, size_t size) -{ - short *buffer; - int samplesread, count; - - buffer = malloc( sizeof( *buffer) * BUFFSIZE); - if (buffer == NULL) fatalperror("Couldn't allocate buffer"); - - while (size > 0) - { - if (size > BUFFSIZE) - count = BUFFSIZE; - else - count = size; - - samplesread = fread( buffer, sizeof(*buffer), count, in); - if (ferror( in) != 0) - fatalperror("Error reading input file"); - size -= samplesread; - } - free( buffer); -} - diff --git a/1.2-netsec/utils/frame.h b/1.2-netsec/utils/frame.h deleted file mode 100644 index a07c605ec..000000000 --- a/1.2-netsec/utils/frame.h +++ /dev/null @@ -1,300 +0,0 @@ -/**************************************************************************** - * - * Programs for processing sound files in raw- or WAV-format. - * -- Useful functions for parsing command line options and - * issuing errors, warnings, and chit chat. - * - * Name: frame.h - * Version: see frame.c - * Author: Mark Roberts <mark@manumark.de> - * - ****************************************************************************/ -/**************************************************************************** - * These are useful functions that all DSP programs might find handy - ****************************************************************************/ - -/* fileswitch for parseargs: - - The following are masks for several different ways of opening files. - -------------------------------------------------------------------- - Bit 0: Open infile? - Bit 1: Open infile as binary (as opposed to text) - Bit 2: Open outfile? - Bit 3: Open outfile as binary (as opposed to text) - Bit 4: Do not complain about too many file arguments - Bit 5: Open one file for input AND output, binary. -*/ -#define INTEXT (1+0) -#define INBIN (1+2) -#define OUTTEXT (4) -#define OUTBIN (4+8) -#define NOFILES (0) -#define NOCOMPLAIN (16) -#define IOBIN (32) - -#ifndef FALSE - #define FALSE (0==1) - #define TRUE (0==0) -#endif - -extern int samplefrequency; -extern unsigned short samplewidth; -extern unsigned short channels; -extern int wavout; /* TRUE iff out file is .WAV file */ -extern int iswav; /* TRUE iff in file was found to be a .WAV file */ -extern FILE *in, *out; -extern char *infilename, *outfilename; -extern int verboselevel; -extern char *version; /* String to be issued as version string. Should - be set by application. */ -extern char *usage; /* String to be issued as usage string. Should be - set by application. */ - -#define DEFAULTFREQ 44100 -#define BUFFSIZE 50000 /* How many samples to read in one go (preferred) */ -#define MINBUFFSIZE 5000 /* How many samples to read in one go (minimum) */ - -/************************************************* - * Types of errors handled by argerrornum() * - *************************************************/ -typedef enum -{ - ME_NOINT, - ME_NODOUBLE, - ME_NOTIME, - ME_NOVOL, - ME_NOSWITCH, - ME_TOOMANYFILES, - ME_HEADERONTEXTFILE, - ME_NOINFILE, - ME_NOOUTFILE, - ME_NOIOFILE, - ME_NOSTDIN, - ME_NOSTDOUT, - ME_NOSTDIO, - ME_NOTENOUGHFILES, - ME_THISCANTHAPPEN -} Errornum; - - -/* ----------------------------------------------------------------------- - Create memory and copy 'string', returning a pointer to the copy. - NULL is returned if malloc fails. - -----------------------------------------------------------------------*/ -extern char *malloccopy( char *string); - -/* ----------------------------------------------------------------------- - Start the stopwatch and make sure the user is informed at end of program. - -----------------------------------------------------------------------*/ -extern void startstopwatch(void); - -/* ----------------------------------------------------------------------- - Writes the number of samples to result that are yet to be read from anyin. - I.e. the number of remaining bytes is divided by the number of bytes per - sample value, but not by the number of channels. - Return values are TRUE on success, FALSE on failure. - -----------------------------------------------------------------------*/ -extern int getremainingfilelength( FILE *anyin, long *result); - -/* ----------------------------------------------------------------------- - Read a .pk-header from 'anyin' and printf the entries. - -----------------------------------------------------------------------*/ -void readpkheader( FILE *anyin); - -/* ----------------------------------------------------------------------- - Read a .WAV header from 'anyin'. - If it is recognised, the data is used. - Otherwise, we assume it's PCM-data and ignore the header. - The global variable 'iswav' is set on success, otherwise cleared. - -----------------------------------------------------------------------*/ -extern void readwavheader( FILE *anyin); - -/* ----------------------------------------------------------------------- - Write a .WAV header to 'out'. - The filepointer is placed at the end of 'out' before operation. - This should be called before any data is - written, and again, when ALL the data has been written. - First time, this positions the file pointer correctly; second time, the - missing data can be inserted that wasn't known the first time round. - -----------------------------------------------------------------------*/ -extern void makewavheader( void); - -/* -------------------------------------------------------------------- - Tests the character 'coal' for being a command line option character, - momentarrily '/' or '-'. - -------------------------------------------------------------------- */ -extern int isoptionchar (char coal); - -/* ----------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a time and passed - to *result, where the result is meant to mean 'number of samples' in - that time. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -extern int parsetimearg( int argcount, char *args[], char *string, - int *result); - -/* ----------------------------------------------------------------------- - The string argument is read as a time and passed to *result, where - the result is meant to mean 'number of samples' in that time. On - failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -int parsetime(char *string, int *result); - -/* ----------------------------------------------------------------------- - The string argument is read as a frequency and passed - to *result, where the result is meant to mean 'number of samples' in - one cycle of that frequency. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -----------------------------------------------------------------------*/ -int parsefreq(char *string, double *result); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for a switch -'string'. - return value is TRUE if one exists, FALSE otherwise. - If characters remain after the switch, a fatal error is issued. - -------------------------------------------------------------------- */ -extern int parseswitcharg( int argcount, char *args[], char *string); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as an integer and - passed to &result. - On failure, &result is unchanged. - return value is TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -extern int parseintarg( int argcount, char *args[], char *string, - int *result); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for a filename, i.e. anything - that does not start with the optionchar. The filename is copied to - newly allocated memory, a pointer to which is returned. - The argument is marked as used. Therefore repeated use of this function - will yield a complete list of filenames on the commandline. - If malloc() fails, the function does not return. - -------------------------------------------------------------------- */ -extern char *parsefilearg( int argcount, char *args[]); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a double and - passed to *result. - On failure, *result is unchanged. - return value is TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -extern int parsedoublearg( int argcount, char *args[], char *string, - double *result); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for an option starting - with 'string'. The rest of the option is read as a volume, i.e. - absolute, percent or db. The result is passed to *result. - On failure, *result is unchanged. - -------------------------------------------------------------------- */ -extern int parsevolarg( int argcount, char *args[], char *string, - double *result); - -/* -------------------------------------------------------------------- - Reads the specified string and interprets it as a volume. The string - would be of the form 1.8 or 180% or 5db. - On success, the return value is the relative volume, i.e. 1.8 - On failure, -1 is returned. - -------------------------------------------------------------------- */ -extern int parsevolume(char *s, double *result); - -/* -------------------------------------------------------------------- - Reads through the arguments on the lookout for a switch -'string'. - return value is TRUE if one exists, FALSE otherwise. - If characters remain after the switch, a fatal error is issued. - -------------------------------------------------------------------- */ -extern int parseswitch( char *found, char *wanted); - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. - -------------------------------------------------------------------- */ -extern void argerror(char *s); - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. 'code' indicates the type of error. - -------------------------------------------------------------------- */ -extern void argerrornum(char *s, Errornum code); - -/* -------------------------------------------------------------------- - Reports an error due to parsing the string 's' encountered on the - command line. 'message' explains the type of error. - -------------------------------------------------------------------- */ -extern void argerrortxt(char *s, char *message); - -/* -------------------------------------------------------------------- - Check for any remaining arguments and complain about their existence. - If arguments are found, this function does not return. - -------------------------------------------------------------------- */ -extern void checknoargs( int argcount, char *args[]); - -/* -------------------------------------------------------------------- - Parses the command line arguments as represented by the function - arguments. Sets the global variables 'in', 'out', 'samplefrequency' - and 'samplewidth' accordingly. - According to 'fileswitch', in and out files are opened or not. See - above for an explanation of 'fileswitch'. - -------------------------------------------------------------------- */ -extern void parseargs( int argcount, char *args[], int fileswitch); - -/* -------------------------------------------------------------------- - Returns the index 'i' of the first argument that IS an option, and - which begins with the label 's'. If there is none, -1. - We also mark that option as done with, i.e. we cross it out. - -------------------------------------------------------------------- */ -extern int findoption( int argcount, char *args[], char *s); - -/* -------------------------------------------------------------------- - Finishes off the .WAV header (if any) and exits correctly and formerly. - -------------------------------------------------------------------- */ -extern int myexit (int value); - -/* -------------------------------------------------------------------- - Reads the stated input file bufferwise, calls the function 'work' - with the proper values, and writes the result to the stated output file. - Return value: TRUE on success, FALSE otherwise. - -------------------------------------------------------------------- */ -extern int workloop( FILE *theinfile, FILE *theoutfile, - int (*work)( short *buffer, int length) ); - -/* -------------------------------------------------------------------- - Five functions for printing to stderr. Depending on the level of verbose, - output may be supressed. fatalerror() is like error() but does not return. - fatalperror() is like the standard function perror() but does not return. - -------------------------------------------------------------------- */ -extern int chat( const char *format, ...); -extern int inform( const char *format, ...); -extern int error( const char *format, ...); -extern void fatalerror( const char *format, ...); -extern void fatalperror( const char *string); - -/* -------------------------------------------------------------------- - And one functions for printing to stdout. - -------------------------------------------------------------------- */ -extern int say( const char *format, ...); - -/* -------------------------------------------------------------------- - Allocate memory for it and return a pointer to a string made up of - the two argument strings. - -------------------------------------------------------------------- */ -extern char *mallocconcat( char *one, char *two); - -/* -------------------------------------------------------------------- - Convert a sample value to decibel. - -------------------------------------------------------------------- */ -extern double double2db( double value); - -/* -------------------------------------------------------------------- - Read 'size' samples from file 'in' and lose them. - -------------------------------------------------------------------- */ -extern void readawaysamples( FILE *in, size_t size); diff --git a/1.2-netsec/utils/smsq.c b/1.2-netsec/utils/smsq.c deleted file mode 100644 index 361fc2679..000000000 --- a/1.2-netsec/utils/smsq.c +++ /dev/null @@ -1,763 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2004 - 2005 - * - * SMS queuing application for use with asterisk app_sms - * by Adrian Kennard - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -#include <stdio.h> -#include <popt.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <dirent.h> -#include <string.h> -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> -#include <asterisk/compat.h> -#ifdef SOLARIS -#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000 -#endif -#if !defined(POPT_ARGFLAG_SHOW_DEFAULT) -#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000 -#endif - - -/* reads next USC character from null terminated UTF-8 string and advanced pointer */ -/* for non valid UTF-8 sequences, returns character as is */ -/* Does not advance pointer for null termination */ -static int utf8decode (unsigned char **pp) -{ - unsigned char *p = *pp; - if (!*p) - return 0; /* null termination of string */ - (*pp)++; - if (*p < 0xC0) - return *p; /* ascii or continuation character */ - if (*p < 0xE0) - { - if (*p < 0xC2 || (p[1] & 0xC0) != 0x80) - return *p; /* not valid UTF-8 */ - (*pp)++; - return ((*p & 0x1F) << 6) + (p[1] & 0x3F); - } - if (*p < 0xF0) - { - if ((*p == 0xE0 && p[1] < 0xA0) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80) - return *p; /* not valid UTF-8 */ - (*pp) += 2; - return ((*p & 0x0F) << 12) + ((p[1] & 0x3F) << 6) + (p[2] & 0x3F); - } - if (*p < 0xF8) - { - if ((*p == 0xF0 && p[1] < 0x90) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80) - return *p; /* not valid UTF-8 */ - (*pp) += 3; - return ((*p & 0x07) << 18) + ((p[1] & 0x3F) << 12) + ((p[2] & 0x3F) << 6) + (p[3] & 0x3F); - } - if (*p < 0xFC) - { - if ((*p == 0xF8 && p[1] < 0x88) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80 - || (p[4] & 0xC0) != 0x80) - return *p; /* not valid UTF-8 */ - (*pp) += 4; - return ((*p & 0x03) << 24) + ((p[1] & 0x3F) << 18) + ((p[2] & 0x3F) << 12) + ((p[3] & 0x3F) << 6) + (p[4] & 0x3F); - } - if (*p < 0xFE) - { - if ((*p == 0xFC && p[1] < 0x84) || (p[1] & 0xC0) != 0x80 || (p[2] & 0xC0) != 0x80 || (p[3] & 0xC0) != 0x80 - || (p[4] & 0xC0) != 0x80 || (p[5] & 0xC0) != 0x80) - return *p; /* not valid UTF-8 */ - (*pp) += 5; - return ((*p & 0x01) << 30) + ((p[1] & 0x3F) << 24) + ((p[2] & 0x3F) << 18) + ((p[3] & 0x3F) << 12) + ((p[4] & 0x3F) << 6) + - (p[5] & 0x3F); - } - return *p; /* not sensible */ -} - -/* check for any queued messages in specific queue (queue="" means any queue) */ -/* returns 0 if nothing queued, 1 if queued and outgoing set up OK, 2 of outgoing exists */ -static char txqcheck (char *dir, char *queue, char subaddress, char *channel, char *callerid, int wait, int delay, int retries, int concurrent) -{ - char ogname[100], - temp[100], - dirname[100], - *p=NULL; - FILE *f; - DIR *d; - int ql = strlen (queue), qfl = ql; - struct dirent *fn; - snprintf (dirname, sizeof(dirname), "sms/%s", dir); - d = opendir (dirname); - if (!d) - return 0; - while ((fn = readdir (d)) - && !(*fn->d_name != '.' - && ((!ql && (p = strchr (fn->d_name, '.'))) || (ql && !strncmp (fn->d_name, queue, ql) && fn->d_name[ql] == '.')))); - if (!fn) - { - closedir (d); - return 0; - } - if (!ql) - { /* not searching any specific queue, so use whatr we found as the queue */ - queue = fn->d_name; - qfl = ql = p - queue; - } - p = strchr (queue, '-'); - if (p && p < queue + ql) - { - ql = p - queue; - subaddress = p[1]; - } - snprintf (temp, sizeof(temp), "sms/.smsq-%d", getpid ()); - f = fopen (temp, "w"); - if (!f) - { - perror (temp); - closedir (d); - return 0; - } - fprintf (f, "Channel: "); - if (!channel) - fprintf (f, "Local/%.*s\n", ql, queue); - else - { - p = strchr (channel, '/'); - if (!p) - p = channel; - p = strchr (p, 'X'); - if (p) - fprintf (f, "%.*s%c%s\n", p - channel, channel, subaddress, p + 1); - else - fprintf (f, "%s\n", channel); - } - fprintf (f, "Callerid: SMS <"); - if (!callerid) - fprintf (f, "%.*s", ql, queue); - else - { - p = strchr (callerid, 'X'); - if (p) - fprintf (f, "%.*s%c%s", p - callerid, callerid, subaddress, p + 1); - else - fprintf (f, "%s", callerid); - } - fprintf (f, ">\n"); - fprintf (f, "Application: SMS\n"); - fprintf (f, "Data: %.*s", qfl, queue); - if (dir[1] == 't') - fprintf (f, "|s"); - fprintf (f, "\nMaxRetries: %d\n", retries); - fprintf (f, "RetryTime: %d\n", delay); - fprintf (f, "WaitTime: %d\n", wait); - fclose (f); - closedir (d); - { - int try = 0; - while (try < concurrent) - { - try++; - snprintf(ogname, sizeof(ogname), "outgoing/smsq.%s.%s.%d", dir, queue, try); - if (!link (temp, ogname)) - { /* queued OK */ - unlink (temp); - return 1; - } - } - } - /* failed to create call queue */ - unlink (temp); - return 2; -} - -/* Process received queue entries and run through a process, setting environment variables */ -static void rxqcheck (char *dir, char *queue, char *process) -{ - unsigned char *p; - char dirname[100], - temp[100]; - DIR *d; - int ql = strlen (queue); - struct dirent *fn; - snprintf(temp, sizeof(temp), "sms/.smsq-%d", getpid ()); - snprintf(dirname, sizeof(dirname), "sms/%s", dir); - d = opendir (dirname); - if (!d) - return; - while ((fn = readdir (d))) - if ((*fn->d_name != '.' - && ((!ql && (p = strchr (fn->d_name, '.'))) || (ql && !strncmp (fn->d_name, queue, ql) && fn->d_name[ql] == '.')))) - { /* process file */ - char filename[1010]; - char line[1000]; - unsigned short ud[160]; - unsigned char udl = 0; - FILE *f; - snprintf (filename, sizeof(filename), "sms/%s/%s", dir, fn->d_name); - if (rename (filename, temp)) - continue; /* cannot access file */ - f = fopen (temp, "r"); - unlink (temp); - if (!f) - { - perror (temp); - continue; - } - unsetenv ("oa"); - unsetenv ("da"); - unsetenv ("scts"); - unsetenv ("pid"); - unsetenv ("dcs"); - unsetenv ("mr"); - unsetenv ("srr"); - unsetenv ("rp"); - unsetenv ("vp"); - unsetenv ("udh"); - unsetenv ("ud"); - unsetenv ("ude"); - unsetenv ("ud8"); - unsetenv ("ud16"); - unsetenv ("morx"); - unsetenv ("motx"); - unsetenv ("queue"); - if (*queue) - setenv ("queue", queue, 1); - setenv (dir, "", 1); - while (fgets (line, sizeof (line), f)) - { - for (p = line; *p && *p != '\n' && *p != '\r'; p++); - *p = 0; /* strip eoln */ - p = line; - if (!*p || *p == ';') - continue; /* blank line or comment, ignore */ - while (isalnum (*p)) - { - *p = tolower (*p); - p++; - } - while (isspace (*p)) - *p++ = 0; - if (*p == '=') - { /* = */ - *p++ = 0; - if (!strcmp (line, "oa") || !strcmp (line, "da") || !strcmp (line, "scts") || !strcmp (line, "pid") - || !strcmp (line, "dcs") || !strcmp (line, "mr") || !strcmp (line, "vp")) - setenv (line, p, 1); - else if ((!strcmp (line, "srr") || !strcmp (line, "rp")) && atoi (p)) - setenv (line, "", 1); - else if (!strcmp (line, "ud")) - { /* read the user data as UTF-8 */ - long v; - udl = 0; - while ((v = utf8decode (&p)) && udl < 160) - if (v && v <= 0xFFFF) - ud[udl++] = v; - } - } else if (*p == '#') - { - *p++ = 0; - if (*p == '#') - { /* ## */ - p++; - if (!strcmp (line, "udh")) - setenv (line, p, 1); - else if (!strcmp (line, "ud")) - { /* read user data UCS-2 */ - udl = 0; - while (*p && udl < 160) - { - if (isxdigit (*p) && isxdigit (p[1]) && isxdigit (p[2]) && isxdigit (p[3])) - { - ud[udl++] = - (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 12) + - (((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF)) << 8) + - (((isalpha (p[2]) ? 9 : 0) + (p[2] & 0xF)) << 4) + ((isalpha (p[3]) ? 9 : 0) + (p[3] & 0xF)); - p += 4; - } else - break; - } - } - } else - { /* # */ - if (!strcmp (line, "ud")) - { /* read user data UCS-1 */ - udl = 0; - while (*p && udl < 160) - { - if (isxdigit (*p) && isxdigit (p[1])) - { - ud[udl++] = (((isalpha (*p) ? 9 : 0) + (*p & 0xF)) << 4) + ((isalpha (p[1]) ? 9 : 0) + (p[1] & 0xF)); - p += 2; - } else - break; - } - } - } - } - } - fclose (f); - /* set up user data variables */ - { - char temp[481]; - int n, - p; - for (n = 0, p = 0; p < udl; p++) - { - unsigned short v = ud[p]; - if (v) - { - if (v < 0x80) - temp[n++] = v; - else if (v < 0x800) - { - temp[n++] = (0xC0 + (v >> 6)); - temp[n++] = (0x80 + (v & 0x3F)); - } else - { - temp[n++] = (0xE0 + (v >> 12)); - temp[n++] = (0x80 + ((v >> 6) & 0x3F)); - temp[n++] = (0x80 + (v & 0x3F)); - } - } - } - temp[n] = 0; - setenv ("ud", temp, 1); - for (n = 0, p = 0; p < udl; p++) - { - unsigned short v = ud[p]; - if (v < ' ' || v == '\\') - { - temp[n++] = '\\'; - if (v == '\\') - temp[n++] = '\\'; - else if (v == '\n') - temp[n++] = 'n'; - else if (v == '\r') - temp[n++] = 'r'; - else if (v == '\t') - temp[n++] = 't'; - else if (v == '\f') - temp[n++] = 'f'; - else - { - temp[n++] = '0' + (v >> 6); - temp[n++] = '0' + ((v >> 3) & 7); - temp[n++] = '0' + (v & 7); - } - } else if (v < 0x80) - temp[n++] = v; - else if (v < 0x800) - { - temp[n++] = (0xC0 + (v >> 6)); - temp[n++] = (0x80 + (v & 0x3F)); - } else - { - temp[n++] = (0xE0 + (v >> 12)); - temp[n++] = (0x80 + ((v >> 6) & 0x3F)); - temp[n++] = (0x80 + (v & 0x3F)); - } - } - temp[n] = 0; - setenv ("ude", temp, 1); - for (p = 0; p < udl && ud[p] < 0x100; p++); - if (p == udl) - { - for (n = 0, p = 0; p < udl; p++) - { - sprintf (temp + n, "%02X", ud[p]); - n += 2; - } - setenv ("ud8", temp, 1); - } - for (n = 0, p = 0; p < udl; p++) - { - sprintf (temp + n, "%04X", ud[p]); - n += 4; - } - setenv ("ud16", temp, 1); - } - /* run the command */ - system (process); - } - closedir (d); -} - -/* Main app */ -int -main (int argc, const char *argv[]) -{ - char c; - int mt = 0, - mo = 0, - tx = 0, - rx = 0, - nodial = 0, - nowait = 0, - concurrent = 1, - motxwait = 10, - motxdelay = 1, - motxretries = 10, - mttxwait = 10, - mttxdelay = 30, - mttxretries = 100, - mr = -1, - pid = -1, - dcs = -1, - srr = 0, - rp = 0, - vp = 0, - udl = 0, - utf8 = 0, - ucs1 = 0, - ucs2 = 0; - unsigned short ud[160]; - unsigned char *uds = 0, - *udh = 0; - char *da = 0, - *oa = 0, - *queue = "", - *udfile = 0, - *process = 0, - *spooldir = "/var/spool/asterisk", - *motxchannel = "Local/1709400X", - *motxcallerid = 0, - *mttxchannel = 0, - *mttxcallerid = "080058752X0", - *defaultsubaddress = "9", - subaddress = 0, - *scts = 0; - poptContext optCon; /* context for parsing command-line options */ - const struct poptOption optionsTable[] = { - {"queue", 'q', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &queue, 0, "Queue [inc sub address]", "number[-X]"}, - {"da", 'd', POPT_ARG_STRING, &da, 0, "Destination address", "number"}, - {"oa", 'o', POPT_ARG_STRING, &oa, 0, "Origination address", "number"}, - {"ud", 'm', POPT_ARG_STRING, &uds, 0, "Message", "text"}, - {"ud-file", 'f', POPT_ARG_STRING, &udfile, 0, "Message file", "filename"}, - {"UTF-8", 0, POPT_ARG_NONE, &utf8, 0, "File treated as null terminated UTF-8 (default)", 0}, - {"UCS-1", 0, POPT_ARG_NONE, &ucs1, 0, "File treated as UCS-1", 0}, - {"UCS-2", 0, POPT_ARG_NONE, &ucs2, 0, "File treated as UCS-2", 0}, - {"mt", 't', POPT_ARG_NONE, &mt, 0, "Mobile Terminated", 0}, - {"mo", 0, POPT_ARG_NONE, &mo, 0, "Mobile Originated", 0}, - {"tx", 0, POPT_ARG_NONE, &tx, 0, "Send message", 0}, - {"rx", 'r', POPT_ARG_NONE, &rx, 0, "Queue for receipt", 0}, - {"process", 'e', POPT_ARG_STRING, &process, 0, "Rx queue process command", "command"}, - {"no-dial", 'x', POPT_ARG_NONE, &nodial, 0, "Do not dial", 0}, - {"no-wait", 0, POPT_ARG_NONE, &nowait, 0, "Do not wait if already calling", 0}, - {"concurrent", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &concurrent, 0, "Number of concurrent calls to allow", "n"}, - {"motx-channel", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &motxchannel, 0, "Channel for motx calls", "channel"}, - {"motx-callerid", 0, POPT_ARG_STRING, &motxcallerid, 0, - "Caller ID for motx calls (default is queue name without sub address)", "number"}, - {"motx-wait", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxwait, 0, "Time to wait for motx call to answer", - "seconds"}, - {"motx-delay", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxdelay, 0, "Time between motx call retries", "seconds"}, - {"motx-retries", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &motxretries, 0, "Number of retries for motx call", "n"}, - {"mttx-channel", 0, POPT_ARG_STRING, &mttxchannel, 0, - "Channel for mttx calls (default is Local/ and queue name without sub address)", "channel"}, - {"mttx-callerid", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &mttxcallerid, 0, - "Caller ID for mttx calls (default is queue name without sub address)", "number"}, - {"mttx-wait", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxwait, 0, "Time to wait for mttx call to answer", - "seconds"}, - {"mttx-delay", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxdelay, 0, "Time between mttx call retries", "seconds"}, - {"mttx-retries", 0, POPT_ARG_INT | POPT_ARGFLAG_SHOW_DEFAULT, &mttxretries, 0, "Number of retries for mttx call", "n"}, - {"mr", 'n', POPT_ARG_INT, &mr, 0, "Message reference", "n"}, - {"pid", 'p', POPT_ARG_INT, &pid, 0, "Protocol ID", "n"}, - {"dcs", 'c', POPT_ARG_INT, &dcs, 0, "Data Coding Scheme", "n"}, - {"udh", 0, POPT_ARG_STRING, &udh, 0, "User data header", "hex"}, - {"srr", 0, POPT_ARG_NONE, &srr, 0, "Status Report Request", 0}, - {"rp", 0, POPT_ARG_NONE, &rp, 0, "Return Path request", 0}, - {"v", 0, POPT_ARG_INT, &vp, 0, "Validity Period", "seconds"}, - {"scts", 0, POPT_ARG_STRING, &scts, 0, "Timestamp", "YYYY-MM-SSTHH:MM:SS"}, - {"default-sub-address", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &defaultsubaddress, 0, "Default sub address", "X"}, - {"spool-dir", 0, POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &spooldir, 0, "Asterisk spool dir", "dirname"}, - POPT_AUTOHELP {NULL, 0, 0, NULL, 0} - }; - - optCon = poptGetContext (NULL, argc, argv, optionsTable, 0); - poptSetOtherOptionHelp (optCon, "<oa/da> <message>"); - - /* Now do options processing, get portname */ - if ((c = poptGetNextOpt (optCon)) < -1) - { - /* an error occurred during option processing */ - fprintf (stderr, "%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c)); - return 1; - } - if (!ucs1 && !ucs2) - utf8 = 1; - if (utf8 + ucs1 + ucs2 > 1) - { - fprintf (stderr, "Pick one of UTF-8, UCS-1 or UCS-2 only\n"); - return 1; - } - if (!udfile && (ucs1 || ucs2)) - { - fprintf (stderr, "Command line arguments always treated as UTF-8\n"); - return 1; - } - /* if (!where && poptPeekArg (optCon)) where = (char *) poptGetArg (optCon); */ - if (!mt && !mo && process) - mt = 1; - if (!mt && !mo && oa) - mt = 1; - if (!mt) - mo = 1; - if (mt && mo) - { - fprintf (stderr, "Cannot be --mt and --mo\n"); - return 1; - } - if (!rx && !tx && process) - rx = 1; - if (!rx) - tx = 1; - if (tx && rx) - { - fprintf (stderr, "Cannot be --tx and --rx\n"); - return 1; - } - if (rx) - nodial = 1; - if (uds && udfile) - { - fprintf (stderr, "Cannot have --ud and --ud-file\n"); - return 1; - } - if (mo && !da && poptPeekArg (optCon)) - da = (char *) poptGetArg (optCon); - if (mt && !oa && poptPeekArg (optCon)) - oa = (char *) poptGetArg (optCon); - if (tx && oa && mo) - { - fprintf (stderr, "--oa makes no sense with --mo as CLI is used (i.e. queue name)\n"); - return 1; - } - if (tx && da && mt) - { - fprintf (stderr, "--da makes no sense with --mt as called number is used (i.e. queue name)\n"); - return 1; - } - if (da && strlen (da) > 20) - { - fprintf (stderr, "--da too long\n"); - return 1; - } - if (oa && strlen (oa) > 20) - { - fprintf (stderr, "--oa too long\n"); - return 1; - } - if (queue && strlen (queue) > 20) - { - fprintf (stderr, "--queue name too long\n"); - return 1; - } - if (mo && scts) - { - fprintf (stderr, "scts is set my service centre\n"); - return 1; - } - if (uds) - { /* simple user data command line option in \UTF-8 */ - while (udl < 160 && *uds) - { - int v = utf8decode (&uds); - if (v > 0xFFFF) - { - fprintf (stderr, "Invalid character U+%X at %d\n", v, udl); - return 1; - } - ud[udl++] = v; - } - } - if (!uds && !udfile && poptPeekArg (optCon)) - { /* multiple command line arguments in UTF-8 */ - while (poptPeekArg (optCon) && udl < 160) - { - unsigned char *a = (char *) poptGetArg (optCon); - if (udl && udl < 160) - ud[udl++] = ' '; /* space between arguments */ - while (udl < 160 && *a) - { - int v = utf8decode (&a); - if (v > 0xFFFF) - { - fprintf (stderr, "Invalid character U+%X at %d\n", v, udl); - return 1; - } - ud[udl++] = v; - } - } - } - if (poptPeekArg (optCon)) - { - fprintf (stderr, "Unknown argument %s\n", poptGetArg (optCon)); - return 1; - } - if (udfile) - { /* get message from file */ - unsigned char dat[1204], - *p = dat, - *e; - int f, - n; - if (*udfile) - f = open (udfile, O_RDONLY); - else - f = fileno (stdin); - if (f < 0) - { - perror (udfile); - return 1; - } - n = read (f, dat, sizeof (dat)); - if (n < 0) - { - perror (udfile); - return 1; - } - if (*udfile) - close (f); - e = dat + n; - if (utf8) - { /* UTF-8 */ - while (p < e && udl < 160 && *p) - ud[udl++] = utf8decode (&p); - } else if (ucs1) - { /* UCS-1 */ - while (p < e && udl < 160) - ud[udl++] = *p++; - } else - { /* UCS-2 */ - while (p + 1 < e && udl < 160) - { - ud[udl++] = (*p << 8) + p[1]; - p += 2; - } - } - } - if (queue) - { - char *d = strrchr (queue, '-'); - if (d && d[1]) - subaddress = d[1]; - else - subaddress = *defaultsubaddress; - } - - if (chdir (spooldir)) - { - perror (spooldir); - return 1; - } - - if (oa || da) - { /* send message */ - char temp[100], - queuename[100], - *dir = (mo ? rx ? "sms/morx" : "sms/motx" : rx ? "sms/mtrx" : "sms/mttx"); - FILE *f; - snprintf (temp, sizeof(temp), "sms/.smsq-%d", getpid ()); - mkdir ("sms", 0777); /* ensure directory exists */ - mkdir (dir, 0777); /* ensure directory exists */ - snprintf (queuename, sizeof(queuename), "%s/%s.%ld-%d", dir, *queue ? queue : "0", (long)time (0), getpid ()); - f = fopen (temp, "w"); - if (!f) - { - perror (temp); - return 1; - } - if (oa) - fprintf (f, "oa=%s\n", oa); - if (da) - fprintf (f, "da=%s\n", da); - if (scts) - fprintf (f, "scts=%s\n", scts); - if (pid >= 0) - fprintf (f, "pid=%d\n", pid); - if (dcs >= 0) - fprintf (f, "dcs=%d\n", dcs); - if (mr >= 0) - fprintf (f, "mr=%d\n", mr); - if (srr) - fprintf (f, "srr=1\n"); - if (rp) - fprintf (f, "rp=1\n"); - if (udh) - fprintf (f, "udh#%s\n", udh); - if (vp > 0) - fprintf (f, "vp=%d\n", vp); - if (udl) - { - int p; - for (p = 0; p < udl && ud[p] < 0x100; p++); - if (p == udl) - { - for (p = 0; p < udl && ud[p] < 0x80 && ud[p] >= 0x20; p++); - if (p == udl) - { /* use text */ - fprintf (f, "ud="); - for (p = 0; p < udl; p++) - fputc (ud[p], f); - } else - { /* use one byte hex */ - fprintf (f, "ud#"); - for (p = 0; p < udl; p++) - fprintf (f, "%02X", ud[p]); - } - } else - { /* use two byte hex */ - fprintf (f, "ud##"); - for (p = 0; p < udl; p++) - fprintf (f, "%04X", ud[p]); - } - fprintf (f, "\n"); - } - fclose (f); - if (rename (temp, queuename)) - { - perror (queuename); - unlink (temp); - return 1; - } - } - - if (!nodial && tx && !process) - { /* dial to send messages */ - char ret=0, - try = 3; - if (nowait) - try = 1; - while (try--) - { - if (mo) - ret = txqcheck ("motx", queue, subaddress, motxchannel, motxcallerid, motxwait, motxdelay, motxretries, concurrent); - else - ret = txqcheck ("mttx", queue, subaddress, mttxchannel, mttxcallerid, mttxwait, mttxdelay, mttxretries, concurrent); - if (ret < 2) - break; /* sent, or queued OK */ - if (try) - sleep (1); - } - if (ret == 2 && !nowait) - fprintf (stderr, "No call scheduled as already sending\n"); - } - if (process) - rxqcheck (mo ? rx ? "morx" : "motx" : rx ? "mtrx" : "mttx", queue, process); - - return 0; -} diff --git a/1.2-netsec/utils/stereorize.c b/1.2-netsec/utils/stereorize.c deleted file mode 100644 index 7d72cbdbf..000000000 --- a/1.2-netsec/utils/stereorize.c +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - * - * Programs for processing sound files in raw- or WAV-format. - * -- Merge two mono WAV-files to one stereo WAV-file. - * - * Name: stereorize.c - * Version: 1.1 - * Author: Mark Roberts <mark@manumark.de> - * Michael Labuschke <michael@labuschke.de> - * - ****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <time.h> -#include <assert.h> -#include "frame.h" - -static char *Version = "stereorize 1.1, November 5th 2000"; -static char *Usage = -"Usage: stereorize [options] infile-left infile-right outfile\n\n" - -"Example:\n" -" stereorize left.wav right.wav stereo.wav -h\n\n" - -"Creates stereo.wav (with WAV-header, option -h) from data in mono files\n" -"left.wav and right.wav.\n" -; - -int main( int argcount, char *args[]) -{ - int i, k[2], maxk, stdin_in_use=FALSE; - short *leftsample, *rightsample, *stereosample; - FILE *channel[2]; - char *filename[2], *tempname; - - version = Version; - usage = Usage; - - channel[0] = NULL; - channel[1] = NULL; - - parseargs( argcount, args, NOFILES | NOCOMPLAIN); - - for (i = 0; i < 2; i++) - { - filename[i] = parsefilearg( argcount, args); - if (filename[i] == NULL) - argerrornum( NULL, ME_NOTENOUGHFILES); - if (strcmp (filename[i], "-") == 0) - { - if (stdin_in_use) - argerrortxt( filename[i] + 1, - "Cannot use <stdin> for both input files"); - filename[i] = "<stdin>"; - channel[i] = stdin; - stdin_in_use = TRUE; - } - else - { - channel[i] = fopen(filename[i], "rb"); - } - if (channel[i] == NULL) - fatalerror( "Error opening input file '%s': %s\n", filename[i],strerror(errno)); - else - inform("Using file '%s' as input\n", filename[i]); - } - for (i = 0; i < 2; i++) - { - assert ( channel[i] != NULL); - readwavheader( channel[i]); - if (iswav && channels != 1) - inform("Warning: '%s' is no mono file\n", filename[i]); - } - - outfilename = parsefilearg( argcount, args); - if (outfilename == NULL) argerrornum( NULL, ME_NOOUTFILE); - if (strcmp (outfilename, "-") == 0) - { - outfilename = "<stdout>"; - out = stdout; - } - else - { - out = fopen(outfilename, "wb"); - } - if (out == NULL) - fatalerror( "Error opening output file '%s': %s\n", outfilename,strerror(errno)); - else - inform("Using file '%s' as output\n", outfilename); - - if ((tempname = parsefilearg( argcount, args)) != NULL) - argerrornum( tempname, ME_TOOMANYFILES); - - checknoargs(argcount, args); /* Check that no arguments are left */ - - leftsample = malloc( sizeof(*leftsample) * BUFFSIZE); - rightsample = malloc( sizeof(*leftsample) * BUFFSIZE); - stereosample = malloc( sizeof(*leftsample) * 2 * BUFFSIZE); - if (leftsample == NULL || rightsample == NULL || stereosample == NULL) - fatalperror (""); - - channels = 2; /* Output files are stereo */ - if (wavout) - { - if ((strcmp(outfilename,"<stdout>")!=0) && (fseek( out, 0, SEEK_SET) != 0)) - fatalerror("Couldn't navigate output file '%s': %s\n",outfilename, strerror(errno)); - makewavheader(); - } - - startstopwatch(); - while (TRUE) - { - maxk = 0; - for (i = 0; i < 2; i++) - { - k[i] = fread(i==0? leftsample : rightsample, - sizeof(*leftsample), - BUFFSIZE, - channel[i]); - if (k[i] == -1) - fatalerror("Error reading file '%s': %s\n", filename[i],strerror(errno)); - if (k[i] > maxk) - maxk = k[i]; - } - if (maxk == 0) - myexit (0); - - /*-------------------------------------------------* - * First the left channel as far as it goes ... * - *-------------------------------------------------*/ - for (i = 0; i < k[0]; i++) - stereosample[2 * i] = leftsample[i]; - /*-------------------------------------------------* - * ... and fill up till the end of this buffer. * - *-------------------------------------------------*/ - for (; i < maxk; i++) - stereosample[2 * i] = 0; - - /*-------------------------------------------------* - * Next the right channel as far as it goes ... * - *-------------------------------------------------*/ - for (i = 0; i < k[1]; i++) - stereosample[2 * i + 1] = rightsample[i]; - /*-------------------------------------------------* - * ... and fill up till the end of this buffer. * - *-------------------------------------------------*/ - for (; i < maxk; i++) - stereosample[2 * i + 1] = 0; - - fwrite(stereosample, sizeof(*leftsample), 2 * maxk, out); - if (ferror( out) != 0) - fatalerror("Error writing to file '%s': %s\n", - outfilename, strerror(errno)); - } - /* That was an endless loop. This point is never reached. */ -} diff --git a/1.2-netsec/utils/streamplayer.c b/1.2-netsec/utils/streamplayer.c deleted file mode 100644 index 24f3142b8..000000000 --- a/1.2-netsec/utils/streamplayer.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2005, Digium, Inc. - * - * Russell Bryant <russell@digium.com> - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -/* -* -* streamplayer.c -* -* A utility for reading from a stream -* -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <netdb.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__) -#include <netinet/in.h> -#endif -#include <sys/time.h> - - -int main(int argc, char *argv[]) -{ - struct sockaddr_in sin; - struct hostent *hp; - int s; - int res; - char buf[2048]; - fd_set wfds; - struct timeval tv; - - if (argc != 3) { - fprintf(stderr, "streamplayer -- A utility for reading from a stream.\n"); - fprintf(stderr, "Written for use with Asterisk (http://www.asterisk.org)\n"); - fprintf(stderr, "Copyright (C) 2005 -- Russell Bryant -- Digium, Inc.\n\n"); - fprintf(stderr, "Usage: ./streamplayer <ip> <port>\n"); - exit(1); - } - - hp = gethostbyname(argv[1]); - if (!hp) { - fprintf(stderr, "Unable to lookup IP for host '%s'\n", argv[1]); - exit(1); - } - - memset(&sin, 0, sizeof(sin)); - - sin.sin_family = AF_INET; - sin.sin_port = htons(atoi(argv[2])); - memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); - - s = socket(AF_INET, SOCK_STREAM, 0); - - if (s < 0) { - fprintf(stderr, "Unable to allocate socket!\n"); - exit(1); - } - - res = connect(s, (struct sockaddr *)&sin, sizeof(sin)); - - if (res) { - fprintf(stderr, "Unable to connect to host!\n"); - close(s); - exit(1); - } - - while (1) { - res = read(s, buf, sizeof(buf)); - - if (res < 1) - break; - - memset(&tv, 0, sizeof(tv)); - FD_ZERO(&wfds); - FD_SET(1, &wfds); - - select(2, NULL, &wfds, NULL, &tv); - - if (FD_ISSET(1, &wfds)) - write(1, buf, res); - } - - close(s); - exit(res); -} |