static void extractStructReferences( c_structure m, c_object o, void *data) { c_long i,length; c_member member; c_type type; c_object *ref; if (m->references == NULL) return; length = c_arraySize(m->references); for (i=0;i<length;i++) { member = c_member(m->references[i]); type = c_typeActualType(c_specifier(member)->type); while (c_baseObject(type)->kind == M_TYPEDEF) { type = c_typeDef(type)->alias; } switch (c_baseObject(type)->kind) { case M_CLASS: case M_INTERFACE: case M_COLLECTION: case M_BASE: ref = C_DISPLACE(data,member->offset); *ref = NULL; c_copyOut(type,C_REFGET(o,member->offset),ref); break; case M_EXCEPTION: case M_STRUCTURE: case M_UNION: copyReferences(type,C_DISPLACE(o,member->offset), C_DISPLACE(data,member->offset)) ; break; default: assert(FALSE); break; } } }
os_int32 idl_stacDefFindMemberIndexByName( c_array members, const os_char* name) { os_uint32 membersSize; os_int32 memberIndex = -1; c_member member; os_uint32 i; membersSize = c_arraySize(members); for(i = 0; i < membersSize && memberIndex == -1 ; i++) { member = c_member(members[i]); if(0 == strcmp(c_specifier(member)->name, name)) { memberIndex = (os_int32) i; } } return memberIndex; }
c_field c_fieldNew ( c_type type, const c_char *fieldName) { c_array path; c_field field; c_metaObject o; c_long n,length; c_address offset; c_iter nameList, refsList; c_string name; c_base base; if ((fieldName == NULL) || (type == NULL)) { OS_REPORT(OS_ERROR, "c_fieldNew failed",0, "illegal parameter"); return NULL; } base = c__getBase(type); if (base == NULL) { OS_REPORT(OS_ERROR, "c_fieldNew failed",0, "failed to retreive base"); return NULL; } nameList = c_splitString(fieldName,"."); length = c_iterLength(nameList); field = NULL; if (length > 0) { o = NULL; offset = 0; refsList = NULL; path = c_newArray(c_fieldPath_t(base),length); if (path) { for (n=0;n<length;n++) { name = c_iterTakeFirst(nameList); o = c_metaResolve(c_metaObject(type),name); os_free(name); if (o == NULL) { c_iterWalk(nameList,(c_iterWalkAction)os_free,NULL); c_iterFree(nameList); c_iterFree(refsList); c_free(path); return NULL; } path[n] = o; switch (c_baseObject(o)->kind) { case M_ATTRIBUTE: case M_RELATION: type = c_property(o)->type; offset += c_property(o)->offset; break; case M_MEMBER: type = c_specifier(o)->type; offset += c_member(o)->offset; break; default: c_iterWalk(nameList,(c_iterWalkAction)os_free,NULL); c_iterFree(nameList); c_iterFree(refsList); c_free(path); return NULL; } switch (c_baseObject(type)->kind) { case M_INTERFACE: case M_CLASS: case M_COLLECTION: /*Longs are inserted in an iterator? Explanation please...*/ refsList = c_iterInsert(refsList,(c_voidp)offset); offset = 0; break; default: break; } } if (offset > 0) { refsList = c_iterInsert(refsList,(c_voidp)offset); } field = c_new(c_field_t(base)); field->name = c_stringNew(base,fieldName); field->path = path; field->type = c_keep(type); field->kind = c_metaValueKind(o); field->refs = NULL; if (refsList) { length = c_iterLength(refsList); field->offset = 0; if (length > 0) { field->refs = c_newArray(c_fieldRefs_t(base),length); if (field->refs) { for (n=(length-1);n>=0;n--) { field->refs[n] = c_iterTakeFirst(refsList); } } else { OS_REPORT(OS_ERROR, "c_fieldNew failed",0, "failed to allocate field->refs array"); c_free(field); field = NULL; } } c_iterFree(refsList); } else { field->offset = offset; } } else { OS_REPORT(OS_ERROR, "c_fieldNew failed",0, "failed to allocate field->path array"); c_iterWalk(nameList,(c_iterWalkAction)os_free,NULL); c_iterFree(nameList); } c_iterFree(nameList); } else { OS_REPORT_1(OS_ERROR, "c_fieldNew failed",0, "failed to process field name <%s>", fieldName); } return field; }
/* This operation scans through the list of items within the 'stac' pragma. * For each structure that is identified it will locate the corresponding * meta structure. It will then locate each member mentioned in the 'stac' * pragma within the member list of said meta structure. It will verify the * located member is indeed a character array. * It will then proceed to replace the meta data describing the located member * with new meta data with as goal to have the new meta data identify the member * as a string instead of as a character array. * All replaced meta data is stored in out variables to facilitate restore the * member list of the meta structure back into it's original configuration. * This operation is needed then the meta data of the found structure is * converted to XML. As the XML generation code is located in the database and * we do not want the database to get knowledge of the 'stac' pragma. */ c_iter idl_stacDefConvertAll( idl_stacDef stacDef) { os_uint32 size; os_uint32 i; idl_stacMap stacMapItem; c_structure structure; c_iter memberNames; os_uint32 memberNamesSize; os_uint32 j; os_char* memberName; os_int32 memberIndex; c_member member; c_member newMember; os_uint32* replacedIndex; idl_stacDefReplaceInfo replaceData; c_iter replaceInfo = NULL; c_base base; c_iter boundedStringToBeConverted; os_boolean stacCanBeApplied = OS_TRUE; os_boolean onlyExclusionlistings; if(stacDef) { /* Create collections to hold the original members and their respective * indexes in the member collection so we can easily restore the meta * structure to it's original configuration at a later time. */ replaceInfo = c_iterNew(NULL); size = c_iterLength (stacDef->stacList); for(i = 0; i < size; i++) { stacMapItem = c_iterObject (stacDef->stacList, i); /* find the matching structure in the meta data */ structure = idl_stacDefFindMetaStructureResolved( stacMapItem->scope, stacMapItem->typeName); assert(structure); replaceData = os_malloc(C_SIZEOF(idl_stacDefReplaceInfo)); replaceData->structure = structure; replaceData->replacedIndexes = c_iterNew(NULL); replaceData->replacedMembers = c_iterNew(NULL); memberNames = c_splitString(stacMapItem->stacList, ","); onlyExclusionlistings = idl_stacDefOnlyExclusionsDefined(stacMapItem->stacList); memberNamesSize = c_iterLength(memberNames); boundedStringToBeConverted = c_iterNew(NULL); if(memberNamesSize == 0 || onlyExclusionlistings) { os_uint32 membersSize; membersSize = c_arraySize(structure->members); for(j = 0; j < membersSize; j++) { member = c_member(structure->members[j]); memberName = c_specifier(member)->name; /* check if this member is in the list of member names when * the member names list contains exclusion listings */ if((onlyExclusionlistings && c_iterResolve(memberNames, idl_stacDefNamesAreEqual, memberName) == NULL) || memberNamesSize == 0) { stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type); if(stacCanBeApplied) { /* this is a bounded string, so we want to convert */ c_iterInsert(boundedStringToBeConverted, member); } } } } else { for(j = 0; j < memberNamesSize; j++) { memberName = c_iterTakeFirst(memberNames); if(memberName[0] == '!') { printf("FATAL ERROR | #pragma stac: Illegal syntax combination detected. " "The pragma stac definition for structure %s contains both normal " "member listings (without the '!' character in front of them) as " "well as exclusion member listings (with the '!' character in front " "of them). This has no relevant meaning, please see the deployment manual " "for information on usage of pragma stac.\n" "Ignoring the following member defintion: '%s'\n", c_metaScopedName(c_metaObject(structure)), memberName); exit(-2); } memberIndex = idl_stacDefFindMemberIndexByName( structure->members, memberName); if(memberIndex == -1) { printf("FATAL ERROR | #pragma stac: Unable to locate member %s " "within structure %s.\n", memberName, c_metaScopedName(c_metaObject(structure))); exit(-2); } member = structure->members[memberIndex]; /* Verify the member is a bounded string as required */ stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type); if(!stacCanBeApplied) { printf("FATAL ERROR | #pragma stac: Member %s within structure " "%s is not a bounded string (note: may be embedded within an array or sequence) as required.\n", memberName, c_metaScopedName(c_metaObject(structure))); assert(0); exit(-2); } /* this is a bounded string, so we want to convert */ c_iterInsert(boundedStringToBeConverted, member); } } while(c_iterLength(boundedStringToBeConverted) > 0) { member = c_iterTakeFirst(boundedStringToBeConverted); memberIndex = idl_stacDefFindMemberIndexByName( structure->members, c_specifier(member)->name); assert(memberIndex != -1); newMember = c_metaDefine(c_metaObject(structure), M_MEMBER); base = c_getBase(member); c_specifier(newMember)->name = c_stringNew(base, c_specifier(member)->name); c_specifier(newMember)->type = idl_stacDefConvertStacApprovedMember(structure, c_specifier(member)->type); if(!c_specifier(newMember)->type) { printf("FATAL ERROR | #pragma stac: An internal error occured. Member %s within structure " "%s failed to convert from a bounded string to a character array.\n", c_specifier(newMember)->name, c_metaScopedName(c_metaObject(structure))); assert(0); exit(-2); } structure->members[memberIndex] = newMember; c_iterInsert(replaceData->replacedMembers, member); replacedIndex = os_malloc(sizeof(os_uint32)); *replacedIndex = (os_uint32)memberIndex; c_iterInsert(replaceData->replacedIndexes, replacedIndex); } c_iterInsert(replaceInfo, replaceData); } } return replaceInfo; }
static c_bool c__cloneReferences ( c_type type, c_voidp data, c_voidp dest) { c_type refType; c_class cls; c_array references, labels, ar, destar; c_sequence seq, destseq; c_property property; c_member member; c_long i,j,length,size; c_long nrOfRefs,nrOfLabs; c_value v; switch (c_baseObject(type)->kind) { case M_CLASS: cls = c_class(type); while (cls) { length = c_arraySize(c_interface(cls)->references); for (i=0;i<length;i++) { property = c_property(c_interface(cls)->references[i]); refType = property->type; _cloneReference(refType, C_DISPLACE(data, property->offset), C_DISPLACE(dest, property->offset)); } cls = cls->extends; } break; case M_INTERFACE: length = c_arraySize(c_interface(type)->references); for (i=0;i<length;i++) { property = c_property(c_interface(type)->references[i]); refType = property->type; _cloneReference(refType, C_DISPLACE(data, property->offset), C_DISPLACE(dest, property->offset)); } break; case M_EXCEPTION: case M_STRUCTURE: length = c_arraySize(c_structure(type)->references); for (i=0;i<length;i++) { member = c_member(c_structure(type)->references[i]); refType = c_specifier(member)->type; _cloneReference(refType, C_DISPLACE(data, member->offset), C_DISPLACE(dest, member->offset)); } break; case M_UNION: #define _CASE_(k,t) case k: v = t##Value(*((t *)data)); break switch (c_metaValueKind(c_metaObject(c_union(type)->switchType))) { _CASE_(V_BOOLEAN, c_bool); _CASE_(V_OCTET, c_octet); _CASE_(V_SHORT, c_short); _CASE_(V_LONG, c_long); _CASE_(V_LONGLONG, c_longlong); _CASE_(V_USHORT, c_ushort); _CASE_(V_ULONG, c_ulong); _CASE_(V_ULONGLONG, c_ulonglong); _CASE_(V_CHAR, c_char); _CASE_(V_WCHAR, c_wchar); default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal union switch type detected"); assert(FALSE); return FALSE; break; } #undef _CASE_ references = c_union(type)->references; if (references != NULL) { i=0; refType=NULL; nrOfRefs = c_arraySize(references); while ((i<nrOfRefs) && (refType == NULL)) { labels = c_unionCase(references[i])->labels; j=0; nrOfLabs = c_arraySize(labels); while ((j<nrOfLabs) && (refType == NULL)) { if (c_valueCompare(v,c_literal(labels[j])->value) == C_EQ) { c__cloneReferences(c_type(references[i]), C_DISPLACE(data, c_type(type)->alignment), C_DISPLACE(dest, c_type(type)->alignment)); refType = c_specifier(references[i])->type; } j++; } i++; } } break; case M_COLLECTION: refType = c_typeActualType(c_collectionType(type)->subType); switch (c_collectionType(type)->kind) { case C_ARRAY: ar = c_array(data); destar = c_array(dest); length = c_collectionType(type)->maxSize; if (length == 0) { length = c_arraySize(ar); } if (c_typeIsRef(refType)) { for (i=0;i<length;i++) { c_cloneIn(refType, ar[i], &destar[i]); } } else { if (c_typeHasRef(refType)) { size = refType->size; for (i=0;i<length;i++) { _cloneReference(refType, C_DISPLACE(data, (i*size)), C_DISPLACE(dest, (i*size))); } } } break; case C_SEQUENCE: seq = c_sequence(data); destseq = c_sequence(dest); length = c_sequenceSize(seq); if (c_typeIsRef(refType)) { for (i=0;i<length;i++) { c_cloneIn(refType, seq[i], &destseq[i]); } } else { if (c_typeHasRef(refType)) { size = refType->size; for (i=0;i<length;i++) { _cloneReference(refType, C_DISPLACE(seq, (i*size)), C_DISPLACE(dest, (i*size))); } } } break; default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal collectionType found"); break; } break; case M_BASE: break; case M_TYPEDEF: c__cloneReferences(c_type(c_typeDef(type)->alias), data, dest); break; case M_ATTRIBUTE: case M_RELATION: refType = c_typeActualType(c_property(type)->type); _cloneReference(refType, C_DISPLACE(data, c_property(type)->offset), C_DISPLACE(dest, c_property(type)->offset)); break; case M_MEMBER: refType = c_typeActualType(c_specifier(type)->type); _cloneReference(refType, C_DISPLACE(data, c_member(type)->offset), C_DISPLACE(dest, c_member(type)->offset)); break; case M_UNIONCASE: refType = c_typeActualType(c_specifier(type)->type); _cloneReference(refType, data, dest); break; case M_MODULE: /* Do nothing */ break; case M_PRIMITIVE: /* Do nothing */ break; case M_EXTENT: case M_EXTENTSYNC: default: OS_REPORT(OS_ERROR, "c__cloneReferences",0, "illegal meta object specified"); assert(FALSE); return FALSE; } return TRUE; }