? tarpatch.diff
? test.php
? src/test.tar
? src/examples/php/acout.in
? src/examples/php/doc.lst
? src/examples/php/install.lst
? src/mapiclient/mclient.html
Index: src/mapiclient/MapiClient.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/MapiClient.mx,v
retrieving revision 1.151.2.1
diff -r1.151.2.1 MapiClient.mx
1779a1780,1849
> /* note: octalStr must be nul-terminated */
> size_t 
> fetchOctal(char *octalStr) {
> 	size_t result = 0;
> 	int i = 0;
> 	while (octalStr[i] != '\0') {
> 		result = (result*8) + ((int)octalStr[i] - '0');
> 		i++;
> 	}
> 	return result;
> }
> 
> void
> readTAR(Mapi mid, char *colname, FILE *fp) {
> 	size_t length, result;
> 	char buf[BUFSIZ];
> 	MapiMsg rc;
> 
> 	/* see http://en.wikipedia.org/wiki/Tar_(file_format) */
> 	char *fileNameStr = buf + 0; 
> 	char *fileSizeStr = buf + 124; 
> 	char *docName;
> 	int fileType = 156;
> 
> 	/* repeat */
> 	while (1) {
> 		/* - read 512-byte header */
> 		result = fread(buf, 1, 512, fp);
> 
> 		/* - if EOF break */
> 		if (result == 0)
> 			break;
> 		if (result != 512) {
> 			fprintf(stderr, "TAR file format exception: unexpected EOF, expected 512-byte blocks\n");
> 			exit(1);
> 		}
> 
> 		if (buf[fileType] != '0')
> 			continue;
> 
> 		/* - fetch name from header */
> 		docName = fileNameStr;
> 		buf[99] = '\0'; /* make sure the filename is nul-terminated */
> 		
> 		/* - fetch size from header */
> 		fileSizeStr[11] = '\0'; /* make sure the size-string is nul-terminated */
> 		length = fetchOctal(fileSizeStr);
> 		fprintf(stderr, "Name: %s Length: %d\n", docName, (int)length);
> 		
> 		/* FIXME: if empty file, or no .xml, skip */
> 		/* FIXME: construct docName */
> 
> 		/* - read document */
>                 rc = mapi_stream_into(mid, docName, colname, stdin, length);
>                 if (rc != MOK) {
>                         mapi_explain(mid, stderr);
>                         exit(1);
>                 }
> 		
> 		/* - align on 512-byte boundary */
> 		length = 512 - (length % 512);
> 		result = fread(buf, 1, length, fp);
> 		if (result != length) {
> 			fprintf(stderr, "TAR file format exception: unexpected EOF, expected 512-byte blocks\n");
>                         exit(1);
> 		}
> 	}
> }
> 
> 
2120a2191,2197
> 	if (colname != NULL && input == NULL && mode == XQUERY) {
> 		/* try to read a tar file from stdin... */
> 		fprintf(stderr, "Copying TAR file into collection: '%s'\n", colname);
> 		readTAR(mid, colname, stdin);
> 		interactive = 0;
> 	}
> 
2125c2202
< 		rc = mapi_stream_into(mid, input, colname, stdin);
---
> 		rc = mapi_stream_into(mid, input, colname, stdin, SSIZE_MAX);
Index: src/mapilib/Mapi.mx
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapilib/Mapi.mx,v
retrieving revision 1.79.2.2
diff -r1.79.2.2 Mapi.mx
742c742
< @item MapiMsg  mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp)
---
> @item MapiMsg  mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp, size_t size)
1187c1187
< mapi_export MapiMsg mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp);
---
> mapi_export MapiMsg mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp, size_t size);
3347a3348,3352
> /*
>  * Size must be the size of the file to read from the stream
>  * or SSIZE_MAX if unknown. In case of SSIZE_MAX, the stream will be read until
>  * EOF.
>  */
3349c3354
< mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp)
---
> mapi_stream_into(Mapi mid, char *docname, char *colname, FILE *fp, size_t size)
3357a3363
> 
3368c3374
< 	while ((length = fread(buf, 1, sizeof(buf), fp)) > 0) {
---
> 	while ((length = fread(buf, 1, (sizeof(buf) < size) ? sizeof(buf) : size, fp)) > 0) {
3370a3377
> 		size -= length;
