Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fcgi/cgi creation in same makefile, consolidated fastcgi cgic patch

  • Loading branch information...
commit a371be4fc635458b582b25fbf0e95f2d047e9aaa 1 parent 83eb29e
Alan Dipert authored
View
28 Makefile
@@ -1,33 +1,35 @@
CC=gcc
-LIBS=-L/usr/local/lib cgic/libcgic.a -lcurl -lfcgi
-FCGI_HEADERS=-I/usr/local/include
-INCLUDE=-Icgic $(FCGI_HEADERS)
+LIBS=-L/usr/local/lib cgic/libcgic.a -lcurl
+FCGI_INCLUDE=-I/usr/local/include
+FCGI_LIBS=-lfcgi
+INCLUDE=-Icgic
CFLAGS+=-g -Wall
-CFLAGS+=$(INCLUDE)
#CFLAGS+=-O2
OBJECTS+=main.o fetch.o error.o request.o
CGIC_VER = 205
CGIC_URL = http://www.boutell.com/cgic/cgic$(CGIC_VER).tar.gz
-INSTALLDIR = /Users/alan/Sites/cgi-bin
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =
all: jsonptunnel.fcgi
-jsonptunnel.fcgi: $(OBJECTS) libcgic
- $(CC) $(CFLAGS) $(INCLUDE) -o jsonptunnel.fcgi $(OBJECTS) $(LIBS)
+cgi: jsonptunnel.cgi
+
+fcgi: jsonptunnel.fcgi
-install: jsonptunnel.fcgi
- cp jsonptunnel.fcgi $(INSTALLDIR)
+jsonptunnel.cgi: $(OBJECTS) libcgic
+ $(CC) $(CFLAGS) $(INCLUDE) -o jsonptunnel.cgi $(OBJECTS) $(LIBS)
+
+jsonptunnel.fcgi: $(OBJECTS) libcgic
+ $(CC) $(CFLAGS) -DUSE_FASTCGI=1 $(INCLUDE) $(FCGI_INCLUDE) -o jsonptunnel.fcgi $(OBJECTS) $(LIBS) $(FCGI_LIBS)
libcgic:
$(QUIET_SUBDIR0)cgic $(QUIET_SUBDIR1) libcgic.a
get-cgic:
- curl $(CGIC_URL) | tar -xz && rm -rf git && mv cgic$(CGIC_VER) cgic
- patch cgic/cgic.c patches/cgic.c.patch
- patch cgic/cgic.h patches/cgic.h.patch
+ curl $(CGIC_URL) | tar -xz && rm -rf cgic && mv cgic$(CGIC_VER) cgic
+ patch cgic/cgic.c patches/fastcgic-cgic.patch
clean:
- rm -f *.o *.a jsonptunnel.fcgi
+ rm -f *.o *.a jsonptunnel.fcgi jsonptunnel.cgi
View
4 error.c
@@ -1,4 +1,8 @@
+#if USE_FASTCGI
#include <fcgi_stdio.h>
+#else
+#include <stdio.h>
+#endif
#include "cgic/cgic.h"
#include "jsonptunnel.h"
View
9 fetch.c
@@ -1,7 +1,14 @@
+#if USE_FASTCGI
#include <fcgi_stdio.h>
+#else
+#include <stdio.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
#include "cgic/cgic.h"
#include "jsonptunnel.h"
@@ -11,6 +18,8 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream) {
int doPostReq(struct extRequest *req) {
+ cgiHeaderContentType("text/json");
+
CURL *curl;
CURLcode res;
View
4 jsonptunnel.h
@@ -1,7 +1,3 @@
-#include <fcgi_stdio.h>
-#include <curl/curl.h>
-#include <curl/types.h>
-#include <curl/easy.h>
/*
* Required parameters.
View
4 main.c
@@ -8,7 +8,11 @@
* HTTP action to cgiOut (stdout).
*/
+#if USE_FASTCGI
#include <fcgi_stdio.h>
+#else
+#include <stdio.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include "cgic/cgic.h"
View
63 patches/cgic.c.patch
@@ -1,63 +0,0 @@
---- cgic.c 2004-11-15 11:57:59.000000000 -0500
-+++ ../jsonptunnel/cgic/cgic.c 2008-12-16 20:42:33.000000000 -0500
-@@ -22,7 +22,8 @@
- #define CGICDEBUGEND
- #endif /* CGICDEBUG */
-
--#include <stdio.h>
-+//#include <stdio.h>
-+#include <fcgi_stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
-@@ -120,7 +121,8 @@ static int cgiStrEqNc(char *s1, char *s2
- static int cgiStrBeginsNc(char *s1, char *s2);
-
- int main(int argc, char *argv[]) {
-- int result;
-+ while(FCGI_Accept() >= 0) {
-+ //int result;
- char *cgiContentLengthString;
- char *e;
- cgiSetupConstants();
-@@ -236,7 +238,7 @@ int main(int argc, char *argv[]) {
- CGICDEBUGEND
- #endif /* CGICDEBUG */
- cgiFreeResources();
-- return -1;
-+ //return -1;
- }
- #ifdef CGICDEBUG
- CGICDEBUGSTART
-@@ -256,7 +258,7 @@ int main(int argc, char *argv[]) {
- CGICDEBUGEND
- #endif /* CGICDEBUG */
- cgiFreeResources();
-- return -1;
-+ //return -1;
- }
- #ifdef CGICDEBUG
- CGICDEBUGSTART
-@@ -275,7 +277,7 @@ int main(int argc, char *argv[]) {
- CGICDEBUGEND
- #endif /* CGICDEBUG */
- cgiFreeResources();
-- return -1;
-+ //return -1;
- } else {
- #ifdef CGICDEBUG
- CGICDEBUGSTART
-@@ -284,9 +286,11 @@ int main(int argc, char *argv[]) {
- #endif /* CGICDEBUG */
- }
- }
-- result = cgiMain();
-+ cgiMain();
- cgiFreeResources();
-- return result;
-+ }
-+
-+ return 0;
- }
-
- static void cgiGetenv(char **s, char *var){
View
11 patches/cgic.h.patch
@@ -1,11 +0,0 @@
---- cgic.h 2004-04-22 16:49:47.000000000 -0400
-+++ ../jsonptunnel/cgic/cgic.h 2008-12-16 15:35:13.000000000 -0500
-@@ -9,7 +9,7 @@
- /* Bring in standard I/O since some of the functions refer to
- types defined by it, such as FILE *. */
-
--#include <stdio.h>
-+#include <fcgi_stdio.h>
-
- /* The various CGI environment variables. Instead of using getenv(),
- the programmer should refer to these, which are always
View
32 patches/fastcgic-cgic.patch
@@ -0,0 +1,32 @@
+--- cgic.c 2004-11-15 08:57:59.000000000 -0800
++++ cgic.c.patched 2008-12-18 08:19:02.000000000 -0800
+@@ -120,7 +120,11 @@
+ static int cgiStrBeginsNc(char *s1, char *s2);
+
+ int main(int argc, char *argv[]) {
++ #ifdef USE_FASTCGI
++ while(FCGI_Accept() >= 0) {
++ #else
+ int result;
++ #endif
+ char *cgiContentLengthString;
+ char *e;
+ cgiSetupConstants();
+@@ -284,9 +288,17 @@
+ #endif /* CGICDEBUG */
+ }
+ }
++ #ifdef USE_FASTCGI
++ cgiMain();
++ cgiFreeResources();
++ }
++
++ return 1;
++ #else
+ result = cgiMain();
+ cgiFreeResources();
+ return result;
++ #endif
+ }
+
+ static void cgiGetenv(char **s, char *var){
View
5 request.c
@@ -1,5 +1,8 @@
-//#include <stdio.h>
+#if USE_FASTCGI
#include <fcgi_stdio.h>
+#else
+#include <stdio.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include "cgic/cgic.h"
Please sign in to comment.
Something went wrong with that request. Please try again.