version 1.1, 2003/11/03 03:11:21 |
version 1.5, 2003/11/27 14:18:43 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_ntl/oxserv.c,v 1.4 2003/11/17 09:55:52 iwane Exp $ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <signal.h> |
|
#include <setjmp.h> |
|
|
#include "oxserv.h" |
#include "oxserv.h" |
|
#include "oxstack.h" |
|
|
|
#include "gc/gc.h" |
|
|
#define DPRINTF(x) printf x; fflush(stdout) |
#define DPRINTF(x) printf x; fflush(stdout) |
|
|
#define delete_cmo(m) |
#define FP stdout |
|
#define EPRINTF(x) fprintf x; fflush(FP) |
|
|
#define OXSERV_INIT_STACK_SIZE 2048 |
#if 1 |
#define OXSERV_EXT_STACK_SIZE 2048 |
|
|
|
#if 0 |
|
/*===========================================================================* |
/*===========================================================================* |
* for DEBUG |
* for DEBUG |
*===========================================================================*/ |
*===========================================================================*/ |
Line 39 dprintf(const char *fmt, ...) |
|
Line 41 dprintf(const char *fmt, ...) |
|
#endif |
#endif |
|
|
/*===========================================================================* |
/*===========================================================================* |
* Global Variables. |
* MACRO |
*===========================================================================*/ |
*===========================================================================*/ |
/* cmo stack */ |
#define oxserv_get_cmo_tag(m) ((G_getCmoTag == NULL) ? m->tag : G_getCmoTag(m)) |
static int G_ox_stack_size = 0; |
|
static int G_ox_stack_pointer = 0; |
|
static cmo **G_ox_stack = NULL; |
|
|
|
/* ox */ |
|
static cmo_mathcap *G_oxserv_mathcap = NULL; |
|
|
|
/* User Function */ |
#define oxserv_delete_cmo(c) \ |
static cmo *(*G_userExecuteFunction)(const char *, cmo **, int) = NULL; |
do { \ |
static cmo *(*G_userExecuteStringParser)(const char *) = NULL; |
if (c != NULL) { \ |
|
if (G_DeleteCmo != NULL) \ |
|
G_DeleteCmo((cmo *)c); \ |
|
else \ |
|
c = NULL; \ |
|
} \ |
|
} while (0) |
|
|
static cmo *(*G_convertCmo)(cmo *) = NULL; /* convert user object ==> cmo */ |
|
|
|
/*===========================================================================* |
/*===========================================================================* |
* CMO STACK FUNCTIONs |
* Global Variables. |
*===========================================================================*/ |
*===========================================================================*/ |
/***************************************************************************** |
/* ox */ |
* return the number of cmo in the stack. |
static OXFILE *G_oxfilep = NULL; |
* PARAM : NONE |
static cmo_mathcap *G_oxserv_mathcap = NULL; |
* RETURN : the number of cmo in the stack. |
|
*****************************************************************************/ |
|
#define oxserv_get_stack_pointer() G_ox_stack_pointer |
|
|
|
|
/* signal */ |
|
int G_oxserv_sigusr1flag = 0; |
|
int G_oxserv_sigusr1cnt = 0; |
|
static jmp_buf G_jmpbuf; |
|
|
/***************************************************************************** |
/* User Function */ |
* initialize stack. |
static void (*G_userExecuteFunction)(const char *, cmo **, int) = NULL; |
* PARAM : NONE |
static void (*G_userExecuteStringParser)(const char *) = NULL; |
* RETURN : if success return OXSERV_SUCCESS, else OXSERV_FAILURE. |
|
*****************************************************************************/ |
|
static int |
|
oxserv_init_stack(void) |
|
{ |
|
free(G_ox_stack); |
|
|
|
G_ox_stack_pointer = 0; |
static cmo *(*G_convertCmo)(cmo *) = NULL; /* convert user object ==> cmo */ |
G_ox_stack_size = OXSERV_INIT_STACK_SIZE; |
|
G_ox_stack = (cmo **)malloc(G_ox_stack_size * sizeof(cmo *)); |
|
if (G_ox_stack == NULL) { |
|
DPRINTF(("server: %d: %s\n", errno, strerror(errno))); |
|
return (OXSERV_FAILURE); |
|
} |
|
return (OXSERV_SUCCESS); |
|
} |
|
|
|
/***************************************************************************** |
static void (*G_DeleteCmo)(cmo *) = NULL; |
* |
|
* PARAM : NONE |
|
* RETURN : if success return OXSERV_SUCCESS, else OXSERV_FAILURE. |
|
*****************************************************************************/ |
|
static int |
|
oxserv_extend_stack(void) |
|
{ |
|
int size2 = G_ox_stack_size + OXSERV_EXT_STACK_SIZE; |
|
cmo **stack2 = (cmo **)malloc(size2 * sizeof(cmo *)); |
|
if (stack2 == NULL) { |
|
DPRINTF(("server: %d: %s\n", errno, strerror(errno))); |
|
return (OXSERV_FAILURE); |
|
} |
|
|
|
memcpy(stack2, G_ox_stack, G_ox_stack_size * sizeof(cmo *)); |
static int (*G_getCmoTag)(cmo *) = NULL; |
free(G_ox_stack); |
|
|
|
G_ox_stack = stack2; |
|
G_ox_stack_size = size2; |
|
|
|
return (OXSERV_SUCCESS); |
/*===========================================================================* |
} |
* CMO_ERROR2 |
|
*===========================================================================*/ |
|
#define new_cmo_error2_string(msg) new_cmo_error2((cmo *)new_cmo_string(msg)) |
|
|
/***************************************************************************** |
|
* push a cmo onto the topof the stack. |
|
* PARAM : m : the cmo to be pushed on the stack. |
|
* RETURN : if success return OXSERV_SUCCESS, else OXSERV_FAILURE. |
|
*****************************************************************************/ |
|
static int |
|
oxserv_push(cmo *m) |
|
{ |
|
int ret; |
|
|
|
if (G_ox_stack_pointer >= G_ox_stack_size) { |
static void |
ret = oxserv_extend_stack(); |
oxserv_push_errormes(char *msg) |
if (ret != OXSERV_SUCCESS) |
|
return (ret); |
|
} |
|
|
|
G_ox_stack[G_ox_stack_pointer] = m; |
|
G_ox_stack_pointer++; |
|
|
|
return (OXSERV_SUCCESS); |
|
} |
|
|
|
/***************************************************************************** |
|
* remove thd CMO at the top of this stack and |
|
* returns that cmo as the value of this function. |
|
* PARAM : NONE |
|
* RETURN : CMO at the top of the stack. |
|
*****************************************************************************/ |
|
static cmo * |
|
oxserv_pop(void) |
|
{ |
{ |
cmo *c; |
EPRINTF((FP, "%s\n", msg)); |
if (G_ox_stack_pointer > 0) { |
oxstack_push((cmo *)new_cmo_error2_string(msg)); |
G_ox_stack_pointer--; |
|
c = G_ox_stack[G_ox_stack_pointer]; |
|
G_ox_stack[G_ox_stack_pointer] = NULL; |
|
return (c); |
|
} |
|
return (NULL); |
|
} |
} |
|
|
/***************************************************************************** |
/*===========================================================================* |
* return the cmo at the specified position in the stack without removing it from the stack. |
* synchronized malloc |
* PARAM : NONE |
*===========================================================================*/ |
* RETURN: thd cmo at the specified position in the stack. |
void * |
*****************************************************************************/ |
oxserv_malloc(size_t size) |
static cmo * |
|
oxserv_get(int i) |
|
{ |
{ |
if (i < G_ox_stack_pointer && i >= 0) { |
void *ptr; |
return (G_ox_stack[i]); |
|
} |
|
return (NULL); |
|
} |
|
|
|
|
BLOCK_INPUT(); |
|
ptr = GC_malloc(size); |
|
UNBLOCK_INPUT(); |
|
|
/***************************************************************************** |
return (ptr); |
* return the cmo at the top of the stack without removing it from the stack. |
} |
* PARAM : NONE |
|
* RETURN: the cmo at the top of the stack. |
void |
*****************************************************************************/ |
oxserv_free(void *ptr, size_t size) |
static cmo * |
|
oxserv_peek(void) |
|
{ |
{ |
return (oxserv_get(G_ox_stack_pointer - 1)); |
/* nothing */ |
} |
} |
|
|
/***************************************************************************** |
void * |
* |
oxserv_realloc(void *org, size_t old, size_t size) |
* defined for SM_pops |
|
* |
|
* PARAM : n : remove count |
|
* RETURN: NONE |
|
*****************************************************************************/ |
|
static void |
|
oxserv_remove(int n) |
|
{ |
{ |
int i; |
void *ptr; |
cmo *m; |
|
|
|
if (n > G_ox_stack_size) |
BLOCK_INPUT(); |
n = G_ox_stack_size; |
ptr = GC_realloc(org, size); |
|
UNBLOCK_INPUT(); |
for (i = 0; i < n; i++) { |
|
--G_ox_stack_pointer; |
return (ptr); |
m = G_ox_stack[G_ox_stack_pointer]; |
|
G_ox_stack[G_ox_stack_pointer] = NULL; |
|
delete_cmo(m); |
|
} |
|
} |
} |
|
|
|
|
|
|
/*===========================================================================* |
/*===========================================================================* |
* OX_SERVER |
* OX_SERVER |
*===========================================================================*/ |
*===========================================================================*/ |
|
|
/***************************************************************************** |
/***************************************************************************** |
* pop n and to discard element from the stack |
* -- SM_popCMO -- |
|
* pop an object from the stack, convert it into a serialized from according |
|
* to the standard CMO encoding scheme, and send it to the stream |
|
* |
* PARAM : fd : OXFILE |
* PARAM : fd : OXFILE |
* RETURN: NONE |
* RETURN: NONE |
*****************************************************************************/ |
*****************************************************************************/ |
static void |
static void |
oxserv_sm_popCMO(OXFILE *fd) |
oxserv_sm_popCMO(OXFILE *fd) |
{ |
{ |
cmo *m = oxserv_pop(); |
cmo *m, *n; |
|
m = oxstack_pop(); |
if (m == NULL) { |
if (m == NULL) { |
|
EPRINTF((FP, "stack underflow in popCMO\n")); |
m = new_cmo_null(); |
m = new_cmo_null(); |
} else if (G_convertCmo) { |
} else if (G_convertCmo) { |
m = G_convertCmo(m); |
n = G_convertCmo(m); |
|
if (m != n) { |
|
oxserv_delete_cmo(m); |
|
m = n; |
|
} |
} |
} |
|
|
send_ox_cmo(fd, m); |
send_ox_cmo(fd, m); |
|
|
delete_cmo(m); |
oxserv_delete_cmo(m); |
} |
} |
|
|
/***************************************************************************** |
/***************************************************************************** |
|
* -- SM_popString -- |
* pop an cmo from stack, convert it into a string according to the |
* pop an cmo from stack, convert it into a string according to the |
* output format of the local system, and send the string. |
* output format of the local system, and send the string. |
|
* |
* PARAM : fd : OXFILE |
* PARAM : fd : OXFILE |
* RETURN: NONE |
* RETURN: NONE |
*****************************************************************************/ |
*****************************************************************************/ |
|
|
oxserv_sm_popString(OXFILE *fd) |
oxserv_sm_popString(OXFILE *fd) |
{ |
{ |
char *str; |
char *str; |
cmo *m = oxserv_pop(); |
cmo *m = oxstack_pop(); |
cmo_string *m_str; |
cmo_string *m_str; |
|
|
if (m == NULL) |
if (m == NULL) { |
|
EPRINTF((FP, "stack underflow in popString\n")); |
m = new_cmo_null(); |
m = new_cmo_null(); |
|
} |
|
|
str = new_string_set_cmo(m); |
str = new_string_set_cmo(m); |
|
|
Line 248 oxserv_sm_popString(OXFILE *fd) |
|
Line 187 oxserv_sm_popString(OXFILE *fd) |
|
|
|
send_ox_cmo(fd, (cmo *)m_str); |
send_ox_cmo(fd, (cmo *)m_str); |
|
|
delete_cmo(m); |
oxserv_delete_cmo(m); |
delete_cmo(m_str); |
oxserv_delete_cmo(m_str); |
|
|
/* free(str); */ |
/* free(str); */ |
} |
} |
|
|
/***************************************************************************** |
/***************************************************************************** |
|
* -- SM_pops -- |
* pop n and to discard element from the stack |
* pop n and to discard element from the stack |
* PARAM : fd : OXFILE |
* |
|
* PARAM : NONE |
* RETURN: NONE |
* RETURN: NONE |
*****************************************************************************/ |
*****************************************************************************/ |
static void |
static void |
oxserv_sm_pops() |
oxserv_sm_pops() |
{ |
{ |
cmo_int32 *c; |
cmo_int32 *c; |
|
cmo *m; |
|
int n; |
|
int i; |
|
|
c = (cmo_int32 *)oxserv_pop(); /* suppose */ |
c = (cmo_int32 *)oxstack_pop(); /* suppose */ |
|
if (c == NULL) { |
|
EPRINTF((FP, "stack underflow in pops\n")); |
|
return ; |
|
} |
|
|
oxserv_remove(c->i) |
n = oxstack_get_stack_pointer(); |
|
if (c->i < n) |
|
n = c->i; |
|
|
delete_cmo(c); |
for (i = 0; i < n; i++) { |
|
m = oxstack_pop(); |
|
oxserv_delete_cmo(m); |
|
} |
|
|
|
oxserv_delete_cmo(c); |
|
|
} |
} |
|
|
/***************************************************************************** |
/***************************************************************************** |
* for SM_getsp |
* -- SM_getsp -- |
|
* push the current stack pointer onto the stack. |
* |
* |
* PARAM : fd : OXFILE |
* PARAM : fd : OXFILE |
* RETURN: NONE |
* RETURN: NONE |
Line 280 oxserv_sm_pops() |
|
Line 237 oxserv_sm_pops() |
|
static void |
static void |
oxserv_sm_getsp() |
oxserv_sm_getsp() |
{ |
{ |
cmo_int32 *m = new_cmo_int32(oxserv_get_stack_pointer()); |
cmo_int32 *m = new_cmo_int32(oxstack_get_stack_pointer()); |
oxserv_push((cmo *)m); |
oxstack_push((cmo *)m); |
} |
} |
|
|
/***************************************************************************** |
/***************************************************************************** |
Line 367 oxserv_mathcap_init(int ver, char *vstr, char *sysname |
|
Line 324 oxserv_mathcap_init(int ver, char *vstr, char *sysname |
|
|
|
mathcap_init(ver, vstr, sysname, cmos, sms); |
mathcap_init(ver, vstr, sysname, cmos, sms); |
|
|
delete_cmo(G_oxserv_mathcap); |
oxserv_delete_cmo(G_oxserv_mathcap); |
|
|
G_oxserv_mathcap = mathcap_get(new_mathcap()); |
G_oxserv_mathcap = mathcap_get(new_mathcap()); |
} |
} |
|
|
|
/***************************************************************************** |
|
* -- SM_mathcap -- |
|
* push the mathcap of the server. |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_mathcap() |
oxserv_sm_mathcap() |
{ |
{ |
Line 379 oxserv_sm_mathcap() |
|
Line 343 oxserv_sm_mathcap() |
|
oxserv_mathcap_init(0, "", "oxserv", NULL, NULL); |
oxserv_mathcap_init(0, "", "oxserv", NULL, NULL); |
} |
} |
|
|
oxserv_push((cmo *)G_oxserv_mathcap); |
oxstack_push((cmo *)G_oxserv_mathcap); |
} |
} |
|
|
|
/***************************************************************************** |
|
* -- SM_executeStringByLocalParserInBatchMode -- |
|
* peek a character string s, parse it by the local parser of the stack machine, |
|
* and interpret by the local interpreter. |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_executeStringByLocalParserInBatchMode(void) |
oxserv_sm_executeStringByLocalParserInBatchMode(void) |
{ |
{ |
cmo_string *str = (cmo_string *)oxserv_peek(); |
cmo_string *str = (cmo_string *)oxstack_peek(); |
cmo *c; |
if (str == NULL) { |
c = G_userExecuteStringParser(str->s); |
oxserv_push_errormes("stack underflow in executeStringByLocalParserInBatchMode"); |
oxserv_push(c); |
return ; |
|
} |
|
G_userExecuteStringParser(str->s); |
} |
} |
|
|
|
/***************************************************************************** |
|
* -- SM_executeStringByLocalParser -- |
|
* pop a character string s, parse it by the local parser of the stack machine, |
|
* and interpret by the local interpreter. |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_executeStringByLocalParser(void) |
oxserv_sm_executeStringByLocalParser(void) |
{ |
{ |
cmo_string *str = (cmo_string *)oxserv_pop(); |
cmo_string *str = (cmo_string *)oxstack_pop(); |
cmo *c; |
if (str == NULL) { |
c = G_userExecuteStringParser(str->s); |
oxserv_push_errormes("stack underflow in executeStringByLocalParser"); |
oxserv_push(c); |
return ; |
|
} |
|
G_userExecuteStringParser(str->s); |
} |
} |
|
|
|
|
|
|
|
/***************************************************************************** |
|
* -- SM_executeFunction -- |
|
* pop s as a function name, pop n as the number of arguments and to execute a |
|
* local function s with n arguments poped from the stack. |
|
* |
|
* suppose G_userExecuteFunction not equal NULL |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_executeFunction(void) |
oxserv_sm_executeFunction(void) |
{ |
{ |
int i; |
int i; |
cmo_string *name = (cmo_string *)oxserv_pop(); |
cmo_string *name = (cmo_string *)oxstack_pop(); |
cmo_int32 *cnt = (cmo_int32 *)oxserv_pop(); |
cmo_int32 *cnt = (cmo_int32 *)oxstack_pop(); |
cmo **arg = (cmo **)malloc(cnt->i * sizeof(cmo *)); |
cmo **arg; |
cmo *ret; |
|
|
|
|
|
|
if (name == NULL || cnt == NULL) { |
|
oxserv_push_errormes("stack underflow in executeFunction"); |
|
return ; |
|
} |
|
|
|
arg = (cmo **)malloc(cnt->i * sizeof(cmo *)); |
for (i = 0; i < cnt->i; i++) { |
for (i = 0; i < cnt->i; i++) { |
arg[i] = oxserv_pop(); |
arg[i] = oxstack_pop(); |
|
if (arg[i] == NULL) { |
|
oxserv_push_errormes("stack underflow in executeFunction"); |
|
|
|
for (i--; i >= 0; i--) |
|
oxserv_delete_cmo(arg[i]); |
|
free(arg); |
|
return ; |
|
} |
} |
} |
|
|
/* user function */ |
/* user function */ |
ret = G_userExecuteFunction(name->s, arg, cnt->i); |
G_userExecuteFunction(name->s, arg, cnt->i); |
|
|
oxserv_push(ret); |
|
|
|
for (i = 0; i < cnt->i; i++) { |
for (i = 0; i < cnt->i; i++) { |
delete_cmo(arg[i]); |
oxserv_delete_cmo(arg[i]); |
} |
} |
|
|
delete_cmo(name); |
oxserv_delete_cmo(name); |
delete_cmo(cnt); |
oxserv_delete_cmo(cnt); |
|
|
free(arg); |
free(arg); |
} |
} |
|
|
|
/***************************************************************************** |
|
* -- SM_pushCMOtag -- |
|
* push the CMO tag of the top object on the stack. |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_pushCMOtag() |
oxserv_sm_pushCMOtag() |
{ |
{ |
cmo *c = oxserv_peek(); |
cmo *c = oxstack_peek(); |
cmo_int32 *tag = new_cmo_int32(c->tag); |
cmo_int32 *tag = new_cmo_int32(oxserv_get_cmo_tag(c)); |
|
oxstack_push((cmo *)tag); |
oxserv_push((cmo *)tag); |
|
} |
} |
|
|
|
|
|
/***************************************************************************** |
|
* -- SM_dupErrors -- |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static void |
static void |
oxserv_sm_dupErrors() |
oxserv_sm_dupErrors() |
{ |
{ |
Line 449 oxserv_sm_dupErrors() |
|
Line 468 oxserv_sm_dupErrors() |
|
|
|
list = new_cmo_list(); |
list = new_cmo_list(); |
|
|
for (i = 0; i < oxserv_get_stack_pointer(); i++) { |
for (i = 0; i < oxstack_get_stack_pointer(); i++) { |
c = oxserv_get(i); |
c = oxstack_get(i); |
if (c->tag == CMO_ERROR2) { |
if (c->tag == CMO_ERROR2) { |
list_append(list, c); |
list_append(list, c); |
} |
} |
} |
} |
|
|
oxserv_push((cmo *)list); |
oxstack_push((cmo *)list); |
} |
} |
|
|
|
|
|
|
|
|
|
/***************************************************************************** |
|
* -- SM_control_reset_connection -- signal handler for SIGUSR1 -- |
|
* |
|
* PARAM : NONE |
|
* |
|
* : if (sig == 0) called UNBLOCK_INPUT() |
|
* RETURN: NONE |
|
*****************************************************************************/ |
|
void |
|
oxserv_sm_control_reset_connection(int sig) |
|
{ |
|
int tag; |
|
OXFILE *fd = G_oxfilep; |
|
|
|
if (G_oxserv_sigusr1cnt > 0) { |
|
G_oxserv_sigusr1flag = 1; |
|
return ; |
|
} |
|
|
|
|
|
DPRINTF(("reset -- start ==> ")); |
|
G_oxserv_sigusr1flag = 0; |
|
|
|
send_ox_tag(fd, OX_SYNC_BALL); |
|
|
|
oxstack_init_stack(); |
|
|
|
for (;;) { |
|
tag = receive_ox_tag(fd); |
|
DPRINTF(("[OX:%d=0x%x]", tag, tag)); |
|
if (tag == OX_SYNC_BALL) |
|
break; |
|
if (tag == OX_DATA) |
|
receive_cmo(fd); |
|
else |
|
receive_int32(fd); |
|
} |
|
DPRINTF((" <== end.\n")); |
|
|
|
|
|
longjmp(G_jmpbuf, sig); |
|
} |
|
|
|
/***************************************************************************** |
|
* execute sm command |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
static int |
static int |
oxserv_receive_and_execute_sm_command(OXFILE *fd) |
oxserv_execute_sm_command(OXFILE *fd, int code) |
{ |
{ |
int code = receive_int32(fd); |
|
|
|
DPRINTF(("SM_CODE=%d=0x%x\n", code, code)); |
DPRINTF(("[SM:%d=0x%x]", code, code)); |
|
|
switch (code) { |
switch (code) { |
case SM_popCMO: |
case SM_popCMO: /* 262 */ |
oxserv_sm_popCMO(fd); |
oxserv_sm_popCMO(fd); |
break; |
break; |
case SM_executeStringByLocalParser: |
case SM_executeStringByLocalParser: /* 268 */ |
if (G_userExecuteStringParser) |
if (G_userExecuteStringParser) |
oxserv_sm_executeStringByLocalParser(); |
oxserv_sm_executeStringByLocalParser(); |
break; |
break; |
case SM_executeStringByLocalParserInBatchMode: |
case SM_executeStringByLocalParserInBatchMode: /* 274 */ |
if (G_userExecuteStringParser) |
if (G_userExecuteStringParser) |
oxserv_sm_executeStringByLocalParserInBatchMode(); |
oxserv_sm_executeStringByLocalParserInBatchMode(); |
break; |
break; |
case SM_pops: |
case SM_pops: /* 265 */ |
oxserv_sm_pops(); |
oxserv_sm_pops(); |
break; |
break; |
case SM_popString: |
case SM_popString: /* 263 */ |
oxserv_sm_popString(fd); |
oxserv_sm_popString(fd); |
break; |
break; |
case SM_getsp: |
case SM_getsp: /* 275 */ |
oxserv_sm_getsp(); |
oxserv_sm_getsp(); |
break; |
break; |
case SM_mathcap: |
case SM_mathcap: /* 264 */ |
oxserv_sm_mathcap(); |
oxserv_sm_mathcap(); |
break; |
break; |
case SM_setMathCap: |
case SM_setMathCap: /* 273 */ |
/* dont support */ |
/* dont support */ |
oxserv_pop(); |
oxstack_pop(); |
break; |
break; |
case SM_executeFunction: |
case SM_executeFunction: /* 269 */ |
if (G_userExecuteFunction) |
if (G_userExecuteFunction) |
oxserv_sm_executeFunction(); |
oxserv_sm_executeFunction(); |
break; |
break; |
case SM_pushCMOtag: |
case SM_pushCMOtag: /* 277 */ |
oxserv_sm_pushCMOtag(); |
oxserv_sm_pushCMOtag(); |
break; |
break; |
case SM_dupErrors: |
case SM_dupErrors: /* 276 */ |
oxserv_sm_dupErrors(); |
oxserv_sm_dupErrors(); |
break; |
break; |
|
case SM_popSerializedLocalObject: |
|
case SM_setName: |
|
case SM_evalName: |
|
case SM_beginBlock: |
|
case SM_endBlock: |
|
case SM_shutdown: |
|
case SM_executeFunctionAndPopCMO: |
|
case SM_executeFunctionAndPopSerializedLocalObject: |
|
case SM_control_reset_connection: |
|
case SM_control_reset_connection_server: |
default: |
default: |
break; |
break; |
} |
} |
Line 512 oxserv_receive_and_execute_sm_command(OXFILE *fd) |
|
Line 591 oxserv_receive_and_execute_sm_command(OXFILE *fd) |
|
} |
} |
|
|
|
|
|
|
/***************************************************************************** |
/***************************************************************************** |
* reveice ox_data |
* reveice ox_data |
|
* |
* PARAM : fd : OXFILE |
* PARAM : fd : OXFILE |
* RETURN: NONE |
* RETURN: NONE |
*****************************************************************************/ |
*****************************************************************************/ |
int |
static int |
oxserv_receive(OXFILE *fd) |
oxserv_ox_receive(OXFILE *fd) |
{ |
{ |
int tag; |
int tag; |
cmo *c; |
cmo *c; |
int ret = OXSERV_SUCCESS; |
int ret = OXSERV_SUCCESS; |
|
int code; |
|
|
tag = receive_ox_tag(fd); |
tag = receive_ox_tag(fd); |
|
|
DPRINTF(("oxserv_TAG=%d=0x%x\n", tag, tag)); |
|
switch (tag) { |
switch (tag) { |
case OX_DATA: |
case OX_DATA: |
|
BLOCK_INPUT(); |
c = receive_cmo(fd); |
c = receive_cmo(fd); |
DPRINTF(("CMO_TAG=%d=0x%x\n", c->tag, c->tag)); |
UNBLOCK_INPUT(); |
oxserv_push(c); |
DPRINTF(("[CMO:%d=0x%x]", c->tag, c->tag)); |
|
oxstack_push(c); |
break; |
break; |
|
|
case OX_COMMAND: |
case OX_COMMAND: |
ret = oxserv_receive_and_execute_sm_command(fd); |
code = receive_int32(fd); |
|
ret = oxserv_execute_sm_command(fd, code); |
break; |
break; |
|
|
default: |
default: |
Line 546 oxserv_receive(OXFILE *fd) |
|
Line 630 oxserv_receive(OXFILE *fd) |
|
return (ret); |
return (ret); |
} |
} |
|
|
|
int |
|
oxserv_receive(OXFILE *fd) |
|
{ |
|
int i = 0; |
|
int ret; |
|
|
|
ret = setjmp(G_jmpbuf); |
|
if (ret == 0) { |
|
DPRINTF(("setjmp first time -- %d\n", ret)); |
|
} else { |
|
DPRINTF(("setjmp return from longjmp() -- %d -- \n", ret)); |
|
} |
|
|
|
for (;; i++) { |
|
ret = oxserv_ox_receive(fd); |
|
if (ret != OXSERV_SUCCESS) |
|
break; |
|
} |
|
return (ret); |
|
} |
|
|
|
|
/***************************************************************************** |
/***************************************************************************** |
* initialize oxserver |
* initialize oxserver |
* |
* |
* PARAM : see oxserv_mathcap_init() |
* PARAM : see oxserv_mathcap_init() |
* RETURN: NONE |
* RETURN: success : OXSERV_SUCCESS |
|
* : failure : OXSERV_FAILURE |
* SEE : oxserv_mathcap_init() |
* SEE : oxserv_mathcap_init() |
* : oxserv_set(); |
* : oxserv_set(); |
*****************************************************************************/ |
*****************************************************************************/ |
Line 560 oxserv_init(OXFILE *oxfp, int ver, char *vstr, char *s |
|
Line 666 oxserv_init(OXFILE *oxfp, int ver, char *vstr, char *s |
|
{ |
{ |
int ret; |
int ret; |
|
|
ret = oxserv_init_stack(); |
DPRINTF(("init start\n")); |
|
|
|
ret = oxstack_init_stack(); |
if (ret != OXSERV_SUCCESS) |
if (ret != OXSERV_SUCCESS) |
return (ret); |
return (ret); |
|
|
|
G_oxfilep = oxfp; |
|
|
oxserv_mathcap_init(ver, vstr, sysname, cmos, sms); |
oxserv_mathcap_init(ver, vstr, sysname, cmos, sms); |
|
|
|
signal(SIGUSR1, oxserv_sm_control_reset_connection); |
|
|
|
/* initialize GMP memory functions. */ |
|
mp_set_memory_functions(oxserv_malloc, oxserv_realloc, oxserv_free); |
|
|
|
/* session start */ |
oxf_determine_byteorder_server(oxfp); |
oxf_determine_byteorder_server(oxfp); |
|
|
return (OXSERV_SUCCESS); |
return (OXSERV_SUCCESS); |
Line 573 oxserv_init(OXFILE *oxfp, int ver, char *vstr, char *s |
|
Line 689 oxserv_init(OXFILE *oxfp, int ver, char *vstr, char *s |
|
|
|
|
|
/***************************************************************************** |
/***************************************************************************** |
* set oxserver |
* set oxserver behavior |
|
* |
* PARAM : mode : mode |
* PARAM : mode : mode |
* : |
* : |
* : ptr : |
* : ptr : |
* : rsv : reserve space. |
* : rsv : reserve space. |
* RETURN: NONE |
* RETURN: success : OXSERV_SUCCESS |
|
* : failure : OXSERV_FAILURE |
* SEE : |
* SEE : |
*****************************************************************************/ |
*****************************************************************************/ |
int |
int |
Line 586 oxserv_set(int mode, void *ptr, void *rsv) |
|
Line 704 oxserv_set(int mode, void *ptr, void *rsv) |
|
{ |
{ |
switch (mode) { |
switch (mode) { |
case OXSERV_SET_EXECUTE_FUNCTION: |
case OXSERV_SET_EXECUTE_FUNCTION: |
G_userExecuteFunction = (cmo *(*)(const char *, cmo **, int))ptr; |
G_userExecuteFunction = (void (*)(const char *, cmo **, int))ptr; |
break; |
break; |
case OXSERV_SET_EXECUTE_STRING_PARSER: |
case OXSERV_SET_EXECUTE_STRING_PARSER: |
G_userExecuteStringParser = (cmo *(*)(const char *))ptr; |
G_userExecuteStringParser = (void (*)(const char *))ptr; |
break; |
break; |
case OXSERV_SET_CONVERT_CMO: |
case OXSERV_SET_CONVERT_CMO: |
G_convertCmo = (cmo *(*)(cmo *))ptr; |
G_convertCmo = (cmo *(*)(cmo *))ptr; |
break; |
break; |
|
case OXSERV_SET_DELETE_CMO: |
|
G_DeleteCmo = (void (*)(cmo *))ptr; |
|
break; |
|
case OXSERV_SET_GET_CMOTAG: |
|
G_getCmoTag = (int (*)(cmo *))ptr; |
|
break; |
default: |
default: |
return (OXSERV_FAILURE); |
return (OXSERV_FAILURE); |
} |
} |
Line 605 oxserv_set(int mode, void *ptr, void *rsv) |
|
Line 729 oxserv_set(int mode, void *ptr, void *rsv) |
|
|
|
/***************************************************************************** |
/***************************************************************************** |
* destroy |
* destroy |
* PARAM : mode : mode |
* |
* : |
* PARAM : NONE |
* : ptr : |
|
* : rsv : reserve space. |
|
* RETURN: NONE |
* RETURN: NONE |
* SEE : |
|
*****************************************************************************/ |
*****************************************************************************/ |
void |
void |
oxserv_dest() |
oxserv_dest() |
{ |
{ |
free(G_ox_stack); |
oxserv_delete_cmo(G_oxserv_mathcap); |
|
|
|
oxstack_dest(); |
} |
} |
|
|
|
|
#if 0 |
#if __OXSERV_DEBUG |
|
/*===========================================================================* |
|
* DEBUG |
|
*===========================================================================*/ |
|
|
cmo * |
|
|
void |
oxserv_executeFunction(const char *func, cmo **arg, int argc) |
oxserv_executeFunction(const char *func, cmo **arg, int argc) |
{ |
{ |
int i; |
int i; |
Line 632 oxserv_executeFunction(const char *func, cmo **arg, in |
|
Line 759 oxserv_executeFunction(const char *func, cmo **arg, in |
|
printf("\t%2d: %s\n", i, new_string_set_cmo(arg[i])); |
printf("\t%2d: %s\n", i, new_string_set_cmo(arg[i])); |
} |
} |
|
|
return ((cmo *)new_cmo_int32(0)); |
return ; |
} |
} |
|
|
|
/***************************************************************************** |
|
* main |
|
* |
|
* PARAM : NONE |
|
* RETURN: NONE |
|
*****************************************************************************/ |
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
Line 646 main(int argc, char *argv[]) |
|
Line 779 main(int argc, char *argv[]) |
|
|
|
ox_stderr_init(stderr); |
ox_stderr_init(stderr); |
|
|
oxserv_init(0, "$Date$", "oxserv", NULL, NULL); |
oxserv_set(OXSERV_SET_EXECUTE_FUNCTION, oxserv_executeFunction, NULL); |
|
|
DPRINTF(("main - start\n")); |
oxserv_init(oxfp, 0, "$Date$", "oxserv", NULL, NULL); |
for (i = 0;; i++) { |
|
DPRINTF(("@")); |
|
ret = oxserv_receive(oxfp); |
|
if (ret != OXSERV_SUCCESS) |
|
break; |
|
} |
|
|
|
oxf_close(fd); |
ret = oxserv_receive(oxfp); |
delete_cmo(G_oxserv_mathcap); |
|
|
|
|
oxserv_dest(); |
|
oxf_close(oxfp); |
|
|
return (0); |
return (0); |
} |
} |
|
|
#endif |
#endif |
|
|
|
|