Annotation of OpenXM/src/asir-port/cgi/webasir2.c, Revision 1.1
1.1 ! takayama 1: /* $OpenXM$
! 2: */
! 3: /*
! 4: (httpd-asir2.sm1) run webasir2
! 5: */
! 6: #include <stdio.h>
! 7: #include <sys/types.h>
! 8: #include <sys/socket.h>
! 9: #include <sys/time.h>
! 10: #include <netinet/in.h>
! 11: #include <netdb.h>
! 12: #include <string.h>
! 13:
! 14: #define SIZE 0x10000
! 15:
! 16: int Debug=1;
! 17: int main(int argc,char *argv[]) {
! 18: int dataPort;
! 19: struct hostent *servhost;
! 20: struct sockaddr_in dServer;
! 21: FILE *fp;
! 22: char s[1];
! 23: char fname[SIZE];
! 24: int i;
! 25: char key[SIZE];
! 26: char comm[SIZE];
! 27: int quit;
! 28: quit = 0;
! 29: for (i=1; i<argc; i++) {
! 30: if (strcmp(argv[i],"--quit")==0) quit=1;
! 31: }
! 32:
! 33: system("ls /tmp/webasir*.txt >tmp-webasir.txt");
! 34: fp = fopen("tmp-webasir.txt","r");
! 35: if (fp == NULL) {
! 36: fprintf(stderr,"No webasir2 is running.\n"); return(-1);
! 37: }
! 38: fgets(fname,SIZE-2,fp);
! 39: for (i=strlen(fname)-1; i>=0; i--) {
! 40: if (fname[i] <= ' ') fname[i]=0; else break;
! 41: }
! 42: fclose(fp);
! 43: if (strlen(fname)==0) {
! 44: fprintf(stderr,"No webasir2 pid file.\n"); return(-1);
! 45: }
! 46: fp = fopen(fname,"r");
! 47: if (fp == NULL) {
! 48: fprintf(stderr,"Open error of %s\n",fname); return(-1);
! 49: }
! 50: fgets(key,SIZE-2,fp); sscanf(key,"%d",&dataPort);
! 51: if (Debug) printf("dataPort=%d\n",dataPort);
! 52: fgets(key,SIZE-2,fp);
! 53: for (i=strlen(key)-1; i>=0; i--) {
! 54: if (key[i] <= ' ') key[i]=0; else break;
! 55: }
! 56: if (Debug) printf("key=%s\n",key);
! 57: fclose(fp);
! 58:
! 59: if ((servhost = gethostbyname("localhost")) == NULL) {
! 60: fprintf(stderr,"bad server name.\n"); return(-1);
! 61: }
! 62:
! 63: /* Connecting to the data port */
! 64: bzero((char *)&dServer,sizeof(dServer));
! 65: dServer.sin_family = AF_INET;
! 66: dServer.sin_port = htons(dataPort);
! 67: bcopy(servhost->h_addr,
! 68: (char *)&dServer.sin_addr,servhost->h_length);
! 69: if ((dataPort = socket(AF_INET,SOCK_STREAM,0)) <0) {
! 70: fprintf(stderr,"socket allocation is failed.\n");
! 71: }
! 72: if (Debug) fprintf(stderr,"Trying to connect port %d ",ntohs(dServer.sin_port));
! 73:
! 74: if (connect(dataPort,(struct sockaddr *)&dServer,sizeof(dServer)) == -1) {
! 75: fprintf(stderr,"cannot connect\n");
! 76: }else{ fprintf(stderr,"Connected\n"); }
! 77:
! 78: if (quit) {
! 79: sprintf(comm,"GET /?msg=httpdAsirMeta+quit HTTP/1.1\n\n");
! 80: write(dataPort,comm,strlen(comm));
! 81: fflush(NULL);
! 82: }else{
! 83: sprintf(comm,"GET /?%s=10-21;\n\n",key);
! 84: write(dataPort,comm,strlen(comm));
! 85: fflush(NULL);
! 86: }
! 87:
! 88: /* get result */
! 89: for (i=0; i<SIZE; i++) comm[i]=0;
! 90: read(dataPort,comm,SIZE-2);
! 91: printf("%s\n",comm);
! 92: }
! 93:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>