2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: InterBase Access Method
|
2003-12-22 11:00:59 +01:00
|
|
|
* MODULE: functions.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: External entrypoint definitions
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2001-07-29 19:42:23 +02:00
|
|
|
#include "firebird.h"
|
2004-03-22 12:38:23 +01:00
|
|
|
#include "../jrd/common.h"
|
2004-04-29 00:36:29 +02:00
|
|
|
#include <stdio.h>
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <string.h>
|
2002-10-24 11:01:44 +02:00
|
|
|
#include "../jrd/jrd.h" /* For MAXPATHLEN Bug #126614 */
|
2004-08-21 11:42:42 +02:00
|
|
|
#include "../jrd/dsc_proto.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-04-29 00:36:29 +02:00
|
|
|
/* defined in common.h, which is included by stdio.h: typedef int (*FPTR_INT)(); */
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
2004-05-24 19:31:47 +02:00
|
|
|
struct FN {
|
2003-12-22 11:00:59 +01:00
|
|
|
const char* fn_module;
|
|
|
|
const char* fn_entrypoint;
|
2001-05-23 15:26:42 +02:00
|
|
|
FPTR_INT fn_function;
|
2004-05-24 19:31:47 +02:00
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
// FPTR_INT FUNCTIONS_entrypoint(char*, char*);
|
2004-08-27 06:56:22 +02:00
|
|
|
static int test(const long*, char*);
|
2002-06-30 12:44:49 +02:00
|
|
|
static DSC* ni(DSC*, DSC*);
|
2004-08-21 11:42:42 +02:00
|
|
|
static SLONG* byteLen(const dsc*);
|
2002-06-30 12:44:49 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
#pragma FB_COMPILER_MESSAGE("Fix! function pointer cast!")
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
static const FN isc_functions[] = {
|
2004-06-08 07:50:00 +02:00
|
|
|
{"test_module", "test_function", (FPTR_INT) test},
|
|
|
|
{"test_module", "ni", (FPTR_INT) ni},
|
|
|
|
{"test_module", "ns", (FPTR_INT) ni},
|
|
|
|
{"test_module", "nn", (FPTR_INT) ni},
|
2004-08-21 11:42:42 +02:00
|
|
|
{"test_module", "byte_len", (FPTR_INT) byteLen},
|
2002-01-04 12:34:22 +01:00
|
|
|
{0, 0, 0}
|
2001-05-23 15:26:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-06-08 07:50:00 +02:00
|
|
|
FPTR_INT FUNCTIONS_entrypoint(const char* module, const char* entrypoint)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* F U N C T I O N S _ e n t r y p o i n t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Lookup function in hardcoded table. The module and
|
|
|
|
* entrypoint names are null terminated, but may contain
|
|
|
|
* insignificant trailing blanks.
|
|
|
|
*
|
|
|
|
**************************************/
|
2003-12-22 11:00:59 +01:00
|
|
|
char temp[MAXPATHLEN + 128]; /* Bug #126614 Fix */
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
char* p = temp;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
while (*module && *module != ' ')
|
|
|
|
*p++ = *module++;
|
|
|
|
|
|
|
|
*p++ = 0;
|
2004-03-18 06:56:06 +01:00
|
|
|
const char* const ep = p;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
while (*entrypoint && *entrypoint != ' ')
|
|
|
|
*p++ = *entrypoint++;
|
|
|
|
|
|
|
|
*p = 0;
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
for (const FN* function = isc_functions; function->fn_module; ++function) {
|
2001-05-23 15:26:42 +02:00
|
|
|
if (!strcmp(temp, function->fn_module)
|
|
|
|
&& !strcmp(ep, function->fn_entrypoint))
|
2003-12-22 11:00:59 +01:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
return function->fn_function;
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-27 06:56:22 +02:00
|
|
|
static int test(const long* n, char *result)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* t e s t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Sample extern function. Defined in database by:
|
|
|
|
*
|
2004-06-08 07:50:00 +02:00
|
|
|
* QLI:
|
2001-05-23 15:26:42 +02:00
|
|
|
* define function test module_name "test_module" entry_point "test_function"
|
2004-08-27 06:56:22 +02:00
|
|
|
* long by reference //by value, CVC: BY VALUE is deprecated for input params
|
2001-05-23 15:26:42 +02:00
|
|
|
* char [20] by reference return_argument;
|
2004-06-08 07:50:00 +02:00
|
|
|
* ISQL:
|
|
|
|
* declare external function test
|
2004-08-27 06:56:22 +02:00
|
|
|
* int null, // CVC: with NULL signaling
|
2004-06-08 07:50:00 +02:00
|
|
|
* char(20) returns parameter 2
|
|
|
|
* entry_point 'test_function' module_name 'test_module';
|
2001-05-23 15:26:42 +02:00
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
|
2004-08-27 06:56:22 +02:00
|
|
|
if (n)
|
|
|
|
sprintf(result, "%ld is a number", *n);
|
|
|
|
else
|
|
|
|
sprintf(result, "is NULL");
|
2003-12-22 11:00:59 +01:00
|
|
|
const char* const end = result + 20;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
while (*result)
|
|
|
|
result++;
|
|
|
|
|
|
|
|
while (result < end)
|
|
|
|
*result++ = ' ';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
static dsc* ni(dsc* v, dsc* v2)
|
2002-06-30 12:44:49 +02:00
|
|
|
{
|
|
|
|
if (v)
|
|
|
|
return v;
|
|
|
|
else
|
|
|
|
return v2;
|
|
|
|
}
|
|
|
|
|
2004-08-21 11:42:42 +02:00
|
|
|
|
|
|
|
// byteLen: return the length in bytes of a given argument. For NULL, return NULL, too.
|
|
|
|
// v = input descriptor
|
|
|
|
// rc = return value, allocated dynamically. To be freed by the engine.
|
|
|
|
// The declaration through SQL is:
|
|
|
|
// declare external function sys_byte_len
|
|
|
|
// int by descriptor
|
|
|
|
// returns int free_it
|
|
|
|
// entry_point 'byte_len' module_name 'test_module';
|
|
|
|
static SLONG* byteLen(const dsc* v)
|
|
|
|
{
|
|
|
|
if (!v || !v->dsc_address || (v->dsc_flags & DSC_null))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SLONG& rc = *(SLONG*) malloc(sizeof(SLONG));
|
|
|
|
switch (v->dsc_dtype)
|
|
|
|
{
|
|
|
|
case dtype_text:
|
|
|
|
{
|
|
|
|
const UCHAR* const ini = v->dsc_address;
|
|
|
|
const UCHAR* end = ini + v->dsc_length;
|
|
|
|
while (ini < end && *--end == ' '); // empty loop body
|
|
|
|
rc = end - ini + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dtype_cstring:
|
|
|
|
{
|
|
|
|
rc = 0;
|
|
|
|
for (const UCHAR* p = v->dsc_address; *p; ++p, ++rc); // empty loop body
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dtype_varying:
|
|
|
|
rc = reinterpret_cast<const vary*>(v->dsc_address)->vary_length;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = DSC_string_length(v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
} // extern "C"
|
2003-12-22 11:00:59 +01:00
|
|
|
|