libopc
Typedefs | Enumerations | Functions
container.h File Reference
#include <opc/config.h>
#include <opc/file.h>

Go to the source code of this file.

Typedefs

typedef struct OPC_CONTAINER_STRUCT opcContainer
 

Enumerations

enum  opcContainerOpenMode {
  OPC_OPEN_READ_ONLY, OPC_OPEN_WRITE_ONLY, OPC_OPEN_READ_WRITE, OPC_OPEN_TEMPLATE,
  OPC_OPEN_TRANSITION
}
 
enum  opcContainerCloseMode { OPC_CLOSE_NOW, OPC_CLOSE_TRIM, OPC_CLOSE_DEFRAG }
 

Functions

opcContaineropcContainerOpen (const xmlChar *fileName, opcContainerOpenMode mode, void *userContext, const xmlChar *destName)
 
opcContaineropcContainerOpenMem (const opc_uint8_t *data, opc_uint32_t data_len, opcContainerOpenMode mode, void *userContext)
 
opcContaineropcContainerOpenIO (opcFileReadCallback *ioread, opcFileWriteCallback *iowrite, opcFileCloseCallback *ioclose, opcFileSeekCallback *ioseek, opcFileTrimCallback *iotrim, opcFileFlushCallback *ioflush, void *iocontext, pofs_t file_size, opcContainerOpenMode mode, void *userContext)
 
opc_error_t opcContainerClose (opcContainer *c, opcContainerCloseMode mode)
 
void * opcContainerGetUserContext (opcContainer *c)
 
opc_error_t opcContainerDump (opcContainer *c, FILE *out)
 
int opcContainerFlatExport (opcContainer *c, const xmlChar *fileName)
 
int opcContainerFlatImport (opcContainer *c, const xmlChar *fileName)
 
const xmlChar * opcContentTypeFirst (opcContainer *container)
 
const xmlChar * opcContentTypeNext (opcContainer *container, const xmlChar *type)
 
const xmlChar * opcExtensionFirst (opcContainer *container)
 
const xmlChar * opcExtensionNext (opcContainer *container, const xmlChar *ext)
 
const xmlChar * opcExtensionGetType (opcContainer *container, const xmlChar *ext)
 
const xmlChar * opcExtensionRegister (opcContainer *container, const xmlChar *ext, const xmlChar *type)
 
const xmlChar * opcRelationTypeFirst (opcContainer *container)
 
const xmlChar * opcRelationTypeNext (opcContainer *container, const xmlChar *type)
 
const xmlChar * opcExternalTargetFirst (opcContainer *container)
 
const xmlChar * opcExternalTargetNext (opcContainer *container, const xmlChar *target)
 

Detailed Description

The container.h module has the fundamental methods for dealing with ZIP-based OPC container.

OPC container can be opened in READ-ONLY mode, WRITE-ONLY mode, READ/WRITE mode, TEMPLATE mode and TRANSITION mode. The most notable mode is the READ/WRITE mode, which gives you concurrent stream-based READ and WRITE access to a single ZIP-based OPC container. This is achieved without the use of temporary files by taking advantage of the OPC specific “interleave” mode.

See also
http://standards.iso.org/ittf/PubliclyAvailableStandards/c051459_ISOIEC_29500-2_2008(E).zip

The TEMPLATE mode allows very fast customized "cloning" of ZIP-based OPC container by using "RAW access" to the ZIP streams. The TRANSITION mode is a special version of the TEMPLATE mode, which allows transition-based READ/WRITE access to the ZIP-based OPC container using a temporary file.

Typedef Documentation

Handle to an OPC container created by opcContainerOpen.

See also
opcContainerOpen.

Enumeration Type Documentation

Modes for opcContainerClose.

See also
opcContainerClose.
Enumerator
OPC_CLOSE_NOW 

Close the OPC container without any further postprocessing.

OPC_CLOSE_TRIM 

Close the OPC container and trim the file by removing unused fragments like e.g. deleted parts.

OPC_CLOSE_DEFRAG 

Close the OPC container like in OPC_CLOSE_TRIM mode, but additionally remove any "interleaved" parts by reordering them.

