void OPC_Remove_relation(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT Param1;
	C_TEXT Param2;
	C_LONGINT Param3;
	C_TEXT Param4;	
	C_LONGINT returnValue;
	
	Param1.fromParamAtIndex(pParams, 1);
	Param2.fromParamAtIndex(pParams, 2);
	Param3.fromParamAtIndex(pParams, 3);
	Param4.fromParamAtIndex(pParams, 4);
	
	if(Param3.getIntValue() > 0) {
		
		CUTF8String path, type, name;
		
		if(!Param4.getUTF16Length()) {
			name = DEFAULT_RELATION_PREFIX;
		}else{
			Param4.copyUTF8String(&name);
		}
		
		Param1.copyPath(&path);
		Param2.copyUTF8String(&type);
		
		std::stringstream ss;
		ss << Param3.getIntValue();
		name +=	(const uint8_t *)ss.str().c_str();
		
		opcContainer *c = opcContainerOpen(_X(path.c_str()), OPC_OPEN_READ_WRITE, NULL, NULL);
		
		if(c) {
			
			opcPart part = opcPartFind(c, _X(type.c_str()), NULL, 0);
			
			if (OPC_PART_INVALID != part) {
			
				if (OPC_RELATION_INVALID != opcRelationFind(c, part, (const xmlChar *)name.c_str(), NULL)) {
					returnValue.setIntValue(opcRelationDelete(c, part, (const xmlChar *)name.c_str(), NULL));
				}else{
					returnValue.setIntValue(OPC_ERROR_INVALID_RELATION_ID);
				}
				
			}else{returnValue.setIntValue(OPC_ERROR_INVALID_RESOURCE_ID);}	
			
			opcContainerClose(c, OPC_CLOSE_TRIM);
			
		}else{returnValue.setIntValue(OPC_ERROR_INVALID_PATH);}	
		
	}else{returnValue.setIntValue(OPC_ERROR_INVALID_RELATION_ID);}
	
	returnValue.setReturn(pResult);
}
void OPC_RELATION_LIST(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT Param1;
	C_TEXT Param2;
	ARRAY_TEXT Param3;
	ARRAY_TEXT Param4;
	ARRAY_TEXT Param5;
	ARRAY_TEXT Param6;
	
	Param1.fromParamAtIndex(pParams, 1);
	Param2.fromParamAtIndex(pParams, 2);
	
	CUTF8String path;
	Param1.copyPath(&path);
	
	opcContainer *c = opcContainerOpen(_X(path.c_str()), OPC_OPEN_READ_ONLY, NULL, NULL);
	
	if (c) {
		
		Param3.setSize(1);	
		Param4.setSize(1);
		Param5.setSize(1);
		Param6.setSize(1);
		
		opcPart part = getPart(c, Param2);
				
		traverseRelation(c, part, Param3, Param4, Param5, Param6);
		
		opcContainerClose(c, OPC_CLOSE_NOW);
		
	}
	
	Param3.toParamAtIndex(pParams, 3);
	Param4.toParamAtIndex(pParams, 4);
	Param5.toParamAtIndex(pParams, 5);	
	Param6.toParamAtIndex(pParams, 6);		
}
Exemple #3
0
int main( int argc, const char* argv[] )
{
#ifdef WIN32
     _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
    int ret=-1;
    time_t start_time=time(NULL);
    FILE *file=NULL;
    const xmlChar *containerPath8=NULL;
    const xmlChar *partName8=NULL;
    xmlTextWriter *writer=NULL;
    int writer_indent=0;
    opc_bool_t reader_mce=OPC_TRUE;
    for(int i=1;i<argc;i++) {
        if ((0==xmlStrcmp(_X("--understands"), _X(argv[i])) || 0==xmlStrcmp(_X("-u"), _X(argv[i]))) && i+1<argc) {
	    i++; // skip namespace, registered later when parser was created.
        } else if ((0==xmlStrcmp(_X("--out"), _X(argv[i])) || 0==xmlStrcmp(_X("--out"), _X(argv[i]))) && i+1<argc && NULL==file) {
            const char *filename=argv[++i];
            file=fopen(filename, "w");
        } else if (0==xmlStrcmp(_X("--indent"), _X(argv[i]))) {
            writer_indent=1;
        } else if (0==xmlStrcmp(_X("--raw"), _X(argv[i]))) {
            reader_mce=OPC_FALSE;
        } else if (NULL==containerPath8) {
            containerPath8=_X(argv[i]);
        } else if (NULL==partName8) {
            partName8=_X(argv[i]);
        } else {
            fprintf(stderr, "IGNORED: %s\n", argv[i]);
        }
    }
    if (NULL!=file) {
        xmlOutputBuffer *out=xmlOutputBufferCreateIO(xmlOutputWrite, xmlOutputClose, file, NULL);
        if (NULL!=out) {
            writer=xmlNewTextWriter(out);
        }
    } else {
        xmlOutputBuffer *out=xmlOutputBufferCreateIO(xmlOutputWrite, xmlOutputClose, stdout, NULL);
        if (NULL!=out) {
            writer=xmlNewTextWriter(out);
        }
    }
    if (NULL==containerPath8 || NULL==writer) {
        printf("mce_extract FILENAME.\n\n");
        printf("Sample: mce_extract test.docx word/document.xml\n");
    } else if (OPC_ERROR_NONE==opcInitLibrary()) {
        xmlTextWriterSetIndent(writer, writer_indent);
        opcContainer *c=NULL;
        if (NULL!=(c=opcContainerOpen(containerPath8, OPC_OPEN_READ_ONLY, NULL, NULL))) {
            if (NULL==partName8) {
                dumpPartsAsJSON(c, writer_indent);
            } else {
                opcPart part=OPC_PART_INVALID;
                if ((part=opcPartFind(c, partName8, NULL, 0))!=OPC_PART_INVALID) {
                    mceTextReader_t reader;
                    if (OPC_ERROR_NONE==opcXmlReaderOpen(c, &reader, part, NULL, NULL, 0)) {
                        mceTextReaderDisableMCE(&reader, !reader_mce);
                        for(int i=1;i<argc;i++) {
                            if ((0==xmlStrcmp(_X("--understands"), _X(argv[i])) || 0==xmlStrcmp(_X("-u"), _X(argv[i]))) && i+1<argc) {
                                const xmlChar *ns=_X(argv[++i]);
                                mceTextReaderUnderstandsNamespace(&reader, ns);
                            }
                        }

                        if (-1==mceTextReaderDump(&reader, writer, PTRUE)) {
                            ret=mceTextReaderGetError(&reader);
                        } else {
                            ret=0;
                        }
                        mceTextReaderCleanup(&reader);
                    } else {
                        fprintf(stderr, "ERROR: part \"%s\" could not be opened for XML reading.\n", argv[2]);
                    }
                } else {
                    fprintf(stderr, "ERROR: part \"%s\" could not be opened in \"%s\".\n", argv[2], argv[1]);
                }
            }
            opcContainerClose(c, OPC_CLOSE_NOW);
        } else {
            fprintf(stderr, "ERROR: file \"%s\" could not be opened.\n", argv[1]);
        }
        opcFreeLibrary();
    } else {
        fprintf(stderr, "ERROR: initialization of libopc failed.\n");    
    }
    if (NULL!=writer) xmlFreeTextWriter(writer);
    if (NULL!=file) fclose(file);
    time_t end_time=time(NULL);
    fprintf(stderr, "time %.2lfsec\n", difftime(end_time, start_time));
    return ret;
}
void OPC_Create_relation(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT Param1;
	C_TEXT Param2;
	C_TEXT Param3;
	C_TEXT Param4;
	C_LONGINT Param5;
	C_TEXT Param6;	
	C_LONGINT returnValue;
	
	Param1.fromParamAtIndex(pParams, 1);
	Param2.fromParamAtIndex(pParams, 2);
	Param3.fromParamAtIndex(pParams, 3);
	Param4.fromParamAtIndex(pParams, 4);
	Param5.fromParamAtIndex(pParams, 5);

	if(Param4.getUTF16Length()) {
		
		if(Param5.getIntValue() > 0) {
			
			CUTF8String path, src, dst, type, name;
			
			if(!Param6.getUTF16Length()) {
				name = DEFAULT_RELATION_PREFIX;
			}else{
				Param6.copyUTF8String(&name);
			}
				
			Param1.copyPath(&path);
			Param2.copyUTF8String(&src);
			Param3.copyUTF8String(&dst);	
			Param4.copyUTF8String(&type);	
			
			std::stringstream ss;
			ss << Param5.getIntValue();
			name +=	(const uint8_t *)ss.str().c_str();
		
			opcContainer *c = opcContainerOpen(_X(path.c_str()), OPC_OPEN_READ_WRITE, NULL, NULL);
			
			if(c) {
				
				opcPart srcPart = opcPartFind(c, _X(src.c_str()), NULL, 0);
				
				if (OPC_PART_INVALID != srcPart) {
					
					opcPart dstPart = opcPartFind(c, _X(dst.c_str()), NULL, 0);
					
					if (OPC_PART_INVALID != dstPart) {
						
						signed int status = (signed int)opcRelationAdd(c, srcPart, (const xmlChar *)name.c_str(), dstPart, (const xmlChar *)type.c_str());
		
						if((status) == -1) {
							returnValue.setIntValue(OPC_ERROR_INVALID_RELATION_ID);
						}else{
							returnValue.setIntValue(status);
						}
						
					}else{returnValue.setIntValue(OPC_ERROR_INVALID_RESOURCE_ID);}	
					
				}else{returnValue.setIntValue(OPC_ERROR_INVALID_RESOURCE_ID);}	
				
				opcContainerClose(c, OPC_CLOSE_NOW);
				
			}else{returnValue.setIntValue(OPC_ERROR_INVALID_PATH);}	
			
		}else{returnValue.setIntValue(OPC_ERROR_INVALID_RELATION_ID);}
		   
	}else{returnValue.setIntValue(OPC_ERROR_INVALID_RELATION_TYPE);}	   
	   
	returnValue.setReturn(pResult);
}