Changeset 6 for trunk/thirds
- Timestamp:
- Aug 11, 2010, 2:51:39 PM (14 years ago)
- Location:
- trunk/thirds/cgic206
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/thirds/cgic206/Makefile
r1 r6 3 3 AR=ar 4 4 RANLIB=ranlib 5 LIBS=-L./ -lcgic ../fcgi-2.4.0/libfcgi/.libs/libfcgi.a5 LIBS=-L./ -lcgic /usr/lib/libfcgi.a 6 6 CFLAGS=-I//var/www/localhost/include 7 7 -
trunk/thirds/cgic206/cgic.c
r1 r6 136 136 cgiGetenv(&cgiServerPort, "SERVER_PORT"); 137 137 cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD"); 138 if(strcmp(cgiRequestMethod,"")==0 && argc>=1) 139 cgiRequestMethod="GET"; 138 140 cgiGetenv(&cgiPathInfo, "PATH_INFO"); 139 141 cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED"); 140 142 cgiGetenv(&cgiScriptName, "SCRIPT_NAME"); 141 143 cgiGetenv(&cgiQueryString, "QUERY_STRING"); 144 if(strcmp(cgiQueryString,"")==0 && argc>=2){ 145 cgiQueryString=argv[1]; 146 }else 147 fprintf(stderr,"cgiQueryString : %s\n",cgiQueryString); 142 148 cgiGetenv(&cgiRemoteHost, "REMOTE_HOST"); 143 149 cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR"); … … 190 196 cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH"); 191 197 cgiContentLength = atoi(cgiContentLengthString); 198 if(cgiContentLength==0 && argc>=2){ 199 cgiContentLength=strlen(argv[1]); 200 } 201 fprintf(stderr,"%d\n",cgiContentLength); 192 202 cgiGetenv(&cgiAccept, "HTTP_ACCEPT"); 193 203 cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT"); … … 208 218 #endif /* WIN32 */ 209 219 cgiFormEntryFirst = 0; 210 cgiIn = stdin;211 cgiOut = stdout;220 cgiIn = FCGI_stdin; 221 cgiOut = FCGI_stdout; 212 222 cgiRestored = 0; 213 223 … … 293 303 cgiFreeResources(); 294 304 } 305 FCGI_Finish(); 295 306 return result; 296 307 } -
trunk/thirds/cgic206/cgictest.c
r1 r6 23 23 cgiReadEnvironment("/home/boutell/public_html/capcgi.dat"); 24 24 #endif 25 cgiHeaderContentType("text/html"); 26 fprintf(cgiOut, "<HTML><HEAD>\n"); 27 fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n"); 28 fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n"); 25 dup2(cgiOut,stdout); 26 printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 27 //cgiHeaderContentType("text/html"); 28 printf( "<HTML><HEAD>\n"); 29 printf( "<TITLE>cgic test</TITLE></HEAD>\n"); 30 printf( "<BODY><H1>cgic test</H1>\n"); 29 31 Name(); 30 32 Address(); … … 36 38 NonExButtons(); 37 39 RadioButtons(); 38 fprintf(cgiOut,"</BODY></HTML>\n");40 printf( "</BODY></HTML>\n"); 39 41 return 0; 40 42 } … … 45 47 switch (result) { 46 48 case cgiFormSuccess: 47 fprintf(cgiOut,"Name fetched, result code: cgiFormSuccess<br>\n");49 printf( "Name fetched, result code: cgiFormSuccess<br>\n"); 48 50 break; 49 51 case cgiFormTruncated: 50 fprintf(cgiOut,"Name fetched, result code: cgiFormTruncated<br>\n");52 printf( "Name fetched, result code: cgiFormTruncated<br>\n"); 51 53 break; 52 54 case cgiFormEmpty: 53 fprintf(cgiOut,"Name fetched, result code: cgiFormEmpty<br>\n");55 printf( "Name fetched, result code: cgiFormEmpty<br>\n"); 54 56 break; 55 57 case cgiFormNotFound: 56 fprintf(cgiOut,"Name fetched, result code: cgiFormNotFound<br>\n");58 printf( "Name fetched, result code: cgiFormNotFound<br>\n"); 57 59 break; 58 60 case cgiFormMemory: 59 fprintf(cgiOut,"Name fetched, result code: cgiFormMemory<br>\n");61 printf( "Name fetched, result code: cgiFormMemory<br>\n"); 60 62 break; 61 63 default: 62 fprintf(cgiOut,"Name fetched, unexpected result code: %d\n", result);64 printf( "Name fetched, unexpected result code: %d\n", result); 63 65 break; 64 66 } 65 fprintf(cgiOut,"Name: %s<BR>\n", name);67 printf( "Name: %s<BR>\n", name); 66 68 } 67 69 … … 69 71 char address[241]; 70 72 cgiFormString("address", address, 241); 71 fprintf(cgiOut,"Address: <PRE>\n%s</PRE>\n", address);73 printf( "Address: <PRE>\n%s</PRE>\n", address); 72 74 } 73 75 74 76 void Hungry() { 75 77 if (cgiFormCheckboxSingle("hungry") == cgiFormSuccess) { 76 fprintf(cgiOut,"I'm Hungry!<BR>\n");78 printf( "I'm Hungry!<BR>\n"); 77 79 } else { 78 fprintf(cgiOut,"I'm Not Hungry!<BR>\n");80 printf( "I'm Not Hungry!<BR>\n"); 79 81 } 80 82 } … … 83 85 double temperature; 84 86 cgiFormDoubleBounded("temperature", &temperature, 80.0, 120.0, 98.6); 85 fprintf(cgiOut,"My temperature is %f.<BR>\n", temperature);87 printf( "My temperature is %f.<BR>\n", temperature); 86 88 } 87 89 … … 89 91 int frogsEaten; 90 92 cgiFormInteger("frogs", &frogsEaten, 0); 91 fprintf(cgiOut,"I have eaten %d frogs.<BR>\n", frogsEaten);93 printf( "I have eaten %d frogs.<BR>\n", frogsEaten); 92 94 } 93 95 … … 101 103 int colorChoice; 102 104 cgiFormSelectSingle("colors", colors, 3, &colorChoice, 0); 103 fprintf(cgiOut,"I am: %s<BR>\n", colors[colorChoice]);105 printf( "I am: %s<BR>\n", colors[colorChoice]); 104 106 } 105 107 … … 118 120 flavorChoices, &invalid); 119 121 if (result == cgiFormNotFound) { 120 fprintf(cgiOut,"I hate ice cream.<p>\n");122 printf( "I hate ice cream.<p>\n"); 121 123 } else { 122 fprintf(cgiOut,"My favorite ice cream flavors are:\n");123 fprintf(cgiOut,"<ul>\n");124 printf( "My favorite ice cream flavors are:\n"); 125 printf( "<ul>\n"); 124 126 for (i=0; (i < 3); i++) { 125 127 if (flavorChoices[i]) { 126 fprintf(cgiOut,"<li>%s\n", flavors[i]);128 printf( "<li>%s\n", flavors[i]); 127 129 } 128 130 } 129 fprintf(cgiOut,"</ul>\n");131 printf( "</ul>\n"); 130 132 } 131 133 } … … 146 148 cgiFormRadio("age", ages, 4, &ageChoice, 0); 147 149 148 fprintf(cgiOut,"Age of Truck: %s (method #1)<BR>\n",150 printf( "Age of Truck: %s (method #1)<BR>\n", 149 151 ages[ageChoice]); 150 152 … … 157 159 cgiFormString("age", ageText, 10); 158 160 159 fprintf(cgiOut,"Age of Truck: %s (method #2)<BR>\n", ageText);161 printf( "Age of Truck: %s (method #2)<BR>\n", ageText); 160 162 } 161 163 … … 178 180 since votes for nonexistent candidates should probably 179 181 be discounted... */ 180 fprintf(cgiOut,"Votes (method 1):<BR>\n");182 printf( "Votes (method 1):<BR>\n"); 181 183 result = cgiFormCheckboxMultiple("vote", votes, 4, 182 184 voteChoices, &invalid); 183 185 if (result == cgiFormNotFound) { 184 fprintf(cgiOut,"I hate them all!<p>\n");186 printf( "I hate them all!<p>\n"); 185 187 } else { 186 fprintf(cgiOut,"My preferred candidates are:\n");187 fprintf(cgiOut,"<ul>\n");188 printf( "My preferred candidates are:\n"); 189 printf( "<ul>\n"); 188 190 for (i=0; (i < 4); i++) { 189 191 if (voteChoices[i]) { 190 fprintf(cgiOut,"<li>%s\n", votes[i]);192 printf( "<li>%s\n", votes[i]); 191 193 } 192 194 } 193 fprintf(cgiOut,"</ul>\n");195 printf( "</ul>\n"); 194 196 } 195 197 … … 198 200 than the code and invented responses are not a danger 199 201 or can be checked in some other way. */ 200 fprintf(cgiOut,"Votes (method 2):<BR>\n");202 printf( "Votes (method 2):<BR>\n"); 201 203 result = cgiFormStringMultiple("vote", &responses); 202 204 if (result == cgiFormNotFound) { 203 fprintf(cgiOut,"I hate them all!<p>\n");205 printf( "I hate them all!<p>\n"); 204 206 } else { 205 207 int i = 0; 206 fprintf(cgiOut,"My preferred candidates are:\n");207 fprintf(cgiOut,"<ul>\n");208 printf( "My preferred candidates are:\n"); 209 printf( "<ul>\n"); 208 210 while (responses[i]) { 209 fprintf(cgiOut,"<li>%s\n", responses[i]);211 printf( "<li>%s\n", responses[i]); 210 212 i++; 211 213 } 212 fprintf(cgiOut,"</ul>\n");214 printf( "</ul>\n"); 213 215 } 214 216 /* We must be sure to free the string array or a memory
Note: See TracChangeset
for help on using the changeset viewer.