78 Usage: fakesmsc [-H host] [-r port] [-i interval] [-m max] [-z <type>] <msg> ... \n\ 80 * 'host' and 'port' define bearerbox connection (default localhost:10000),\n\ 81 * 'interval' is time in seconds (floats allowed) between generated messages,\n\ 82 * 'max' is the total number sent (-1, default, means unlimited),\n\ 83 * <type> bitmask of which elements to add randomized numbers for MO messages,\n\ 84 * 1: src no, 2: recv no, 4: last text element,\n\ 85 * where the given static elements in <msg> are used as constant prefixes,\n\ 86 * <msg> is message to send, if several are given, they are sent randomly.\n\ 88 msg format: \"sender receiver type(text|data|ucs2|udh-data|udh-text|route|dlr-mask) [udhdata|route|dlrmask] msgdata\"\n\ 90 Type \"text\" means plaintext msgdata, \"data\" url-encoded, \"udh\" url-encoded udh+msg,\n\ 91 \"utf8\" utf-8 url-encoded msgdata, \"ucs2\" unicode url-encoded msgdata \n\ 92 and \"route\" means smsbox-id routed plaintext msgdata\n\ 95 fakesmsc -m 1 \"123 345 udh %04udh%3f message+data+here\"\n\ 96 fakesmsc -m 1 \"123 345 route smsbox1 message+data+here\"\n\ 97 fakesmsc -i 0.01 -m 1000 \"123 345 text nop\" \"1 2 text another message here\"\n\ 98 fakesmsc -z 7 -m 1000 \"123<rand> 345<rand> text nop <rand>\"\n\ 100 Server replies are shown in the same message format.\n";
109 #include <sys/time.h> 113 #include <sys/param.h> 117 #define IN_BUFSIZE 256 130 if (signum == SIGINT)
133 panic(0,
"Caught signal with no handler?!");
139 struct sigaction act;
142 sigemptyset(&act.sa_mask);
144 sigaction(SIGINT, &act, NULL);
152 return msgs[
gw_rand() % num_msgs];
162 gettimeofday(&now, &tz);
163 return (
double) now.tv_sec + now.tv_usec / 1e6;
169 if (strcmp(argv[i],
"-r")==0 || strcmp(argv[i],
"--port")==0)
170 port = atoi(argv[i+1]);
171 else if (!strcmp(argv[i],
"-H") || !strcmp(argv[i],
"--host"))
173 else if (strcmp(argv[i],
"-m")==0 || strcmp(argv[i],
"--messages")==0) {
178 else if (strcmp(argv[i],
"-i")==0 || strcmp(argv[i],
"--interval")==0)
180 else if (strcmp(argv[i],
"-z")==0 || strcmp(argv[i],
"--randomize")==0) {
181 rnd = atoi(argv[i+1]);
182 if (rnd < 0 || rnd > 7)
223 int main(
int argc,
char **argv)
231 double first_received_at, last_received_at;
232 double first_sent_at, last_sent_at;
235 int interactive, maxfd;
239 struct timeval alarm;
248 num_msgs = argc - mptr;
256 info(0,
"Entering interactive mode. Type your message on the command line");
262 msgs = gw_malloc(
sizeof(
Octstr *) * num_msgs);
263 for (i = 0; i < num_msgs; i ++) {
267 info(0,
"Host %s Port %d interval %.3f max-messages %ld",
270 srand((
unsigned int) time(NULL));
272 info(0,
"fakesmsc starting");
275 panic(0,
"Failed to open connection");
280 first_received_at = 0;
282 last_received_at = 0;
288 if (interactive == 1) {
290 if ( num_msgs > 0 ) {
291 for (i = 0; i < num_msgs; i ++)
298 FD_SET(fileno(fp), &rset);
300 maxfd = fileno(fp) + 1;
306 if (select(maxfd, &rset, NULL, NULL, &alarm) == -1)
309 if (FD_ISSET(fileno(fp), &rset)) {
313 if( strlen( cptr ) < 2 )
319 msgs = gw_malloc(
sizeof(
Octstr*));
328 panic(0,
"write failed");
340 if (first_sent_at == 0)
341 first_sent_at = last_sent_at;
357 if (first_received_at == 0)
358 first_received_at = last_received_at;
361 info(0,
"Got message %ld: <%s>", num_received,
364 debug(
"receive", 0,
"Got message %ld: <%s>", num_received,
376 for (i = 0; i < num_msgs; i ++)
382 info(0,
"fakesmsc: %ld messages sent and %ld received",
num_sent, num_received);
384 delta = last_sent_at - first_sent_at;
388 info(0,
"fakesmsc: from first to last sent message %.1f s, " 389 "%.1f msgs/s", delta, (
num_sent - 1) / delta);
390 delta = last_received_at - first_received_at;
393 if (num_received > 1)
394 info(0,
"fakesmsc: from first to last received message %.1f s, " 395 "%.1f msgs/s", delta, (num_received - 1) / delta);
396 info(0,
"fakesmsc: terminating");
Octstr * conn_read_line(Connection *conn)
void info(int err, const char *fmt,...)
Connection * conn_open_tcp(Octstr *host, int port, Octstr *our_host)
static Octstr * choose_message(Octstr **msgs, int num_msgs)
static void setup_signal_handlers(void)
long gwlist_len(List *list)
void * gwlist_get(List *list, long pos)
void octstr_append_char(Octstr *ostr, int ch)
int main(int argc, char **argv)
static Octstr * randomize(Octstr *os)
static void signal_handler(int signum)
int conn_eof(Connection *conn)
#define octstr_get_cstr(ostr)
int conn_write(Connection *conn, Octstr *data)
void conn_destroy(Connection *conn)
List * octstr_split_words(const Octstr *ostr)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
void octstr_destroy_item(void *os)
static int check_args(int i, int argc, char **argv)
int conn_wait(Connection *conn, double seconds)
void debug(const char *place, int err, const char *fmt,...)
void octstr_format_append(Octstr *os, const char *fmt,...)
static void server(int lport, int pport)
int conn_error(Connection *conn)
static int sigint_received
int get_and_set_debugs(int argc, char **argv, int(*find_own)(int index, int argc, char **argv))
static XMLRPCDocument * msg
static double get_current_time(void)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)