Browse Source

Added

experimental/namespaces
Mark L. Woodward 25 years ago
parent
commit
ba2bc65d31
  1. 3
      ext/msession/CREDITS
  2. 16
      ext/msession/Makefile
  3. 11
      ext/msession/Makefile.in
  4. 21
      ext/msession/README
  5. 15
      ext/msession/config.m4
  6. 7
      ext/msession/libs.mk
  7. 802
      ext/msession/msession.c
  8. 10
      ext/msession/msession.php
  9. 105
      ext/msession/php_msession.h
  10. 108
      ext/msession/reqclient.h

3
ext/msession/CREDITS

@ -0,0 +1,3 @@
msession
Mark L. Woodward
mailto:mlwmohawk@mohawksoft.com

16
ext/msession/Makefile

@ -0,0 +1,16 @@
top_srcdir = /local/projects/php/php4
top_builddir = /local/projects/php/php4
srcdir = /local/projects/php/php4/ext/msession
builddir = /local/projects/php/php4/ext/msession
VPATH = /local/projects/php/php4/ext/msession
# $Id$
LTLIBRARY_NAME = libmsession.la
LTLIBRARY_SOURCES = msession.c
LTLIBRARY_SHARED_NAME = msession.la
LTLIBRARY_SHARED_LIBADD = $(PHOENIX_LIB)
EXTRA_INCLUDES = $(PHOENIX_INCLUDE)
include $(top_srcdir)/build/dynlib.mk

11
ext/msession/Makefile.in

@ -0,0 +1,11 @@
# $Id$
LTLIBRARY_NAME = libmsession.la
LTLIBRARY_SOURCES = msession.c
LTLIBRARY_SHARED_NAME = msession.la
LTLIBRARY_SHARED_LIBADD = $(PHOENIX_LIB)
EXTRA_INCLUDES = $(PHOENIX_INCLUDE)
include $(top_srcdir)/build/dynlib.mk

21
ext/msession/README

@ -0,0 +1,21 @@
This is msession, it is an interface to a stand-alone session
management system. The msession daemon can be found at
HTTP://www.mohawksoft.com under Project Phoenix
Requirements:
Mohawk Software's Phoenix library.
Mohawk Software's msession daemon.
http://www.mohawksoft.com/phoenix.html
Building:
I am still a newbee at PHP hacking so I am scared to death
I will break something, and I (regretfully) have not invested
the time to make all this stuff automatic.
In the config.m4 file you will need to specify the include
and library directories for Phoenix. The setting in config.m4
is probably wrong.

15
ext/msession/config.m4

@ -0,0 +1,15 @@
PHP_ARG_WITH(msession, for msession support,
[ --with-msession Include msession support])
if test "$PHP_MSESSION" != "no"; then
PHOENIX_HOME="/local/projects/phoenix"
AC_DEFINE(HAVE_MSESSION, 1, [ ])
PHP_EXTENSION(msession, $ext_shared)
PHOENIX_INCLUDE_="-I/local/projects/phoenix/lib"
PHP_ADD_LIBRARY_WITH_PATH(phoenix, "/local/projects/phoenix/lib", PHOENIX_LIB)
PHP_SUBST(PHOENIX_INCLUDE)
PHP_SUBST(PHOENIX_LIB)
fi

7
ext/msession/libs.mk

@ -0,0 +1,7 @@
include $(top_builddir)/config_vars.mk
LTLIBRARY_OBJECTS = $(LTLIBRARY_SOURCES:.c=.lo) $(LTLIBRARY_OBJECTS_X)
LTLIBRARY_SHARED_OBJECTS = $(LTLIBRARY_OBJECTS:.lo=.slo)
$(LTLIBRARY_NAME): $(LTLIBRARY_OBJECTS) $(LTLIBRARY_DEPENDENCIES)
$(LINK) $(LTLIBRARY_LDFLAGS) $(LTLIBRARY_OBJECTS) $(LTLIBRARY_LIBADD)
targets = $(LTLIBRARY_NAME)

802
ext/msession/msession.c

