Bladeren bron

add getcontent

stanley-king 9 jaren geleden
bovenliggende
commit
0b0a6d98b9
2 gewijzigde bestanden met toevoegingen van 33 en 1 verwijderingen
  1. 32 1
      fcgi.c
  2. 1 0
      php_fcgi.h

+ 32 - 1
fcgi.c

@@ -38,6 +38,7 @@ const zend_function_entry fcgi_functions[] = {
 	PHP_FE(fcgi_finish,	NULL)	
 	PHP_FE(fcgi_getparam, NULL)
 	PHP_FE(fcgi_echo, NULL)
+	PHP_FE(fcgi_getcontent, NULL)
 	PHP_FE_END	/* Must be the last line in fcgi_functions[] */
 };
 
@@ -150,12 +151,42 @@ PHP_FUNCTION(fcgi_getparam)
 	}
 
 	const char* ret = FCGX_GetParam(arg, stParams);
-	ret == NULL ? "" : ret;
+	ret = (ret == NULL) ? "" : ret;
 
 	char* result = estrdup(ret);
 	RETURN_STRINGL(result,strlen(result),0);
 }
 
+static int content_length()
+{
+	const char* pbuf = FCGX_GetParam("CONTENT_LENGTH", stParams);
+	if(pbuf)
+	{
+	    if(strlen(pbuf) == 0)
+	        return 0;
+	    else
+	        return atoi(pbuf);
+	} else {
+	    return 0;
+	}
+}
+
+PHP_FUNCTION(fcgi_getcontent)
+{
+	int con_len = content_length();
+	if(con_len) {
+		char* pCon = (char*)malloc(con_len + 1);
+		con_len = FCGX_GetStr(pCon, con_len, stInstream);
+		pCon[con_len] = '\0';	
+
+		char* result = estrdup(pCon);
+		RETURN_STRINGL(result,strlen(result),0);
+	} else {
+		char* result = estrdup("");
+		RETURN_STRINGL(result,strlen(result),0);
+	}
+}
+
 PHP_FUNCTION(fcgi_echo)
 {
 	char *arg = NULL;	 

+ 1 - 0
php_fcgi.h

@@ -52,6 +52,7 @@ PHP_FUNCTION(fcgi_accept);
 PHP_FUNCTION(fcgi_finish);
 PHP_FUNCTION(fcgi_getparam);
 PHP_FUNCTION(fcgi_echo);
+PHP_FUNCTION(fcgi_getcontent);