version 1.2, 2014/08/30 22:47:20 |
version 1.3, 2014/08/31 07:53:57 |
|
|
/* $OpenXM: OpenXM/src/asir-port/cgi/webasir2.c,v 1.1 2014/08/30 12:25:56 takayama Exp $ |
/* $OpenXM: OpenXM/src/asir-port/cgi/webasir2.c,v 1.2 2014/08/30 22:47:20 takayama Exp $ |
*/ |
*/ |
/* |
/* |
(httpd-asir2.sm1) run webasir2 |
(httpd-asir2.sm1) run webasir2 |
|
>log 2>&1 |
|
Todo, timer(limit, command, message) implement in sm1. |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <unistd.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <netinet/in.h> |
#include <netinet/in.h> |
|
|
char *byteArrayToUrlEncoding(char *s,int size); |
char *byteArrayToUrlEncoding(char *s,int size); |
|
|
int Debug=1; |
int Debug=1; |
|
int SetTimer=0; |
int main(int argc,char *argv[]) { |
int main(int argc,char *argv[]) { |
int dataPort; |
int dataPort; |
struct hostent *servhost; |
struct hostent *servhost; |
Line 23 int main(int argc,char *argv[]) { |
|
Line 27 int main(int argc,char *argv[]) { |
|
FILE *fp; |
FILE *fp; |
char s[1]; |
char s[1]; |
char fname[SIZE]; |
char fname[SIZE]; |
int i; |
int i,j,c; |
char key[SIZE]; |
char key[SIZE]; |
char comm[SIZE]; |
char comm[SIZE]; |
char *asircomm; |
char *asircomm; |
int quit; |
int quit; |
|
char workf[SIZE]; |
quit = 0; |
quit = 0; |
asircomm="3-2;"; |
asircomm="3-2;"; |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
Line 36 int main(int argc,char *argv[]) { |
|
Line 41 int main(int argc,char *argv[]) { |
|
i++; |
i++; |
if (i <argc) asircomm = argv[i]; |
if (i <argc) asircomm = argv[i]; |
else { usage(); return(-1); } |
else { usage(); return(-1); } |
|
}else if (strcmp(argv[i],"--debug")==0) { |
|
i++; |
|
if (i <argc) sscanf(argv[i],"%d",&Debug); |
|
else { usage(); return(-1); } |
|
}else if (strcmp(argv[i],"--settimer")==0) { |
|
i++; |
|
if (i <argc) sscanf(argv[i],"%d",&SetTimer); |
|
else { usage(); return(-1); } |
|
} else if (strcmp(argv[i],"--stdin")==0) { |
|
asircomm = (char *) malloc(SIZE); |
|
asircomm[0] = 0; j=0; |
|
while ((c=getchar()) != EOF) { |
|
asircomm[j] = c; j++; asircomm[j] = 0; |
|
if (j > SIZE-3) { |
|
fprintf(stderr,"error, too big input.\n"); return(-1); |
|
} |
|
} |
|
} else { |
|
usage(); return(0); |
} |
} |
} |
} |
|
|
system("ls /tmp/webasir*.txt >tmp-webasir.txt"); |
sprintf(workf,"/tmp/tmp-webasir-%d.txt",(int) getpid()); |
fp = fopen("tmp-webasir.txt","r"); |
sprintf(comm,"ls /tmp/webasir*.txt >%s",workf); |
|
system(comm); |
|
fp = fopen(workf,"r"); |
if (fp == NULL) { |
if (fp == NULL) { |
fprintf(stderr,"No webasir2 is running.\n"); return(-1); |
fprintf(stderr,"No webasir2 is running.\n"); return(-1); |
} |
} |
Line 64 int main(int argc,char *argv[]) { |
|
Line 90 int main(int argc,char *argv[]) { |
|
} |
} |
if (Debug) printf("key=%s\n",key); |
if (Debug) printf("key=%s\n",key); |
fclose(fp); |
fclose(fp); |
|
sprintf(comm,"rm -f %s",workf); |
|
system(comm); |
|
|
if ((servhost = gethostbyname("localhost")) == NULL) { |
if ((servhost = gethostbyname("localhost")) == NULL) { |
fprintf(stderr,"bad server name.\n"); return(-1); |
fprintf(stderr,"bad server name.\n"); return(-1); |
Line 81 int main(int argc,char *argv[]) { |
|
Line 109 int main(int argc,char *argv[]) { |
|
if (Debug) fprintf(stderr,"Trying to connect port %d ",ntohs(dServer.sin_port)); |
if (Debug) fprintf(stderr,"Trying to connect port %d ",ntohs(dServer.sin_port)); |
|
|
if (connect(dataPort,(struct sockaddr *)&dServer,sizeof(dServer)) == -1) { |
if (connect(dataPort,(struct sockaddr *)&dServer,sizeof(dServer)) == -1) { |
fprintf(stderr,"cannot connect\n"); |
fprintf(stderr,"error: cannot connect\n"); |
}else{ fprintf(stderr,"Connected\n"); } |
}else{ if (Debug) fprintf(stderr,"Connected\n"); } |
|
|
|
if (SetTimer) { |
|
strcpy(comm,asircomm); |
|
for (i=strlen(comm)-1; i>=0; i--) { |
|
if ((comm[i] == ';') || (comm[i] <= ' ')) comm[i] = 0; |
|
else break; |
|
} |
|
sprintf(asircomm,"timer(%d,%s,\"error(timeout %d sec)\");", |
|
SetTimer,comm,SetTimer); |
|
} |
if (quit) { |
if (quit) { |
sprintf(comm,"GET /?msg=httpdAsirMeta+quit HTTP/1.1\n\n"); |
sprintf(comm,"GET /?msg=httpdAsirMeta+quit HTTP/1.1\n\n"); |
write(dataPort,comm,strlen(comm)); |
write(dataPort,comm,strlen(comm)); |
Line 142 char *byteArrayToUrlEncoding(char *s,int size) { |
|
Line 179 char *byteArrayToUrlEncoding(char *s,int size) { |
|
|
|
usage() { |
usage() { |
fprintf(stderr,"webasir2 [--quit] [--asir command_string]\n"); |
fprintf(stderr,"webasir2 [--quit] [--asir command_string]\n"); |
|
fprintf(stderr," [--debug level]\n"); |
|
fprintf(stderr," [--settimer seconds]\n"); |
|
fprintf(stderr,"webasir2 --stdin ; command is obtained from the stdin.\n"); |
} |
} |