From edf9c8316f5c4e9dd05b0ce8313d3b45bdcc9ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurek=20Muszy=C5=84ski?= Date: Fri, 19 Apr 2024 15:18:16 +0200 Subject: [PATCH] NPP_PHP for Windows --- lib/npp.h | 5 ++++- lib/npp_eng_app.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- lib/npp_lib.c | 29 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/lib/npp.h b/lib/npp.h index 540a439..6574f2f 100644 --- a/lib/npp.h +++ b/lib/npp.h @@ -100,7 +100,7 @@ typedef char bool; macros -------------------------------------------------------------------------- */ -#define NPP_VERSION "3.1.0" +#define NPP_VERSION "3.2.0" #ifndef FALSE @@ -1787,6 +1787,9 @@ extern int G_ASYNCId; extern int G_ASYNCSvcProcesses; extern int G_ASYNCDefTimeout; extern int G_callHTTPTimeout; +#ifdef NPP_PHP +extern char G_phpPathWindows[256]; +#endif /* end of config params */ diff --git a/lib/npp_eng_app.c b/lib/npp_eng_app.c index a07b5ae..987be6a 100644 --- a/lib/npp_eng_app.c +++ b/lib/npp_eng_app.c @@ -2994,6 +2994,10 @@ static bool init(int argc, char **argv) ALWAYS(" callHTTPTimeout = %d", G_callHTTPTimeout); +#ifdef NPP_PHP + ALWAYS(" phpPathWindows = %s", G_phpPathWindows); +#endif + ALWAYS(""); ALWAYS_LINE_LONG; ALWAYS(""); @@ -5067,6 +5071,48 @@ static void process_php() char cmd[4096]; +#ifdef _WIN32 + + STRM_BEGIN(cmd); + + if ( NPP_CONN_IS_PAYLOAD(G_connections[G_ci].flags) && G_connections[G_ci].clen > 0 && G_connections[G_ci].clen < 3072 ) + { + STRM("echo \"%s\" | ", npp_filter_qs(G_connections[G_ci].in_data)); + } + + STRM("set REDIRECT_STATUS=CGI "); + STRM("& set SCRIPT_FILENAME=%s/res/%s ", G_appdir, G_connections[G_ci].uri_no_qs); + STRM("& set REQUEST_METHOD=%s ", G_connections[G_ci].method); + +#ifdef NPP_PHP_ALL_COOKIES + if ( G_connections[G_ci].in_cookie[0] ) + STRM("& set \"HTTP_COOKIE=%s\" ", npp_filter_cookie(G_connections[G_ci].in_cookie)); +#else + if ( G_connections[G_ci].php_sessid[0] ) + STRM("& set \"HTTP_COOKIE=PHPSESSID=%s\" ", npp_filter_strict(G_connections[G_ci].php_sessid)); +#endif + + if ( REQ_GET && qs && *(qs+1) != EOS ) + { + STRM("& set \"QUERY_STRING=%s\" ", npp_filter_qs(qs+1)); + STRM("& set CONTENT_LENGTH=%d ", strlen(qs+1)); + STRM("& set CONTENT_TYPE=application/www-form-urlencoded "); + } + else if ( NPP_CONN_IS_PAYLOAD(G_connections[G_ci].flags) && G_connections[G_ci].clen > 0 && G_connections[G_ci].clen < 3072 ) + { + STRM("& set CONTENT_LENGTH=%d ", G_connections[G_ci].clen); + + if ( G_connections[G_ci].in_ctypestr[0] ) + STRM("& set CONTENT_TYPE=%s ", G_connections[G_ci].in_ctypestr); + else + STRM("& set CONTENT_TYPE=application/www-form-urlencoded "); + } + + STRM("| %s\\php-cgi", G_phpPathWindows); + STRM_END; + +#else /* Linux */ + STRM_BEGIN(cmd); if ( NPP_CONN_IS_PAYLOAD(G_connections[G_ci].flags) && G_connections[G_ci].clen > 0 && G_connections[G_ci].clen < 3072 ) @@ -5078,10 +5124,11 @@ static void process_php() STRM("SCRIPT_FILENAME=%s/res/%s ", G_appdir, G_connections[G_ci].uri_no_qs); STRM("REQUEST_METHOD=%s ", G_connections[G_ci].method); - if ( G_connections[G_ci].in_cookie[0] ) #ifdef NPP_PHP_ALL_COOKIES + if ( G_connections[G_ci].in_cookie[0] ) STRM("HTTP_COOKIE=\"%s\" ", npp_filter_cookie(G_connections[G_ci].in_cookie)); #else + if ( G_connections[G_ci].php_sessid[0] ) STRM("HTTP_COOKIE=\"PHPSESSID=%s\" ", npp_filter_strict(G_connections[G_ci].php_sessid)); #endif @@ -5104,6 +5151,8 @@ static void process_php() STRM("php-cgi"); STRM_END; +#endif /* _WIN32 */ + DBG("Executing [%s]...", cmd); FILE *pipe = popen(cmd, "r"); diff --git a/lib/npp_lib.c b/lib/npp_lib.c index a74cc93..c39206e 100644 --- a/lib/npp_lib.c +++ b/lib/npp_lib.c @@ -121,6 +121,10 @@ char G_call_http_content_type[NPP_MAX_VALUE_LEN+1]; int G_call_http_res_len=0; int G_qs_len=0; +#ifdef NPP_PHP +char G_phpPathWindows[256]="C:\\php"; +#endif + /* locals */ @@ -10510,6 +10514,10 @@ void npp_lib_read_conf(bool first) #endif G_callHTTPTimeout = CALL_HTTP_DEFAULT_TIMEOUT; + +#ifdef NPP_PHP + strcpy(G_phpPathWindows, "C:\\php"); +#endif } /* -------------------------------------------------- */ @@ -10804,6 +10812,27 @@ void npp_lib_read_conf(bool first) } } + /* -------------------------------------------------- */ + /* PHP path on Windows */ + +#ifdef NPP_PHP + + if ( first ) + { + npp_read_param_str("phpPathWindows", G_phpPathWindows); + } + else /* npp_reload_conf */ + { + char tmp_phpPathWindows[256]=""; + + npp_read_param_str("phpPathWindows", tmp_phpPathWindows); + + if ( strcmp(tmp_phpPathWindows, G_phpPathWindows) != 0 ) + strcpy(G_phpPathWindows, tmp_phpPathWindows); + } + +#endif /* NPP_PHP */ + #endif /* NPP_APP */ /* -------------------------------------------------- */