@ -0,0 +1,802 @@
/*
+----------------------------------------------------------------------+
| msession 1.0 |
+----------------------------------------------------------------------+
| Copyright (c) 2001 Mark L. Woodward (Mohawk Software) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Mark Woodward <markw@mohawksoft.com> |
| Portions copyright the PHP group. |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "php_ini.h"
#include "php_msession.h"
#include "reqclient.h"
#if HAVE_MSESSION
// #define ERR_DEBUG
/* If you declare any globals in php_msession.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(msession)
*/
/* True global resources - no need for thread safety here */
static int le_msession;
static char g_defhost[]="localhost";
static char * g_host=g_defhost;
static int g_port=8086;
static void * g_conn=NULL;
static REQB * g_reqb=NULL;
#define REQ_SIZE 1024
#define GET_REQB \
if(!g_reqb) { RETURN_NULL(); }
/* Every user visible function must have an entry in msession_functions[].
*/
function_entry msession_functions[] = {
PHP_FE(confirm_msession_compiled, NULL) /* For testing, remove later. */
PHP_FE(msession_connect,NULL)
PHP_FE(msession_disconnect,NULL)
PHP_FE(msession_lock,NULL)
PHP_FE(msession_unlock,NULL)
PHP_FE(msession_count,NULL)
PHP_FE(msession_create,NULL)
PHP_FE(msession_destroy,NULL)
PHP_FE(msession_set,NULL)
PHP_FE(msession_get,NULL)
PHP_FE(msession_find,NULL)
PHP_FE(msession_get_array,NULL)
PHP_FE(msession_timeout,NULL)
PHP_FE(msession_inc,NULL)
PHP_FE(msession_setdata,NULL)
PHP_FE(msession_getdata,NULL)
PHP_FE(msession_listvar,NULL)
PHP_FE(msession_list,NULL)
PHP_FE(msession_uniq,NULL)
{NULL, NULL, NULL} /* Must be the last line in msession_functions[] */
};
zend_module_entry msession_module_entry = {
"msession",
msession_functions,
PHP_MINIT(msession),
PHP_MSHUTDOWN(msession),
PHP_RINIT(msession), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(msession),/* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(msession),
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_MSESSION
ZEND_GET_MODULE(msession)
#endif
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
PHP_INI_END()
*/
PHP_MINIT_FUNCTION(msession)
{
/* Remove comments if you have entries in php.ini
REGISTER_INI_ENTRIES();
*/
g_conn = NULL;
g_host = g_defhost;
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(msession)
{
/* Remove comments if you have entries in php.ini
UNREGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* Remove if there's nothing to do at request start */
PHP_RINIT_FUNCTION(msession)
{
return SUCCESS;
}
/* Remove if there's nothing to do at request end */
PHP_RSHUTDOWN_FUNCTION(msession)
{
if(g_conn)
{
CloseReqConn(g_conn);
g_conn = NULL;
}
if(g_reqb)
{
FreeRequestBuffer(g_reqb);
g_reqb=NULL;
}
return SUCCESS;
}
PHP_MINFO_FUNCTION(msession)
{
php_info_print_table_start();
php_info_print_table_header(2, "msession support", "enabled");
php_info_print_table_end();
/* Remove comments if you have entries in php.ini
DISPLAY_INI_ENTRIES();
*/
}
PHP_FUNCTION(confirm_msession_compiled)
{
zval **arg;
int len;
char string[256];
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(arg);
len = sprintf(string, "(%s) Module %s is compiled into PHP, g_host:%s, g_port:%d",
__TIME__,
Z_STRVAL_PP(arg),
g_host,
g_port);
RETURN_STRINGL(string, len, 1);
}
int PHPMsessionConnect(char *szhost, int nport)
{
if(!g_reqb)
g_reqb = AllocateRequestBuffer(2048);
if(!g_reqb) // no buffer, it won't work!
return 0;
if(g_conn)
{
CloseReqConn(g_conn);
php_log_err("Call to connect with non-null g_conn");
}
if(strcmp(g_host, szhost))
{
if(g_host != g_defhost)
free(g_host);
g_host = strdup(szhost);
}
if(nport)
g_port = nport;
g_conn = OpenReqConn(g_host, g_port);
#ifdef ERR_DEBUG
{
char buffer[256];
sprintf(buffer,"Connect: %s [%d] = %d (%X)\n",
g_host, g_port, (g_conn != NULL), (unsigned)g_conn);
php_log_err(buffer);
}
#endif
return (g_conn) ? 1 : 0;
}
void PHPMsessionDisconnect()
{
if(g_conn)
{
CloseReqConn(g_conn);
g_conn = NULL;
}
if(g_reqb)
{
FreeRequestBuffer(g_reqb);
g_reqb = NULL;
}
}
char *PHPMsessionGetData(char *session)
{
char *ret = NULL;
#ifdef ERR_DEBUG
sprintf(buffer,"PHPMsessionGetData: %s (%X)\n", session, (unsigned)g_conn);
php_log_err(buffer);
#endif
if(!g_reqb)
{
return NULL ;
}
FormatRequest(&g_reqb, REQ_DATAGET, session,"","",0);
DoRequest(g_conn, &g_reqb);
if(g_reqb->req.stat==REQ_OK)
ret = safe_estrdup(g_reqb->req.datum);
return ret;
}
int PHPMsessionSetData(char *session, char *data)
{
int ret=0;
#ifdef ERR_DEBUG
sprintf(buffer,"PHPMsessionSetData: %s=%s (%X)\n", session, data, (unsigned)g_conn);
php_log_err(buffer);
#endif
if(!g_reqb)
{
return 0;
}
FormatRequest(&g_reqb, REQ_DATASET, session,"",data,0);
DoRequest(g_conn,&g_reqb);
ret = (g_reqb->req.stat==REQ_OK);
return ret;
}
int PHPMsessionDestroy(char *session)
{
int ret=0;
if(!g_reqb)
{
return 0;
}
FormatRequest(&g_reqb, REQ_DROP, session, "","",0);
DoRequest(g_conn,&g_reqb);
ret = (g_reqb->req.stat==REQ_OK);
return ret;
}
PHP_FUNCTION(msession_connect)
{
char *szhost;
int nport;
zval **zhost;
zval **zport;
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &zhost, &zport) == FAILURE)
{
WRONG_PARAM_COUNT;
}
convert_to_string_ex(zhost);
convert_to_string_ex(zport);
szhost = Z_STRVAL_PP(zhost);
nport = atoi(Z_STRVAL_PP(zport));
if(PHPMsessionConnect(szhost,nport))
{
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
PHP_FUNCTION(msession_disconnect)
{
PHPMsessionDisconnect();
RETURN_NULL();
}
PHP_FUNCTION(msession_count)
{
if(g_conn)
{
int count;
GET_REQB
FormatRequest(&g_reqb, REQ_COUNT, "", "","",0);
DoRequest(g_conn,&g_reqb);
count = (g_reqb->req.stat == REQ_OK) ? g_reqb->req.param : 0;
RETURN_LONG(count);
}
RETURN_NULL();
}
PHP_FUNCTION(msession_create)
{
int stat;
char *val;
zval **session;
GET_REQB
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &session) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
FormatRequest(&g_reqb, REQ_CREATE, Z_STRVAL_PP(session), "","",0);
DoRequest(g_conn,&g_reqb);
stat = (g_reqb->req.stat==REQ_OK);
if(stat)
{
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
PHP_FUNCTION(msession_destroy)
{
char *val;
zval **session;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &session) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
PHPMsessionDestroy(Z_STRVAL_PP(session));
RETURN_TRUE;
}
PHP_FUNCTION(msession_lock)
{
long key;
char *val;
zval **session;
GET_REQB
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &session) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
FormatRequest(&g_reqb, REQ_SLOCK, Z_STRVAL_PP(session), "","",0);
DoRequest(g_conn,&g_reqb);
key = (g_reqb->req.stat == REQ_OK) ? g_reqb->req.param : 0;
RETURN_LONG( key);
}
PHP_FUNCTION(msession_unlock)
{
long lkey;
char *val;
zval **session;
zval **key;
GET_REQB
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &session, &key) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
convert_to_long_ex(key);
FormatRequest(&g_reqb, REQ_SUNLOCK, Z_STRVAL_PP(session), "","",Z_LVAL_PP(key));
DoRequest(g_conn,&g_reqb);
lkey = (g_reqb->req.stat == REQ_OK) ? g_reqb->req.param : 0;
RETURN_LONG( lkey);
}
PHP_FUNCTION(msession_set)
{
zval **session;
zval **name;
zval **value;
GET_REQB
if(ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &session, &name, &value) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
convert_to_string_ex(name);
convert_to_string_ex(value);
FormatRequest(&g_reqb, REQ_SETVAL, Z_STRVAL_PP(session), Z_STRVAL_PP(name), Z_STRVAL_PP(value),0);
DoRequest(g_conn,&g_reqb);
if(g_reqb->req.stat==REQ_OK)
{
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
PHP_FUNCTION(msession_get)
{
char *val;
zval **session;
zval **name;
zval **value;
GET_REQB
if(ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &session, &name, &value) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
convert_to_string_ex(name);
convert_to_string_ex(value);
val = Z_STRVAL_PP(value);
FormatRequest(&g_reqb, REQ_GETVAL, Z_STRVAL_PP(session), Z_STRVAL_PP(name), val,0);
DoRequest(g_conn, &g_reqb);
if(g_reqb->req.stat==REQ_OK)
val = safe_estrdup(g_reqb->req.datum);
RETURN_STRING(val, 0)
}
PHP_FUNCTION(msession_uniq)
{
long val;
zval **param;
GET_REQB
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,&param) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_long_ex(param);
val = Z_LVAL_PP(param);
FormatRequest(&g_reqb, REQ_UNIQ,"", "", "",val);
DoRequest(g_conn, &g_reqb);
if(g_reqb->req.stat==REQ_OK)
{
char *szval = safe_estrdup(g_reqb->req.datum);
RETURN_STRING(szval, 0)
}
else
{
RETURN_NULL();
}
}
PHP_FUNCTION(msession_find)
{
zval **name;
zval **value;
GET_REQB
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &name, &value) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(name);
convert_to_string_ex(value);
FormatRequest(&g_reqb, REQ_FIND, "", Z_STRVAL_PP(name), Z_STRVAL_PP(value),0);
DoRequest(g_conn,&g_reqb);
if(g_reqb->req.stat==REQ_OK && g_reqb->req.param)
{
int i;
char *str = g_reqb->req.datum;
array_init(return_value);
for(i=0; i < g_reqb->req.param; i++)
{
int element_len = strlen(str);
char *data = safe_estrdup(str);
add_index_string(return_value, i, data, 0);
str += (element_len+1);
}
}
else
{
RETURN_NULL();
}
}
PHP_FUNCTION(msession_list)
{
zval **name;
zval **value;
GET_REQB
if(!g_conn)
{
RETURN_FALSE;
}
FormatRequest(&g_reqb, REQ_LIST, "", "", "",0);
DoRequest(g_conn,&g_reqb);
if(g_reqb->req.stat==REQ_OK && g_reqb->req.param)
{
int i;
char *str = g_reqb->req.datum;
array_init(return_value);
for(i=0; i < g_reqb->req.param; i++)
{
int element_len = strlen(str);
char *data = safe_estrdup(str);
add_index_string(return_value, i, data, 0);
str += (element_len+1);
}
}
else
{
RETURN_NULL();
}
}
PHP_FUNCTION(msession_get_array)
{
zval **session;
GET_REQB
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &session) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
FormatRequest(&g_reqb, REQ_GETALL, Z_STRVAL_PP(session), "", "",0);
DoRequest(g_conn,&g_reqb);
array_init(return_value);
if(g_reqb->req.stat == REQ_OK)
{
int i;
char *str = g_reqb->req.datum;
int num = g_reqb->req.param*2;
for(i=0; i < num; i+=2)
{
int value_len;
int name_len;
char *value_data;
char *name_data;
name_len = strlen(str);
name_data = safe_estrndup(str,name_len);
str += (name_len+1);
value_len = strlen(str);
value_data = safe_estrndup(str,value_len);
str += (value_len+1);
add_assoc_string(return_value, name_data, value_data, 0);
}
}
}
PHP_FUNCTION(msession_listvar)
{
zval **session;
zval **name;
GET_REQB
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &name) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(name);
FormatRequest(&g_reqb, REQ_LISTVAR, "", Z_STRVAL_PP(name), "",0);
DoRequest(g_conn,&g_reqb);
array_init(return_value);
if(g_reqb->req.stat == REQ_OK)
{
int i;
char *str = g_reqb->req.datum;
int num = g_reqb->req.param*2;
for(i=0; i < num; i+=2)
{
int value_len;
int name_len;
char *value_data;
char *name_data;
name_len = strlen(str);
name_data = safe_estrndup(str,name_len);
str += (name_len+1);
value_len = strlen(str);
value_data = safe_estrndup(str,value_len);
str += (value_len+1);
add_assoc_string(return_value, name_data, value_data, 0);
}
}
}
PHP_FUNCTION(msession_timeout)
{
char *val;
zval **session;
int ac = ZEND_NUM_ARGS();
int zstat = FAILURE;
int timeout = 0;
GET_REQB
if(ac == 1)
{
zstat = zend_get_parameters_ex(1, &session);
}
else if(ac == 2)
{
zval **param;
zstat = zend_get_parameters_ex(2, &session, &param);
convert_to_long_ex(param);
timeout = Z_LVAL_PP(param);
}
if(zstat == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
FormatRequest(&g_reqb, REQ_TIMEOUT, Z_STRVAL_PP(session), "","",timeout);
DoRequest(g_conn,&g_reqb);
if(g_reqb->req.stat == REQ_OK)
{
RETURN_LONG( g_reqb->req.param);
}
else
{
RETURN_NULL();
}
}
PHP_FUNCTION(msession_inc)
{
char *val;
zval **session;
zval **name;
GET_REQB
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &session, &name) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
convert_to_string_ex(name);
FormatRequest(&g_reqb, REQ_INC, Z_STRVAL_PP(session), Z_STRVAL_PP(name),0,0);
DoRequest(g_conn, &g_reqb);
if(g_reqb->req.stat==REQ_OK)
{
val = safe_estrdup(g_reqb->req.datum);
RETURN_STRING(val, 0)
}
else
{
RETURN_FALSE;
}
}
PHP_FUNCTION(msession_getdata)
{
char *val;
zval **session;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &session) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
val = PHPMsessionGetData(Z_STRVAL_PP(session));
if(val)
{
RETURN_STRING(val, 0)
}
else
{
RETURN_NULL();
}
}
PHP_FUNCTION(msession_setdata)
{
zval **session;
zval **value;
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &session, &value) == FAILURE)
{
WRONG_PARAM_COUNT;
}
if(!g_conn)
{
RETURN_FALSE;
}
convert_to_string_ex(session);
convert_to_string_ex(value);
if(PHPMsessionSetData(Z_STRVAL_PP(session),Z_STRVAL_PP(value)))
{
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
#endif /* HAVE_MSESSION */

10
ext/msession/msession.php

@ -0,0 +1,10 @@
<?
$module = 'msession';
$function = 'confirm_' . $module . '_compiled';
if (extension_loaded($module)) {
$str = $function($module);
} else {
$str = "Module $module is not compiled into PHP";
}
echo "$str\n";
?>

105
ext/msession/php_msession.h

@ -0,0 +1,105 @@
/*
+----------------------------------------------------------------------+
| PHP version 4.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
#ifndef PHP_MSESSION_H
#define PHP_MSESSION_H
/* You should tweak config.m4 so this symbol (or some else suitable)
gets defined.
*/
#if HAVE_MSESSION
extern zend_module_entry msession_module_entry;
#define phpext_msession_ptr &msession_module_entry
#ifdef PHP_WIN32
#define PHP_MSESSION_API __declspec(dllexport)
#else
#define PHP_MSESSION_API
#endif
PHP_MINIT_FUNCTION(msession);
PHP_MSHUTDOWN_FUNCTION(msession);
PHP_RINIT_FUNCTION(msession);
PHP_RSHUTDOWN_FUNCTION(msession);
PHP_MINFO_FUNCTION(msession);
PHP_FUNCTION(confirm_msession_compiled); /* For testing, remove later. */
PHP_FUNCTION();
PHP_FUNCTION(msession_connect);
PHP_FUNCTION(msession_disconnect);
PHP_FUNCTION(msession_lock);
PHP_FUNCTION(msession_unlock);
PHP_FUNCTION(msession_count);
PHP_FUNCTION(msession_create);
PHP_FUNCTION(msession_destroy);
PHP_FUNCTION(msession_set);
PHP_FUNCTION(msession_get);
PHP_FUNCTION(msession_find);
PHP_FUNCTION(msession_get_array);
PHP_FUNCTION(msession_timeout);
PHP_FUNCTION(msession_inc);
PHP_FUNCTION(msession_setdata);
PHP_FUNCTION(msession_getdata);
PHP_FUNCTION(msession_listvar);
PHP_FUNCTION(msession_list);
PHP_FUNCTION(msession_uniq);
PHP_FUNCTION();
/*
Declare any global variables you may need between the BEGIN
and END macros here:
ZEND_BEGIN_MODULE_GLOBALS(msession)
int global_variable;
void *conn;
char *host;
ZEND_END_MODULE_GLOBALS(msession)
*/
/* In every function that needs to use variables in php_msession_globals,
do call MSESSIONLS_FETCH(); after declaring other variables used by
that function, and always refer to them as MSESSIONG(variable).
You are encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/
#ifdef ZTS
#define MSESSIONG(v) (msession_globals->v)
#define MSESSIONLS_FETCH() php_msession_globals *msession_globals = ts_resource(msession_globals_id)
#else
#define MSESSIONG(v) (msession_globals.v)
#define MSESSIONLS_FETCH()
#endif
#else
#define phpext_msession_ptr NULL
#endif
#endif /* PHP_MSESSION_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

108
ext/msession/reqclient.h

@ -0,0 +1,108 @@
/*
Mohawk Software Framework by Mohawk Software
Copyright (C) 1998-2001 Mark L. Woodward
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
If you want support or to professionally license this library, the author
can be reached at info@mohawksoft.com
*/
enum REQ_TYPES
{
REQ_ERR,
REQ_OK,
REQ_STAT,
REQ_SETVAL,
REQ_GETVAL,
REQ_CREATE,
REQ_DROP,
REQ_GETALL,
REQ_FIND,
REQ_COUNT,
REQ_FLUSH,
REQ_SLOCK,
REQ_SUNLOCK,
REQ_TIMEOUT,
REQ_INC,
REQ_DATAGET,
REQ_DATASET,
REQ_LIST,
REQ_LISTVAR,
REQ_UNIQ,
REQ_LAST,
REQ_POPEN=1024,
REQ_PCLOSE
};
typedef struct _requestPacket
{
int version;
int stat;
int len;
int session;
int name;
int value;
int param;
char datum[0];
}REQ;
typedef struct _requestBuf
{
unsigned int type;
unsigned int size;
REQ req;
}REQB;
#define MAX_REQ 16384
#define REQB_STATIC 1
#define REQB_DYNAMIC 2
#define STATIC_REQB( len ) \
char buffer [ len ]; \
REQB *preq = StaticRequestBuffer(buffer, len);
#if defined (__cplusplus)
extern "C" {
#endif
#define SIZEREQB(REQB,SIZE) (((REQB)->size >= (unsigned int) SIZE) ? REQB : SizeRequestBuffer(REQB,SIZE))
REQB *AllocateRequestBuffer(unsigned size);
void FreeRequestBuffer(REQB *req);
REQB *SizeRequestBuffer(REQB *req, unsigned int size);
REQB *StaticRequestBuffer(char *buffer, unsigned int cb);
int FormatRequest(REQB **buffer, int stat, char *session, char *name, char *value, int param);
int FormatRequestMulti(REQB **buffer, int stat, char *session, int n, char **pairs, int param);
int DoSingleRequest(char *hostname, int port, REQB **preq);
void *OpenReqConn(char *hostname, int port);
void CloseReqConn(void *conn);
int DoRequest(void *conn, REQB **preq);
char *ReqErr(int param);
#define ASSERT_STAT(PREQ) if(PREQ->stat != REQ_OK) \
{fprintf(stderr, "Error in Request %s %d %s\n", \
__FILE__,__LINE__, ReqErr(PREQ->param)); exit(-1); }
#if defined (__cplusplus)
// C API but with class definitions
int ReadRequestTimeout(REQB **ppreq, MSock *sock, int timeout);
int ReadRequest(REQB **preq, MSock *sock);
int WriteRequest(REQB *preq, MSock *sock);
}
#endif
Loading…
Cancel
Save