From 75ab44c7d23e3149a5154d3b46d7157aaa1e31d5 Mon Sep 17 00:00:00 2001 From: Slava Kulpichev Date: Wed, 2 Apr 2014 11:43:43 +0400 Subject: [PATCH] PHP extension repository begin --- CREDITS | 2 ++ Makefile_manual | 27 +++++++++++++++++++++++ build.sh | 6 +++++ clean.sh | 3 +++ config.m4 | 6 +++++ nw_util.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ test.sh | 4 ++++ 7 files changed, 106 insertions(+) create mode 100644 CREDITS create mode 100644 Makefile_manual create mode 100755 build.sh create mode 100755 clean.sh create mode 100644 config.m4 create mode 100644 nw_util.c create mode 100755 test.sh diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..f995cc3 --- /dev/null +++ b/CREDITS @@ -0,0 +1,2 @@ +nw_util +Denis Kozik diff --git a/Makefile_manual b/Makefile_manual new file mode 100644 index 0000000..77107f2 --- /dev/null +++ b/Makefile_manual @@ -0,0 +1,27 @@ + +CC = cc +LD = cc +GCC = gcc + +PHP_INC =/usr/include/php + +INCLUDES = -I . -I$(PHP_INC)/main -I$(PHP_INC)/Zend -I$(PHP_INC)/TSRM -I$(PHP_INC) + +CFLAGS = -DLINUX -Wall -O -fPIC +LDFLAGS = -g -shared -Wl + +OBJS = nw_util.o + +all: nw_util.so + +nw_util.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) $(CLIBS) +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< +clean: + rm -f ./*.o + rm -f ./*.so + rm -f ./*.lo + rm -f ./*.slo + rm -f ./*.libs + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..55e0cc4 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +phpize +./configure --enable-nw_util +make +make install \ No newline at end of file diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..583d31b --- /dev/null +++ b/clean.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +phpize --clean \ No newline at end of file diff --git a/config.m4 b/config.m4 new file mode 100644 index 0000000..327811e --- /dev/null +++ b/config.m4 @@ -0,0 +1,6 @@ +PHP_ARG_ENABLE(nw_util, Enable nw_util support) + +if test "$PHP_NW_UTIL" != "no"; then + AC_DEFINE(HAVE_NW_UTIL, 1, [You have nw_util extension]) + PHP_NEW_EXTENSION(nw_util, nw_util.c, $ext_shared) +fi diff --git a/nw_util.c b/nw_util.c new file mode 100644 index 0000000..1213538 --- /dev/null +++ b/nw_util.c @@ -0,0 +1,58 @@ +#include "php.h" + +PHP_FUNCTION(imagemagic_convert); + + +const zend_function_entry nw_util_functions[] = + { + PHP_FE(imagemagic_convert, NULL) + {NULL, NULL, NULL} + }; + +zend_module_entry nw_util_module_entry = + { + STANDARD_MODULE_HEADER, + "nw_util", + nw_util_functions, + NULL, + NULL, + NULL, + NULL, + NULL, + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES + }; + +ZEND_GET_MODULE(nw_util); + +PHP_FUNCTION(imagemagic_convert) +{ + char *params; + int plen; + char *execstr=NULL; + int res=0; + char *cmd="convert ", *pcmd=" > /dev/null 2>&1"; + int clen=strlen(cmd), pclen=strlen(pcmd); + char *cptr=NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", ¶ms, &plen) == FAILURE) { + return; + } + + execstr = malloc(plen+clen+pclen+1); + cptr=execstr; + memcpy(cptr, cmd, clen); cptr+=clen; + memcpy(cptr, params, plen); cptr+=plen; + memcpy(cptr, pcmd, pclen); cptr+=pclen; +// printf("execstr: [%s]\n", execstr); + *cptr='\0'; + + // popen http://www.sw-at.com/blog/2011/03/23/popen-execute-shell-command-from-cc/ + + res = system(execstr); + free(execstr); +// printf("res: %d\n", res); +// RETURN_STRING(params, 1); + RETURN_LONG(res); +// RETURN_STRING(execstr, 1); +} diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..818562f --- /dev/null +++ b/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +php -c /etc/php.ini -r "echo \"PHP RUNING TEST:\";" +php -c /etc/php.ini -r "echo \"[\".imagemagic_convert(\"$1\").\"]\n\";" \ No newline at end of file