static void set_value(ValueStruct *value, VALUE obj) { VALUE class_path, str; if (NIL_P(obj)) { ValueIsNil(value); } else { ValueIsNonNil(value); switch (TYPE(obj)) { case T_TRUE: case T_FALSE: SetValueBool(value, RTEST(obj) ? TRUE : FALSE); break; case T_FIXNUM: SetValueInteger(value, FIX2INT(obj)); break; case T_BIGNUM: SetValueInteger(value, NUM2INT(obj)); break; case T_FLOAT: SetValueFloat(value, RFLOAT(obj)->value); break; case T_STRING: switch (ValueType(value)) { case GL_TYPE_BYTE: case GL_TYPE_BINARY: SetValueBinary(value, RSTRING(obj)->ptr, RSTRING(obj)->len); break; default: SetValueStringWithLength(value, RSTRING(obj)->ptr, RSTRING(obj)->len, codeset); break; } break; default: class_path = rb_class_path(CLASS_OF(obj)); if (strcasecmp(StringValuePtr(class_path), "BigDecimal") == 0) { str = rb_funcall(obj, rb_intern("to_s"), 1, rb_str_new2("F")); } else if (strcasecmp(StringValuePtr(class_path), "Time") == 0) { str = rb_funcall(obj, rb_intern("strftime"), 1, rb_str_new2("%Y%m%d%H%M%S")); dbgprintf("strftime [%s]",StringValuePtr(str)); } else { str = rb_funcall(obj, rb_intern("to_s"), 0); } SetValueString(value, StringValuePtr(str), codeset); break; } } }
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); }
extern size_t OpenCOBOL_UnPackValue(CONVOPT *opt, unsigned char *p, ValueStruct *value) { int32_t i; char buff[SIZE_NUMBUF + 1]; unsigned char *q; ValueStruct *child; q = p; if (value != NULL) { ValueIsNonNil(value); switch (ValueType(value)) { case GL_TYPE_INT: i = *(int32_t*)p; IntegerCobol2C(opt, &i); SetValueInteger(value, (int64_t)i); p += sizeof(int32_t); break; case GL_TYPE_FLOAT: ValueFloat(value) = *(double *)p; p += sizeof(double); break; case GL_TYPE_BOOL: SetValueBool(value,(*(char *)p == 'T') ? TRUE : FALSE); p++; break; case GL_TYPE_OBJECT: StringCobol2C(p, SIZE_UUID); memcpy(ValueBody(value), p, SIZE_UUID); p += SIZE_UUID; break; case GL_TYPE_BYTE: memcpy(ValueByte(value), p, ValueByteLength(value)); p += ValueByteLength(value); break; case GL_TYPE_BINARY: SetValueBinary(value, p, opt->textsize); p += opt->textsize; break; case GL_TYPE_TEXT: case GL_TYPE_SYMBOL: StringCobol2C(p, opt->textsize); SetValueStringWithLength(value, p, opt->textsize, ConvCodeset(opt)); p += opt->textsize; break; case GL_TYPE_CHAR: case GL_TYPE_VARCHAR: case GL_TYPE_DBCODE: StringCobol2C(p, ValueStringLength(value)); SetValueStringWithLength(value, p, ValueStringLength(value), ConvCodeset(opt)); p += ValueStringLength(value); break; case GL_TYPE_NUMBER: memcpy(buff, p, ValueFixedLength(value)); FixedCobol2C(buff, ValueFixedLength(value)); strcpy(ValueFixedBody(value), buff); p += ValueFixedLength(value); break; case GL_TYPE_TIMESTAMP: ValueDateTimeYear(value) = StrToInt(p, 4); p += 4; ValueDateTimeMon(value) = StrToInt(p, 2) - 1; p += 2; ValueDateTimeMDay(value) = StrToInt(p, 2); p += 2; ValueDateTimeHour(value) = StrToInt(p, 2); p += 2; ValueDateTimeMin(value) = StrToInt(p, 2); p += 2; ValueDateTimeSec(value) = StrToInt(p, 2); p += 2; mktime(ValueDateTime(value)); break; case GL_TYPE_TIME: ValueDateTimeYear(value) = 0; ValueDateTimeMon(value) = 0; ValueDateTimeMDay(value) = 0; ValueDateTimeHour(value) = StrToInt(p, 2); p += 2; ValueDateTimeMin(value) = StrToInt(p, 2); p += 2; ValueDateTimeSec(value) = StrToInt(p, 2); p += 2; break; case GL_TYPE_DATE: ValueDateTimeYear(value) = StrToInt(p, 4); p += 4; ValueDateTimeMon(value) = StrToInt(p, 2) - 1; p += 2; ValueDateTimeMDay(value) = StrToInt(p, 2); p += 2; ValueDateTimeHour(value) = 0; ValueDateTimeMin(value) = 0; ValueDateTimeSec(value) = 0; mktime(ValueDateTime(value)); break; case GL_TYPE_ARRAY: for (i = 0; i < ValueArraySize(value); i++) { child = ValueArrayItem(value, i); if (child != NULL) { p += OpenCOBOL_UnPackValue(opt, p, child); ValueParent(child) = value; } } break; case GL_TYPE_ROOT_RECORD: case GL_TYPE_RECORD: for (i = 0; i < ValueRecordSize(value); i++) { child = ValueRecordItem(value, i); if (child != NULL) { p += OpenCOBOL_UnPackValue(opt, p, child); ValueParent(child) = value; } } break; default: ValueIsNil(value); break; } } return (p - q); }