static void startElement1_(ValueContext *ctx, xmlChar *name, xmlChar **atts) { xmlChar *vname, *p, *q; p = NextName(ctx); q = p; if ((vname = GetAttribute(atts, (xmlChar *)"name")) != NULL) { if ((char *)p != ctx->longname) { *p++ = '.'; } sprintf((char *)p, "%s", (char *)vname); } #ifdef DEBUG printf("startElement_(%s)[%s]\n", (char *)name, ctx->longname); #endif if (stricmp((char *)name, "lm:item") == 0) { ctx->value = GetItemLongName(ctx->root, ctx->longname); *q = 0; ctx->fStart = TRUE; } else if (stricmp((char *)name, "lm:record") == 0) { if (ctx->value == NULL) { *q = 0; } ctx->value = GetItemLongName(ctx->root, ctx->longname); ctx->fStart = FALSE; } else if (stricmp((char *)name, "lm:array") == 0) { *q = 0; ctx->fStart = FALSE; } else if (stricmp((char *)name, "lm:block") == 0) { ctx->value = NULL; ctx->fStart = FALSE; } }
static Bool _ExecuteProcess(MessageHandler *handler, ProcessNode *node) { int (*apl)(char *, char *, char *, char *); char *module; long start, end; Bool rc; module = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.module")); if ((apl = cob_resolve(module)) != NULL) { PutApplication(node); start = GetNowTime(); (void)apl(McpData, SpaData, LinkData, ScrData); end = GetNowTime(); TimerPrintf(start, end, "OpenCOBOL %s:%s:%s\n", module, node->widget, node->event); GetApplication(node); if (ValueInteger(GetItemLongName(node->mcprec->value, "rc")) < 0) { rc = FALSE; } else { rc = TRUE; } } else { Warning("%s - %s is not found.", cob_resolve_error(), module); rc = FALSE; } return (rc); }
extern int MCP_ReturnComponent(ProcessNode *node, char *event) { ValueStruct *mcp; mcp = node->mcprec->value; if (event != NULL) { SetValueString(GetItemLongName(mcp, "dc.event"), event, NULL); } SetValueString(GetItemLongName(mcp, "dc.puttype"), MCP_PUT_RETURN, NULL); SetValueString(GetItemLongName(mcp, "dc.status"), "PUTG", NULL); SetValueInteger(GetItemLongName(mcp, "rc"), 0); return (0); }
static ValueStruct *_OpenXML(DBG_Struct *dbg, DBCOMM_CTRL *ctrl, RecordStruct *rec, ValueStruct *args) { int rc; ValueStruct *obj, *mode, *ret; char *buff; size_t size; xmlNodePtr root; DBG_Struct *mondbg; XMLpos = 0; XMLDoc = NULL; XMLmode = MODE_NONE; rc = MCP_BAD_OTHER; ret = NULL; if (rec->type != RECORD_DB) { rc = MCP_BAD_ARG; } else { if ((obj = GetItemLongName(args, "object")) != NULL && (mode = GetItemLongName(args, "mode")) != NULL) { XMLmode = ValueInteger(mode); if (XMLmode == MODE_WRITE) { XMLDoc = xmlNewDoc("1.0"); root = xmlNewDocNode(XMLDoc, NULL, "data", NULL); xmlDocSetRootElement(XMLDoc, root); ret = DuplicateValue(args, TRUE); rc = MCP_OK; } else { mondbg = GetDBG_monsys(); if (blob_export_mem(mondbg, ValueObjectId(obj), &buff, &size)) { if (size > 0) { XMLDoc = xmlReadMemory(buff, size, "http://www.montsuqi.org/", NULL, XML_PARSE_NOBLANKS | XML_PARSE_NOENT); if (XMLDoc != NULL) { rc = MCP_OK; } } xfree(buff); } } } else { rc = MCP_BAD_ARG; } } if (ctrl != NULL) { ctrl->rc = rc; } return ret; }
extern int MCP_PutWindow(ProcessNode *node, char *wname, char *type) { ValueStruct *mcp; mcp = node->mcprec->value; if (wname != NULL) { dbgprintf("window = [%s]", wname); SetValueString(GetItemLongName(mcp, "dc.window"), wname, NULL); } SetValueString(GetItemLongName(mcp, "dc.widget"), "", NULL); SetValueString(GetItemLongName(mcp, "dc.puttype"), type, NULL); SetValueString(GetItemLongName(mcp, "dc.status"), "PUTG", NULL); SetValueInteger(GetItemLongName(mcp, "rc"), 0); return (0); }
static ValueStruct * FETCH( DBG_Struct *dbg, DBCOMM_CTRL *ctrl, RecordStruct *rec, ValueStruct *args) { ValueStruct *ret,*v; char vname[256]; ENTER_FUNC; ret = NULL; ctrl->rc = MCP_BAD_OTHER; if (rec->type != RECORD_DB || !hasData){ ctrl->rc = MCP_BAD_ARG; return ret; } if (idx >= numData) { ctrl->rc = MCP_EOF; return ret; } if (sysdbvals == NULL) { ctrl->rc = MCP_EOF; return ret; } snprintf(vname,sizeof(vname),"values[%d]",idx); v = GetItemLongName(sysdbvals,vname); if (v != NULL) { ret = DuplicateValue(v,TRUE); } idx += 1; ctrl->rc = MCP_OK; LEAVE_FUNC; return ret; }
static void SetDBAudit(DBG_Struct *dbg) { ValueStruct *audit; LargeByteString *lbs; if (dbg->auditlog > 0) { if (ThisEnv->auditrec->value != NULL) { audit = ThisEnv->auditrec->value; SetValueInteger(GetItemLongName(audit, "ticket_id"), dbg->ticket_id); lbs = dbg->last_query; if ((lbs != NULL) && (LBS_Size(lbs) > 0)) { SetValueString(GetItemLongName(audit, "exec_query"), LBS_Body(lbs), dbg->coding); } } } }
static char *file_export(DBG_Struct *dbg, char *id, char *socket) { static char *filename; char *str; json_object *obj; NETFILE *fp; ValueStruct *ret, *value; ValueStruct *retval; ret = monblob_export(dbg, id); obj = json_object_new_object(); if (!ret) { fprintf(stderr, "[%s] is not registered\n", id); json_object_object_add(obj, "status", json_object_new_int(404)); retval = NULL; } else { value = GetItemLongName(ret, "file_data"); retval = unescape_bytea(dbg, value); char *id; id = ValueToString(GetItemLongName(ret, "id"), dbg->coding); json_object_object_add(obj, "id", json_object_new_string(id)); filename = ValueToString(GetItemLongName(ret, "filename"), dbg->coding); json_object_object_add(obj, "filename", json_object_new_string(filename)); char *content_type; content_type = ValueToString(GetItemLongName(ret, "content_type"), dbg->coding); if (content_type == NULL || strlen(content_type) == 0) { json_object_object_add( obj, "content-type", json_object_new_string("application/octet-stream")); } else { json_object_object_add(obj, "content-type", json_object_new_string(content_type)); } json_object_object_add(obj, "status", json_object_new_int(200)); } str = (char *)json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN); fp = ConnectBlobAPI(socket); SendString(fp, str); SendValue(fp, retval); FreeValueStruct(retval); Flush(fp); DisconnectBlobAPI(fp); FreeValueStruct(ret); return filename; }
static Bool _ExecuteProcess( MessageHandler *handler, ProcessNode *node) { VALUE app_class; VALUE app; ValueStruct *dc_module_value; char *dc_module; int state; ENTER_FUNC; if (handler->loadpath == NULL) { Warning("loadpath is required"); return FALSE; } dc_module_value = GetItemLongName(node->mcprec->value, "dc.module"); dc_module = ValueStringPointer(dc_module_value); app_class = load_application(handler->loadpath, dc_module); if (NIL_P(app_class)) { Warning("%s is not found", dc_module); return FALSE; } app = rb_protect_funcall(app_class, rb_intern("new"), &state, 0); if (state && error_handle(state)) { return FALSE; } PutApplication(node); rb_protect_funcall(app,rb_intern("exec_process"),&state,1,node_info); if (state && error_handle(state)) { Warning("eval exec_process failed"); return FALSE; } GetApplication(node); if (ValueInteger(GetItemLongName(node->mcprec->value, "rc")) < 0) { return FALSE; } else { return TRUE; } LEAVE_FUNC; }
extern void InitSystem( char *name) { char *user = NULL; char *term = NULL; ENTER_FUNC; InitData(BD_Name); if ( ( ThisBD = GetBD(BD_Name) ) == NULL ) { Error("BD file not found."); } if ( ThisBD->home != NULL ) { chdir(ThisBD->home); } ThisLD = NULL; ThisDBD = NULL; InitiateBatchHandler(); ThisDB = ThisBD->db; DB_Table = ThisBD->DB_Table; TextSize = ThisBD->textsize; if ( ThisEnv->mcprec != NULL ) { InitializeValue(ThisEnv->mcprec->value); } SetValueString(GetItemLongName(ThisEnv->mcprec->value,"dc.module"),name,NULL); if ((user = getenv("MONTSUQIUSER")) != NULL) { SetValueString(GetItemLongName(ThisEnv->mcprec->value,"dc.user"),user,NULL); } if ((term = getenv("MONTSUQITERM")) != NULL) { SetValueString(GetItemLongName(ThisEnv->mcprec->value,"dc.term"),term,NULL); } if ( ( Bind = g_hash_table_lookup(ThisBD->BatchTable,name) ) == NULL ) { Error("%s application is not in BD.",name); } InitDB_Process(AppName); ReadyHandlerDB(Bind->handler); LEAVE_FUNC; }
extern void *MCP_GetEventHandler(GHashTable *StatusTable, ProcessNode *node) { char *status, *event; GHashTable *EventTable; void (*handler)(ProcessNode *); status = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.status")); event = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.event")); dbgprintf("status = [%s]", status); dbgprintf("event = [%s]", status, event); if ((EventTable = g_hash_table_lookup(StatusTable, status)) == NULL) { EventTable = g_hash_table_lookup(StatusTable, ""); } if (EventTable != NULL) { if ((handler = g_hash_table_lookup(EventTable, event)) == NULL) { handler = g_hash_table_lookup(EventTable, ""); } } else { handler = NULL; } return (handler); }
static ValueStruct *_CloseXML(DBG_Struct *dbg, DBCOMM_CTRL *ctrl, RecordStruct *rec, ValueStruct *args) { ValueStruct *obj, *ret; xmlChar *buff; int size; DBG_Struct *mondbg; buff = NULL; ret = NULL; if (rec->type != RECORD_DB) { ctrl->rc = MCP_BAD_ARG; return NULL; } if ((obj = GetItemLongName(args, "object")) == NULL) { ctrl->rc = MCP_BAD_ARG; return NULL; } if (XMLDoc == NULL) { ctrl->rc = MCP_BAD_OTHER; return NULL; } ctrl->rc = MCP_OK; if (XMLmode == MODE_WRITE) { xmlDocDumpFormatMemoryEnc(XMLDoc, &buff, &size, "UTF-8", 0); if (buff != NULL) { mondbg = GetDBG_monsys(); ValueObjectId(obj) = blob_import_mem(mondbg, 0, "XMLIO.xml", "application/xml", 0, buff, size); if (ValueObjectId(obj) != GL_OBJ_NULL) { ret = DuplicateValue(args, TRUE); ctrl->rc = MCP_OK; } else { Warning("monblob_import_mem failure"); ctrl->rc = MCP_BAD_OTHER; } } xfree(buff); } xmlFreeDoc(XMLDoc); XMLDoc = NULL; XMLpos = 0; XMLmode = MODE_NONE; return ret; }
extern RecordStruct *SetAuditRec(ValueStruct *mcp, RecordStruct *rec) { time_t now; struct tm tm_now; ValueStruct *audit; audit = rec->value; now = time(NULL); localtime_r(&now, &tm_now); SetValueDateTime(GetItemLongName(audit, "exec_date"), tm_now); CopyValuebyName(audit, "func", mcp, "func"); CopyValuebyName(audit, "result", mcp, "rc"); CopyValuebyName(audit, "username", mcp, "dc.user"); CopyValuebyName(audit, "term", mcp, "dc.term"); CopyValuebyName(audit, "windowname", mcp, "dc.window"); CopyValuebyName(audit, "widget", mcp, "dc.widget"); CopyValuebyName(audit, "event", mcp, "dc.event"); CopyValuebyName(audit, "comment", mcp, "db.logcomment"); return (rec); }
static VALUE recval_aref(VALUE self, VALUE name) { VALUE obj; value_struct_data *data; ValueStruct *val; Data_Get_Struct(self, value_struct_data, data); if (!NIL_P(obj = rb_hash_aref(data->cache, name))) return obj; val = GetItemLongName(data->value, StringValuePtr(name)); if (val == NULL) rb_raise(rb_eArgError, "no such field: %s", StringValuePtr(name)); obj = get_value(val); if (CACHEABLE(val)) rb_hash_aset(data->cache, name, obj); return obj; }
static void startElement2_(ValueContext *ctx, xmlChar *name, xmlChar **atts) { xmlChar *vname, *rname, *p, *q, *type; xmlChar buff[SIZE_LONGNAME + 1]; int count; Bool fArray; strcpy((char *)buff, (char *)name); if ((p = (xmlChar *)strchr((char *)buff, ':')) != NULL) { *p = 0; rname = buff; vname = p + 1; } else { rname = (xmlChar *)""; vname = buff; } if ((p = (xmlChar *)strchr((char *)vname, ':')) != NULL) { *p = 0; count = atoi((char *)p + 1); fArray = TRUE; } else { fArray = FALSE; count = 0; } p = NextName(ctx); q = p; if ((char *)p != ctx->longname) { *p++ = '.'; } if (fArray) { sprintf((char *)p, "%s[%d]", (char *)vname, count); } else { sprintf((char *)p, "%s", (char *)vname); } #ifdef DEBUG printf("startElement_(%s)[%s]\n", (char *)name, ctx->longname); #endif if (stricmp((char *)rname, ctx->opt->recname) == 0) { if (stricmp((char *)vname, "data") == 0) { *ctx->longname = 0; ctx->value = NULL; ctx->fStart = FALSE; } else { type = GetAttribute(atts, (xmlChar *)"type"); if (stricmp((char *)type, "record") == 0) { if (ctx->value == NULL) { *q = 0; } ctx->value = GetItemLongName(ctx->root, ctx->longname); ctx->fStart = FALSE; } else if (stricmp((char *)type, "array") == 0) { *q = 0; ctx->fStart = FALSE; } else { ctx->value = GetItemLongName(ctx->root, ctx->longname); ctx->fStart = TRUE; } } } else { *q = 0; ctx->fStart = FALSE; } }
extern int main( int argc, char **argv) { #define SIZE_DATA 128 char name[SIZE_DATA]; unsigned char *p; int i; ValueStruct *val , *val2; unsigned char *buff; char method[SIZE_LONGNAME+1]; FILE *fp; RecordDir = "."; RecParserInit(); val = BuildMcpArea(10); /* set */ printf("***** Value setting *****\n"); SetValueString(GetItemLongName(val,"func"),"aaa",SRC_CODE); SetValueString(GetItemLongName(val,"rc"),"0",SRC_CODE); SetValueString(GetItemLongName(val,"dc.window"),"1 Ë",SRC_CODE); SetValueString(GetItemLongName(val,"dc.widget"),"widget",SRC_CODE); SetValueString(GetItemLongName(val,"dc.event"),"1002 ",SRC_CODE); SetValueString(GetItemLongName(val,"dc.fromwin"),"fromwin",SRC_CODE); SetValueString(GetItemLongName(val,"dc.status"),"status",SRC_CODE); SetValueString(GetItemLongName(val,"dc.puttype"),"puttype",SRC_CODE); SetValueString(GetItemLongName(val,"dc.term"),"term",SRC_CODE); SetValueString(GetItemLongName(val,"dc.user"),"user",SRC_CODE); for ( i = 0 ; i < N_PATH ; i ++ ) { sprintf(name,"db.path[%d].blocks",i); SetValueInteger(GetItemLongName(val,name),i); sprintf(name,"db.path[%d].rname",i); SetValueInteger(GetItemLongName(val,name),i); sprintf(name,"db.path[%d].pname",i); SetValueInteger(GetItemLongName(val,name),i); sprintf(name,"db.path[%d].name",i); SetValueString(GetItemLongName(val,name),name,SRC_CODE); } SetValueString(GetItemLongName(val,"private.count"),"1",SRC_CODE); for ( i = 0 ; i < 100 ; i ++ ) { sprintf(name,"private.swindow[%d]",i); SetValueString(GetItemLongName(val,name),name,SRC_CODE); } for ( i = 0 ; i < ValueArraySize(GetItemLongName(val,"private.state")) ; i ++ ) { sprintf(name,"private.state[%d]",i); SetValueString(GetItemLongName(val,name),name,SRC_CODE); } for ( i = 0 ; i < ValueArraySize(GetItemLongName(val,"private.index")) ; i ++ ) { sprintf(name,"private.index[%d]",i); SetValueString(GetItemLongName(val,name),name,SRC_CODE); } SetValueString(GetItemLongName(val,"private.pstatus"),"1",SRC_CODE); SetValueString(GetItemLongName(val,"private.pputtype"),"2",SRC_CODE); SetValueString(GetItemLongName(val,"private.prc"),"3",SRC_CODE); buff = xmalloc(SIZE_BUFF); memset(buff,0,SIZE_BUFF); for ( p = buff, i = 0 ; i < 256 ; i ++ , p ++) { *p = (unsigned char)i; } SetValueBinary(GetItemLongName(val,"bin"),buff,256); printf("***** SOAP ****\n"); memset(buff,0,SIZE_BUFF); SOAP_PackValue(buff,val,"Put","mcp","http://oreore",TRUE,FALSE); printf("%s\n",buff); fp = fopen("test.SOAP","w"); fprintf(fp,"%s\n",buff); fclose(fp); val2 = DuplicateValue(val,FALSE); SOAP_UnPackValue(val2,(char *)buff,method); printf("method = [%s]\n",method); DumpByXML(val2,"mcparea"); SOAP_PackValue(buff,val,"Put","mcp","http://oreore",TRUE,FALSE); val2 = SOAP_LoadValue((char *)buff,method); printf("method = [%s]\n",method); DumpByXML(val2,"mcparea"); //DumpValueStruct(val2); return (0); }
static Bool _ExecuteProcess(MessageHandler *handler, ProcessNode *node) { char *module; int pid; int pAPR[2], pAPW[2], pDBR[2], pDBW[2]; Bool rc; NETFILE *fpAPR, *fpAPW; char line[SIZE_BUFF], **cmd; if (handler->loadpath == NULL) { handler->loadpath = ExecPath; } signal(SIGPIPE, SignalHandler); module = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.module")); ExpandStart(line, handler->start, handler->loadpath, module, ""); cmd = ParCommandLine(line); if (pipe(pAPR) != 0) { perror("pipe"); exit(1); } if (pipe(pAPW) != 0) { perror("pipe"); exit(1); } if (pipe(pDBR) != 0) { perror("pipe"); exit(1); } if (pipe(pDBW) != 0) { perror("pipe"); exit(1); } if (setjmp(SubError) == 0) { if ((pid = fork()) == 0) { dup2(pAPW[0], STDIN_FILENO); dup2(pAPR[1], STDOUT_FILENO); close(pAPW[0]); close(pAPW[1]); close(pAPR[0]); close(pAPR[1]); dup2(pDBW[0], DBIN_FILENO); dup2(pDBR[1], DBOUT_FILENO); close(pDBW[0]); close(pDBW[1]); close(pDBR[0]); close(pDBR[1]); execv(cmd[0], cmd); } else { fpAPR = FileToNet(pAPR[0]); close(pAPR[1]); fpAPW = FileToNet(pAPW[1]); close(pAPW[0]); fpDBR = FileToNet(pDBR[0]); close(pDBR[1]); fpDBW = FileToNet(pDBW[1]); close(pDBW[0]); StartDB(handler); PutApplication(handler, fpAPW, node); GetApplication(handler, fpAPR, node); (void)wait(&pid); CancelDB(); signal(SIGPIPE, SIG_DFL); CloseNet(fpAPW); CloseNet(fpAPR); CloseNet(fpDBW); CloseNet(fpDBR); } rc = TRUE; } else { rc = FALSE; } return (rc); }
int main(int argc, char *argv[]) { ValueStruct *value, *v; size_t size; char *buf; RecParserInit(); value = RecParseValueMem(recdef, NULL); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); v = GetItemLongName(value, "record1[0].record2.col21"); SetValueString(v, "cccc", NULL); v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "double1"); SetValueFloat(v, -3.2); fprintf(stderr, "\n---- JSON_PackValue\n"); size = JSON_SizeValue(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValue(NULL, buf, value); fprintf(stderr, "[%s]\nsize:%ld\n", buf, strlen(buf)); fprintf(stderr, "\n---- JSON_UnPackValue 1\n"); JSON_UnPackValue(NULL, buf, value); DumpValueStruct(value); free(buf); fprintf(stderr, "\n---- JSON_UnPackValue 2\n"); JSON_UnPackValue(NULL, "{\"int1\":1000,\"int2\":2000}", value); DumpValueStruct(value); /* ommit */ fprintf(stderr, "\n-------------------\n"); fprintf(stderr, "ommit\n"); fprintf(stderr, "-------------------\n\n"); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); v = GetItemLongName(value, "record1[0].record2.col21"); SetValueString(v, "cccc", NULL); v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "record3[1].record4[1].vc41"); SetValueString(v, "vc41", NULL); fprintf(stderr, "\n---- JSON_PackValueOmmit\n"); size = JSON_SizeValueOmmit(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValueOmmit(NULL, buf, value); fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf); free(buf); fprintf(stderr, "\n---- JSON_UnPackValueOmmit\n"); JSON_UnPackValueOmmit(NULL, "{\"int1\":1000,\"int2\":2000}", value); DumpValueStruct(value); fprintf(stderr, "\n---- JSON_UnPackValueOmmit 2\n"); JSON_UnPackValueOmmit( NULL, "{\"int1\":1234,\"int2\":5678,\"bool1\":false,\"double1\":3.141592}", value); DumpValueStruct(value); fprintf(stderr, "\n---- JSON_UnPackValueOmmit 3\n"); JSON_UnPackValueOmmit( NULL, "{\"int1\":1000,\"command\":\"moge\",\"record1\":[{\"col1\":\"muge\"," "\"record2\":{\"col21\":\"gage\"}},{},{\"col2\":\"nuge\"}],\"record3\":[{" "},{\"record4\":[{},{\"vc41\":\"vc41\"}]}]}", value); DumpValueStruct(value); InitializeValue(value); fprintf(stderr, "\n---- test\n"); JSON_UnPackValueOmmit(NULL, "{\"int1\":10,\"int0\":[0,1,2,3,0,5,0,6],\"bool1\":" "false,\"arg1\":\"hogehoge\"}", value); size = JSON_SizeValueOmmit(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size); memset(buf, 0, size); JSON_PackValueOmmit(NULL, buf, value); fprintf(stderr, "size:%d %s\n", (int)strlen(buf), buf); free(buf); fprintf(stderr, "\n\n\n\n\n\n---- JSON_PackValueOmmitString\n"); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); #if 0 v = GetItemLongName(value,"record1[0].record2.col21"); SetValueString(v,"cccc",NULL); #endif v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "record3[1].record4[1].vc41"); SetValueString(v, "vc41", NULL); DumpValueStruct(value); size = JSON_SizeValueOmmitString(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValueOmmitString(NULL, buf, value); fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf); free(buf); return 0; }
static void ExecuteDB_Server(MessageHandler *handler) { RecordStruct *rec; ValueStruct *value, *ret; PathStruct *path; DB_Operation *op; size_t size; int rno, pno, ono; DBCOMM_CTRL ctrl; char *rname, *pname, *func; ConvFuncs *conv; InitializeCTRL(&ctrl); conv = handler->serialize; while (TRUE) { dbgmsg("read"); LBS_EmitStart(dbbuff); RecvLargeString(fpDBR, dbbuff); ON_IO_ERROR(fpDBR, badio); ConvSetRecName(handler->conv, recDBCTRL->name); InitializeValue(recDBCTRL->value); conv->UnPackValue(handler->conv, LBS_Body(dbbuff), recDBCTRL->value); rname = ValueStringPointer(GetItemLongName(recDBCTRL->value, "rname")); strncpy(ctrl.rname, rname, SIZE_NAME); value = NULL; ret = NULL; if ((rname != NULL) && ((rno = (int)(long)g_hash_table_lookup(DB_Table, rname)) != 0)) { ctrl.rno = rno - 1; rec = ThisDB[ctrl.rno]; value = rec->value; pname = ValueStringPointer(GetItemLongName(recDBCTRL->value, "pname")); strncpy(ctrl.pname, pname, SIZE_NAME); if ((pno = (int)(long)g_hash_table_lookup(rec->opt.db->paths, pname)) != 0) { ctrl.pno = pno - 1; path = rec->opt.db->path[pno - 1]; value = (path->args != NULL) ? path->args : value; } else { ctrl.pno = 0; path = NULL; } } else { rec = NULL; path = NULL; } func = ValueStringPointer(GetItemLongName(recDBCTRL->value, "func")); if (*func != 0) { if (path == NULL) { Error("path is NULL"); } else if ((ono = (int)(long)g_hash_table_lookup(path->opHash, func)) != 0) { op = path->ops[ono - 1]; value = (op->args != NULL) ? op->args : value; } if (rec != NULL) { ConvSetRecName(handler->conv, rec->name); } else { Error("rec is NULL"); } InitializeValue(value); conv->UnPackValue(handler->conv, LBS_Body(dbbuff), value); strncpy(ctrl.func, func, SIZE_FUNC); ret = ExecDB_Process(&ctrl, rec, value); } else { ctrl.rc = 0; } dbgmsg("write"); SetValueInteger(GetItemLongName(recDBCTRL->value, "rc"), ctrl.rc); ConvSetRecName(handler->conv, recDBCTRL->name); LBS_EmitStart(dbbuff); size = conv->SizeValue(handler->conv, recDBCTRL->value); LBS_ReserveSize(dbbuff, size, FALSE); conv->PackValue(handler->conv, LBS_Body(dbbuff), recDBCTRL->value); LBS_EmitEnd(dbbuff); SendLargeString(fpDBW, dbbuff); ON_IO_ERROR(fpDBW, badio); if (ret != NULL) { Send(fpDBW, conv->fsep, strlen(conv->fsep)); ON_IO_ERROR(fpDBW, badio); LBS_EmitStart(dbbuff); if (rec != NULL) { ConvSetRecName(handler->conv, rec->name); } size = conv->SizeValue(handler->conv, ret); LBS_ReserveSize(dbbuff, size, FALSE); conv->PackValue(handler->conv, LBS_Body(dbbuff), ret); LBS_EmitEnd(dbbuff); SendLargeString(fpDBW, dbbuff); ON_IO_ERROR(fpDBW, badio); FreeValueStruct(ret); } Send(fpDBW, conv->bsep, strlen(conv->bsep)); ON_IO_ERROR(fpDBW, badio); } badio: return; }
static void CopyValuebyName(ValueStruct *to, char *to_name, ValueStruct *from, char *from_name) { CopyValue(GetItemLongName(to, to_name), GetItemLongName(from, from_name)); }