]> git.sesse.net Git - vlc/blob - modules/access/zip/zipstream.c
Zip: don't use hacks but rewrite the path.
[vlc] / modules / access / zip / zipstream.c
1 /*****************************************************************************
2  * zipstream.c: stream_filter that creates a XSPF playlist from a Zip archive
3  *****************************************************************************
4  * Copyright (C) 2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Philippe André <jpeg@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /** **************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "zip.h"
33 #include <stddef.h>
34
35 /* FIXME remove */
36 #include <vlc_input.h>
37
38 #define FILENAME_TEXT N_( "Media in Zip" )
39 #define FILENAME_LONGTEXT N_( "Path to the media in the Zip archive" )
40
41 /** **************************************************************************
42  * Module descriptor
43  *****************************************************************************/
44 vlc_module_begin()
45     set_shortname( "Zip" )
46     set_category( CAT_INPUT )
47     set_subcategory( SUBCAT_INPUT_STREAM_FILTER )
48     set_description( _( "Zip files filter" ) )
49     set_capability( "stream_filter", 1 )
50     set_callbacks( StreamOpen, StreamClose )
51     add_submodule()
52         set_subcategory( SUBCAT_INPUT_ACCESS )
53         set_description( _( "Zip access" ) )
54         set_capability( "access", 0 )
55         add_shortcut( "unzip" )
56         add_shortcut( "zip" )
57         set_callbacks( AccessOpen, AccessClose )
58 vlc_module_end()
59
60 /** *************************************************************************
61  * Local prototypes
62  ****************************************************************************/
63 static int Read   ( stream_t *, void *p_read, unsigned int i_read );
64 static int Peek   ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
65 static int Control( stream_t *, int i_query, va_list );
66
67 typedef struct node node;
68 typedef struct item item;
69
70 static int CreatePlaylist( stream_t *s, char **pp_buffer );
71 static int GetFilesInZip( stream_t*, unzFile, vlc_array_t*, vlc_array_t* );
72 static node* findOrCreateParentNode( node *root, const char *fullpath );
73 static int WriteXSPF( char **pp_buffer, vlc_array_t *p_filenames,
74                       const char *psz_zippath );
75 static int nodeToXSPF( char **pp_buffer, node *n, bool b_root );
76 static node* findOrCreateParentNode( node *root, const char *fullpath );
77
78 /** **************************************************************************
79  * Struct definitions
80  *****************************************************************************/
81 struct stream_sys_t
82 {
83     /* zlib / unzip members */
84     unzFile zipFile;
85     zlib_filefunc_def *fileFunctions;
86     char *psz_path;
87
88     /* xspf data */
89     char *psz_xspf;
90     size_t i_len;
91     size_t i_pos;
92 };
93
94 struct item {
95     int id;
96     item *next;
97 };
98
99 struct node {
100     char *name;
101     item *media;
102     node *child;
103     node *next;
104 };
105
106 /** **************************************************************************
107  * Some helpers
108  *****************************************************************************/
109
110 inline static node* new_node( char *name )
111 {
112     node *n = (node*) calloc( 1, sizeof(node) );
113     n->name = convert_xml_special_chars( name );
114     return n;
115 }
116
117 inline static item* new_item( int id )
118 {
119     item *media = (item*) calloc( 1, sizeof(item) );
120     media->id = id;
121     return media;
122 }
123
124 inline static void free_all_node( node *root )
125 {
126     while( root )
127     {
128         free_all_node( root->child );
129         free( root->name );
130         node *tmp = root->next;
131         free( root );
132         root = tmp;
133     }
134 }
135
136 /* Allocate strcat and format */
137 static int astrcatf( char **ppsz_dest, const char *psz_fmt_src, ... )
138 {
139     va_list args;
140     va_start( args, psz_fmt_src );
141
142     char *psz_tmp;
143     int i_ret = vasprintf( &psz_tmp, psz_fmt_src, args );
144     if( i_ret == -1 ) return -1;
145
146     va_end( args );
147
148     int i_len = strlen( *ppsz_dest ) + strlen( psz_tmp ) + 1;
149     char *psz_out = realloc( *ppsz_dest, i_len );
150     if( !psz_out ) return -1;
151
152     strcat( psz_out, psz_tmp );
153     free( psz_tmp );
154
155     *ppsz_dest = psz_out;
156     return i_len;
157 }
158
159 /** **************************************************************************
160  * Zip file identifier
161  *****************************************************************************/
162 static const uint8_t p_zip_marker[] = { 0x50, 0x4b, 0x03, 0x04 }; // "PK^C^D"
163 static const int i_zip_marker = 4;
164
165
166 /** **************************************************************************
167  * Open
168  *****************************************************************************/
169 int StreamOpen( vlc_object_t *p_this )
170 {
171     stream_t *s = (stream_t*) p_this;
172     stream_sys_t *p_sys;
173
174     /* Verify file format */
175     const uint8_t *p_peek;
176     if( stream_Peek( s->p_source, &p_peek, i_zip_marker ) < i_zip_marker )
177         return VLC_EGENERIC;
178     if( memcmp( p_peek, p_zip_marker, i_zip_marker ) )
179         return VLC_EGENERIC;
180
181     s->p_sys = p_sys = calloc( sizeof( *p_sys ), 1 );
182     if( !p_sys )
183         return VLC_ENOMEM;
184
185     s->pf_read = Read;
186     s->pf_peek = Peek;
187     s->pf_control = Control;
188
189     p_sys->fileFunctions = ( zlib_filefunc_def * )
190             calloc( 1, sizeof( zlib_filefunc_def ) );
191     if( !p_sys->fileFunctions )
192     {
193         free( p_sys );
194         return VLC_ENOMEM;
195     }
196     p_sys->fileFunctions->zopen_file   = ZipIO_Open;
197     p_sys->fileFunctions->zread_file   = ZipIO_Read;
198     p_sys->fileFunctions->zwrite_file  = ZipIO_Write;
199     p_sys->fileFunctions->ztell_file   = ZipIO_Tell;
200     p_sys->fileFunctions->zseek_file   = ZipIO_Seek;
201     p_sys->fileFunctions->zclose_file  = ZipIO_Close;
202     p_sys->fileFunctions->zerror_file  = ZipIO_Error;
203     p_sys->fileFunctions->opaque       = ( void * ) s;
204     p_sys->zipFile = unzOpen2( NULL /* path */, p_sys->fileFunctions );
205     if( !p_sys->zipFile )
206     {
207         msg_Warn( s, "unable to open file" );
208         free( p_sys );
209         free( p_sys->fileFunctions );
210         return VLC_EGENERIC;
211     }
212
213     /* Find the stream uri */
214     char *psz_tmp;
215     if( asprintf( &psz_tmp, "%s.xspf", s->psz_path ) == -1 )
216     {
217         free( p_sys );
218         free( p_sys->fileFunctions );
219         return VLC_ENOMEM;
220     }
221     p_sys->psz_path = s->psz_path;
222     s->psz_path = psz_tmp;
223
224     return VLC_SUCCESS;
225 }
226
227 /** *************************************************************************
228  * Close
229  ****************************************************************************/
230 void StreamClose( vlc_object_t *p_this )
231 {
232     stream_t *s = (stream_t*)p_this;
233     stream_sys_t *p_sys = s->p_sys;
234
235     free( p_sys->fileFunctions );
236     free( p_sys->psz_xspf );
237     free( p_sys->psz_path );
238     free( p_sys );
239 }
240
241 /** *************************************************************************
242  * Stream filters functions
243  ****************************************************************************/
244
245 /** *************************************************************************
246  * Read
247  ****************************************************************************/
248 static int Read( stream_t *s, void *p_read, unsigned int i_read )
249 {
250     stream_sys_t *p_sys = s->p_sys;
251
252     if( !p_read ) return 0;
253
254     /* Fill the buffer */
255     if( p_sys->psz_xspf == NULL )
256     {
257         int i_ret = CreatePlaylist( s, &p_sys->psz_xspf );
258         if( i_ret < 0 )
259             return -1;
260         p_sys->i_len = strlen( p_sys->psz_xspf );
261         p_sys->i_pos = 0;
262     }
263
264     /* Read the buffer */
265     int i_len = __MIN( i_read, p_sys->i_len - p_sys->i_pos );
266     memcpy( p_read, p_sys->psz_xspf + p_sys->i_pos, i_len );
267     p_sys->i_pos += i_len;
268
269     return i_len;
270 }
271
272 /** *************************************************************************
273  * Peek
274  ****************************************************************************/
275 static int Peek( stream_t *s, const uint8_t **pp_peek, unsigned int i_peek )
276 {
277     stream_sys_t *p_sys = s->p_sys;
278
279     /* Fill the buffer */
280     if( p_sys->psz_xspf == NULL )
281     {
282         int i_ret = CreatePlaylist( s, &p_sys->psz_xspf );
283         if( i_ret < 0 )
284             return -1;
285         p_sys->i_len = strlen( p_sys->psz_xspf );
286         p_sys->i_pos = 0;
287     }
288
289
290     /* Point to the buffer */
291     int i_len = __MIN( i_peek, p_sys->i_len - p_sys->i_pos );
292     *pp_peek = (uint8_t*) p_sys->psz_xspf + p_sys->i_pos;
293
294     return i_len;
295 }
296
297 /** *************************************************************************
298  * Control
299  ****************************************************************************/
300 static int Control( stream_t *s, int i_query, va_list args )
301 {
302     stream_sys_t *p_sys = s->p_sys;
303
304     switch( i_query )
305     {
306         case STREAM_SET_POSITION:
307         {
308             int64_t i_position = (int64_t)va_arg( args, int64_t );
309             if( i_position >= p_sys->i_len )
310                 return VLC_EGENERIC;
311             else
312             {
313                 p_sys->i_len = (size_t) i_position;
314                 return VLC_SUCCESS;
315             }
316         }
317
318         case STREAM_GET_POSITION:
319         {
320             int64_t *pi_position = (int64_t*)va_arg( args, int64_t* );
321             *pi_position = p_sys->i_pos;
322             return VLC_SUCCESS;
323         }
324
325         case STREAM_GET_SIZE:
326         {
327             int64_t *pi_size = (int64_t*)va_arg( args, int64_t* );
328             *pi_size = (int64_t) p_sys->i_len;
329             return VLC_SUCCESS;
330         }
331
332         case STREAM_GET_CONTENT_TYPE:
333             return VLC_EGENERIC;
334
335         case STREAM_UPDATE_SIZE:
336         case STREAM_CONTROL_ACCESS:
337         case STREAM_CAN_SEEK:
338         case STREAM_CAN_FASTSEEK:
339         case STREAM_SET_RECORD_STATE:
340             return stream_vaControl( s->p_source, i_query, args );
341
342         default:
343             return VLC_EGENERIC;
344     }
345 }
346
347 static int CreatePlaylist( stream_t *s, char **pp_buffer )
348 {
349     /* Get some infos about zip archive */
350     int i_ret = 0;
351     unzFile file = s->p_sys->zipFile;
352     vlc_array_t *p_filenames = vlc_array_new(); /* Will contain char* */
353
354     /* List all file names in Zip archive */
355     i_ret = GetFilesInZip( s, file, p_filenames, NULL );
356     if( i_ret < 0 )
357     {
358         unzClose( file );
359         i_ret = -1;
360         goto exit;
361     }
362
363     // msg_Dbg( s, "%d files in Zip", vlc_array_count( p_filenames ) );
364
365     /* Close archive */
366     unzClose( file );
367     s->p_sys->zipFile = NULL;
368
369     /* Construct the xspf playlist */
370     i_ret = WriteXSPF( pp_buffer, p_filenames, s->p_sys->psz_path );
371     if( i_ret > 0 )
372         i_ret = 1;
373     else if( i_ret < 0 )
374         i_ret = -1;
375
376 exit:
377     for( int i = 0; i < vlc_array_count( p_filenames ); i++ )
378     {
379         free( vlc_array_item_at_index( p_filenames, i ) );
380     }
381     vlc_array_destroy( p_filenames );
382     return i_ret;
383 }
384
385
386 /** **************************************************************************
387  * Zip utility functions
388  *****************************************************************************/
389
390 /** **************************************************************************
391  * \brief List files in zip and append their names to p_array
392  * \param p_this
393  * \param file Opened zip file
394  * \param p_array vlc_array_t which will receive all filenames
395  *
396  * In case of error, returns VLC_EGENERIC.
397  * In case of success, returns number of files found, and goes back to first file.
398  *****************************************************************************/
399 static int GetFilesInZip( stream_t *p_this, unzFile file,
400                           vlc_array_t *p_filenames, vlc_array_t *p_fileinfos )
401 {
402     if( !p_filenames || !p_this )
403         return VLC_EGENERIC;
404
405     int i_ret = 0;
406
407     /* Get global info */
408     unz_global_info info;
409
410     if( unzGetGlobalInfo( file, &info ) != UNZ_OK )
411     {
412         msg_Warn( p_this, "this is not a valid zip archive" );
413         return VLC_EGENERIC;
414     }
415
416     /* Go to first file in archive */
417     unzGoToFirstFile( file );
418
419     /* Get info about each file */
420     for( unsigned long i = 0; i < info.number_entry; i++ )
421     {
422         char *psz_fileName = calloc( ZIP_FILENAME_LEN, 1 );
423         unz_file_info *p_fileInfo = calloc( 1, sizeof( unz_file_info ) );
424
425         if( !p_fileInfo || !psz_fileName )
426         {
427             msg_Warn( p_this, "not enough memory" );
428             return VLC_ENOMEM;
429         }
430
431         if( unzGetCurrentFileInfo( file, p_fileInfo, psz_fileName,
432                                    ZIP_FILENAME_LEN, NULL, 0, NULL, 0 )
433             != UNZ_OK )
434         {
435             msg_Warn( p_this, "can't get info about file in zip" );
436             return VLC_EGENERIC;
437         }
438
439         if( p_filenames )
440             vlc_array_append( p_filenames, strdup( psz_fileName ) );
441         free( psz_fileName );
442
443         if( p_fileinfos )
444             vlc_array_append( p_fileinfos, p_fileInfo );
445         else
446             free( p_fileInfo );
447
448         if( i < ( info.number_entry - 1 ) )
449         {
450             /* Go the next file in the archive */
451             if( unzGoToNextFile( file ) != UNZ_OK )
452             {
453                 msg_Warn( p_this, "can't go to next file in zip" );
454                 return VLC_EGENERIC;
455             }
456         }
457
458         i_ret++;
459     }
460
461     /* i_ret should be equal to info.number_entry */
462     unzGoToFirstFile( file );
463     return i_ret;
464 }
465
466
467 /** **************************************************************************
468  * XSPF generation functions
469  *****************************************************************************/
470
471 /** **************************************************************************
472  * \brief Write the XSPF playlist given the list of files
473  *****************************************************************************/
474 static int WriteXSPF( char **pp_buffer, vlc_array_t *p_filenames,
475                       const char *psz_zippath )
476 {
477     char *psz_zip = strrchr( psz_zippath, DIR_SEP_CHAR );
478     psz_zip = convert_xml_special_chars( psz_zip ? (psz_zip+1) : psz_zippath );
479
480     if( asprintf( pp_buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
481         "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\" "
482                 "xmlns:vlc=\"http://www.videolan.org/vlc/playlist/ns/0/\">\n"
483                 " <title>%s</title>\n"
484                 " <trackList>\n", psz_zip ) == -1)
485         return -1;
486
487     /* Root node */
488     node *playlist = new_node( psz_zip );
489
490     /* Web-Encode the URI and append '!' */
491     char *psz_pathtozip = vlc_UrlEncode( psz_zippath );
492     if( astrcatf( &psz_pathtozip, ZIP_SEP ) < 0 ) return -1;
493
494     int i_track = 0;
495     for( int i = 0; i < vlc_array_count( p_filenames ); ++i )
496     {
497         char *psz_name = (char*) vlc_array_item_at_index( p_filenames, i );
498         int i_len = strlen( psz_name );
499
500         if( !i_len ) continue;
501
502         /* Is it a folder ? */
503         if( psz_name[i_len-1] == '/' )
504         {
505             /* Do nothing */
506         }
507         else /* File */
508         {
509             /* Extract file name */
510             char *psz_file = strrchr( psz_name, '/' );
511             psz_file = convert_xml_special_chars( psz_file ?
512                     (psz_file+1) : psz_name );
513
514             /* Build full MRL */
515             char *psz_path = strdup( psz_pathtozip );
516             if( astrcatf( &psz_path, psz_name ) < 0 ) return -1;
517
518             /* Double url-encode */
519             char *psz_tmp = psz_path;
520             psz_path = vlc_UrlEncode( psz_tmp );
521             free( psz_tmp );
522
523             /* Track information */
524             if( astrcatf( pp_buffer,
525                         "  <track>\n"
526                         "   <location>zip://%s</location>\n"
527                         "   <title>%s</title>\n"
528                         "   <extension application=\"http://www.videolan.org/vlc/playlist/0\">\n"
529                         "    <vlc:id>%d</vlc:id>\n"
530                         "   </extension>\n"
531                         "  </track>\n",
532                         psz_path, psz_file, i_track ) < 0 ) return -1;
533
534             free( psz_file );
535             free( psz_path );
536
537             /* Find the parent node */
538             node *parent = findOrCreateParentNode( playlist, psz_name );
539             assert( parent );
540
541             /* Add the item to this node */
542             item *tmp = parent->media;
543             if( !tmp )
544             {
545                 parent->media = new_item( i_track );
546             }
547             else
548             {
549                 while( tmp->next )
550                 {
551                     tmp = tmp->next;
552                 }
553                 tmp->next = new_item( i_track );
554             }
555
556             ++i_track;
557         }
558     }
559
560     free( psz_pathtozip );
561
562     /* Close tracklist, open the extension */
563     if( astrcatf( pp_buffer,
564         " </trackList>\n"
565         " <extension application=\"http://www.videolan.org/vlc/playlist/0\">\n"
566                 ) < 0 ) return -1;
567
568     /* Write the tree */
569     if( nodeToXSPF( pp_buffer, playlist, true ) < 0 ) return -1;
570
571     /* Close extension and playlist */
572     if( astrcatf( pp_buffer, " </extension>\n</playlist>\n" ) < 0 ) return -1;
573
574     /* printf( "%s", *pp_buffer ); */
575
576     free_all_node( playlist );
577
578     return VLC_SUCCESS;
579 }
580
581 /** **************************************************************************
582  * \brief Recursively convert a node to its XSPF representation
583  *****************************************************************************/
584 static int nodeToXSPF( char **pp_buffer, node *n, bool b_root )
585 {
586     if( !b_root )
587     {
588         if( astrcatf( pp_buffer, "  <vlc:node title=\"%s\">\n", n->name ) < 0 )
589             return -1;
590     }
591     if( n->child )
592         nodeToXSPF( pp_buffer, n->child, false );
593     item *i = n->media;
594     while( i )
595     {
596         if( astrcatf( pp_buffer, "   <vlc:item tid=\"%d\" />\n", i->id ) < 0 )
597             return -1;
598         i = i->next;
599     }
600     if( !b_root )
601     {
602         if( astrcatf( pp_buffer, "  </vlc:node>\n" ) < 0 )
603             return -1;
604     }
605     return VLC_SUCCESS;
606 }
607
608 /** **************************************************************************
609  * \brief Either create or find the parent node of the item
610  *****************************************************************************/
611 static node* findOrCreateParentNode( node *root, const char *fullpath )
612 {
613     char *folder;
614     char *path = strdup( fullpath );
615     folder = path;
616
617     assert( root );
618
619     char *sep = strchr( folder, '/' );
620     if( !sep )
621     {
622         free( path );
623         return root;
624     }
625
626     *sep = '\0';
627     ++sep;
628
629     node *current = root->child;
630
631     while( current )
632     {
633         if( !strcmp( current->name, folder ) )
634         {
635             /* We found the folder, go recursively deeper */
636             return findOrCreateParentNode( current, sep );
637         }
638         current = current->next;
639     }
640
641     /* If we are here, then it means that we did not find the parent */
642     node *ret = new_node( folder );
643     if( !root->child )
644         root->child = ret;
645     else
646     {
647         current = root->child;
648         while( current->next )
649         {
650             current = current->next;
651         }
652         current->next = ret;
653     }
654
655     /* And now, create the subfolders */
656     ret = findOrCreateParentNode( ret, sep );
657
658     free( path );
659     return ret;
660 }
661
662
663 /** **************************************************************************
664  * ZipIO function definitions : how to use vlc_stream to read the zip
665  *****************************************************************************/
666
667 /** **************************************************************************
668  * \brief interface for unzip module to open a file using a vlc_stream
669  * \param opaque
670  * \param filename
671  * \param mode how to open the file (read/write ?). We support only read
672  * \return opaque
673  *****************************************************************************/
674 static void ZCALLBACK *ZipIO_Open( void *opaque, const char *file, int mode )
675 {
676     (void) file;
677     stream_t *s = (stream_t*) opaque;
678     if( mode & ( ZLIB_FILEFUNC_MODE_CREATE | ZLIB_FILEFUNC_MODE_WRITE ) )
679     {
680         msg_Dbg( s, "ZipIO_Open: we cannot write into zip files" );
681         return NULL;
682     }
683     return s;
684 }
685
686 /** **************************************************************************
687  * \brief read something from stream into buffer
688  * \param opaque should be the stream
689  * \param stream stream created by ZipIO_Open
690  * \param buf buffer to read the file
691  * \param size length of this buffer
692  * \return return the number of bytes read (<= size)
693  *****************************************************************************/
694 static unsigned long ZCALLBACK ZipIO_Read( void *opaque, void *stream,
695                                            void *buf, unsigned long size )
696 {
697     (void) stream;
698     stream_t *s = (stream_t*) opaque;
699     return (unsigned long) stream_Read( s->p_source, buf, (int) size );
700 }
701
702 /** **************************************************************************
703  * \brief tell size of stream
704  * \param opaque should be the stream
705  * \param stream stream created by ZipIO_Open
706  * \return size of the file / stream
707  * ATTENTION: this is not stream_Tell, but stream_Size !
708  *****************************************************************************/
709 static long ZCALLBACK ZipIO_Tell( void *opaque, void *stream )
710 {
711     (void) stream;
712     stream_t *s = (stream_t*) opaque;
713     return (long) stream_Size( s->p_source ); /* /!\ not stream_Tell /!\ */
714 }
715
716 /** **************************************************************************
717  * \brief seek in the stream
718  * \param opaque should be the stream
719  * \param stream stream created by ZipIO_Open
720  * \param offset positive offset to seek
721  * \param origin current position in stream
722  * \return ¿ VLC_SUCCESS or an error code ?
723  *****************************************************************************/
724 static long ZCALLBACK ZipIO_Seek ( void *opaque, void *stream,
725                                    unsigned long offset, int origin )
726 {
727     (void) stream;
728     stream_t *s = (stream_t*) opaque;
729     long l_ret;
730
731     uint64_t pos = offset + origin;
732     l_ret = (long) stream_Seek( s->p_source, pos );
733     return l_ret;
734 }
735
736 /** **************************************************************************
737  * \brief close the stream
738  * \param opaque should be the stream
739  * \param stream stream created by ZipIO_Open
740  * \return always VLC_SUCCESS
741  * This closes zip archive
742  *****************************************************************************/
743 static int ZCALLBACK ZipIO_Close ( void *opaque, void *stream )
744 {
745     (void) stream;
746     (void) opaque;
747 //     stream_t *s = (stream_t*) opaque;
748 //    if( p_demux->p_sys && p_demux->p_sys->zipFile )
749 //        p_demux->p_sys->zipFile = NULL;
750 //     stream_Seek( s->p_source, 0 );
751     return VLC_SUCCESS;
752 }
753
754 /** **************************************************************************
755  * \brief I/O functions for the ioapi: write (assert insteadof segfault)
756  *****************************************************************************/
757 static uLong ZCALLBACK ZipIO_Write( void* opaque, void* stream,
758                                     const void* buf, uLong size )
759 {
760     (void)opaque; (void)stream; (void)buf; (void)size;
761     int ERROR_zip_cannot_write_this_should_not_happen = 0;
762     assert( ERROR_zip_cannot_write_this_should_not_happen );
763     return 0;
764 }
765
766 /** **************************************************************************
767  * \brief I/O functions for the ioapi: test error (man 3 ferror)
768  *****************************************************************************/
769 static int ZCALLBACK ZipIO_Error( void* opaque, void* stream )
770 {
771     (void)opaque;
772     (void)stream;
773     //msg_Dbg( p_access, "error" );
774     return 0;
775 }
776