Warning
Currently not implemented. Same semantic as OPC_CLOSE_TRIM.

Modes for opcContainerOpen();

See also
opcContainerOpen
Enumerator
OPC_OPEN_READ_ONLY 

Opens the OPC container denoted by fileName in READ-ONLY mode. The destName parameter must be NULL.

OPC_OPEN_WRITE_ONLY 

Opens the OPC container denoted by fileName in WRITE-ONLY mode. The destName parameter must be NULL.

OPC_OPEN_READ_WRITE 

Opens the OPC container denoted by fileName in READ/WRITE mode. The destName parameter must be NULL.

OPC_OPEN_TEMPLATE 

This mode will open the container denoted by fileName in READ-ONLY mode and the container denoted by destName in write-only mode. Any modifications will be written to the container denoted by destName and the unmodified streams from fileName will be written to destName on closing.

Warning
Currently not implemented.
OPC_OPEN_TRANSITION 

Like the OPC_OPEN_TEMPLATE mode, but the destName will be renamed to the fileName on closing. If destName is NULL, then the name of the temporary file will be generated automatically.

Warning
Currently not implemented.

Function Documentation

opc_error_t opcContainerClose ( opcContainer c,
opcContainerCloseMode  mode 
)

Close an OPC container.

Parameters
[in]c.opcContainer openered by opcContainerOpen.
[in]mode.For more information see opcContainerCloseMode.
Returns
Non-zero if successful.
See also
opcContainerOpen
opcContainerCloseMode
Examples:
mce_write.c, opc_dump.c, opc_extract.c, opc_generate.c, opc_image.c, opc_mem.c, opc_part.c, opc_relation.c, opc_text.c, opc_trim.c, opc_type.c, opc_xml.c, and opc_xml2.c.
opc_error_t opcContainerDump ( opcContainer c,
FILE *  out 
)

List all types, relations and parts of the container c to out.

Sample:
/*
Dump all information about an OPC container.
Ussage:
opc_dump FILENAME
Sample:
opc_dump OOXMLI1.docx
*/
#include <opc/opc.h>
#include <stdio.h>
#include <time.h>
#ifdef WIN32
#include <crtdbg.h>
#endif
int main( int argc, const char* argv[] )
{
#ifdef WIN32
_CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
time_t start_time=time(NULL);
opc_error_t err=OPC_ERROR_NONE;
if (OPC_ERROR_NONE==opcInitLibrary()) {
if (2==argc) {
opcContainer *c=NULL;
if (NULL!=(c=opcContainerOpen(_X(argv[1]), OPC_OPEN_READ_ONLY, NULL, NULL))) {
opcContainerDump(c, stdout);
} else {
printf("ERROR: \"%s\" could not be opened.\n", argv[1]);
err=OPC_ERROR_STREAM;
}
}
} else if (2==argc) {
printf("ERROR: initialization of libopc failed.\n");
err=OPC_ERROR_STREAM;
} else {
printf("opc_dump FILENAME.\n\n");
printf("Sample: opc_dump test.docx\n");
}
time_t end_time=time(NULL);
fprintf(stderr, "time %.2lfsec\n", difftime(end_time, start_time));
#ifdef WIN32
OPC_ASSERT(!_CrtDumpMemoryLeaks());
#endif
return (OPC_ERROR_NONE==err?0:3);
}
Examples:
opc_dump.c, opc_mem.c, opc_trim.c, and opc_xml.c.
int opcContainerFlatExport ( opcContainer c,
const xmlChar *  fileName 
)

