Xcid import

This commit is contained in:
dcp1990 2005-06-23 02:23:14 +00:00
parent 247b4cfd88
commit b7ce836556
5 changed files with 464 additions and 0 deletions

25
xcid/Makefile Normal file
View File

@ -0,0 +1,25 @@
# for xcid
# $Amigan: phoned/xcid/Makefile,v 1.1 2005/06/23 02:23:14 dcp1990 Exp $
CPPFLAGS+=-I/usr/X11R6/include
LDFLAGS=-L/usr/X11R6/lib -lXt -lX11 -lXaw -lpthread
.ifdef DEBUG
CPPFLAGS+=-DDEBUG
.endif
.ifndef NO_XOSD
LDFLAGS+=-lxosd
CPPFLAGS+=-DUSE_XOSD
.endif
CFLAGS+=-g -Wall $(CPPFLAGS)
OBJS=xcid.o network.o wind.o
SRCS=xcid.c network.c wind.c
all: xcid
xcid: ${OBJS}
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o xcid
xcid.o: xcid.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c xcid.c
network.o: network.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c network.c
wind.o: wind.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c wind.c
clean:
rm -f *.o core.* *.core *~ xcid

5
xcid/README Normal file
View File

@ -0,0 +1,5 @@
To build without XOSD, type
make NO_XOSD=yes
instead of just
make.
Pretty simple to use; you just start it. Stuff can be tweaked in the source to your liking.

122
xcid/network.c Normal file
View File

@ -0,0 +1,122 @@
/*
* XCid - network stuff
* (C)2004, Dan Ponte
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Dan Ponte nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DAN PONTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL DAN PONTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define PORT 3890
#define BUFFERL 256
struct sockaddr_in servsad;
char servaddr[256];
void telluser(char* buf);
void sendtoser(char* txt)
{
int s;
struct sockaddr_in sin;
s = socket(PF_INET, SOCK_DGRAM, 0);
bzero(&sin, sizeof sin);
sin.sin_family = AF_INET;
sin.sin_addr = servsad.sin_addr;/*.s_addr = inet_addr(servaddr); */
#ifdef DEBUG
printf("it is %s\n", inet_ntoa(sin.sin_addr));
#endif
sin.sin_port = htons(1450);
if(connect(s, (struct sockaddr *)&sin, sizeof sin) < 0) {
perror("Connect");
exit(-1);
}
write(s, txt, strlen(txt) + 1);
close(s);
return;
}
int start_netloop(void)
{
int sockfd, addr_len, nbytes;
struct sockaddr_in ouraddr;
struct sockaddr_in* bcasaddr;
struct timeval tv;
bcasaddr = &servsad;
bzero(&servsad, sizeof servsad);
fd_set fds_read;
FD_ZERO(&fds_read);
char buffer[BUFFERL];
if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("sock");
exit(-1);
}
ouraddr.sin_family = AF_INET;
ouraddr.sin_port = htons(PORT);
ouraddr.sin_addr.s_addr = INADDR_ANY;
memset(&(ouraddr.sin_zero), 0, 8);
if(bind(sockfd, (struct sockaddr*)&ouraddr, sizeof(struct sockaddr)) == -1) {
perror("bind");
exit(-2);
}
addr_len = sizeof(struct sockaddr);
while(1)
{
FD_ZERO(&fds_read);
FD_SET(sockfd, &fds_read);
tv.tv_sec = 3; tv.tv_usec = 0;
switch(select(sockfd + 1, &fds_read, NULL, NULL, NULL))
{
case -1:
perror("select");
exit(-1);
break;
default:
if(FD_ISSET(sockfd, &fds_read) != 0)
{
if((nbytes = recvfrom(sockfd, buffer, BUFFERL - 1, 0, (struct sockaddr*)bcasaddr, &addr_len
)) == -1) {
perror("recv");
exit(-3);
}
buffer[nbytes] = 0;
#ifdef DEBUG
printf("got %s\n", buffer);
#endif
telluser(buffer);
memset(buffer, 0, BUFFERL);
}
}
}
close(sockfd);
return 0;
}

219
xcid/wind.c Normal file
View File

