Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. This file is a product of SunSoft, Inc. and is provided for unrestricted use provided that this legend is included on all media and as a part of the software program in whole or part. Users may copy, modify or distribute this file at will. THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. This file is provided with no support and without any obligation on the part of SunSoft, Inc. to assist in its use, correction, modification or enhancement. SUNSOFT AND SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE OR ANY PART THEREOF. IN NO EVENT WILL SUNSOFT OR SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL DAMAGES, EVEN IF THEY HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SunSoft, Inc. 2550 Garcia Avenue Mountain View, California 94043 animate.c Page 1 #include #include #include #include #include #include #include "sunraster.h" XtAppContext context; Widget toplevel, da; Display *display; GC gc; Pixmap frame_scr_1[4]; Pixmap frame_scr_2[4]; static int counter1, counter2; Atom START1, START2; XtIntervalId time_out_id_1, time_out_id_2; void da_callback(Widget, XtPointer, XtPointer); void startstop(XEvent *); void start_ani_1(XtPointer, XtIntervalId *); void start_ani_2(XtPointer, XtIntervalId *); String fallback_resources[] = { "*resizeCorners: False", "*title: ATM USERS", "*da.layoutType: ignore", "*da.width: 550", "*da.height: 320", "*da.borderwidth: 1", NULL }; main(int argc, char **argv) { char temp[30]; int i; XImage *ximage; XEvent event, event_send; Window root; counter1 = counter2 = 0; toplevel = XtVaAppInitialize(&context, "Animate", (XrmOptionDescList)NULL, 0, (Cardinal *)&argc, argv, (const char **)fallback_resources, 0); display = XtDisplay(toplevel); gc = DefaultGC(display, 0); root = DefaultRootWindow(display); da = XtVaCreateManagedWidget("da", drawAreaWidgetClass, toplevel, animate.c Page 2 NULL); XtAddCallback(da, XtNexposeCallback, da_callback, NULL); XtAddCallback(da, XtNgraphicsExposeCallback, da_callback, NULL); START1 = OlInternAtom(display, "ATM1"); START2 = OlInternAtom(display, "ATM2"); XtRealizeWidget (toplevel); for (i = 0; i < 4; i++) { sprintf(temp, "../packaging/%dright.rf\0", i+1); ReadSunRasterToImage(display, temp, &ximage); if (ximage->depth != 8) { printf("Animate: can only support 8 bit color display\n"); exit(1); } frame_scr_1[i] = XCreatePixmap(display, XtWindow(toplevel), ximage->width, ximage->height, ximage->depth); XPutImage(display, frame_scr_1[i], gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); sprintf(temp, "../packaging/%dleft.rf\0", i+1); ReadSunRasterToImage(display, temp, &ximage); if (ximage->depth != 8) { printf("Animate: can only support 8 bit color display\n"); exit(1); } frame_scr_2[i] = XCreatePixmap(display, XtWindow(toplevel), ximage->width, ximage->height, ximage->depth); XPutImage(display, frame_scr_2[i], gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); XDestroyImage(ximage); } while (1) { XtAppNextEvent(context, &event); switch(event.type) { case PropertyNotify: if(event.xproperty.window == root && event.xproperty.atom == START1 || event.xproperty.atom == START2 ) { memcpy((void *)&event_send, (const void *)&event, sizeof(XEvent)); startstop(&event_send); } else XtDispatchEvent(&event); break; animate.c Page 3 default: XtDispatchEvent(&event); } } } void da_callback(Widget w, XtPointer client_data, XtPointer call_data) { XCopyArea(display, frame_scr_1[0], XtWindow(da), gc, 0, 0, 275, 320, 0, 0); XCopyArea(display, frame_scr_2[0], XtWindow(da), gc, 0, 0, 275, 320, 275, 0); counter1++; counter2++; } void startstop(XEvent *event) { int format; unsigned long nitems, left; Atom type; int *data; if (event->xproperty.atom == START1) { XGetWindowProperty(display, DefaultRootWindow(display), START1, 0, sizeof(int), False, XA_INTEGER, &type, &format, &nitems, &left, (unsigned char **)&data); if (*data == 1) start_ani_1((XtPointer)NULL, (XtIntervalId *)NULL); else if (*data ==0) { XtRemoveTimeOut(time_out_id_1); XClearArea(display, XtWindow(da), 0, 0, 275, 320, True); } } if (event->xproperty.atom == START2) { XGetWindowProperty(display, DefaultRootWindow(display), START2, 0, sizeof(int), False, XA_INTEGER, &type, &format, &nitems, &left, (unsigned char **)&data); if (*data == 1) start_ani_2((XtPointer)NULL, (XtIntervalId *)NULL); else if (*data == 0) { XtRemoveTimeOut(time_out_id_2); XClearArea(display, XtWindow(da), 275, 0, 275, 320, True); } } } void start_ani_1(XtPointer client_data, XtIntervalId *id) { XCopyArea(display, frame_scr_1[counter1 % 4], XtWindow(da), gc, 0, 0, 275, 320, 0, 0); counter1++; animate.c Page 4 time_out_id_1 = XtAppAddTimeOut(context, 1500, (XtTimerCallbackProc)start_ani_1, NULL); } void start_ani_2(XtPointer client_data, XtIntervalId *id) { XCopyArea(display, frame_scr_2[counter2 % 4], XtWindow(da), gc, 0, 0, 275, 320, 275, 0); counter2++; time_out_id_2 = XtAppAddTimeOut(context, 1450, (XtTimerCallbackProc)start_ani_2, NULL); } client-nogui.c Page 1 #include "client.h" /* GLOBAL Var Declaration */ client_request cltreq; ApplicationData data; XtAppContext context; Display *display; GC gc; String fallback_resources[] = { "*resizeCorners: False", "*title: Automatic Teller Machine", "*bb.layoutType: maximize", "*bb.width: 20", "*bb.height: 20", "*excl_auto.noneSet: TRUE", NULL }; main(int argc, char **argv) { String classname = "Mtclient-nogui"; widget_table widtblinst; char temp[50]; XImage *ximage; Pixmap atmpix; widtblinst.onceonly = 1; widtblinst.resetval = 0; OlToolkitInitialize(NULL); widtblinst.toplevel = XtVaAppInitialize(&context, classname, (XrmOptionDescList)options, XtNumber(options), (Cardinal *)&argc, argv, (const char **)fallback_resources, 0); display = XtDisplay(widtblinst.toplevel); gc = DefaultGC(display, 0); XtGetApplicationResources(widtblinst.toplevel, &data, resources, XtNumber(resources), NULL, 0); widtblinst.srv_addr = atoi(data.opt_port); widtblinst.srv_addr1 = atoi(data.opt_port1); widtblinst.atm_id = atoi(data.atm_id); if (widtblinst.atm_id == -1) { usage(); exit(1); } if(strcmp(data.client_id, "\0") == 0) { usage(); exit(1); client-nogui.c Page 2 } widtblinst.bb = XtVaCreateManagedWidget("bb", bulletinBoardWidgetClass, widtblinst.toplevel, NULL); widtblinst.excl_auto = XtVaCreateManagedWidget("excl_auto", exclusivesWidgetClass, widtblinst.bb, NULL); widtblinst.butt_auto = XtVaCreateManagedWidget("Auto", rectButtonWidgetClass, widtblinst.excl_auto, NULL); XtAddCallback(widtblinst.butt_auto, XtNselect, auto_callback, &widtblinst); XtRealizeWidget (widtblinst.toplevel); init_client_data(); cltreq.client_id[0] = '\0'; make_server_address(&widtblinst); init_tt(&widtblinst); XtAppMainLoop(context); exit(0); } void init_tt(widget_table *widtblinst) { Tt_pattern pat; char *procid; int ttfd; widtblinst->session = tt_X_session(DisplayString(display)); tt_default_session_set(widtblinst->session); procid = tt_open(); ttfd = tt_fd(); pat = tt_pattern_create(); tt_pattern_category_set(pat, TT_OBSERVE); tt_pattern_scope_add(pat, TT_SESSION); tt_pattern_session_add(pat, widtblinst->session); tt_pattern_op_add(pat, "ATMSTARTUP"); tt_pattern_register(pat); pat = tt_pattern_create(); tt_pattern_category_set(pat, TT_OBSERVE); tt_pattern_scope_add(pat, TT_SESSION); tt_pattern_session_add(pat, widtblinst->session); tt_pattern_op_add(pat, "ATMSTOP"); tt_pattern_register(pat); tt_session_join(widtblinst->session); XtAppAddInput(context, ttfd, (XtPointer)XtInputReadMask, client-nogui.c Page 3 (XtInputCallbackProc)receive_mesg, (XtPointer)widtblinst); } void usage() { fprintf(stderr, "To Run The ATM Client:\n"); fprintf(stderr, "client -atmNumber # [-serverHostName -optionalPort # -optionalPortDisp #]\n"); fprintf(stderr, "where:\n"); fprintf(stderr, "- serverHostName is hostname of server if different from client\n"); fprintf(stderr, "- optionalPort is port number where you would like client to bind\n"); fprintf(stderr, " with request server\n"); fprintf(stderr, "- optionalPortDisp is port number where you would like client to\n"); fprintf(stderr, " bind with display server\n"); fprintf(stderr, "NOTE: optionalPort and optionalPortDisp are for people who know\n"); fprintf(stderr, " the internal working of the program...\n"); } void init_client_data() { cltreq.data = -1; cltreq.req_type = -1; cltreq.ret_val = -1; } void make_server_address(widget_table *widtblinst) { struct hostent *host; struct utsname name; struct netconfig *netconf; char abyte[MAXSTR]; char uaddr[MAXSTR], hostaddr[MAXSTR]; int i; #ifdef DEBUG printf("entered make_server_address\n"); printf("the server hostname is %s\n", data.serv_hostname); #endif if(strcmp(data.serv_hostname, "local") == 0) { uname(&name); host = gethostbyname(name.nodename); } else { host = gethostbyname(data.serv_hostname); } if (host == NULL) { strcpy(hostaddr, "127.0.0.1"); fprintf(stderr, "Host \"%s\" not found, using localhost.\n", client-nogui.c Page 4 data.serv_hostname); } else { hostaddr[0] = '\0'; for(i = 0; i < host->h_length; i++) { sprintf(abyte, "%d", (unsigned char)host->h_addr_list[0][i]); strcat(hostaddr, abyte); if (i < host->h_length - 1) strcat(hostaddr, "."); } } if(widtblinst->srv_addr == -1) sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + widtblinst->srv_addr, 1); #ifdef DEBUG printf("the official hostname is %s\n", host->h_name); printf("the uaddr we created is %s\n", uaddr); #endif netconf = getnetconfigent(TRANSPORT_NETCONFID); widtblinst->addr = uaddr2taddr(netconf, uaddr); if(widtblinst->srv_addr1 == -1) sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR1, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + widtblinst->srv_addr1, 1); widtblinst->addr1 = uaddr2taddr(netconf, uaddr); freenetconfigent(netconf); } void make_server_request(widget_table *widtblinst) { char temp[20]; int fd, flags; int nbytes; extern int t_errno; struct t_call *sndcall; client_request getcltreq; #ifdef DEBUG printf ("entered make_server_request \n"); printf ("request type is %d\n", cltreq.req_type); if (cltreq.req_type != BALANCE) printf ("data is %d \n", cltreq.data); printf ("now requesting from server...\n"); #endif if ((fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) { t_error("t_open failed"); exit(1); } if (t_bind(fd, (struct t_bind *)NULL, (struct t_bind *) NULL) == -1) { t_error("t_bind failed"); client-nogui.c Page 5 exit(2); } if((sndcall = (struct t_call *) t_alloc(fd, T_CALL, 0)) == (struct t_call *) NULL) { t_error ("t_alloc failed"); exit(3); } sndcall->addr.maxlen = widtblinst->addr->maxlen; sndcall->addr.len = widtblinst->addr->len; sndcall->addr.buf = widtblinst->addr->buf; if (t_connect(fd, sndcall, (struct t_call *)NULL) == -1) { t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); make_server_request(widtblinst); } if(t_snd(fd, (char *)&cltreq, sizeof(client_request), 0) == -1) { t_error("t_snd failed"); exit(5); } nbytes = t_rcv(fd, (char *)&getcltreq, sizeof(client_request), &flags); if(getcltreq.ret_val != -1) { } else { fprintf(stderr, "received incorrect data from server\n"); exit(11); } while((nbytes = t_rcv(fd, temp, 20, &flags)) != -1); if (t_errno == TLOOK && (t_look(fd) == T_ORDREL)) { if(t_rcvrel(fd) == -1) { t_error("t_rcvrel failed"); exit(6); } if (t_sndrel(fd) == -1) { t_error("t_sndrel failed"); exit(7); } t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); } } client-nogui.c Page 6 void receive_mesg(widget_table *widtblinst, int *source, XtInputId *id) { Tt_message incoming; String buttlabel; incoming = tt_message_receive(); if (incoming == NULL) return; if (strcmp("ATMSTARTUP", tt_message_op(incoming)) == 0) { XtVaGetValues(widtblinst->butt_auto, XtNlabel, &buttlabel, NULL); if(strcmp(buttlabel, "Stop") != 0) { XtVaSetValues(widtblinst->butt_auto, XtNlabel, "Stop", NULL); init_client_data(); widtblinst->work_proc_id = XtAppAddWorkProc(context, (XtWorkProc)auto_proc, widtblinst); } } else if (strcmp("ATMSTOP", tt_message_op(incoming)) == 0) { XtVaGetValues(widtblinst->butt_auto, XtNlabel, &buttlabel, NULL); if(strcmp(buttlabel, "Auto") != 0) { XtVaSetValues(widtblinst->butt_auto, XtNlabel, "Auto", NULL); XtRemoveWorkProc(widtblinst->work_proc_id); init_client_data(); } } tt_message_destroy(incoming); if (widtblinst->onceonly) { strcpy((char *)cltreq.client_id, data.client_id); widtblinst->onceonly = 0; } } void auto_callback(Widget w, XtPointer client_data, XtPointer call_data) { widget_table *widtblinst = (widget_table *)client_data; String buttlabel; Tt_message outgoing; XtVaGetValues(w, XtNlabel, &buttlabel, NULL); if(strcmp(buttlabel, "Auto") == 0) { XtVaSetValues(w, client-nogui.c Page 7 XtNlabel, "Stop", XtNset, False, NULL); init_client_data(); outgoing = tt_message_create(); tt_message_class_set(outgoing, TT_NOTICE); tt_message_scope_set(outgoing, TT_SESSION); tt_message_session_set(outgoing, widtblinst->session); tt_message_op_set(outgoing, "ATMSTARTUP"); tt_message_send(outgoing); tt_message_destroy(outgoing); widtblinst->work_proc_id = XtAppAddWorkProc(context, (XtWorkProc)auto_proc, widtblinst); } else { XtVaSetValues(w, XtNlabel, "Auto", XtNset, False, NULL); XtRemoveWorkProc(widtblinst->work_proc_id); outgoing = tt_message_create(); tt_message_class_set(outgoing, TT_NOTICE); tt_message_scope_set(outgoing, TT_SESSION); tt_message_session_set(outgoing, widtblinst->session); tt_message_op_set(outgoing, "ATMSTOP"); tt_message_send(outgoing); tt_message_destroy(outgoing); init_client_data(); } if (widtblinst->onceonly) { strcpy((char *)cltreq.client_id, data.client_id); widtblinst->onceonly = 0; } } Boolean auto_proc(widget_table *widtblinst) { cltreq.req_type = (rand()&1100) % 3; if (cltreq.req_type != BALANCE) cltreq.data = 200; make_server_request(widtblinst); init_client_data(); display_data(widtblinst); return False; } void display_data(widget_table *widtblinst) client-nogui.c Page 8 { char temp[20]; int fd, flags; int nbytes; extern int t_errno; struct t_call *sndcall; client_display cltdisp; #ifdef DEBUG printf ("entered display_data \n"); #endif if ((fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) { t_error("t_open failed"); exit(11); } if (t_bind(fd, (struct t_bind *)NULL, (struct t_bind *) NULL) == -1) { t_error("t_bind failed"); exit(12); } if((sndcall = (struct t_call *) t_alloc(fd, T_CALL, 0)) == (struct t_call *) NULL) { t_error ("t_alloc failed"); exit(13); } sndcall->addr.maxlen = widtblinst->addr1->maxlen; sndcall->addr.len = widtblinst->addr1->len; sndcall->addr.buf = widtblinst->addr1->buf; if (t_connect(fd, sndcall, (struct t_call *)NULL) == -1) { t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); display_data(widtblinst); } if (widtblinst->resetval == 0) cltdisp.atm_id = widtblinst->atm_id; else cltdisp.atm_id = -1; if(t_snd(fd, (char *)&cltdisp, sizeof(client_display), 0) == -1) { t_error("t_snd failed"); exit(15); } while((nbytes = t_rcv(fd, temp, 20, &flags)) != -1); if (t_errno == TLOOK && (t_look(fd) == T_ORDREL)) { if(t_rcvrel(fd) == -1) { t_error("t_rcvrel failed"); exit(16); } if (t_sndrel(fd) == -1) client-nogui.c Page 9 { t_error("t_sndrel failed"); exit(17); } } t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); } client.c Page 1 #include "client.h" #include "sunraster.h" /* GLOBAL Var Declaration */ client_request cltreq; ApplicationData data; XtAppContext context; Display *display; GC gc; String fallback_resources[] = { "*resizeCorners: False", "*title: Automatic Teller Machine", "*bb.layoutType: maximize", "*bb.width: 275", "*bb.height: 318", "*loginst.background: black", "*loginst.foreground: white", "*loginst.fontColor: white", "*loginst.font: Times-bold-19", "*loginst.x: 83", "*loginst.y: 80", "*loginst.string: Login", "*loginst.width: 104", "*loginst.recomputeSize: False", "*passwdst.background: black", "*passwdst.foreground: white", "*passwdst.fontColor: white", "*passwdst.font: Times-bold-19", "*passwdst.x: 83", "*passwdst.y: 100", "*passwdst.string: Passwd", "*passwdst.width: 104", "*passwdst.recomputeSize: False", "*excl_auto.noneSet: TRUE", "*excl_auto.x: 232", "*excl_auto.y: 295", "*butt_auto.x: 232", "*butt_auto.y: 295", NULL }; main(int argc, char **argv) { String classname = "Mtclient"; widget_table widtblinst; char temp[50]; XImage *ximage; Pixmap atmpix; widtblinst.onceonly = 1; widtblinst.resetval = 0; OlToolkitInitialize(NULL); widtblinst.toplevel = XtVaAppInitialize(&context, classname, (XrmOptionDescList)options, client.c Page 2 XtNumber(options), (Cardinal *)&argc, argv, (const char **)fallback_resources, 0); display = XtDisplay(widtblinst.toplevel); gc = DefaultGC(display, 0); XtGetApplicationResources(widtblinst.toplevel, &data, resources, XtNumber(resources), NULL, 0); widtblinst.srv_addr = atoi(data.opt_port); widtblinst.srv_addr1 = atoi(data.opt_port1); widtblinst.atm_id = atoi(data.atm_id); if (widtblinst.atm_id == -1) { usage(); exit(1); } if(strcmp(data.client_id, "\0") == 0) { usage(); exit(1); } widtblinst.bb = XtVaCreateManagedWidget("bb", bulletinBoardWidgetClass, widtblinst.toplevel, NULL); widtblinst.loginst = XtVaCreateManagedWidget("loginst", staticTextWidgetClass, widtblinst.bb, NULL); widtblinst.passwdst = XtVaCreateManagedWidget("passwdst", staticTextWidgetClass, widtblinst.bb, NULL); widtblinst.excl_auto = XtVaCreateManagedWidget("excl_auto", exclusivesWidgetClass, widtblinst.bb, NULL); widtblinst.butt_auto = XtVaCreateManagedWidget("Auto", rectButtonWidgetClass, widtblinst.excl_auto, NULL); if(widtblinst.atm_id == 1) widtblinst.START1 = OlInternAtom(display, "ATM1"); if(widtblinst.atm_id == 2) widtblinst.START2 = OlInternAtom(display, "ATM2"); XtAddCallback(widtblinst.butt_auto, XtNselect, auto_callback, &widtblinst); XtRealizeWidget (widtblinst.toplevel); ReadSunRasterToImage(display, "../packaging/atm_mt.rf", &ximage); if(ximage->depth != 8) client.c Page 3 { printf("client: can only support 8 bit color display\n"); exit(1); } atmpix = XCreatePixmap(display, XtWindow(widtblinst.toplevel), ximage->width, ximage->height, ximage->depth); XPutImage(display, atmpix, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); XDestroyImage(ximage); XtVaSetValues(widtblinst.bb, XtNbackgroundPixmap, atmpix, NULL); init_client_data(); cltreq.client_id[0] = '\0'; make_server_address(&widtblinst); init_tt(&widtblinst); XtAppMainLoop(context); exit(0); } void init_tt(widget_table *widtblinst) { Tt_pattern pat; char *procid; int ttfd; widtblinst->session = tt_X_session(DisplayString(display)); tt_default_session_set(widtblinst->session); procid = tt_open(); ttfd = tt_fd(); pat = tt_pattern_create(); tt_pattern_category_set(pat, TT_OBSERVE); tt_pattern_scope_add(pat, TT_SESSION); tt_pattern_session_add(pat, widtblinst->session); tt_pattern_op_add(pat, "ATMSTARTUP"); tt_pattern_register(pat); pat = tt_pattern_create(); tt_pattern_category_set(pat, TT_OBSERVE); tt_pattern_scope_add(pat, TT_SESSION); tt_pattern_session_add(pat, widtblinst->session); tt_pattern_op_add(pat, "ATMSTOP"); tt_pattern_register(pat); tt_session_join(widtblinst->session); XtAppAddInput(context, ttfd, (XtPointer)XtInputReadMask, (XtInputCallbackProc)receive_mesg, (XtPointer)widtblinst); } void usage() { fprintf(stderr, "To Run The ATM Client:\n"); client.c Page 4 fprintf(stderr, "client -atmNumber # [-serverHostName -optionalPort # -optionalPortDisp #]\n"); fprintf(stderr, "where:\n"); fprintf(stderr, "- serverHostName is hostname of server if different from client\n"); fprintf(stderr, "- optionalPort is port number where you would like client to bind\n"); fprintf(stderr, " with request server\n"); fprintf(stderr, "- optionalPortDisp is port number where you would like client to\n"); fprintf(stderr, " bind with display server\n"); fprintf(stderr, "NOTE: optionalPort and optionalPortDisp are for people who know\n"); fprintf(stderr, " the internal working of the program...\n"); } void init_client_data() { cltreq.data = -1; cltreq.req_type = -1; cltreq.ret_val = -1; } void make_server_address(widget_table *widtblinst) { struct hostent *host; struct utsname name; struct netconfig *netconf; char abyte[MAXSTR]; char uaddr[MAXSTR], hostaddr[MAXSTR]; int i; #ifdef DEBUG printf("entered make_server_address\n"); printf("the server hostname is %s\n", data.serv_hostname); #endif if(strcmp(data.serv_hostname, "local") == 0) { uname(&name); host = gethostbyname(name.nodename); } else { host = gethostbyname(data.serv_hostname); } if (host == NULL) { strcpy(hostaddr, "127.0.0.1"); fprintf(stderr, "Host \"%s\" not found, using localhost.\n", data.serv_hostname); } else { hostaddr[0] = '\0'; for(i = 0; i < host->h_length; i++) { sprintf(abyte, "%d", (unsigned char)host->h_addr_list[0][i]); client.c Page 5 strcat(hostaddr, abyte); if (i < host->h_length - 1) strcat(hostaddr, "."); } } if(widtblinst->srv_addr == -1) sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + widtblinst->srv_addr, 1); #ifdef DEBUG printf("the official hostname is %s\n", host->h_name); printf("the uaddr we created is %s\n", uaddr); #endif netconf = getnetconfigent(TRANSPORT_NETCONFID); widtblinst->addr = uaddr2taddr(netconf, uaddr); if(widtblinst->srv_addr1 == -1) sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR1, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + widtblinst->srv_addr1, 1); widtblinst->addr1 = uaddr2taddr(netconf, uaddr); freenetconfigent(netconf); } void make_server_request(widget_table *widtblinst) { char temp[20]; int fd, flags; int nbytes; extern int t_errno; struct t_call *sndcall; client_request getcltreq; #ifdef DEBUG printf ("entered make_server_request \n"); printf ("request type is %d\n", cltreq.req_type); if (cltreq.req_type != BALANCE) printf ("data is %d \n", cltreq.data); printf ("now requesting from server...\n"); #endif if ((fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) { t_error("t_open failed"); exit(1); } if (t_bind(fd, (struct t_bind *)NULL, (struct t_bind *) NULL) == -1) { t_error("t_bind failed"); exit(2); } if((sndcall = (struct t_call *) t_alloc(fd, T_CALL, 0)) == (struct t_call *) NULL) { t_error ("t_alloc failed"); exit(3); client.c Page 6 } sndcall->addr.maxlen = widtblinst->addr->maxlen; sndcall->addr.len = widtblinst->addr->len; sndcall->addr.buf = widtblinst->addr->buf; if (t_connect(fd, sndcall, (struct t_call *)NULL) == -1) { t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); make_server_request(widtblinst); } if(t_snd(fd, (char *)&cltreq, sizeof(client_request), 0) == -1) { t_error("t_snd failed"); exit(5); } nbytes = t_rcv(fd, (char *)&getcltreq, sizeof(client_request), &flags); if(getcltreq.ret_val != -1) { if (cltreq.req_type == BALANCE) { XtVaSetValues(widtblinst->loginst, XtNstring, STRING6, NULL); sprintf(temp, "%d", getcltreq.ret_val); XtVaSetValues(widtblinst->passwdst, XtNstring, temp, NULL); } if (cltreq.req_type == DEPOSIT) { XtVaSetValues(widtblinst->loginst, XtNstring, STRING8, NULL); sprintf(temp, "%d", getcltreq.ret_val); XtVaSetValues(widtblinst->passwdst, XtNstring, temp, NULL); } if (cltreq.req_type == WITHDRAW) { XtVaSetValues(widtblinst->loginst, XtNstring, STRING7, NULL); sprintf(temp, "%d", getcltreq.ret_val); XtVaSetValues(widtblinst->passwdst, XtNstring, temp, NULL); } } else { fprintf(stderr, "received incorrect data from server\n"); exit(11); } while((nbytes = t_rcv(fd, temp, 20, &flags)) != -1); if (t_errno == TLOOK && (t_look(fd) == T_ORDREL)) { if(t_rcvrel(fd) == -1) { t_error("t_rcvrel failed"); exit(6); } if (t_sndrel(fd) == -1) client.c Page 7 { t_error("t_sndrel failed"); exit(7); } t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); } } void receive_mesg(widget_table *widtblinst, int *source, XtInputId *id) { Tt_message incoming; String buttlabel; int i; int propdata; incoming = tt_message_receive(); if (incoming == NULL) return; if (strcmp("ATMSTARTUP", tt_message_op(incoming)) == 0) { XtVaGetValues(widtblinst->butt_auto, XtNlabel, &buttlabel, NULL); if(strcmp(buttlabel, "Stop") != 0) { XtVaSetValues(widtblinst->butt_auto, XtNlabel, "Stop", NULL); init_client_data(); widtblinst->work_proc_id = XtAppAddWorkProc(context, (XtWorkProc)auto_proc, widtblinst); propdata = 1; if (widtblinst->atm_id == 1) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START1, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } if (widtblinst->atm_id == 2) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START2, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } } } else if (strcmp("ATMSTOP", tt_message_op(incoming)) == 0) client.c Page 8 { XtVaGetValues(widtblinst->butt_auto, XtNlabel, &buttlabel, NULL); if(strcmp(buttlabel, "Auto") != 0) { XtVaSetValues(widtblinst->butt_auto, XtNlabel, "Auto", NULL); XtVaSetValues(widtblinst->loginst, XtNstring, STRING1, NULL); XtVaSetValues(widtblinst->passwdst, XtNstring, "000", NULL); XtRemoveWorkProc(widtblinst->work_proc_id); propdata = 0; if (widtblinst->atm_id == 1) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START1, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } if (widtblinst->atm_id == 2) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START2, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } init_client_data(); widtblinst->resetval = 1; display_data(widtblinst); widtblinst->resetval = 0; } } tt_message_destroy(incoming); if (widtblinst->onceonly) { strcpy((char *)cltreq.client_id, data.client_id); XtVaSetValues(widtblinst->loginst, XtNstring, STRING1, NULL); XtVaSetValues(widtblinst->passwdst, XtNstring, "000", NULL); widtblinst->onceonly = 0; } } void auto_callback(Widget w, XtPointer client_data, XtPointer call_data) { widget_table *widtblinst = (widget_table *)client_data; String buttlabel; int i; int propdata; Tt_message outgoing; XtVaGetValues(w, XtNlabel, &buttlabel, NULL); client.c Page 9 if(strcmp(buttlabel, "Auto") == 0) { XtVaSetValues(w, XtNlabel, "Stop", XtNset, False, NULL); init_client_data(); outgoing = tt_message_create(); tt_message_class_set(outgoing, TT_NOTICE); tt_message_scope_set(outgoing, TT_SESSION); tt_message_session_set(outgoing, widtblinst->session); tt_message_op_set(outgoing, "ATMSTARTUP"); tt_message_send(outgoing); tt_message_destroy(outgoing); widtblinst->work_proc_id = XtAppAddWorkProc(context, (XtWorkProc)auto_proc, widtblinst); propdata = 1; if (widtblinst->atm_id == 1) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START1, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } if (widtblinst->atm_id == 2) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START2, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } } else { XtVaSetValues(w, XtNlabel, "Auto", XtNset, False, NULL); XtVaSetValues(widtblinst->loginst, XtNstring, STRING1, NULL); XtVaSetValues(widtblinst->passwdst, XtNstring, "000", NULL); XtRemoveWorkProc(widtblinst->work_proc_id); outgoing = tt_message_create(); tt_message_class_set(outgoing, TT_NOTICE); tt_message_scope_set(outgoing, TT_SESSION); tt_message_session_set(outgoing, widtblinst->session); tt_message_op_set(outgoing, "ATMSTOP"); tt_message_send(outgoing); tt_message_destroy(outgoing); propdata = 0; if (widtblinst->atm_id == 1) client.c Page 10 { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START1, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } if (widtblinst->atm_id == 2) { XChangeProperty(display, DefaultRootWindow(display), widtblinst->START2, XA_INTEGER, 32, PropModeReplace, (unsigned char *)&propdata, 1); } init_client_data(); widtblinst->resetval = 1; display_data(widtblinst); widtblinst->resetval = 0; } if (widtblinst->onceonly) { strcpy((char *)cltreq.client_id, data.client_id); XtVaSetValues(widtblinst->loginst, XtNstring, STRING1, NULL); XtVaSetValues(widtblinst->passwdst, XtNstring, "000", NULL); widtblinst->onceonly = 0; } } Boolean auto_proc(widget_table *widtblinst) { cltreq.req_type = (rand()&1100) % 3; if (cltreq.req_type != BALANCE) cltreq.data = 200; make_server_request(widtblinst); init_client_data(); display_data(widtblinst); return False; } void display_data(widget_table *widtblinst) { char temp[20]; int fd, flags; int nbytes; extern int t_errno; struct t_call *sndcall; client_display cltdisp; #ifdef DEBUG printf ("entered display_data \n"); #endif if ((fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) client.c Page 11 { t_error("t_open failed"); exit(11); } if (t_bind(fd, (struct t_bind *)NULL, (struct t_bind *) NULL) == -1) { t_error("t_bind failed"); exit(12); } if((sndcall = (struct t_call *) t_alloc(fd, T_CALL, 0)) == (struct t_call *) NULL) { t_error ("t_alloc failed"); exit(13); } sndcall->addr.maxlen = widtblinst->addr1->maxlen; sndcall->addr.len = widtblinst->addr1->len; sndcall->addr.buf = widtblinst->addr1->buf; if (t_connect(fd, sndcall, (struct t_call *)NULL) == -1) { t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); display_data(widtblinst); } if (widtblinst->resetval == 0) cltdisp.atm_id = widtblinst->atm_id; else cltdisp.atm_id = -1; if(t_snd(fd, (char *)&cltdisp, sizeof(client_display), 0) == -1) { t_error("t_snd failed"); exit(15); } while((nbytes = t_rcv(fd, temp, 20, &flags)) != -1); if (t_errno == TLOOK && (t_look(fd) == T_ORDREL)) { if(t_rcvrel(fd) == -1) { t_error("t_rcvrel failed"); exit(16); } if (t_sndrel(fd) == -1) { t_error("t_sndrel failed"); exit(17); } } t_close(fd); sndcall->addr.buf = NULL; t_free((char *)sndcall, T_CALL); } dispserver.c Page 1 #include "dispserver.h" /* Global Var Declarations */ int conn_fd; int gui_fd[2]; main(int argc, char **argv) { int listen_fd; struct t_call *call; struct t_bind *bind; struct t_unitdata *ud; struct netconfig *netconf; struct netbuf *addr; struct utsname name; struct hostent *host; char uaddr[MAXSTR], hostaddr[MAXSTR]; char abyte[MAXSTR]; struct sigaction act, oact; int i, pid; int srv_addr; struct t_optmgmt req, resp; struct opthdr *opt; char reqbuf[100]; char respbuf[100]; long optval = 1; #ifdef DEBUG printf ("in main routine \n"); #endif if (argc > 1) srv_addr = atoi(argv[1]); else srv_addr = -1; if(pipe(gui_fd) < 0) { perror("pipe"); exit(1); } if((pid = fork()) < 0) { perror("fork failed"); exit(1); } else if(pid > 0) { close(gui_fd[0]); } else { close(gui_fd[1]); create_gui(argc, argv, gui_fd[0]); } dispserver.c Page 2 uname(&name); host = gethostbyname(name.nodename); if (host == NULL) { strcpy(hostaddr, "127.0.0.1"); fprintf(stderr, "Host \"%s\" not found, using localhost.\n", name.nodename); } else { hostaddr[0] = '\0'; for(i = 0; i < host->h_length; i++) { sprintf(abyte, "%d", (unsigned char)host->h_addr_list[0][i]); strcat(hostaddr, abyte); if (i < host->h_length - 1) strcat(hostaddr, "."); } } if (srv_addr == -1) sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR1, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + srv_addr, 1); #ifdef DEBUG printf("the address is %s\n", uaddr); #endif netconf = getnetconfigent(TRANSPORT_NETCONFID); addr = uaddr2taddr(netconf, uaddr); freenetconfigent(netconf); act.sa_handler = SIG_IGN; act.sa_flags = SA_NOCLDWAIT; if(sigaction(SIGCHLD, &act, &oact) < 0) { perror("sigaction"); exit(1); } if ((listen_fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) { t_error("t_open failed for listen_fd"); exit(1); } if ((bind = (struct t_bind *)t_alloc(listen_fd, T_BIND, T_ADDR)) == (struct t_bind *) NULL) { t_error("t_alloc of t_bind structure failed"); exit(2); } bind->addr.maxlen = addr->maxlen; bind->addr.len = addr->len; bind->addr.buf = addr->buf; bind->qlen = 1; req.opt.len = OPTLEN(sizeof(struct opthdr)+sizeof(long)); dispserver.c Page 3 req.opt.maxlen = sizeof(reqbuf); req.opt.buf = reqbuf; resp.opt.len = 0; resp.opt.maxlen = sizeof(respbuf); resp.opt.buf = respbuf; req.flags = T_NEGOTIATE; resp.flags = 0; opt = (struct opthdr *)reqbuf; opt->level = SOL_SOCKET; opt->name = SO_REUSEADDR; opt->len = OPTLEN(sizeof(long)); memcpy((char *)&opt[1], (char *)&optval, opt->len); req.opt.len = sizeof(*opt) + opt->len; if(t_optmgmt(listen_fd, &req, &resp) < 0) { t_error("t_optmgmt"); exit(13); } if (t_bind(listen_fd, bind, bind) < 0) { t_error("t_bind failed for listen_f"); exit(3); } if ((call = (struct t_call *) t_alloc( listen_fd, T_CALL, T_ALL)) == (struct t_call *) NULL) { t_error ("t_alloc of t_call structure failed"); exit (5); } while (1) { again1: if( t_listen(listen_fd, call) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again1; t_error("t_listen failed for listen_fd"); exit(6); } if ((conn_fd = accept_call(listen_fd, call)) != -1) { run_server(listen_fd); } } } int accept_call(int listen_fd, struct t_call *call) { int resfd; extern int t_errno; dispserver.c Page 4 #ifdef DEBUG printf ("in accept_call routine \n"); #endif again2: if ((resfd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *)NULL)) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again2; t_error("t_open for responding fd failed"); exit (7); } again3: if (t_bind(resfd, (struct t_bind *)NULL, (struct t_bind *)NULL) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again3; t_error("t_bind for responding fd failed"); exit (8); } again4: if (t_accept(listen_fd, resfd, call) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again4; if (t_errno == TLOOK) { if (t_rcvdis(listen_fd, (struct t_discon *)NULL) == -1) { t_error("t_rcvdis failed for listen_fd"); exit(9); } if (t_close(resfd) < 0) { t_error("t_close failed for responding fd"); exit (10); } return (-1); } t_error("t_accept failed"); exit (11); } return (resfd); } void connrelease() { #ifdef DEBUG printf ("in connrelease routine \n"); #endif exit (0); dispserver.c Page 5 } void run_server(int listen_fd) { int nbytes; int flags; int pipe_fd[2]; client_display cltdisp, cltdisp1; #ifdef DEBUG printf ("in run_server routine \n"); #endif if(pipe(pipe_fd) < 0) { perror("pipe"); exit(31); } switch (fork()) { case -1: perror("fork failed"); exit(20); default: if( t_close(conn_fd) == -1) { t_error( "t_close failed for conn_fd" ); exit(21); } close(pipe_fd[1]); read(pipe_fd[0], (char *)&cltdisp1, sizeof(client_display)); #ifdef DEBUG printf("Parent Read: atm_id %d", cltdisp1.atm_id); #endif write(gui_fd[1], (char *)&cltdisp1, sizeof(client_display)); close(pipe_fd[0]); return; case 0: if (t_close( listen_fd) == -1) { t_error( "t_close failed for listen_fd" ); exit(22); } close(pipe_fd[0]); nbytes = t_rcv(conn_fd, (char *)&cltdisp, sizeof(client_display), &flags); signal(SIGPOLL, (void (*)())connrelease); if (ioctl(conn_fd, I_SETSIG, S_INPUT) == -1) { perror("ioctl I_SETSIG failed"); exit (24); } dispserver.c Page 6 if (t_look(conn_fd) != 0) { fprintf(stderr, "t_look: unexpected event"); exit(25); } write(pipe_fd[1], (char *)&cltdisp, sizeof(client_display)); if(t_sndrel(conn_fd) == -1) { t_error("t_sendrel failed"); exit(27); } pause(); exit(0); } } void create_gui(int argc, char **argv, int fd) { String classname = "Dispserver"; widget_table widtblinst; String fallback_resources[] = { "*resizeCorners: False", "*title: Display Server", "*control.width: 450", "*control.height: 200", "*control.center:True", "*control.layoutType: fixedcols", "*control.measure: 1", "*control.borderWidth: 2", "*Mainlabel.font: Times-bold-24", "*Mainlabel.string: Old UnixProcess ATM Server", "*Mainlabel.recomputeSize: False", "*Mainlabel.width: 450", "*Totallabel.font: Times-bold-24", "*Totallabel.string: Total ATM Transactions", "*Totallabel.recomputeSize: False", "*Totallabel.width: 450", "*Totalcounter.font: Times-bold-96", "*Totalcounter.string: 00000", NULL }; widtblinst.total = 0; OlToolkitInitialize((XtPointer)NULL); widtblinst.toplevel = XtVaAppInitialize(&widtblinst.context, classname, (XrmOptionDescList)NULL, 0, (Cardinal *)&argc, argv, (const char **)fallback_resources, 0); widtblinst.ca = XtVaCreateManagedWidget("control", controlAreaWidgetClass, widtblinst.toplevel, NULL); dispserver.c Page 7 widtblinst.labst1 = XtVaCreateManagedWidget("Mainlabel", staticTextWidgetClass, widtblinst.ca, NULL); widtblinst.labst = XtVaCreateManagedWidget("Totallabel", staticTextWidgetClass, widtblinst.ca, NULL); widtblinst.st = XtVaCreateManagedWidget("Totalcounter", staticTextWidgetClass, widtblinst.ca, NULL); XtAppAddInput(widtblinst.context, fd, (XtPointer)XtInputReadMask, (XtInputCallbackProc)update_data, &widtblinst); XtRealizeWidget(widtblinst.toplevel); XtAppMainLoop(widtblinst.context); } void update_data(widget_table *widtblinst, int *source, XtInputId *id) { client_display cltdisp; char setvalue[10]; read(gui_fd[0], (char *)&cltdisp, sizeof(client_display)); if (cltdisp.atm_id == -1) { widtblinst->total = 0; sprintf(setvalue, "00000"); } else { widtblinst->total++; sprintf(setvalue, "%d", widtblinst->total); } XtVaSetValues(widtblinst->st, XtNstring, setvalue, NULL); XFlush(XtDisplay(widtblinst->toplevel)); } list.c Page 1 #include "list.h" list list_init () { list ptr; ptr = (list) malloc (sizeof (struct list_struct)); ptr->head = NULL; ptr->tail = NULL; ptr->current = NULL; return ptr; } void list_insert (list ptr, char *chose) { struct list_node *temp; struct list_node *p; p = (struct list_node *) malloc (sizeof (struct list_node)); p -> info = chose; p -> next = NULL; p -> previous = NULL; if (ptr->tail == NULL) { ptr->tail = p; ptr->head = p; ptr->current = ptr->head; } else { temp = ptr -> tail; ptr -> tail -> next = p; ptr -> tail = ptr -> tail -> next; ptr -> tail -> previous = temp; } } char * list_retrieve(list ptr, int direction) { struct list_node *temp; if (ptr == NULL || ptr->current == NULL) { return NULL; } temp = ptr -> current; if (direction == FORWARD) { ptr->current = ptr -> current -> next; } else { ptr -> current = ptr -> current -> previous; list.c Page 2 } return(temp -> info); } void list_reset (list ptr) { if (ptr != NULL) { ptr -> current = ptr -> head; } } void list_delete (list ptr) { struct list_node *temp; list_reset(ptr); while (ptr->current != NULL) { temp = ptr->current; ptr->current = ptr->current->next; free(temp); } } populate.c Page 1 #include #include #include #include #include "data.h" typedef unsigned int Cardinal; #define XtNumber(arr) ((Cardinal) (sizeof(arr) / sizeof(arr[0]))) main(int argc, char **argv) { char *name_list[] = { "John", "Kim", "Bob", "Brian", "Guang", "Mike", "Laura", "Rick", "Alok", "Mary", "Lynn", "Marty", "May", "Tim", "Mark", "Claudia", "Gordon", "Robert", "Marilyn", "Leona", "Robert", "Susan", "Stephanie", "Theresa", "Ian", "Yutaka", "Harry", "Katy", "Jack", "Walter", "Carol", "Rosemary", "Mike", "Tammy", "Greg", "Dianna", "Alden", "Ole", "Mike", "Janice", "Omer", "Emmanuel", "Michael", "Balint", "Denise", populate.c Page 2 "Simon", "Chris", "Kevin", "Albert", "Joseph", "Paul", "Nancy", "Peter", "Charles", "Garth", "Tony", "Chung", "Ayeola", "Andrew", "Shari", "Jim", "Terri", "Dixie", "Dhaval", "Daryl", "Norman", "Fred", "Sidney", "Sam", "Ken", "Sunny" }; ldata data_record; int i; int fd; fd = open("./ATMRECORDS", O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); for (i = 0; i < XtNumber(name_list); i++) { strcpy(data_record.client_name, name_list[i]); data_record.client_passwd[0] = '\0'; data_record.client_money = 20000; write(fd, (const void *)&data_record, sizeof(struct list_data)); } close(fd); } reader.c Page 1 #include #include #include #include "data.h" main(int argc, char **argv) { ldata data_record; int i, retval; int fd; fd = open("./ATMRECORDS", O_RDONLY); while((retval = read(fd, &data_record, sizeof(struct list_data))) != 0) { printf("Name: %s, Passwd: %s, Money: %d\n", data_record.client_name, data_record.client_passwd, data_record.client_money); } close(fd); } server.c Page 1 #include "list.h" #include "server.h" #include "data.h" /* Global Var Declarations */ int conn_fd; main(int argc, char **argv) { int listen_fd; struct t_call *call; struct t_bind *bind; struct t_unitdata *ud; struct netconfig *netconf; struct netbuf *addr; struct utsname name; struct hostent *host; char uaddr[MAXSTR], hostaddr[MAXSTR]; char abyte[MAXSTR]; struct sigaction act, oact; int i; int srv_addr; struct t_optmgmt req, resp; struct opthdr *opt; char reqbuf[100]; char respbuf[100]; long optval = 1; #ifdef DEBUG printf ("in main routine \n"); #endif if (argc > 1) srv_addr = atoi(argv[1]); else srv_addr = -1; uname(&name); host = gethostbyname(name.nodename); if (host == NULL) { strcpy(hostaddr, "127.0.0.1"); fprintf(stderr, "Host \"%s\" not found, using localhost.\n", name.nodename); } else { hostaddr[0] = '\0'; for(i = 0; i < host->h_length; i++) { sprintf(abyte, "%d", (unsigned char)host->h_addr_list[0][i]); strcat(hostaddr, abyte); if (i < host->h_length - 1) strcat(hostaddr, "."); } } if (srv_addr == -1) server.c Page 2 sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + SRV_ADDR, 1); else sprintf(uaddr, "%s.%d.%d", hostaddr, 60 + srv_addr, 1); #ifdef DEBUG printf("the address is %s\n", uaddr); #endif netconf = getnetconfigent(TRANSPORT_NETCONFID); addr = uaddr2taddr(netconf, uaddr); freenetconfigent(netconf); act.sa_handler = SIG_IGN; act.sa_flags = SA_NOCLDWAIT; if(sigaction(SIGCHLD, &act, &oact) < 0) { perror("sigaction"); exit(1); } if ((listen_fd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *) NULL)) == -1) { t_error("t_open failed for listen_fd"); exit(1); } if ((bind = (struct t_bind *)t_alloc(listen_fd, T_BIND, T_ADDR)) == (struct t_bind *) NULL) { t_error("t_alloc of t_bind structure failed"); exit(2); } bind->addr.maxlen = addr->maxlen; bind->addr.len = addr->len; bind->addr.buf = addr->buf; bind->qlen = 1; req.opt.len = OPTLEN(sizeof(struct opthdr)+sizeof(long)); req.opt.maxlen = sizeof(reqbuf); req.opt.buf = reqbuf; resp.opt.len = 0; resp.opt.maxlen = sizeof(respbuf); resp.opt.buf = respbuf; req.flags = T_NEGOTIATE; resp.flags = 0; opt = (struct opthdr *)reqbuf; opt->level = SOL_SOCKET; opt->name = SO_REUSEADDR; opt->len = OPTLEN(sizeof(long)); memcpy((char *)&opt[1], (char *)&optval, opt->len); req.opt.len = sizeof(*opt) + opt->len; if(t_optmgmt(listen_fd, &req, &resp) < 0) { t_error("t_optmgmt"); exit(13); } server.c Page 3 if (t_bind(listen_fd, bind, bind) < 0) { t_error("t_bind failed for listen_f"); exit(3); } if ((call = (struct t_call *) t_alloc( listen_fd, T_CALL, T_ALL)) == (struct t_call *) NULL) { t_error ("t_alloc of t_call structure failed"); exit (5); } while (1) { again: if( t_listen(listen_fd, call) == -1) { extern int t_errno, errno; if(t_errno = TSYSERR && errno == EINTR) goto again; t_error("t_listen failed for listen_fd"); exit(6); } if ((conn_fd = accept_call(listen_fd, call)) != -1) { run_server(listen_fd); } } } int accept_call(int listen_fd, struct t_call *call) { int resfd; extern int t_errno; #ifdef DEBUG printf ("in accept_call routine \n"); #endif again2: if ((resfd = t_open(TRANSPORT_DEV, O_RDWR, (struct t_info *)NULL)) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again2; t_error("t_open for responding fd failed"); exit (7); } again3: if (t_bind(resfd, (struct t_bind *)NULL, (struct t_bind *)NULL) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again3; server.c Page 4 t_error("t_bind for responding fd failed"); exit (8); } again4: if (t_accept(listen_fd, resfd, call) == -1) { extern int t_errno, errno; if(t_errno == TSYSERR && errno == EINTR) goto again4; if (t_errno == TLOOK) { if (t_rcvdis(listen_fd, (struct t_discon *)NULL) == -1) { t_error("t_rcvdis failed for listen_fd"); exit(9); } if (t_close(resfd) < 0) { t_error("t_close failed for responding fd"); exit (10); } return (-1); } t_error("t_accept failed"); exit (11); } return (resfd); } void connrelease() { #ifdef DEBUG printf ("in connrelease routine \n"); #endif exit (0); } void run_server(int listen_fd) { int nbytes; int flags; client_request getcltdata; #ifdef DEBUG printf ("in run_server routine \n"); #endif switch (fork()) { case -1: perror("fork failed"); exit(20); default: if( t_close(conn_fd) == -1) { server.c Page 5 t_error( "t_close failed for conn_fd" ); exit(21); } return; case 0: if (t_close( listen_fd) == -1) { t_error( "t_close failed for listen_fd" ); exit(22); } nbytes = t_rcv(conn_fd, (char *)&getcltdata, sizeof(client_request), &flags); update_database(&getcltdata); signal(SIGPOLL, (void (*)())connrelease); if (ioctl(conn_fd, I_SETSIG, S_INPUT) == -1) { perror("ioctl I_SETSIG failed"); exit (24); } if (t_look(conn_fd) != 0) { fprintf(stderr, "t_look: unexpected event"); exit(25); } if(t_snd(conn_fd, (char *)&getcltdata, sizeof(client_request), 0) == -1) { t_error("t_snd failed"); exit(26); } if(t_sndrel(conn_fd) == -1) { t_error("t_sendrel failed"); exit(27); } pause(); exit(0); } } void update_database(client_request *cltdata) { int retval; ldataptr data_record; struct flock lock; list rlist = list_init(); int fd = open ("./ATMRECORDS", O_RDONLY); lock.l_type = F_RDLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(fd, F_SETLKW, &lock); #ifdef DEBUG server.c Page 6 printf ("in update_database routine \n"); printf ("the client information I got is:\n"); printf ("name = %s, passwd = %s, request = %d, data = %d, ret_val = %d\n", cltdata->client_id, cltdata->passwd_id, cltdata->req_type, cltdata->data, cltdata->ret_val); #endif data_record = (ldataptr)malloc(sizeof(ldata)); while((retval = read(fd, (char *)data_record, sizeof(struct list_data))) != 0) { if(strcmp(data_record->client_name, cltdata->client_id) == 0) { if (cltdata->req_type == BALANCE) { cltdata->ret_val = data_record->client_money; } else if(cltdata->req_type == DEPOSIT) { data_record->client_money = data_record->client_money + cltdata->data; cltdata->ret_val = data_record->client_money; } else if(cltdata->req_type == WITHDRAW) { data_record->client_money = data_record->client_money - cltdata->data; cltdata->ret_val = data_record->client_money; } } #ifdef DEBUG printf("inserting %s %d\n",data_record->client_name, data_record->client_money); #endif list_insert(rlist, (char *)data_record); data_record = (ldataptr)malloc(sizeof(ldata)); } if(cltdata->req_type != BALANCE) { lock.l_type = F_UNLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(fd, F_SETLKW, &lock); close(fd); fd = open ("./ATMRECORDS", O_WRONLY); lock.l_type = F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(fd, F_SETLKW, &lock); list_reset(rlist); while((data_record = (ldataptr) list_retrieve(rlist, FORWARD)) != NULL) { #ifdef DEBUG printf("writing to file %s %d\n",data_record->client_name, data_record->client_money); server.c Page 7 #endif write(fd, (char *)data_record, sizeof(struct list_data)); } } list_delete(rlist); lock.l_type = F_UNLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(fd, F_SETLKW, &lock); close(fd); #ifdef DEBUG printf ("the client information I am returning:\n"); printf ("name = %s, passwd = %s, request = %d, data = %d, ret_val = %d\n", cltdata->client_id, cltdata->passwd_id, cltdata->req_type, cltdata->data, cltdata->ret_val); #endif } sunraster.c Page 1 /* Sunraster File Reading Utility ------------------------------ Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. This utility reads sun rasterfiles into an XImage. It will read color rasterfiles on color systems and black and white rasterfiles on monochrome systems, but it WILL NOT read black and white files on color or vice versa. To Use: Include the "sunraster.h" file in your source file. Linke with "sunraster.o" Call "ReadSunRasterToImage(dpy, filename, **ximage) Display using something like XPutImage() These examples are a product of SunSoft, Inc. and is provided for unrestricted use provided that this legend is included on all media and as a part of the software program in whole or part. Users may copy, modify or distribute this file at will. THESE EXAMPLES ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. These examples are provided with no support and without any obligation on the part of SunSoft, Inc. to assist in its use, correction, modification or enhancement. SUNSOFT AND SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY TH EXAMPLES OR ANY PART THEREOF. IN NO EVENT WILL SUNSOFT OR SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL DAMAGES, EVEN IF THEY HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SunSoft, Inc. 2550 Garcia Avenue Mountain View, California 94043 */ #include "archdep.h" #include "rasterfile.h" #include "sunraster.h" extern unsigned long best_color_match(Display *display, Colormap colormap, XColor xcolor); extern char * read_color_data( Display *dpy, FILE *fp, struct rasterfile header, Colormap colormap); extern char * read_mono_data( Display *dpy, FILE *fp, struct rasterfile header, Colormap colormap); sunraster.c Page 2 int ReadSunRasterToImage(Display *dpy, char *filename, XImage **image) { FILE *fp; struct rasterfile header; int stat; int screen; int target_depth; Visual *visual; Colormap colormap; #ifdef i86pc i_32 bswaped_magic = 0; i_32 bswaped_width = 0; i_32 bswaped_height = 0; i_32 bswaped_depth = 0; i_32 bswaped_length = 0; i_32 bswaped_type = 0; i_32 bswaped_maptype = 0; i_32 bswaped_maplength = 0; #endif screen = DefaultScreen(dpy); visual = DefaultVisual(dpy, screen); colormap = DefaultColormap(dpy, screen); target_depth = DefaultDepth(dpy, screen); if ((fp = fopen (filename, "r")) == NULL) { perror("Sun Rastefile not found"); *image = NULL; return( 0 ); } stat = fread ((char *) &header, sizeof (header), 1, fp); #ifdef i86pc DECODE_LONG(&header.ras_magic, &bswaped_magic); header.ras_magic = bswaped_magic; DECODE_LONG(&header.ras_width, &bswaped_width); header.ras_width = bswaped_width; DECODE_LONG(&header.ras_height, &bswaped_height); header.ras_height = bswaped_height; DECODE_LONG(&header.ras_depth, &bswaped_depth); header.ras_depth = bswaped_depth; DECODE_LONG(&header.ras_length, &bswaped_length); header.ras_length = bswaped_length; DECODE_LONG(&header.ras_type, &bswaped_type); header.ras_type = bswaped_type; DECODE_LONG(&header.ras_maptype, &bswaped_maptype); header.ras_maptype = bswaped_maptype; DECODE_LONG(&header.ras_maplength, &bswaped_maplength); header.ras_maplength = bswaped_maplength; #endif /* Make sure this is something we can understand sunraster.c Page 3 */ if ((header.ras_magic != RAS_MAGIC) || (header.ras_type != RT_STANDARD)) { fprintf(stderr, "Unsupported rasterfile found.\n"); *image = NULL; return( 0 ); } if ((target_depth == 8) && (header.ras_maptype == RMT_EQUAL_RGB)) { *image = XCreateImage(dpy, visual, 8, ZPixmap, 0, read_color_data(dpy, fp, header, colormap), header.ras_width, header.ras_height, 16, 0); } else if ((target_depth == 1) && (header.ras_maptype == RMT_NONE)) { *image = XCreateImage(dpy, visual, 1, XYPixmap, 0, read_mono_data(dpy, fp, header, colormap), header.ras_width, header.ras_height, 16, 0); } else { fprintf(stderr, "Unsupported rasterfile found.\n"); *image = NULL; return( 0 ); } stat = fclose (fp); return( 1 ); } static unsigned long best_color_match(Display *display, Colormap colormap, XColor xcolor) { static int has_alloc_failed = False; static XColor colorcells[NCOLORS]; int cnt; Status status; XColor best; XColor def; double dist; double best_dist; double red_dist; double blue_dist; double green_dist; sunraster.c Page 4 /* Only query the colors once, for performance reasons This could be dangererous, since it could change, but we'll risk it */ if (has_alloc_failed == False) { for (cnt = 0; cnt < NCOLORS; cnt++) { colorcells[cnt].pixel = cnt; } status = XQueryColors (display, colormap, colorcells, NCOLORS); def.pixel = WhitePixel(display, DefaultScreen(display)); has_alloc_failed = True; fprintf(stderr, "Default colormap full, using best approximation.\n"); } best.pixel = def.pixel; dist = 0.0; red_dist = (double) abs(xcolor.red - colorcells[0].red); green_dist = (double) abs(xcolor.green - colorcells[0].green); blue_dist = (double) abs(xcolor.blue - colorcells[0].blue); best_dist = (red_dist*red_dist) + (blue_dist*blue_dist) + (green_dist*green_dist); for (cnt = 1; cnt < NCOLORS; cnt++) { red_dist = (double)abs(xcolor.red-colorcells[cnt].red); green_dist = (double)abs(xcolor.green-colorcells[cnt].green); blue_dist = (double)abs(xcolor.blue-colorcells[cnt].blue); dist= (red_dist*red_dist) + (blue_dist*blue_dist) + (green_dist*green_dist); if (dist < best_dist) { best_dist = dist; best.pixel = colorcells[cnt].pixel; } } return( best.pixel ); } static char * read_color_data( Display *dpy, FILE *fp, struct rasterfile header, Colormap colormap ) { int i, j, k; unsigned char *rasmap; int stat; int status; unsigned char *temp, *t, *r, *g, *b; sunraster.c Page 5 int width, height; unsigned long color_translation[256]; XColor xcolor; unsigned int datasize; char *data; unsigned short red, green, blue; rasmap = (unsigned char *) malloc ((unsigned) header.ras_maplength); stat = fread ((char *) rasmap, header.ras_maplength, 1, fp); datasize = (unsigned)(header.ras_width * header.ras_height); data = (char *) malloc (datasize); stat = fread ((char *) data, datasize,1, fp); k = header.ras_maplength / 3; r = rasmap; g = r + k; b = g + k; /* Allocate Colors and Build Color Translation Table */ for ( j=0; j < k; j++ ) { red = xcolor.red = (unsigned short)(*(r++)) << 8; green = xcolor.green = (unsigned short)(*(g++)) << 8; blue = xcolor.blue = (unsigned short)(*(b++)) << 8; status = XAllocColor(dpy, colormap, &xcolor); if (status == 0) { #ifdef NO_BESTFIT fprintf(stderr, "Out of colors: using white.\n"); color_translation[j] = 0; #else color_translation[j] = best_color_match(dpy, colormap, xcolor); #endif } else { color_translation[j] = xcolor.pixel; } } /* Translate Color Data */ for ( j=0; j < datasize; j++ ) { *(data+j) = (unsigned char)color_translation[(unsigned char)*(data+j)]; } return( data ); } static char * read_mono_data( Display *dpy, FILE *fp, sunraster.c Page 6 struct rasterfile header, Colormap colormap ) { int stat; unsigned int datasize; char *data; datasize = (unsigned)(header.ras_width * header.ras_height); data = (char *) malloc (datasize); stat = fread ((char *) data, datasize, 1, fp); return( data ); } archdep.h Page 1 /* @(#)archdep.h 1.5 89/12/22 SMI */ /* Copyright (c) 1989 by Sun Microsystems, Inc. */ #ifndef _multimedia_archdep_h #define _multimedia_archdep_h /* * Machine-dependent and implementation-dependent definitions * are placed here so that source code can be portable among a wide * variety of machines. */ /* * The following macros are used to generate architecture-specific * code for handling byte-ordering correctly. * * Note that these macros *do not* work for in-place transformations. */ #if defined (mc68000) || defined (sparc) #define DECODE_SHORT(from, to) *((short *)(to)) = *((short *)(from)) #define DECODE_LONG(from, to) *((long *)(to)) = *((long *)(from)) #define DECODE_FLOAT(from, to) *((float *)(to)) = *((float *)(from)) #define DECODE_DOUBLE(from, to) *((double *)(to)) = *((double *)(from)) #endif /*big-endian*/ #if defined (i386) #define DECODE_SHORT(from, to) \ ((char *)(to))[0] = ((char *)(from))[1]; \ ((char *)(to))[1] = ((char *)(from))[0]; #define DECODE_LONG(from, to) \ ((char *)(to))[0] = ((char *)(from))[3]; \ ((char *)(to))[1] = ((char *)(from))[2]; \ ((char *)(to))[2] = ((char *)(from))[1]; \ ((char *)(to))[3] = ((char *)(from))[0]; #define DECODE_FLOAT(from, to) DECODE_LONG((to), (from)) #define DECODE_DOUBLE(from, to) \ ((char *)(to))[0] = ((char *)(from))[7]; \ ((char *)(to))[1] = ((char *)(from))[6]; \ ((char *)(to))[2] = ((char *)(from))[5]; \ ((char *)(to))[3] = ((char *)(from))[4]; \ ((char *)(to))[4] = ((char *)(from))[3]; \ ((char *)(to))[5] = ((char *)(from))[2]; \ ((char *)(to))[6] = ((char *)(from))[1]; \ ((char *)(to))[7] = ((char *)(from))[0]; #endif /*little-endian*/ /* Most architectures are symmetrical with respect to conversions. */ #if defined (mc68000) || defined (sparc) || defined (i386) #define ENCODE_SHORT(from, to) DECODE_SHORT((from), (to)) #define ENCODE_LONG(from, to) DECODE_LONG((from), (to)) #define ENCODE_FLOAT(from, to) DECODE_FLOAT((from), (to)) #define ENCODE_DOUBLE(from, to) DECODE_DOUBLE((from), (to)) archdep.h Page 2 /* Define types of specific length */ typedef char i_8; typedef short i_16; typedef int i_32; typedef unsigned char u_8; typedef unsigned short u_16; typedef unsigned u_32; #endif /*Sun machines*/ #endif /*!_multimedia_archdep_h*/ client.h Page 1 /* System Header Files */ #include #include #include #include #include #include #include #include #include /* X Header Files */ #include #include #include #include #include #include #include #include #include /* Tooltalk Header File */ #include /* UI Defines */ #define STRING1 "WELCOME" #define STRING6 "BALANCE" #define STRING7 "WITHDRW" #define STRING8 "DEPOSIT" #define WITHDRAW 0 #define DEPOSIT 1 #define BALANCE 2 /* TLI Defines */ #define SRV_ADDR 1 #define SRV_ADDR1 11 #define TRANSPORT_DEV "/dev/tcp" #define TRANSPORT_NETCONFID "tcp" #define MAXSTR 256 typedef struct _client_request { char client_id[30]; int req_type; int data; int ret_val; } client_request; typedef struct _client_display { int atm_id; } client_display; typedef struct _widget_table { Widget toplevel, bb, loginst, passwdst, excl_auto, butt_auto; client.h Page 2 struct netbuf *addr, *addr1; int onceonly; XtWorkProcId work_proc_id; Atom START1, START2; int srv_addr, srv_addr1; int atm_id; int resetval; char *session; } widget_table; typedef struct { String serv_hostname; String opt_port; String opt_port1; String atm_id; String client_id; } ApplicationData, *ApplicationDataPtr; static XtResource resources[] = { { "serverHostName", "ServerHostName", XtRString, sizeof(String), XtOffset(ApplicationDataPtr, serv_hostname), XtRString, "local"}, { "optionalPort", "OptionalPort", XtRString, sizeof(String), XtOffset(ApplicationDataPtr, opt_port), XtRString, "-1"}, { "optionalPortDisp", "OptionalPortDisp", XtRString, sizeof(String), XtOffset(ApplicationDataPtr, opt_port1), XtRString, "-1"}, { "atmNumber", "AtmNumber", XtRString, sizeof(String), XtOffset(ApplicationDataPtr, atm_id), XtRString, "-1"}, { "clientName", "ClientName", XtRString, sizeof(String), XtOffset(ApplicationDataPtr, client_id), XtRString, "\0"}, }; static XrmOptionDescRec options[] = { {"-serverHostName", "*serverHostName", XrmoptionSepArg, NULL}, {"-optionalPort", "*optionalPort", XrmoptionSepArg, NULL}, {"-optionalPortDisp", "*optionalPortDisp", XrmoptionSepArg, NULL}, {"-atmNumber", "*atmNumber", XrmoptionSepArg, NULL}, {"-clientName", "*clientName", XrmoptionSepArg, NULL}, }; /* Function Prototypes */ static void make_server_request(widget_table *); static void make_server_address(widget_table *); static void init_client_data(); static Boolean auto_proc(widget_table *); static void auto_callback(Widget, XtPointer, XtPointer); static void display_data(widget_table *); static void usage(); static void receive_mesg(widget_table *, int *, XtInputId *); static void init_tt(widget_table *); data.h Page 1 typedef struct list_data { char client_name[30]; char client_passwd[9]; /* not used */ int client_money; } ldata, *ldataptr; dispserver.h Page 1 /* System Header Files */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* GUI Header Files */ #include #include #include #include #include #include #include #define TRANSPORT_DEV "/dev/tcp" #define TRANSPORT_NETCONFID "tcp" #define SRV_ADDR1 11 #define MAXSTR 256 typedef struct _widget_table { Widget toplevel, ca, labst, labst1, st; XtAppContext context; int onceonly, total; } widget_table; typedef struct _client_display { int atm_id; } client_display; int accept_call(int, struct t_call *); void run_server(int); void connrelease(); void create_gui(int, char **, int); void update_data(widget_table *, int *, XtInputId *); list.h Page 1 #include #define FORWARD 1 #define BACKWARD 2 struct list_node{ char *info; struct list_node * next; struct list_node * previous; }; typedef struct list_struct { struct list_node *head, *tail, *current; } *list; list list_init(); void list_insert(list, char *); char *list_retrieve(list, int); void list_reset(list); void list_delete(list); rasterfile.h Page 1 /* @(#)rasterfile.h 1.11 89/08/21 SMI */ /* * Description of header for files containing raster images */ #ifndef _rasterfile_h #define _rasterfile_h struct rasterfile { int ras_magic; /* magic number */ int ras_width; /* width (pixels) of image */ int ras_height; /* height (pixels) of image */ int ras_depth; /* depth (1, 8, or 24 bits) of pixel */ int ras_length; /* length (bytes) of image */ int ras_type; /* type of file; see RT_* below */ int ras_maptype; /* type of colormap; see RMT_* below */ int ras_maplength; /* length (bytes) of following map */ /* color map follows for ras_maplength bytes, followed by image */ }; #define RAS_MAGIC 0x59a66a95 /* Sun supported ras_type's */ #define RT_OLD 0 /* Raw pixrect image in 68000 byte order */ #define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */ #define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */ #define RT_FORMAT_RGB 3 /* XRGB or RGB instead of XBGR or BGR */ #define RT_FORMAT_TIFF 4 /* tiff <-> standard rasterfile */ #define RT_FORMAT_IFF 5 /* iff (TAAC format) <-> standard rasterfile */ #define RT_EXPERIMENTAL 0xffff /* Reserved for testing */ /* Sun registered ras_maptype's */ #define RMT_RAW 2 /* Sun supported ras_maptype's */ #define RMT_NONE 0 /* ras_maplength is expected to be 0 */ #define RMT_EQUAL_RGB 1 /* red[ras_maplength/3],green[],blue[] */ /* * NOTES: * Each line of the image is rounded out to a multiple of 16 bits. * This corresponds to the rounding convention used by the memory pixrect * package (/usr/include/pixrect/memvar.h) of the SunWindows system. * The ras_encoding field (always set to 0 by Sun's supported software) * was renamed to ras_length in release 2.0. As a result, rasterfiles * of type 0 generated by the old software claim to have 0 length; for * compatibility, code reading rasterfiles must be prepared to compute the * true length from the width, height, and depth fields. */ #endif /*!_rasterfile_h*/ server.h Page 1 /* System Header Files */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TRANSPORT_DEV "/dev/tcp" #define TRANSPORT_NETCONFID "tcp" #define SRV_ADDR 1 #define MAXSTR 256 #define WITHDRAW 0 #define DEPOSIT 1 #define BALANCE 2 typedef struct _client_request { char client_id[30]; int req_type; int data; int ret_val; } client_request; void update_database(client_request *); int accept_call(int, struct t_call *); void run_server(int); void connrelease(); sunraster.h Page 1 #include #include #define NCOLORS 256 extern int ReadSunRasterToImage(Display *dpy, char *filename, XImage **image); Makefile Page 1 # # @(#)Makefile.customer 1.3 91/09/14 SMI # # Makefile for the Olit Programmer's Guide's Examples # #CC = /opt/SUNWspro/bin/cc CC = cc INCLUDE = -I${OPENWINHOME}/include # # If you want to compile for debugging, change "-O" to "-g" # #CFLAGS = ${INCLUDE} -g -DDEBUG CFLAGS = ${INCLUDE} -O # if you want special to pass special loader options to ld, set # LDFLAGS= ... # LIBS = -L${OPENWINHOME}/lib -R${OPENWINHOME}/lib:/usr/lib \ -ltt \ -lXol \ -lXt \ -lX11 \ -lnsl TARGETS = client \ client-nogui \ server \ animate \ dispserver \ populate \ reader all: ${TARGETS} client: client.c client.h client.o sunraster.o ${CC} ${CFLAGS} -o client client.o sunraster.o ${LIBS} client-nogui: client-nogui.c client.h client-nogui.o ${CC} ${CFLAGS} -o client-nogui client-nogui.o ${LIBS} animate: animate.c animate.o ${CC} ${CFLAGS} -o animate animate.o sunraster.o ${LIBS} populate: populate.c data.h populate.o ${CC} ${CFLAGS} ${LDFLAGS} -o populate populate.o reader: reader.o reader.c ${CC} ${CFLAGS} ${LDFLAGS} -o reader reader.o server: server.o server.c list.h data.h server.h list.o ${CC} -O -o server server.o list.o -lnsl Makefile Page 2 dispserver: dispserver.o dispserver.c dispserver.h ${CC} ${CFLAGS} ${LDFLAGS} -o dispserver dispserver.o ${LIBS} list.o: list.c list.h ${CC} -O -c list.c sunraster.o: sunraster.c sunraster.h rasterfile.h archdep.h ${CC} ${CFLAGS} -c sunraster.c clean: rm -f core *.o ${TARGETS}