Alignment of UDF source code

This commit is contained in:
Bernardo Damele 2010-07-01 15:44:47 +00:00
parent 49af0c43a5
commit fa1357b40f
10 changed files with 1221 additions and 1191 deletions

View File

@ -37,7 +37,7 @@ fi
echo -e "\nPlease provide your MySQL root password"
mysql -u ${USER} -P ${PORT} -p mysql < lib_mysqludf_sys.sql
mysql -h 127.0.0.1 -P ${PORT} -u ${USER} -p mysql < lib_mysqludf_sys.sql
if test $? -ne 0; then
echo "ERROR: unable to install the UDF"

View File

@ -19,6 +19,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define DLLEXP __declspec(dllexport)
#else
@ -55,7 +56,7 @@ typedef long long longlong;
extern "C" {
#endif
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
#define LIBVERSION "lib_mysqludf_sys version 0.0.4"
#ifdef __WIN__
#define SETENV(name,value) SetEnvironmentVariable(name,value);
@ -446,7 +447,7 @@ char* sys_eval(
while (fgets(line, sizeof(line), pipe) != NULL) {
linelen = strlen(line);
result = realloc(result, outlen + linelen);
result = (char *)realloc(result, outlen + linelen);
strncpy(result + outlen, line, linelen);
outlen = outlen + linelen;
}
@ -480,7 +481,6 @@ int sys_bineval(
UDF_INIT *initid
, UDF_ARGS *args
){
int32 argv0_size;
size_t len;
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
@ -492,8 +492,7 @@ int sys_bineval(
pid_t pID;
#endif
argv0_size = strlen(args->args[0]);
len = (size_t)argv0_size;
len = (size_t)strlen(args->args[0]);
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
// allocate a +rwx memory page
@ -529,7 +528,22 @@ int sys_bineval(
return 0;
}
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#if defined(_WIN64)
void __exec_payload(LPVOID);
DWORD WINAPI exec_payload(LPVOID lpParameter)
{
__try
{
__exec_payload(lpParameter);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return 0;
}
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
DWORD WINAPI exec_payload(LPVOID lpParameter)
{
__try
@ -542,7 +556,6 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return 0;

View File

@ -48,29 +48,29 @@ PG_MODULE_MAGIC;
char *text_ptr_to_char_ptr(text *arg)
{
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
return retVal;
return retVal;
}
text *chr_ptr_to_text_ptr(char *arg)
{
text *retVal;
text *retVal;
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
#ifdef SET_VARSIZE
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
#else
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
#endif
memcpy(VARDATA(retVal), arg, strlen(arg));
memcpy(VARDATA(retVal), arg, strlen(arg));
return retVal;
return retVal;
}
PG_FUNCTION_INFO_V1(sys_exec);

View File

@ -37,7 +37,7 @@ fi
echo -e "\nPlease provide your MySQL root password"
mysql -u ${USER} -P ${PORT} -p mysql < lib_mysqludf_sys.sql
mysql -h 127.0.0.1 -P ${PORT} -u ${USER} -p mysql < lib_mysqludf_sys.sql
if test $? -ne 0; then
echo "ERROR: unable to install the UDF"

View File

@ -19,6 +19,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define DLLEXP __declspec(dllexport)
#else
@ -55,7 +56,7 @@ typedef long long longlong;
extern "C" {
#endif
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
#define LIBVERSION "lib_mysqludf_sys version 0.0.4"
#ifdef __WIN__
#define SETENV(name,value) SetEnvironmentVariable(name,value);
@ -446,7 +447,7 @@ char* sys_eval(
while (fgets(line, sizeof(line), pipe) != NULL) {
linelen = strlen(line);
result = realloc(result, outlen + linelen);
result = (char *)realloc(result, outlen + linelen);
strncpy(result + outlen, line, linelen);
outlen = outlen + linelen;
}
@ -480,7 +481,6 @@ int sys_bineval(
UDF_INIT *initid
, UDF_ARGS *args
){
int32 argv0_size;
size_t len;
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
@ -492,8 +492,7 @@ int sys_bineval(
pid_t pID;
#endif
argv0_size = strlen(args->args[0]);
len = (size_t)argv0_size;
len = (size_t)strlen(args->args[0]);
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
// allocate a +rwx memory page
@ -529,7 +528,22 @@ int sys_bineval(
return 0;
}
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#if defined(_WIN64)
void __exec_payload(LPVOID);
DWORD WINAPI exec_payload(LPVOID lpParameter)
{
__try
{
__exec_payload(lpParameter);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return 0;
}
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
DWORD WINAPI exec_payload(LPVOID lpParameter)
{
__try
@ -542,7 +556,6 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return 0;

View File

@ -48,29 +48,29 @@ PG_MODULE_MAGIC;
char *text_ptr_to_char_ptr(text *arg)
{
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
return retVal;
return retVal;
}
text *chr_ptr_to_text_ptr(char *arg)
{
text *retVal;
text *retVal;
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
#ifdef SET_VARSIZE
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
#else
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
#endif
memcpy(VARDATA(retVal), arg, strlen(arg));
memcpy(VARDATA(retVal), arg, strlen(arg));
return retVal;
return retVal;
}
PG_FUNCTION_INFO_V1(sys_exec);

View File

@ -56,7 +56,7 @@ typedef long long longlong;
extern "C" {
#endif
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
#define LIBVERSION "lib_mysqludf_sys version 0.0.4"
#ifdef __WIN__
#define SETENV(name,value) SetEnvironmentVariable(name,value);
@ -436,17 +436,18 @@ char* sys_eval(
, char *error
){
FILE *pipe;
char line[1024];
char *line;
unsigned long outlen, linelen;
result = malloc(1);
line = (char *)malloc(1024);
result = (char *)malloc(1);
outlen = 0;
pipe = popen(args->args[0], "r");
while (fgets(line, sizeof(line), pipe) != NULL) {
linelen = strlen(line);
result = realloc(result, outlen + linelen);
result = (char *)realloc(result, outlen + linelen);
strncpy(result + outlen, line, linelen);
outlen = outlen + linelen;
}

View File

@ -48,29 +48,29 @@ PG_MODULE_MAGIC;
char *text_ptr_to_char_ptr(text *arg)
{
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
char *retVal;
int arg_size = VARSIZE(arg) - VARHDRSZ;
retVal = (char *)malloc(arg_size + 1);
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
memcpy(retVal, VARDATA(arg), arg_size);
retVal[arg_size] = '\0';
return retVal;
return retVal;
}
text *chr_ptr_to_text_ptr(char *arg)
{
text *retVal;
text *retVal;
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
#ifdef SET_VARSIZE
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
#else
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
#endif
memcpy(VARDATA(retVal), arg, strlen(arg));
memcpy(VARDATA(retVal), arg, strlen(arg));
return retVal;
return retVal;
}
PG_FUNCTION_INFO_V1(sys_exec);
@ -108,7 +108,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
char *command;
char *result;
FILE *pipe;
char line[1024];
char *line;
int32 outlen, linelen;
command = text_ptr_to_char_ptr(argv0);
@ -118,6 +118,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
elog(NOTICE, "Command evaluated: %s", command);
*/
line = (char *)malloc(1024);
result = (char *)malloc(1);
outlen = 0;

View File

@ -56,7 +56,7 @@ typedef long long longlong;
extern "C" {
#endif
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
#define LIBVERSION "lib_mysqludf_sys version 0.0.4"
#ifdef __WIN__
#define SETENV(name,value) SetEnvironmentVariable(name,value);
@ -436,17 +436,18 @@ char* sys_eval(
, char *error
){
FILE *pipe;
char line[1024];
char *line;
unsigned long outlen, linelen;
result = malloc(1);
line = (char *)malloc(1024);
result = (char *)malloc(1);
outlen = 0;
pipe = popen(args->args[0], "r");
while (fgets(line, sizeof(line), pipe) != NULL) {
linelen = strlen(line);
result = realloc(result, outlen + linelen);
result = (char *)realloc(result, outlen + linelen);
strncpy(result + outlen, line, linelen);
outlen = outlen + linelen;
}

View File

@ -0,0 +1 @@
PostgreSQL does not compile under Windows 64-bit.