9 #define MY_SERVER_CONFIG_DIR "/projects/misc/doct/dgtg/irods/RODS/server/config"
17 #define MAX_ENTRIES 5000
18 #define MYSRBBUFSIZE 2000000
19 #define QSIZE MYSRBBUFSIZE
20 #define HUGE_STRING 5000
48 printf(
"Content-type: text/html%c%c", 10, 10 );
53 printf(
"<B><FONT COLOR=#DC143C>Error: %s: %i</B>\n", msg,
status );
54 printf(
"</body></html>" );
58 char x2c(
char *what ) {
61 digit = ( what[0] >=
'A' ? ( ( what[0] & 0xdf ) -
'A' ) + 10 : ( what[0] -
'0' ) );
63 digit += ( what[1] >=
'A' ? ( ( what[1] & 0xdf ) -
'A' ) + 10 : ( what[1] -
'0' ) );
70 for ( x = 0, y = 0; url[y]; ++x, ++y ) {
71 if ( ( ( url[x] = url[y] ) ==
'%' ) && isxdigit( url[y + 1] ) && isxdigit( url[y + 2] ) ) {
72 url[x] =
x2c( &url[y + 1] );
83 for ( x = 0; str[x]; x++ )
if ( str[x] ==
'+' ) {
93 while ( *tmp1 !=
'\n' ) {
98 strcpy( boundary, *stquery );
105 void *tmpPtr, *tmpPtr1;
107 tmpPtr = (
void * ) inStr;
108 while ( length > 0 ) {
110 tmpPtr1 = memchr( tmpPtr, bound[0], length );
112 if ( tmpPtr1 ==
NULL ) {
115 if ( memcmp( tmpPtr1, (
void * ) bound, j ) == 0 ) {
118 length = length - (
int )( (
char * )tmpPtr1 - (
char * ) tmpPtr ) + 1;
119 tmpPtr = (
void * )( (
char * ) tmpPtr1 + 1 );
126 char *inS, *tmp1, *tmp2, *endStr;
129 if ( strlen( *stquery ) < ( 2 * strlen( boundary ) ) ) {
133 if ( ( tmp1 = strstr( (
char * ) * stquery, boundary ) ) ==
NULL ) {
134 webErrorExit(
"No Beginning Boundary Found In Field:", 0 );
136 if ( ( endStr =
findBoundary( (
char * )( tmp1 + 1 ), boundary, length ) ) ==
NULL ) {
137 webErrorExit(
"No Ending Boundary Found In Field:", 0 );
139 *( endStr - 2 ) =
'\0';
141 if ( ( tmp2 = strstr( tmp1,
"name=\"" ) ) ==
NULL ) {
145 tmp1 = strchr( tmp2,
'\"' );
148 strcpy( iEntry->
name, tmp2 );
149 if ( (
int )( strstr( tmp1,
"filename" ) !=
NULL &&
150 strstr( tmp1,
"filename" ) - tmp1 ) < 5 ) {
152 while ( *tmp1 !=
'\n' ) {
156 while ( *tmp1 !=
'\n' ) {
161 if ( strstr( iEntry->
name,
"filename" ) !=
NULL ) {
166 iEntry->
size = (
int )( endStr - tmp1 );
168 iEntry->
val = (
char * ) malloc( iEntry->
size );
169 memcpy( iEntry->
val, tmp1, iEntry->
size );
177 iEntry->
val = (
char * ) malloc( strlen( tmp1 ) + 3 );
179 strcpy( iEntry->
val, tmp1 );
180 iEntry->
size = strlen( iEntry->
val );
195 while ( ch !=
'\n' ) {
217 while ( ch !=
'\n' ) {
235 for ( x = 0; ( (
line[x] ) && (
line[x] !=
stop ) ); x++ ) {
252 char *word = (
char * ) malloc(
sizeof(
char ) * ( strlen(
line ) + 1 ) );
254 for ( x = 0; ( (
line[x] ) && (
line[x] !=
stop ) ); x++ ) {
277 word = (
char * ) malloc(
sizeof(
char ) * ( wsize + 1 ) );
280 word[ll] = ( char )fgetc( f );
281 printf(
"%c", word[ll] );
287 tmp_ch = (
char * )realloc( word,
sizeof(
char ) * ( wsize + 1 ) );
296 if ( ( word[ll] ==
stop ) || ( feof( f ) ) || ( !( *cl ) ) ) {
297 if ( word[ll] !=
stop ) {
310 for ( x = strlen( s ) - 1; x != -1; x-- )
321 s[i] = ( char )fgetc( f );
327 if ( ( s[i] == 0x4 ) || ( s[i] ==
LF ) || ( i == ( n - 1 ) ) ) {
329 return feof( f ) ? 1 : 0;
352 char *stquery, *tmpq, *tmpStr, *tmpStr1, *tmpPtr;
355 char contentType[100];
363 if ( getenv(
"CONTENT_TYPE" ) !=
NULL ) {
364 strcpy( contentType, getenv(
"CONTENT_TYPE" ) );
367 strcpy( contentType,
"" );
369 if ( getenv(
"REQUEST_METHOD" ) !=
NULL ) {
370 strcpy( reqMethod, getenv(
"REQUEST_METHOD" ) );
373 strcpy( reqMethod,
"" );
375 if ( getenv(
"HTTP_COOKIE" ) !=
NULL ) {
376 strcpy( Sentries->
cookieStr, getenv(
"HTTP_COOKIE" ) );
395 if ( !strcmp( reqMethod,
"POST" ) || !strcmp( reqMethod,
"post" ) ) {
396 msgLength = atoi( getenv(
"CONTENT_LENGTH" ) ) + 10;
397 stquery = malloc( msgLength );
398 if ( fread( stquery, 1, msgLength, stdin ) != ( msgLength - 10 ) ) {
401 stquery[msgLength] =
'\0';
404 stquery = malloc(
QSIZE );
405 if ( getenv(
"QUERY_STRING" ) !=
NULL ) {
406 strcpy( stquery, getenv(
"QUERY_STRING" ) );
409 strcpy( stquery,
"" );
413 if ( strstr( contentType,
"multipart/form-data" ) !=
NULL ) {
418 for ( x = 0; *stquery !=
'\0'; x++ ) {
428 i -= stquery - tmpPtr;
441 for ( x = 0; stquery[0] !=
'\0'; x++ ) {
462 int main(
int argc,
char **argv ) {
516 if ( !strcmp( Sentries->
entries[0].
val,
"showRules" ) ) {
519 else if ( !strcmp( Sentries->
entries[0].
val,
"applyRule" ) ) {
536 char configDirEV[200];
540 strcpy( oldRuleBase,
"" );
541 fprintf( stdout,
"Content-type: text/html%c%c", 10, 10 );
543 fprintf( stdout,
"<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n" );
544 fprintf( stdout,
"<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Base</FONT></B></CENTER>\n" );
553 for ( i = 0; i <= Sentries->
m; i++ ) {
554 if ( !strcmp( Sentries->
entries[i].
name,
"ruleSet" ) ) {
555 if ( strlen( Sentries->
entries[i].
val ) > 0 ) {
562 else if ( !strcmp( Sentries->
entries[i].
name,
"configDir" ) ) {
563 if ( strlen( Sentries->
entries[i].
val ) > 0 ) {
564 snprintf( configDirEV, 199,
"irodsConfigDir=%s", Sentries->
entries[i].
val );
569 putenv( configDirEV );
575 fprintf( stdout,
"<CENTER> <B><FONT COLOR=#0000FF>[%s]</FONT></B></CENTER>\n",
ruleSet );
579 fprintf( stdout,
"<TABLE>\n" );
582 if ( strcmp( oldRuleBase, ruleBase ) ) {
583 if ( strlen( oldRuleBase ) > 0 ) {
584 fprintf( stdout,
"<TR><TD COLSPAN=6><HR NOSHADE COLOR=#00FF00 SIZE=4></TD></TR>" );
586 strcpy( oldRuleBase, ruleBase );
589 fprintf( stdout,
"<TR><TD><BR> %i</TD><TD><BR> <FONT COLOR=#0000FF>ON</FONT></TD><TD COLSPAN=3><BR> <FONT COLOR=#FF0000>%s.</FONT><FONT COLOR=#0000FF>%s</FONT></TD></TR>\n", j, ruleBase, ruleHead );
590 if ( strlen( ruleCondition ) != 0 ) {
591 fprintf( stdout,
"<TR><TD></TD><TD></TD><TD VALIGN=TOP>IF </TD><TD COLSPAN=3 VALIGN=TOP><FONT COLOR=#FF0000>%s</FONT></TD></TR>\n", ruleCondition );
593 for ( i = 0; i < n; i++ ) {
595 fprintf( stdout,
"<TR><TD></TD><TD></TD><TD VALIGN=TOP>DO </TD><TD VALIGN=TOP>%s</TD><TD NOWRAP> </TD><TD VALIGN=TOP>[%s]</TD></TR>\n",
596 actionArray[i], recoveryArray[i] );
598 fprintf( stdout,
"<TR><TD></TD><TD></TD><TD VALIGN=TOP>AND </TD><TD VALIGN=TOP>%s</TD><TD NOWRAP> </TD><TD VALIGN=TOP>[%s]</TD></TR>\n",
599 actionArray[i], recoveryArray[i] );
602 fprintf( stdout,
"</TABLE>\n" );
603 fprintf( stdout,
"</BODY>\n</HTML>\n" );
617 char configDirEV[200];
618 char retestflagEV[200];
619 char reloopbackflagEV[200];
622 hrtime_t ht1, ht2, ht3;
630 sprintf( retestflagEV,
"RETESTFLAG=%i",
HTML_TEST_1 );
631 putenv( retestflagEV );
632 sprintf( reloopbackflagEV,
"RELOOPBACKFLAG=%i",
LOOP_BACK_1 );
633 putenv( reloopbackflagEV );
635 fprintf( stdout,
"Content-type: text/html%c%c", 10, 10 );
637 fprintf( stdout,
"<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n" );
638 fprintf( stdout,
"<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Application</FONT></B></CENTER>\n" );
660 for ( i = 0; i <= Sentries->
m; i++ ) {
662 if ( !strcmp( Sentries->
entries[i].
name,
"action" ) ) {
664 fprintf( stdout,
"<FONT COLOR=#0000FF>Action:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
667 else if ( !strcmp( Sentries->
entries[i].
name,
"objPath" ) ) {
669 fprintf( stdout,
"<FONT COLOR=#0000FF>$objPath:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
672 else if ( !strcmp( Sentries->
entries[i].
name,
"rescName" ) ) {
674 fprintf( stdout,
"<FONT COLOR=#0000FF>$rescName:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
677 else if ( !strcmp( Sentries->
entries[i].
name,
"dataSize" ) ) {
679 fprintf( stdout,
"<FONT COLOR=#0000FF>$dataSize:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
682 else if ( !strcmp( Sentries->
entries[i].
name,
"dataType" ) ) {
684 fprintf( stdout,
"<FONT COLOR=#0000FF>$dataType:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
687 else if ( !strcmp( Sentries->
entries[i].
name,
"dataOwner" ) ) {
696 fprintf( stdout,
"<FONT COLOR=#0000FF>$dataOwner:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
699 else if ( !strcmp( Sentries->
entries[i].
name,
"dataUser" ) ) {
708 fprintf( stdout,
"<FONT COLOR=#0000FF>$dataUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
711 else if ( !strcmp( Sentries->
entries[i].
name,
"dataAccess" ) ) {
713 fprintf( stdout,
"<FONT COLOR=#0000FF>$dataAccess:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
716 else if ( !strcmp( Sentries->
entries[i].
name,
"hostClient" ) ) {
718 fprintf( stdout,
"<FONT COLOR=#0000FF>$hostClient:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
721 else if ( !strcmp( Sentries->
entries[i].
name,
"proxyUser" ) ) {
730 fprintf( stdout,
"<FONT COLOR=#0000FF>$otherUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
733 else if ( !strcmp( Sentries->
entries[i].
name,
"otherUser" ) ) {
742 fprintf( stdout,
"<FONT COLOR=#0000FF>$otherUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
745 else if ( !strcmp( Sentries->
entries[i].
name,
"otherUserType" ) ) {
747 fprintf( stdout,
"<FONT COLOR=#0000FF>$otherUserType:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
750 else if ( !strcmp( Sentries->
entries[i].
name,
"ruleSet" ) ) {
751 if ( strlen( Sentries->
entries[i].
val ) > 0 ) {
758 else if ( !strcmp( Sentries->
entries[i].
name,
"retestflag" ) ) {
759 sprintf( retestflagEV,
"RETESTFLAG=%s", Sentries->
entries[i].
val );
760 putenv( retestflagEV );
761 fprintf( stdout,
"<FONT COLOR=#0000FF>Trace Status</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
764 else if ( !strcmp( Sentries->
entries[i].
name,
"configDir" ) ) {
765 if ( strlen( Sentries->
entries[i].
val ) > 0 ) {
766 snprintf( configDirEV, 199,
"irodsConfigDir=%s", Sentries->
entries[i].
val );
771 putenv( configDirEV );
782 fprintf( stdout,
"<FONT COLOR=#0000FF>Rule Set:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR><HR>\n",
ruleSet );
793 fprintf( stdout,
"Rule Initialization Time = %.2f millisecs\n", (
float )( ht2 - ht1 ) / 1000000 );
794 fprintf( stdout,
"Rule Execution Time = %.2f millisecs\n", (
float )( ht3 - ht1 ) / 1000000 );
797 fprintf( stdout,
"<BR>Rule Initialization Time = %.2f millisecs<BR>\n", (
float )( ht2 - ht1 ) / 1000000 );
798 fprintf( stdout,
"Rule Execution Time = %.2f millisecs<BR>\n", (
float )( ht3 - ht1 ) / 1000000 );