1 /*****************************************************************************
2 * macro.c : Custom <vlc> macro handling
3 *****************************************************************************
4 * Copyright (C) 2001-2005 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
34 #include <vlc_memory.h>
36 static int MacroParse( macro_t *m, char *psz_src )
38 char *dup = strdup( (char *)psz_src );
43 #define EXTRACT( name, l ) \
45 p = strchr( src, '"' ); \
50 m->name = strdup( src ); \
71 if( !strncmp( src, "id=\"", 4 ) )
75 else if( !strncmp( src, "param1=\"", 8 ) )
79 else if( !strncmp( src, "param2=\"", 8 ) )
88 if( strstr( src, "/>" ) )
90 src = strstr( src, "/>" ) + 2;
101 if( m->param1 == NULL )
103 m->param1 = strdup( "" );
105 if( m->param2 == NULL )
107 m->param2 = strdup( "" );
116 static void MacroClean( macro_t *m )
123 static int StrToMacroType( const char *name )
127 if( !name || *name == '\0')
131 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
133 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
135 return StrToMacroTypeTab[i].i_type;
141 static void MacroDo( httpd_file_sys_t *p_args,
143 char *p_request, int i_request,
144 char **pp_data, int *pi_data,
147 intf_thread_t *p_intf = p_args->p_intf;
148 intf_sys_t *p_sys = p_args->p_intf->p_sys;
153 int __i__ = *pp_dst - *pp_data; \
155 *pp_data = realloc_or_free( *pp_data, *pi_data ); \
156 assert( *pp_data ); \
157 *pp_dst = (*pp_data) + __i__; \
159 #define PRINT( str ) \
160 ALLOC( strlen( str ) + 1 ); \
161 *pp_dst += sprintf( *pp_dst, "%s", str );
163 #define PRINTS( str, s ) \
164 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
166 char * psz_cur = *pp_dst; \
167 *pp_dst += sprintf( *pp_dst, str, s ); \
168 while( psz_cur && *psz_cur ) \
170 /* Prevent script injection */ \
171 if( *psz_cur == '<' ) *psz_cur = '*'; \
172 if( *psz_cur == '>' ) *psz_cur = '*'; \
177 switch( StrToMacroType( m->id ) )
184 ExtractURIValue( p_request, "control", control, 512 );
185 if( *m->param1 && !strstr( m->param1, control ) )
187 msg_Warn( p_intf, "unauthorized control=%s", control );
190 switch( StrToMacroType( control ) )
197 ExtractURIValue( p_request, "item", item, 512 );
198 i_item = atoi( item );
199 /* id = 0 : simply ask playlist to play */
202 playlist_Play( p_sys->p_playlist );
203 msg_Dbg( p_intf, "requested playlist play" );
206 //TODO: really locked here ?
207 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
209 playlist_ItemGetById( p_sys->p_playlist,
211 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
215 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP,
217 msg_Dbg( p_intf, "requested playlist stop" );
220 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE,
222 msg_Dbg( p_intf, "requested playlist pause" );
225 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,
227 msg_Dbg( p_intf, "requested playlist next" );
230 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,
232 msg_Dbg( p_intf, "requested playlist previous" );
234 case MVLC_FULLSCREEN:
237 vout_thread_t *p_vout;
239 p_vout = input_GetVout( p_sys->p_input );
242 var_ToggleBool( p_vout, "fullscreen" );
243 vlc_object_release( p_vout );
244 msg_Dbg( p_intf, "requested fullscreen toggle" );
251 ExtractURIValue( p_request, "seek_value", value, 30 );
253 HandleSeek( p_intf, value );
259 audio_volume_t i_volume;
262 ExtractURIValue( p_request, "value", vol, 8 );
263 aout_VolumeGet( p_sys->p_playlist, &i_volume );
268 i_value = atoi( vol + 1 );
269 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
271 aout_VolumeSet( p_sys->p_playlist, AOUT_VOLUME_MAX );
272 msg_Dbg( p_intf, "requested volume set: max" );
276 aout_VolumeSet( p_sys->p_playlist, (i_volume + i_value) );
277 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
280 else if( vol[0] == '-' )
282 i_value = atoi( vol + 1 );
283 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
285 aout_VolumeSet( p_sys->p_playlist, AOUT_VOLUME_MIN );
286 msg_Dbg( p_intf, "requested volume set: min" );
290 aout_VolumeSet( p_sys->p_playlist, (i_volume - i_value) );
291 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
294 else if( strstr(vol, "%") != NULL )
296 i_value = atoi( vol );
297 if( (i_value <= 400) && (i_value>=0) ){
298 aout_VolumeSet( p_sys->p_playlist, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);
299 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
304 i_value = atoi( vol );
305 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
307 aout_VolumeSet( p_sys->p_playlist, atoi( vol ) );
308 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
314 /* playlist management */
317 char mrl[1024], psz_name[1024], tmp[1024];
319 input_item_t *p_input;
321 ExtractURIValue( p_request, "mrl", tmp, 1024 );
323 ExtractURIValue( p_request, "name", psz_name, 1024 );
324 decode_URI( psz_name );
327 memcpy( psz_name, tmp, 1024 );
329 /* addslashes for backward compatibility with the old
332 while( *str != '\0' )
334 if( *str == '"' || *str == '\'' || *str == '\\' )
343 p_input = MRLParse( p_intf, mrl, psz_name );
345 char *psz_uri = p_input ? input_item_GetURI( p_input ) : NULL;
346 if( psz_uri && *psz_uri &&
347 playlist_AddInput( p_sys->p_playlist, p_input,
348 PLAYLIST_APPEND, PLAYLIST_END,
349 true, false) == VLC_SUCCESS )
350 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
352 msg_Warn( p_intf, "adding mrl failed: %s", mrl );
355 vlc_gc_decref( p_input );
361 size_t i_nb_items = 0;
363 const char *p_parser = p_request;
365 /* Get the list of items to delete */
367 ExtractURIValue( p_parser, "item", item, 512 )) )
369 if( !*item ) continue;
371 int i_item = atoi( item );
372 p_items = realloc_or_free( p_items,
373 (i_nb_items + 1) * sizeof(*p_items) );
375 p_items[i_nb_items] = i_item;
379 for( size_t i = 0; i < i_nb_items; i++ )
381 playlist_item_t *p_item;
383 msg_Dbg( p_intf, "requested playlist delete: %d",
385 p_item = playlist_ItemGetById( p_sys->p_playlist,
388 playlist_DeleteFromInput( p_sys->p_playlist,
399 size_t i_nb_items = 0, i;
401 const char *p_parser = p_request;
403 /* Get the list of items to keep */
405 ExtractURIValue( p_parser, "item", item, 512 )) )
407 if( !*item ) continue;
409 int i_item = atoi( item );
410 p_items = realloc_or_free( p_items,
411 (i_nb_items + 1) * sizeof(*p_items) );
413 p_items[i_nb_items] = i_item;
417 size_t size = p_sys->p_playlist->items.i_size;
418 for( i = 0; i < size; i++ )
422 /* Check if the item is in the keep list */
423 for( j = 0 ; j < i_nb_items ; j++ )
426 ARRAY_VAL(p_sys->p_playlist->items,i)->i_id)
429 if( j == i_nb_items )
431 msg_Dbg( p_intf, "requested playlist delete: %d",
432 p_sys->p_playlist->items.p_elems[i]->i_id );
433 playlist_DeleteFromInput( p_sys->p_playlist,
434 p_sys->p_playlist->items.p_elems[i]->p_input,
444 playlist_Clear( p_sys->p_playlist, false );
445 msg_Dbg( p_intf, "requested playlist empty" );
456 ExtractURIValue( p_request, "type", type, 12 );
457 ExtractURIValue( p_request, "order", order, 2 );
458 ExtractURIValue( p_request, "item", item, 512 );
459 i_item = atoi( item );
461 if( order[0] == '0' ) i_order = ORDER_NORMAL;
462 else i_order = ORDER_REVERSE;
464 if( !strcmp( type , "title" ) )
466 playlist_RecursiveNodeSort( p_sys->p_playlist,
467 /* Ugly hack,but not worse than before ... */
468 p_sys->p_playlist->p_root_onelevel,
469 SORT_TITLE_NODES_FIRST,
470 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
471 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
473 else if( !strcmp( type , "author" ) )
475 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
476 p_sys->p_playlist->p_root_onelevel,
478 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
479 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
481 else if( !strcmp( type , "shuffle" ) )
483 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
484 p_sys->p_playlist->p_root_onelevel,
486 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
487 msg_Dbg( p_intf, "requested playlist shuffle");
498 ExtractURIValue( p_request, "psz_pos", psz_pos, 6 );
499 ExtractURIValue( p_request, "psz_newpos", psz_newpos, 6 );
500 i_pos = atoi( psz_pos );
501 i_newpos = atoi( psz_newpos );
502 /* FIXME FIXME TODO TODO XXX XXX
503 ( duplicate from rpn.c )
504 if ( i_pos < i_newpos )
506 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
510 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
512 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
513 FIXME FIXME TODO TODO XXX XXX */
521 ExtractURIValue( p_request, "id", id, 512 );
522 msg_Dbg( p_intf, "requested close id=%s", id );
524 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
526 msg_Warn( p_intf, "close failed for id=%s", id );
533 msg_Dbg( p_intf, "requested shutdown" );
534 libvlc_Quit( p_intf->p_libvlc );
542 static const char vlm_properties[][9] =
545 "enabled", "disabled", "loop", "unloop",
547 "input", "output", "option", "date", "period",
548 "repeat", "append", "",
550 vlm_message_t *vlm_answer;
552 char *psz = malloc( strlen( p_request ) + 1000 );
559 if( p_intf->p_sys->p_vlm == NULL )
560 p_intf->p_sys->p_vlm = vlm_New( p_intf );
562 if( p_intf->p_sys->p_vlm == NULL )
568 ExtractURIValue( p_request, "name", name, 512 );
569 if( StrToMacroType( control ) == MVLC_VLM_NEW )
572 ExtractURIValue( p_request, "type", type, 20 );
573 p += sprintf( psz, "new %s %s", name, type );
577 p += sprintf( psz, "setup %s", name );
579 /* Parse the request */
580 for( i = 0; vlm_properties[i][0]; i++ )
583 ExtractURIValue( p_request,
584 vlm_properties[i], val, 512 );
586 if( strlen( val ) > 0 && i >= 4 )
588 p += sprintf( p, " %s %s", vlm_properties[i], val );
590 else if( TestURIParam( p_request, vlm_properties[i] ) && i < 4 )
592 p += sprintf( p, " %s", vlm_properties[i] );
595 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
596 if( vlm_answer->psz_value == NULL ) /* there is no error */
598 vlm_error = strdup( "" );
602 if( asprintf( &vlm_error , "%s : %s" ,
603 vlm_answer->psz_name,
604 vlm_answer->psz_value ) == -1 )
608 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
610 vlm_MessageDelete( vlm_answer );
618 vlm_message_t *vlm_answer;
621 if( p_intf->p_sys->p_vlm == NULL )
622 p_intf->p_sys->p_vlm = vlm_New( p_intf );
624 if( p_intf->p_sys->p_vlm == NULL ) break;
626 ExtractURIValue( p_request, "name", name, 512 );
627 sprintf( psz, "del %s", name );
629 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
630 /* FIXME do a vlm_answer -> var stack conversion */
631 vlm_MessageDelete( vlm_answer );
640 vlm_message_t *vlm_answer;
643 if( p_intf->p_sys->p_vlm == NULL )
644 p_intf->p_sys->p_vlm = vlm_New( p_intf );
646 if( p_intf->p_sys->p_vlm == NULL ) break;
648 ExtractURIValue( p_request, "name", name, 512 );
649 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
650 sprintf( psz, "control %s play", name );
651 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
652 sprintf( psz, "control %s pause", name );
653 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
654 sprintf( psz, "control %s stop", name );
655 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
658 ExtractURIValue( p_request, "percent", percent, 512 );
659 sprintf( psz, "control %s seek %s", name, percent );
662 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
663 /* FIXME do a vlm_answer -> var stack conversion */
664 vlm_MessageDelete( vlm_answer );
670 vlm_message_t *vlm_answer;
674 if( p_intf->p_sys->p_vlm == NULL )
675 p_intf->p_sys->p_vlm = vlm_New( p_intf );
677 if( p_intf->p_sys->p_vlm == NULL ) break;
679 ExtractURIValue( p_request, "file", file, 512 );
682 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
683 sprintf( psz, "load %s", file );
685 sprintf( psz, "save %s", file );
687 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
688 /* FIXME do a vlm_answer -> var stack conversion */
689 vlm_MessageDelete( vlm_answer );
692 #endif /* ENABLE_VLM */
696 PRINTS( "<!-- control param(%s) unsupported -->", control );
708 if( i_request <= 0 ||
709 *m->param1 == '\0' ||
710 strstr( p_request, m->param1 ) == NULL )
714 ExtractURIValue( p_request, m->param1, value, 512 );
717 switch( StrToMacroType( m->param2 ) )
721 config_PutInt( p_intf, m->param1, i );
725 config_PutFloat( p_intf, m->param1, f );
728 config_PutPsz( p_intf, m->param1, value );
731 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
743 if( *m->param1 == '\0' )
748 switch( StrToMacroType( m->param2 ) )
751 i = config_GetInt( p_intf, m->param1 );
752 sprintf( value, "%d", i );
755 f = config_GetFloat( p_intf, m->param1 );
756 div = lldiv( f * 1000000 , 1000000 );
757 sprintf( value, "%lld.%06u", div.quot,
758 (unsigned int)div.rem );
761 psz = config_GetPsz( p_intf, m->param1 );
764 strlcpy( value, psz,sizeof( value ) );
769 msg_Dbg( p_intf, "%d: value = \"%s\"", __LINE__, value );
772 snprintf( value, sizeof( value ),
773 "invalid type(%s) in set", m->param2 );
776 PRINTS( "%s", value );
786 EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m->param1 );
787 s = SSPop( &p_args->stack );
788 v = mvar_GetValue( p_args->vars, s );
792 v = s = SSPop( &p_args->stack );
800 EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m->param1 );
803 /* Useful to learn stack management */
807 msg_Dbg( p_intf, "stack" );
808 for (i=0;i<(&p_args->stack)->i_stack;i++)
809 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
815 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
816 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
825 char *MacroSearch( char *src, char *end, int i_mvlc, bool b_after )
832 if( src + 4 < end && !strncmp( (char *)src, "<vlc", 4 ) )
837 i_skip = MacroParse( &m, src );
839 i_id = StrToMacroType( m.id );
856 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
857 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
859 return src + ( b_after ? i_skip : 0 );
861 else if( i_level < 0 )
877 void Execute( httpd_file_sys_t *p_args,
878 char *p_request, int i_request,
879 char **pp_data, int *pi_data,
881 char *_src, char *_end )
883 intf_thread_t *p_intf = p_args->p_intf;
885 char *src, *dup, *end;
888 src = dup = malloc( _end - _src + 1 );
889 end = src +( _end - _src );
893 memcpy( src, _src, _end - _src );
896 /* we parse searching <vlc */
902 p = (char *)strstr( (char *)src, "<vlc" );
903 if( p < end && p == src )
907 src += MacroParse( &m, src );
909 //msg_Dbg( p_intf, "macro_id=%s", m.id );
911 switch( StrToMacroType( m.id ) )
918 char psz_file[MAX_DIR_SIZE];
928 if( m.param1[0] != sep )
930 strcpy( psz_file, p_args->file );
931 p = strrchr( psz_file, sep );
933 strcpy( p + 1, m.param1 );
935 strcpy( psz_file, m.param1 );
939 strcpy( psz_file, m.param1 );
942 /* We hereby assume that psz_file is in the
943 * local character encoding */
944 if( ( f = fopen( psz_file, "r" ) ) == NULL )
946 msg_Warn( p_args->p_intf,
947 "unable to include file %s (%m)",
952 /* first we load in a temporary buffer */
953 FileLoad( f, &p_buffer, &i_buffer );
955 /* we parse executing all <vlc /> macros */
956 Execute( p_args, p_request, i_request, pp_data, pi_data,
957 &dst, &p_buffer[0], &p_buffer[i_buffer] );
967 EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m.param1 );
968 if( SSPopN( &p_args->stack, p_args->vars ) )
976 endif = MacroSearch( src, end, MVLC_END, true );
980 char *start = MacroSearch( src, endif, MVLC_ELSE, true );
984 char *stop = MacroSearch( start, endif, MVLC_END, false );
987 Execute( p_args, p_request, i_request,
988 pp_data, pi_data, &dst, start, stop );
992 else if( i_test == 1 )
995 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, false ) ) == NULL )
997 stop = MacroSearch( src, endif, MVLC_END, false );
1001 Execute( p_args, p_request, i_request,
1002 pp_data, pi_data, &dst, src, stop );
1011 char *endfor = MacroSearch( src, end, MVLC_END, true );
1013 char *stop = MacroSearch( src, end, MVLC_END, false );
1020 if( !strcmp( m.param2, "integer" ) )
1022 char *arg = SSPop( &p_args->stack );
1023 index = mvar_IntegerSetNew( m.param1, arg );
1026 else if( !strcmp( m.param2, "directory" ) )
1028 char *arg = SSPop( &p_args->stack );
1029 index = mvar_FileSetNew( p_intf, m.param1, arg );
1032 else if( !strcmp( m.param2, "object" ) )
1034 char *arg = SSPop( &p_args->stack );
1035 index = mvar_ObjectSetNew( p_intf, m.param1, arg );
1038 else if( !strcmp( m.param2, "playlist" ) )
1040 index = mvar_PlaylistSetNew( p_intf, m.param1,
1041 p_intf->p_sys->p_playlist );
1043 else if( !strcmp( m.param2, "information" ) )
1045 index = mvar_InfoSetNew( m.param1,
1046 p_intf->p_sys->p_input );
1048 else if( !strcmp( m.param2, "program" )
1049 || !strcmp( m.param2, "title" )
1050 || !strcmp( m.param2, "chapter" )
1051 || !strcmp( m.param2, "audio-es" )
1052 || !strcmp( m.param2, "video-es" )
1053 || !strcmp( m.param2, "spu-es" ) )
1055 index = mvar_InputVarSetNew( p_intf, m.param1,
1056 p_intf->p_sys->p_input,
1060 else if( !strcmp( m.param2, "vlm" ) )
1062 if( p_intf->p_sys->p_vlm == NULL )
1063 p_intf->p_sys->p_vlm = vlm_New( p_intf );
1064 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
1068 else if( !strcmp( m.param2, "hosts" ) )
1070 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
1072 else if( !strcmp( m.param2, "urls" ) )
1074 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
1076 else if( !strcmp( m.param2, "connections" ) )
1078 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
1081 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
1083 index = mvar_Duplicate( v );
1087 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
1092 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
1094 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
1096 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
1099 f->name = strdup( m.param1 );
1102 mvar_PushVar( p_args->vars, f );
1103 Execute( p_args, p_request, i_request,
1104 pp_data, pi_data, &dst, start, stop );
1105 mvar_RemoveVar( p_args->vars, f );
1109 mvar_Delete( index );
1116 MacroDo( p_args, &m, p_request, i_request,
1117 pp_data, pi_data, &dst );
1125 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
1128 int i_index = dst - *pp_data;
1131 *pp_data = realloc_or_free( *pp_data, *pi_data );
1133 dst = (*pp_data) + i_index;
1135 memcpy( dst, src, i_copy );