@ -0,0 +1,219 @@
/*
* XCid - For use with CIDServ
* (C)2004, Dan Ponte
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Dan Ponte nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DAN PONTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL DAN PONTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Label.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef USE_XOSD
#define DEF_XOSD_TIMEOUT 5
#define DEF_XOSD_COLOUR "green"
#define DEF_XOSD_VOFFSET 30
#define DEF_XOSD_FONT "-misc-fixed-medium-r-semicondensed-*-13-*-*-*-c-*-koi8-r"
#include <xosd.h>
extern int XOSD_TIMEOUT, XOSD_VOFFSET;
extern char *XOSD_COLOUR, *XOSD_FONT;
#endif
short int tsec = 10;
typedef struct cis
{
char *name;
char *number;
char *date;
char *time;
} cidinfo;
void sendtoser(char* txt);
XtAppContext app_context;
Widget toplevel; /* The overall window. */
Widget form; /* The layout of the window. */
Widget quit_button; /* The button in the window. */
Widget telemar;
Widget mlabel;
XtIntervalId timer;
XtPointer test;
short int tflag = 0;
void htime(XtPointer client_data, XtIntervalId *timer)
{
XEvent bogus_event;
Display** displays;
int numdr;
#ifdef DEBUG
printf("here\n");
#endif
if(--tsec == 0) {
// XtDestroyApplicationContext (app_context);
#ifdef DEBUG
printf("alive\n");
#endif
/* This is EVIL */
tflag = 1;
XtGetDisplays(app_context, &displays, &numdr);
bogus_event.type = 0; /* XAnyEvent type, ignored. */
bogus_event.xany.display = displays[0];
bogus_event.xany.window = 0;
XPutBackEvent(displays[0], &bogus_event);
XtAppSetExitFlag (app_context); }
else {
timer = (XtIntervalId)XtAppAddTimeOut(app_context,
(unsigned long)1000,
(XtTimerCallbackProc)htime,
test);
}
}
/* The callback function for the quit button. */
void
quit_proc (Widget w, XtPointer client_data, XtPointer call_data)
{
XtDestroyApplicationContext (app_context);
XtAppSetExitFlag (app_context);
}
void telecall (Widget w, XtPointer client_data, XtPointer call_data)
{
sendtoser("AHU\n");
}
int
wind (int argc, char **argv, char *labtext)
{
/* Create the window and its contents' appearance. */
toplevel = XtOpenApplication (&app_context, "xcid", NULL, 0, &argc,
argv, NULL,
applicationShellWidgetClass, NULL, 0);
XtVaSetValues(toplevel, XtNtitle, "XCid - Incoming Call", NULL);
form = XtVaCreateManagedWidget ("form", formWidgetClass, toplevel, NULL);
mlabel =
XtVaCreateManagedWidget ("mlabel", labelWidgetClass, form, XtNwidth, 200,
XtNheight, 200, NULL);
telemar =
XtVaCreateManagedWidget ("telemar", commandWidgetClass, form, XtNlabel,
"Telemarketerize", XtNfromVert, mlabel, NULL);
quit_button = XtVaCreateManagedWidget ("quit_button", commandWidgetClass,
form, XtNlabel, "Close", XtNfromHoriz,
telemar, XtNfromVert, mlabel, NULL);
timer = XtAppAddTimeOut(app_context, 1000, htime, (XtPointer) 0);
/* Create window's behavior. */
XtAddCallback (quit_button, XtNcallback, quit_proc, NULL);
XtAddCallback(telemar, XtNcallback, telecall, NULL);
/* Display the window. */
XtRealizeWidget (toplevel);
XtVaSetValues (mlabel, XtNlabel, labtext, NULL);
/* Infinite loop, waiting for events to happen. */
XtAppMainLoop (app_context);
if(tflag) {
#ifdef DEBUG
printf("about...\n");
#endif
XtDestroyApplicationContext (app_context);
tflag = 0;
tsec = 10;
#ifdef DEBUG
printf("done...\n");
#endif
}
return 0;
}
void
parseinfo (buffer, cifo)
char *buffer;
cidinfo *cifo;
{
char *bfrp;
char *origbuf;
origbuf = buffer;
bfrp = origbuf;
/* 9005:2010:0:WIRELESS CALL :401213123123 */
cifo->date = strsep (&bfrp, ":");
cifo->time = strsep (&bfrp, ":");
if(cifo->time == NULL) return;
strsep (&bfrp, ":");
cifo->name = strsep (&bfrp, ":");
cifo->number = bfrp;
}
void
telluser (buf)
char *buf;
{
cidinfo cid;
#ifdef USE_XOSD
xosd *osd;
#endif
#ifndef USE_XOSD
char *tav[] = { "xcid", NULL };
char *ltx;
size_t lent;
#endif
bzero(&cid, sizeof cid);
parseinfo (buf, &cid);
if(cid.name == NULL) return;
#ifdef DEBUG
printf ("Name: %s\nNum: %s\nDate: %s\nTime: %s\n",
cid.name, cid.number, cid.date, cid.time);
#endif
if(cid.name == NULL || cid.number == NULL) {return;}
#ifdef USE_XOSD
/* lent += sizeof(" -- \nDate: -- Time:\n ");
ltx = malloc(lent);
memset(ltx, 0, lent);
snprintf(ltx, lent, "%s -- %s\nDate: %s -- Time: %s",
cid.name, cid.number, cid.date, cid.time);*/
osd = xosd_create(2);
xosd_set_font(osd, XOSD_FONT);
xosd_set_colour(osd, XOSD_COLOUR);
xosd_set_timeout(osd, XOSD_TIMEOUT);
xosd_set_pos(osd, XOSD_top);
xosd_set_align(osd, XOSD_right);
xosd_set_vertical_offset(osd, XOSD_VOFFSET);
xosd_set_shadow_offset(osd, 1);
xosd_display(osd, 0, XOSD_printf, "%s -- %s", cid.name, cid.number);
xosd_display(osd, 1, XOSD_printf, "Date: %s -- Time: %s", cid.date,
cid.time);
xosd_wait_until_no_display(osd);
xosd_destroy(osd);
#else
lent += sizeof ("Name: \nNumber: \nDate: \nTime: \n ");
lent =
sizeof (char) * (strlen (cid.name) + strlen (cid.number) +
strlen (cid.date) + strlen (cid.time));
ltx = (char *) malloc (lent);
memset (ltx, 0, lent);
snprintf (ltx, lent, "Name: %s\nNumber: %s\nDate: %s\nTime: %s\n",
cid.name, cid.number, cid.date, cid.time);
wind (0, tav, ltx);
free (ltx);
#endif
}

