static SessionData * NewSessionData(void) { SessionData *data; ENTER_FUNC; data = New(SessionData); memclear(data,sizeof(SessionData)); data->type = SESSION_TYPE_TERM; data->status = SESSION_STATUS_NORMAL; data->hdr = New(MessageHeader); memclear(data->hdr,sizeof(MessageHeader)); data->hdr->command = APL_COMMAND_LINK; data->apsid = -1; data->spadata = NewNameHash(); data->scrpool = NewNameHash(); gettimeofday(&(data->create_time), NULL); gettimeofday(&(data->access_time), NULL); timerclear(&(data->process_time)); timerclear(&(data->total_process_time)); data->apidata = New(APIData); data->apidata->status = WFC_API_OK; data->apidata->rec = NewLBS(); data->sysdbval = RecParseValueMem(SYSDBVAL_DEF,NULL); InitializeValue(data->sysdbval); data->count = 0; data->w.sp = 0; LEAVE_FUNC; return (data); }
extern void OpenDB_RedirectPort( DBG_Struct *dbg) { int fh; DBG_Struct *rdbg; ENTER_FUNC; dbgprintf("dbg [%s]\n",dbg->name); if ( ( fNoRedirect ) || ( dbg->redirect == NULL ) ) { dbg->fpLog = NULL; dbg->redirectData = NULL; } else { rdbg = dbg->redirect; if ( ( rdbg->redirectPort == NULL ) || (( fh = ConnectSocket(rdbg->redirectPort,SOCK_STREAM) ) < 0 ) ) { dbgmsg("loging server not ready"); dbg->fpLog = NULL; dbg->redirectData = NULL; if ( !fNoCheck ){ ChangeDBStatus_Redirect(dbg, DB_STATUS_REDFAILURE); } } else { dbg->fpLog = SocketToNet(fh); dbg->redirectData = NewLBS(); if ( !RecvSTATUS_Redirect(dbg) ){ CloseDB_RedirectPort(dbg); } } } LEAVE_FUNC; }
extern void InitProtocol(void) { ENTER_FUNC; LargeBuff = NewLBS(); THISWINDOW(Session) = NULL; WINDOWTABLE(Session) = NewNameHash(); WIDGETTABLE(Session) = NewNameHash(); LEAVE_FUNC; }
static LargeByteString * NewLinkData(void) { LargeByteString *linkdata; size_t size; if (ThisEnv->linkrec != NULL) { linkdata = NewLBS(); size = NativeSizeValue(NULL,ThisEnv->linkrec->value); LBS_ReserveSize(linkdata,size,FALSE); NativePackValue(NULL,LBS_Body(linkdata),ThisEnv->linkrec->value); } else { linkdata = NULL; } return linkdata; }
static ValueStruct * _DBOPEN( DBG_Struct *dbg, DBCOMM_CTRL *ctrl) { ENTER_FUNC; OpenDB_RedirectPort(dbg); dbg->process[PROCESS_UPDATE].conn = (void *)NewLBS(); dbg->process[PROCESS_UPDATE].dbstatus = DB_STATUS_CONNECT; dbg->process[PROCESS_READONLY].dbstatus = DB_STATUS_NOCONNECT; if ( ctrl != NULL ) { ctrl->rc = MCP_OK; } LEAVE_FUNC; return (NULL); }
PacketClass SYSDB_GetDataAll(NETFILE *fp, int *size, ValueStruct *vals) { PacketClass rc; LargeByteString *buf; rc = SESSION_CONTROL_NG; buf = NewLBS(); SendPacketClass(fp, SYSDATA_SYSDB); ON_IO_ERROR(fp, badio); SendPacketClass(fp, SYSDB_GET_DATA_ALL); ON_IO_ERROR(fp, badio); rc = RecvPacketClass(fp); *size = RecvInt(fp); RecvLBS(fp, buf); NativeUnPackValue(NULL, LBS_Body(buf), vals); badio: FreeLBS(buf); return rc; }
static PacketClass SYSDB_RequestCommon(NETFILE *fp, PacketClass pc, ValueStruct *val) { PacketClass rc; LargeByteString *buf; rc = SESSION_CONTROL_NG; buf = NewLBS(); LBS_ReserveSize(buf, NativeSizeValue(NULL, val), FALSE); NativePackValue(NULL, LBS_Body(buf), val); SendPacketClass(fp, SYSDATA_SYSDB); ON_IO_ERROR(fp, badio); SendPacketClass(fp, pc); ON_IO_ERROR(fp, badio); SendLBS(fp, buf); ON_IO_ERROR(fp, badio); rc = RecvPacketClass(fp); RecvLBS(fp, buf); NativeUnPackValue(NULL, LBS_Body(buf), val); badio: FreeLBS(buf); return rc; }
extern LargeByteString * ValueToLBS( ValueStruct *val, char *codeset) { byte work[SIZE_NUMBUF+1]; byte work2[SIZE_NUMBUF+2]; byte *p , *q; int i; int size; LargeByteString *ret; ENTER_FUNC; if ( val == NULL ) { ret = NULL; } else { dbgprintf("type = %X\n",(int)ValueType(val)); if ( ValueStr(val) == NULL ) { ValueStr(val) = NewLBS(); } LBS_EmitStart(ValueStr(val)); if ( IS_VALUE_NIL(val) ) { LBS_EmitChar(ValueStr(val),CHAR_NIL); } else switch (ValueType(val)) { case GL_TYPE_CHAR: case GL_TYPE_VARCHAR: case GL_TYPE_TEXT: case GL_TYPE_SYMBOL: case GL_TYPE_DBCODE: if ( ValueString(val) != NULL ) { RewindLBS(ValueStr(val)); if ( IS_VALUE_EXPANDABLE(val) ) { LBS_EmitStringCodeset(ValueStr(val),ValueString(val), ValueStringSize(val), ValueStringLength(val),codeset); if ( ( size = ValueStringLength(val) - ValueSize(val) ) > 0 ) { for ( ; size > 0 ; size -- ) { LBS_EmitChar(ValueStr(val),0); } } } else { LBS_EmitStringCodeset(ValueStr(val),ValueString(val), ValueStringSize(val), 0,codeset); } } break; case GL_TYPE_BYTE: case GL_TYPE_BINARY: #ifdef BINARY_IS_BASE64 size = ( ( ValueByteLength(val) + 2 ) / 3 ) * 4; p = (char *)xmalloc(size); size = EncodeBase64(p,size,ValueByte(val),ValueByteLength(val)); LBS_ReserveSize(ValueStr(val),size+1); strcpy(ValueStrBody(val),p); xfree(p); #else p = ValueByte(val); for ( i = 0 ; i < ValueByteLength(val) ; i ++ , p ++ ) { switch (*p) { case '\\': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'\\'); break; case '"': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'"'); break; case '/': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'/'); break; case '\b': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'b'); break; case '\f': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'f'); break; case '\n': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'n'); break; case '\r': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'r'); break; case '\t': LBS_EmitChar(ValueStr(val),'\\'); LBS_EmitChar(ValueStr(val),'t'); break; default: if ( isprint(*p) ) { LBS_EmitChar(ValueStr(val),*p); } else { sprintf(work,"\\u%02X",(int)*p); LBS_EmitString(ValueStr(val),work); } break; } } if ( ( size = ValueStringLength(val) - ValueSize(val) ) > 0 ) { for ( ; size > 0 ; size -- ) { LBS_EmitByte(ValueStr(val),0); } } #endif break; case GL_TYPE_NUMBER: strcpy(work,ValueFixedBody(val)); p = work; q = work2; if ( *p >= 0x70 ) { *q ++ = '-'; *p ^= 0x40; } strcpy(q,p); if ( ValueFixedSlen(val) > 0 ) { p = work2 + strlen(work2); *(p + 1) = 0; q = p - 1; for ( i = 0 ; i < ValueFixedSlen(val) ; i ++ ) { *p -- = *q --; } *p = '.'; } LBS_EmitString(ValueStr(val),work2); break; case GL_TYPE_INT: sprintf(work,"%d",ValueInteger(val)); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_OBJECT: sprintf(work,"%d",(int)ValueObjectId(val)); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_FLOAT: sprintf(work,"%g",ValueFloat(val)); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_BOOL: sprintf(work,"%s",ValueBool(val) ? "TRUE" : "FALSE"); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_TIMESTAMP: sprintf(work,"%04d%02d%02d%02d%02d%02d", ValueDateTimeYear(val), ValueDateTimeMon(val) + 1, ValueDateTimeMDay(val), ValueDateTimeHour(val), ValueDateTimeMin(val), ValueDateTimeSec(val)); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_DATE: sprintf(work,"%04d%02d%02d", ValueDateTimeYear(val), ValueDateTimeMon(val) + 1, ValueDateTimeMDay(val)); LBS_EmitString(ValueStr(val),work); break; case GL_TYPE_TIME: sprintf(work,"%02d%02d%02d", ValueDateTimeHour(val), ValueDateTimeMin(val), ValueDateTimeSec(val)); LBS_EmitString(ValueStr(val),work); break; default: break; } LBS_EmitEnd(ValueStr(val)); ret = ValueStr(val); } LEAVE_FUNC; return (ret); }
extern byte * ValueToBinary( ValueStruct *val) { byte *ret; ENTER_FUNC; if ( val == NULL ) { ret = NULL; } else { dbgprintf("type = %X\n",(int)ValueType(val)); if ( ValueStr(val) == NULL ) { ValueStr(val) = NewLBS(); } LBS_EmitStart(ValueStr(val)); if ( IS_VALUE_NIL(val) ) { LBS_EmitChar(ValueStr(val),CHAR_NIL); } else { switch (ValueType(val)) { case GL_TYPE_CHAR: case GL_TYPE_VARCHAR: case GL_TYPE_DBCODE: case GL_TYPE_TEXT: case GL_TYPE_SYMBOL: if ( ValueString(val) != NULL ) { LBS_ReserveSize(ValueStr(val),strlen(ValueString(val))+1,FALSE); strcpy(ValueStrBody(val),ValueString(val)); } else { LBS_EmitChar(ValueStr(val),CHAR_NIL); } break; case GL_TYPE_BYTE: case GL_TYPE_BINARY: LBS_ReserveSize(ValueStr(val),ValueByteLength(val),FALSE); memcpy(ValueStrBody(val),ValueByte(val),ValueByteLength(val)); break; case GL_TYPE_NUMBER: LBS_ReserveSize(ValueStr(val),sizeof(Fixed),FALSE); memcpy(ValueStrBody(val),&ValueFixed(val),sizeof(Fixed)); break; case GL_TYPE_INT: LBS_ReserveSize(ValueStr(val),sizeof(int),FALSE); memcpy(ValueStrBody(val),&ValueInteger(val),sizeof(int)); break; case GL_TYPE_OBJECT: LBS_ReserveSize(ValueStr(val),sizeof(MonObjectType),FALSE); memcpy(ValueStrBody(val),&ValueObject(val),sizeof(MonObjectType)); break; case GL_TYPE_FLOAT: LBS_ReserveSize(ValueStr(val),sizeof(double),FALSE); memcpy(ValueStrBody(val),&ValueFloat(val),sizeof(double)); break; case GL_TYPE_BOOL: LBS_ReserveSize(ValueStr(val),sizeof(Bool),FALSE); memcpy(ValueStrBody(val),&ValueBool(val),sizeof(Bool)); break; case GL_TYPE_TIMESTAMP: case GL_TYPE_DATE: case GL_TYPE_TIME: LBS_ReserveSize(ValueStr(val),sizeof(int)*9,FALSE); memcpy(ValueStrBody(val),&ValueDateTime(val),sizeof(int)*9); break; default: break; } } ret = ValueStrBody(val); } LEAVE_FUNC; return (ret); }