Exports the OPC container to "Flat OPC" (http://blogs.msdn.com/b/ericwhite/archive/2008/09/29/the-flat-opc-format.aspx). The flat versions of an OPC file are very important when dealing with e.g XSL(T)-based or Javascript-based transformations.

See also
opcContainerFlatImport.
Todo:
Implementation needed.
int opcContainerFlatImport ( opcContainer c,
const xmlChar *  fileName 
)

Imports the flat version of an OPC container.

See also
opcContainerFlatExport.
Todo:
Implementation needed.
void* opcContainerGetUserContext ( opcContainer c)

Returns the unmodified user context passed to opcContainerOpen.

See also
opcContainerOpen
opcContainer* opcContainerOpen ( const xmlChar *  fileName,
opcContainerOpenMode  mode,
void *  userContext,
const xmlChar *  destName 
)

Opens a ZIP-based OPC container.

Parameters
[in]fileName.For more details see opcContainerOpenMode.
[in]mode.For more details see opcContainerOpenMode.
[in]userContext.Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
[in]destName.For more details see opcContainerOpenMode.
Returns
NULL if failed.
See also
opcContainerOpenMode
opcContainerDump
Examples:
mce_write.c, opc_dump.c, opc_extract.c, opc_generate.c, opc_image.c, opc_part.c, opc_relation.c, opc_text.c, opc_trim.c, opc_type.c, opc_xml.c, and opc_xml2.c.
opcContainer* opcContainerOpenIO ( opcFileReadCallback ioread,
opcFileWriteCallback iowrite,
opcFileCloseCallback ioclose,
opcFileSeekCallback ioseek,
opcFileTrimCallback iotrim,
opcFileFlushCallback ioflush,
void *  iocontext,
pofs_t  file_size,
opcContainerOpenMode  mode,
void *  userContext 
)

Opens a ZIP-based OPC container from memory.

Parameters
[in]ioread.
[in]iowrite.
[in]ioclose.
[in]ioseek.
[in]iotrim.
[in]ioflush.
[in]iocontext.
[in]file_size.
[in]userContext.Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
[in]mode.For more details see opcContainerOpenMode.
Returns
NULL if failed.
opcContainer* opcContainerOpenMem ( const opc_uint8_t data,
opc_uint32_t  data_len,
opcContainerOpenMode  mode,
void *  userContext 
)

Opens a ZIP-based OPC container from memory.

Parameters
[in]data.
[in]data_len.
[in]userContext.Will not be modified by libopc. Can be used to e.g. store the "this" pointer for C++ bindings.
[in]mode.For more details see opcContainerOpenMode.
Returns
NULL if failed.
Examples:
opc_mem.c.
const xmlChar* opcContentTypeFirst ( opcContainer container)

Iterate all types.

1 for(xmlChar *type=opcContentTypeFirst(c);
2  NULL!=type;
3  type=opcContentTypeNext(c, type)) {
4  printf("%s\n", type);
5 }
const xmlChar* opcContentTypeNext ( opcContainer container,
const xmlChar *  type 
)
const xmlChar* opcExtensionFirst ( opcContainer container)

Iterate extensions.

1 for(const xmlChar *ext=opcExtensionFirst(c);
2  NULL!=ext;
3  ext=opcExtensionNext(ext)) {
4  printf("%s\n", ext);
5 }
Examples:
opc_generate.c.
const xmlChar* opcExtensionGetType ( opcContainer container,
const xmlChar *  ext 
)

Get registered type for extension.

See also
opcExtensionRegister()
Examples:
opc_generate.c.
const xmlChar* opcExtensionNext ( opcContainer container,
const xmlChar *  ext 
)
See also
opcExtensionFirst()
Examples:
opc_generate.c.
const xmlChar* opcExtensionRegister ( opcContainer container,
const xmlChar *  ext,
const xmlChar *  type 
)

Register a mime-type and and extension.

See also
opcExtensionGetType()
Examples:
mce_write.c.
const xmlChar* opcExternalTargetFirst ( opcContainer container)

Iterator through all relation types of the container:

1 for(xmlChar *target=opcExternalTargetFirst(c);
2  NULL!=target;
3  type=opcExternalTargetNext(c, target)) {
4  printf("%s\n", target);
5 }
const xmlChar* opcExternalTargetNext ( opcContainer container,
const xmlChar *  target 
)
const xmlChar* opcRelationTypeFirst ( opcContainer container)

Iterator through all relation types of the container:

1 for(xmlChar *type=opcRelationTypeFirst(c);
2  NULL!=type;
3  type=opcRelationTypeNext(c, type)) {
4  printf("%s\n", type);
5 }
const xmlChar* opcRelationTypeNext ( opcContainer container,
const xmlChar *  type 
)