93
xcid/xcid.c Normal file
View File

@ -0,0 +1,93 @@
/*
* XCid - For use with CIDServ and phoned
* (C)2004-2005, Dan Ponte
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Dan Ponte nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DAN PONTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL DAN PONTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Amigan: phoned/xcid/xcid.c,v 1.1 2005/06/23 02:23:15 dcp1990 Exp $ */
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
char* servaddr;
int start_netloop (void);
static const char rcsid[] = "$Amigan: phoned/xcid/xcid.c,v 1.1 2005/06/23 02:23:15 dcp1990 Exp $";
#ifdef USE_XOSD
#define DEF_XOSD_TIMEOUT 5
#define DEF_XOSD_COLOUR "green"
#define DEF_XOSD_VOFFSET 30
#define DEF_XOSD_FONT "-misc-fixed-medium-r-semicondensed-*-13-*-*-*-c-*-koi8-r"
int XOSD_VOFFSET = DEF_XOSD_VOFFSET, XOSD_TIMEOUT = DEF_XOSD_TIMEOUT;
char *XOSD_FONT = DEF_XOSD_FONT;
char *XOSD_COLOUR = DEF_XOSD_COLOUR;
#endif
void usage(void)
{
fprintf(stderr, "Usage: xcid [-c colourname] [-f fontspec] [-o voffset"
"] [-t timeoutsecs]\n");
}
int
main (int argc, char *argv[])
{
/* if(argc < 2) {
fprintf(stderr, "Usage: %s server-ip\n", argv[0]);
exit(1);
}
servaddr = strdup(argv[1]); */
#ifdef USE_XOSD
int ch;
while ((ch = getopt(argc, argv, "f:t:o:c:")) != -1) {
switch(ch) {
case 'f':
XOSD_FONT = strdup(optarg);
break;
case 't':
XOSD_TIMEOUT = atoi(optarg);
if(XOSD_TIMEOUT < 1) XOSD_TIMEOUT =
DEF_XOSD_TIMEOUT;
break;
case 'o':
XOSD_VOFFSET = atoi(optarg);
break;
case 'c':
XOSD_COLOUR = strdup(optarg);
break;
case '?':
default:
usage();
exit(-1);
}
}
argc -= optind;
argv += optind;
#endif
start_netloop ();
#ifdef USE_XOSD
free(XOSD_COLOUR);
free(XOSD_FONT);
#endif
return 0;
}