/***************************************************************************** * ParseURL : Split an http:// URL into host, path, and port * * Example: "62.216.251.205:80/protocol_1.2" * will be split into "62.216.251.205", 80, "protocol_1.2" * * psz_url will be freed before returning * *psz_file & *psz_host will be freed before use * * Return value: * VLC_ENOMEM Out Of Memory * VLC_EGENERIC Invalid url provided * VLC_SUCCESS Success *****************************************************************************/ int ParseURL(char* url, char** host, char** path, int* port) { unsigned char port_given = 0, path_given = 0; if(url == NULL) return -1; FREENULL(*host); FREENULL(*path); if(strstr(url, "http://") == url) { url = url + 7; } size_t port_separator_position = strcspn(url, ":"); size_t path_separator_position = strcspn(url, "/"); if(port_separator_position != strlen(url)) { port_given = 1; *host = strndup(url, port_separator_position); if(*host == NULL) return VLC_ENOMEM; } if(path_separator_position != strlen(url)) { path_given = 1; if(!port_given) { *host = strndup(url, path_separator_position); if(*host == NULL) return VLC_ENOMEM; } } if(port_given) { *port = atoi(url + port_separator_position + 1); *host = strndup(url, port_separator_position); if(*host == NULL) return VLC_ENOMEM; } else { *port = 80; } if(path_given) { *path = strdup(url + path_separator_position + 1); } else { *path = strdup("/"); } if(*path == NULL) return VLC_ENOMEM; return VLC_SUCCESS; }
static void AVI_ChunkFree_indx( avi_chunk_t *p_chk ) { avi_chunk_indx_t *p_indx = (avi_chunk_indx_t*)p_chk; FREENULL( p_indx->idx.std ); FREENULL( p_indx->idx.field ); FREENULL( p_indx->idx.super ); }
/***************************************************************************** * DeleteSong : Delete the char pointers in a song *****************************************************************************/ static void DeleteSong(audioscrobbler_song_t* p_song) { FREENULL(p_song->psz_a); FREENULL(p_song->psz_b); FREENULL(p_song->psz_t); FREENULL(p_song->psz_m); FREENULL(p_song->psz_n); }
/** * Empty the release struct * * \param p_update update_t* pointer * \return nothing */ static void EmptyRelease( update_t *p_update ) { p_update->release.i_major = 0; p_update->release.i_minor = 0; p_update->release.i_revision = 0; FREENULL( p_update->release.psz_url ); FREENULL( p_update->release.psz_desc ); }
void journal_pack( journal_t *journal, char **packed, size_t *size ) { char *packed_journal_header = NULL; size_t packed_journal_header_size = 0; char *packed_channel = NULL; size_t packed_channel_size = 0; char *packed_channel_buffer = NULL; size_t packed_channel_buffer_size = 0; char *p = NULL; int i = 0; *packed = NULL; *size = 0; if( ! journal ) return; logging_printf( LOGGING_DEBUG, "journal_pack: journal_has_data = %s header->totchan=%u\n", ( journal_has_data( journal ) ? "YES" : "NO" ) , journal->header->totchan); if( ! journal_has_data( journal ) ) return; journal_header_pack( journal->header, &packed_journal_header, &packed_journal_header_size ); for( i = 0 ; i < MAX_MIDI_CHANNELS ; i++ ) { if( ! journal->channels[i] ) continue; channel_pack( journal->channels[i], &packed_channel, &packed_channel_size ); packed_channel_buffer = ( char * )realloc( packed_channel_buffer, packed_channel_buffer_size + packed_channel_size ); if( ! packed_channel_buffer ) goto journal_pack_cleanup; p = packed_channel_buffer + packed_channel_buffer_size; memset( p, 0, packed_channel_size ); packed_channel_buffer_size += packed_channel_size; memcpy( p, packed_channel, packed_channel_size ); FREENULL( "packed_channel", (void **)&packed_channel ); } // Join it all together *packed = ( char * )malloc( packed_journal_header_size + packed_channel_buffer_size ); p = *packed; memcpy( p, packed_journal_header, packed_journal_header_size ); *size += packed_journal_header_size; p += packed_journal_header_size; memcpy( p, packed_channel_buffer, packed_channel_buffer_size ); *size += packed_channel_buffer_size; journal_pack_cleanup: FREENULL( "packed_channel", (void **)&packed_channel ); FREENULL( "packed_channel_buffer", (void **)&packed_channel_buffer ); FREENULL( "packed_journal_header", (void **)&packed_journal_header ); }
void sms_queue_free( sms_queue_t* queue ) { item_t *item = queue->first, *next = NULL; while( item ) { next = item->next; FREENULL( item ); item = next; } FREENULL( queue ); }
static void AVI_ChunkFree_strf( avi_chunk_t *p_chk ) { avi_chunk_strf_t *p_strf = (avi_chunk_strf_t*)p_chk; if( p_strf->common.i_cat == AUDIO_ES ) { FREENULL( p_strf->auds.p_wf ); } else if( p_strf->common.i_cat == VIDEO_ES ) { FREENULL( p_strf->vids.p_bih ); } }
void midi_payload_destroy( midi_payload_t **payload ) { if( ! payload ) return; if( ! *payload ) return; (*payload)->buffer = NULL; if( (*payload)->header ) { FREENULL( (void **)&((*payload)->header) ); } FREENULL( (void **)payload ); }
/***************************************************************************** * VCDClose: closes VCD releasing allocated memory. *****************************************************************************/ void VCDClose ( vlc_object_t *p_this ) { access_t *p_access = (access_t *)p_this; vcdplayer_t *p_vcdplayer = (vcdplayer_t *)p_access->p_sys; dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "VCDClose" ); { unsigned int i; for (i=0 ; i<p_vcdplayer->i_titles; i++) if (p_vcdplayer->p_title[i]) free(p_vcdplayer->p_title[i]->psz_name); } vcdinfo_close( p_vcdplayer->vcd ); if( p_vcdplayer->p_input ) vlc_object_release( p_vcdplayer->p_input ); FREENULL( p_vcdplayer->p_entries ); FREENULL( p_vcdplayer->p_segments ); FREENULL( p_vcdplayer->psz_source ); FREENULL( p_vcdplayer->track ); FREENULL( p_vcdplayer->segment ); FREENULL( p_vcdplayer->entry ); FREENULL( p_access->psz_demux ); FREENULL( p_vcdplayer ); p_vcd_access = NULL; }
void config_ChainDestroy( config_chain_t *p_cfg ) { while( p_cfg != NULL ) { config_chain_t *p_next; p_next = p_cfg->p_next; FREENULL( p_cfg->psz_name ); FREENULL( p_cfg->psz_value ); free( p_cfg ); p_cfg = p_next; } }
/***************************************************************************** * ParseURL : Split an http:// URL into host, file, and port * * Example: "62.216.251.205:80/protocol_1.2" * will be split into "62.216.251.205", 80, "protocol_1.2" * * psz_url will be freed before returning * *psz_file & *psz_host will be freed before use * * Return value: * VLC_ENOMEM Out Of Memory * VLC_EGENERIC Invalid url provided * VLC_SUCCESS Success *****************************************************************************/ static int ParseURL( char *psz_url, char **psz_host, char **psz_file, int *i_port ) { int i_pos; int i_len = strlen( psz_url ); bool b_no_port = false; FREENULL( *psz_host ); FREENULL( *psz_file ); i_pos = strcspn( psz_url, ":" ); if( i_pos == i_len ) { *i_port = 80; i_pos = strcspn( psz_url, "/" ); b_no_port = true; } *psz_host = strndup( psz_url, i_pos ); if( !*psz_host ) return VLC_ENOMEM; if( !b_no_port ) { i_pos++; /* skip the ':' */ *i_port = atoi( psz_url + i_pos ); if( *i_port <= 0 ) { FREENULL( *psz_host ); return VLC_EGENERIC; } i_pos = strcspn( psz_url, "/" ); } if( i_pos == i_len ) return VLC_EGENERIC; i_pos++; /* skip the '/' */ *psz_file = strdup( psz_url + i_pos ); if( !*psz_file ) { FREENULL( *psz_host ); return VLC_ENOMEM; } free( psz_url ); return VLC_SUCCESS; }
int sms_queue_put( sms_queue_t *queue, const uint64_t value ) { /* Remove the last (and oldest) item */ item_t *item, *prev = NULL; int count = 0; for( item = queue->first; item != NULL; item = item->next ) { count++; if( count == queue->length ) { FREENULL( item ); if( prev ) prev->next = NULL; break; } else prev = item; } /* Now insert the new item */ item_t *_new = (item_t *)malloc( sizeof( item_t ) ); // sunqueen modify if( unlikely( !_new ) ) // sunqueen modify return VLC_ENOMEM; _new->value = value; // sunqueen modify _new->next = queue->first; // sunqueen modify queue->first = _new; // sunqueen modify return VLC_SUCCESS; }
bool cDVDList::Create(char *dir, char *exts, char *dirs, eFileList smode, bool sub) { MYDEBUG("DVDList: %s, %s", exts, dirs); Clear(); FREENULL(DVDExts); FREENULL(DVDDirs); DVDExts = exts ? strdup(exts) : NULL; DVDDirs = dirs ? strdup(dirs) : NULL; if(!DVDExts && !DVDDirs) return false; return Load(dir, smode, sub); }
void channel_destroy( channel_t **channel ) { if( ! channel ) return; if( ! *channel ) return; if( (*channel)->chapter_n ) { chapter_n_destroy( &( (*channel)->chapter_n ) ); } if( (*channel)->chapter_c ) { chapter_c_destroy( &( (*channel)->chapter_c ) ); } if( (*channel)->chapter_p ) { chapter_p_destroy( &( (*channel)->chapter_p ) ); } if( (*channel)->header ) { channel_header_destroy( &( (*channel)->header ) ); } FREENULL("channel", (void **) channel); }
static chunk_t * gotoNextChunk( stream_sys_t *p_sys ) { assert(p_sys->p_current_stream); chunk_t *p_prev = p_sys->p_current_stream->p_playback; if ( p_prev ) { if ( p_sys->b_live ) { /* Discard chunk and update stream pointers */ assert( p_sys->p_current_stream->p_chunks == p_sys->p_current_stream->p_playback ); p_sys->p_current_stream->p_playback = p_sys->p_current_stream->p_playback->p_next; p_sys->p_current_stream->p_chunks = p_sys->p_current_stream->p_chunks->p_next; if ( p_sys->p_current_stream->p_lastchunk == p_prev ) p_sys->p_current_stream->p_lastchunk = NULL; chunk_Free( p_prev ); } else { /* Just cleanup chunk for reuse on seek */ p_sys->p_current_stream->p_playback = p_sys->p_current_stream->p_playback->p_next; FREENULL(p_prev->data); p_prev->read_pos = 0; p_prev->offset = CHUNK_OFFSET_UNSET; p_prev->size = 0; } } /* Select new current pointer among streams playback heads */ p_sys->p_current_stream = next_playback_stream( p_sys ); if ( !p_sys->p_current_stream ) return NULL; return p_sys->p_current_stream->p_playback; }
char *cFileInfo::FileNameWithoutExt(void) { char *ext = NULL; char *filename = NULL; if(Extension()) ext = strdup(Extension()); if(FileName()) filename = strdup(FileName()); FREENULL(buffer); if(ext && filename) { int len = strlen(filename) - strlen(ext) + 1; buffer = (char*)malloc(len); strn0cpy(buffer, filename, len); } else if(filename) buffer = strdup(filename); free(ext); free(filename); MYDEBUG("FileInfo: FileNameWithoutExt: %s", buffer); return buffer; }
bool cFileList::Read(char *dir, bool withsub) { bool ret = false; char *buffer = NULL; struct dirent *DirData = NULL; cReadDir Dir(dir); if(Dir.Ok()) { while((DirData = Dir.Next()) != NULL) { if(CheckIncludes(dir, DirData->d_name) && !CheckExcludes(dir, DirData->d_name) && CheckType(dir, DirData->d_name, Type)) SortIn(dir, DirData->d_name); if(withsub && CheckType(dir, DirData->d_name, tDir) && !RegIMatch(DirData->d_name, "^\\.{1,2}$")) { asprintf(&buffer, "%s/%s", dir, DirData->d_name); Read(buffer, withsub); FREENULL(buffer); } } ret = true; } return ret; }
/* <genrelist> * <genre name="the name"></genre> * ... * </genrelist> **/ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader, input_item_node_t *p_input_node ) { const char *node; char *psz_name = NULL; /* genre name */ int type; while( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 ) { switch( type ) { case XML_READER_STARTELEM: { if( !strcmp( node, "genre" ) ) { // Read the attributes const char *name, *value; while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) ) { if( !strcmp( name, "name" ) ) { free(psz_name); psz_name = strdup( value ); } else msg_Warn( p_demux, "unexpected attribute %s in <%s>", name, node ); } } break; } case XML_READER_ENDELEM: if( !strcmp( node, "genre" ) && psz_name != NULL ) { char* psz_mrl; if( asprintf( &psz_mrl, SHOUTCAST_BASE_URL "?genre=%s", psz_name ) != -1 ) { input_item_t *p_input; vlc_xml_decode( psz_mrl ); p_input = input_item_New( psz_mrl, psz_name ); input_item_CopyOptions( p_input_node->p_item, p_input ); free( psz_mrl ); input_item_node_AppendItem( p_input_node, p_input ); vlc_gc_decref( p_input ); } FREENULL( psz_name ); } break; } } free( psz_name ); return 0; }
void http_auth_Reset( http_auth_t *p_auth ) { p_auth->i_nonce = 0; FREENULL( p_auth->psz_realm ); FREENULL( p_auth->psz_domain ); FREENULL( p_auth->psz_nonce ); FREENULL( p_auth->psz_opaque ); FREENULL( p_auth->psz_stale ); FREENULL( p_auth->psz_algorithm ); FREENULL( p_auth->psz_qop ); FREENULL( p_auth->psz_cnonce ); FREENULL( p_auth->psz_HA1 ); }
static void cleanup_attributes(custom_attrs_t **cp) { if( !*cp ) return; free( (*cp)->psz_key ); free( (*cp)->psz_value ); FREENULL( *cp ); }
static void Run( fingerprinter_thread_t *p_fingerprinter ) { fingerprinter_sys_t *p_sys = p_fingerprinter->p_sys; /* main loop */ for (;;) { vlc_mutex_lock( &p_sys->processing.lock ); mutex_cleanup_push( &p_sys->processing.lock ); vlc_cond_timedwait( &p_sys->incoming_queue_filled, &p_sys->processing.lock, mdate() + 1000000 ); vlc_cleanup_run(); QueueIncomingRequests( p_sys ); vlc_mutex_lock( &p_sys->processing.lock ); // L0 mutex_cleanup_push( &p_sys->processing.lock ); vlc_cleanup_push( cancelRun, p_sys ); // C1 //** for ( p_sys->i = 0 ; p_sys->i < vlc_array_count( p_sys->processing.queue ); p_sys->i++ ) { fingerprint_request_t *p_data = vlc_array_item_at_index( p_sys->processing.queue, p_sys->i ); acoustid_fingerprint_t acoustid_print; memset( &acoustid_print , 0, sizeof(acoustid_fingerprint_t) ); vlc_cleanup_push( clearPrint, &acoustid_print ); // C2 p_sys->psz_uri = input_item_GetURI( p_data->p_item ); if ( p_sys->psz_uri ) { /* overwrite with hint, as in this case, fingerprint's session will be truncated */ if ( p_data->i_duration ) acoustid_print.i_duration = p_data->i_duration; DoFingerprint( VLC_OBJECT(p_fingerprinter), p_sys, &acoustid_print ); DoAcoustIdWebRequest( VLC_OBJECT(p_fingerprinter), &acoustid_print ); fill_metas_with_results( p_data, &acoustid_print ); FREENULL( p_sys->psz_uri ); } vlc_cleanup_run( ); // C2 /* copy results */ vlc_mutex_lock( &p_sys->results.lock ); vlc_array_append( p_sys->results.queue, p_data ); vlc_mutex_unlock( &p_sys->results.lock ); vlc_testcancel(); } if ( vlc_array_count( p_sys->processing.queue ) ) { var_TriggerCallback( p_fingerprinter, "results-available" ); vlc_array_clear( p_sys->processing.queue ); } vlc_cleanup_pop( ); // C1 //** vlc_cleanup_run(); // L0 } }
static http_cookie_t *cookie_parse(const char *value, const char *host, const char *path) { http_cookie_t *cookie = calloc( 1, sizeof( http_cookie_t ) ); if ( unlikely( !cookie ) ) return NULL; char *content = cookie_get_content(value); if ( !content ) { cookie_destroy( cookie ); return NULL; } const char *eq = strchr( content, '=' ); if ( eq ) { cookie->psz_name = strndup( content, eq-content ); cookie->psz_value = strdup( eq + 1 ); } else { cookie->psz_name = strdup( content ); cookie->psz_value = NULL; } cookie->psz_domain = cookie_get_domain(value); if ( !cookie->psz_domain || strlen(cookie->psz_domain) == 0 ) { free(cookie->psz_domain); cookie->psz_domain = strdup(host); cookie->b_host_only = true; } else cookie->b_host_only = false; cookie->psz_path = cookie_get_attribute_value(value, "path" ); if ( !cookie->psz_path || strlen(cookie->psz_path) == 0 ) { free(cookie->psz_path); cookie->psz_path = cookie_default_path(path); } cookie->b_secure = cookie_has_attribute(value, "secure" ); FREENULL( content ); if ( !cookie->psz_domain || !cookie->psz_path || !cookie->psz_name ) { cookie_destroy( cookie ); return NULL; } return cookie; }
/***************************************************************************** * Called through lua_scripts_batch_execute to call 'probe' on * the script pointed by psz_filename. *****************************************************************************/ static int probe_luascript( vlc_object_t *p_this, const char * psz_filename, lua_State * L, void * user_data ) { VLC_UNUSED(user_data); demux_t * p_demux = (demux_t *)p_this; p_demux->p_sys->psz_filename = strdup(psz_filename); /* In lua, setting a variable's value to nil is equivalent to deleting it */ lua_pushnil( L ); lua_pushnil( L ); lua_setglobal( L, "probe" ); lua_setglobal( L, "parse" ); /* Load and run the script(s) */ if( luaL_dofile( L, psz_filename ) ) { msg_Warn( p_demux, "Error loading script %s: %s", psz_filename, lua_tostring( L, lua_gettop( L ) ) ); goto error; } lua_getglobal( L, "probe" ); if( !lua_isfunction( L, -1 ) ) { msg_Warn( p_demux, "Error while runing script %s, " "function probe() not found", psz_filename ); goto error; } if( lua_pcall( L, 0, 1, 0 ) ) { msg_Warn( p_demux, "Error while runing script %s, " "function probe(): %s", psz_filename, lua_tostring( L, lua_gettop( L ) ) ); goto error; } if( lua_gettop( L ) ) { if( lua_toboolean( L, 1 ) ) { msg_Dbg( p_demux, "Lua playlist script %s's " "probe() function was successful", psz_filename ); lua_pop( L, 1 ); return VLC_SUCCESS; } } error: lua_pop( L, 1 ); FREENULL( p_demux->p_sys->psz_filename ); return VLC_EGENERIC; }
/***************************************************************************** * sout_NewInstance: creates a new stream output instance *****************************************************************************/ sout_instance_t *sout_NewInstance( vlc_object_t *p_parent, const char *psz_dest ) { sout_instance_t *p_sout; char *psz_chain; assert( psz_dest != NULL ); if( psz_dest[0] == '#' ) { psz_chain = strdup( &psz_dest[1] ); } else { psz_chain = sout_stream_url_to_chain( var_InheritBool(p_parent, "sout-display"), psz_dest ); } if(!psz_chain) return NULL; /* *** Allocate descriptor *** */ p_sout = vlc_custom_create( p_parent, sizeof( *p_sout ), "stream output" ); if( p_sout == NULL ) { free( psz_chain ); return NULL; } msg_Dbg( p_sout, "using sout chain=`%s'", psz_chain ); /* *** init descriptor *** */ p_sout->psz_sout = strdup( psz_dest ); p_sout->i_out_pace_nocontrol = 0; vlc_mutex_init( &p_sout->lock ); p_sout->p_stream = NULL; var_Create( p_sout, "sout-mux-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); p_sout->p_stream = sout_StreamChainNew( p_sout, psz_chain, NULL, NULL ); if( p_sout->p_stream ) { free( psz_chain ); return p_sout; } msg_Err( p_sout, "stream chain failed for `%s'", psz_chain ); free( psz_chain ); FREENULL( p_sout->psz_sout ); vlc_mutex_destroy( &p_sout->lock ); vlc_object_release( p_sout ); return NULL; }
char* cCMDImage::Rename(char *file) { MYDEBUG("CMDImage Rename"); if(file) { FREENULL(File); File = strdup(file); } return File; }
eOSState cCMDDir::New(eKeys Key) { switch(Key) { case kOk: if(!isempty(Dir)) { char *buffer = NULL; asprintf(&buffer, "%s/%s", CurrentDir(), stripspace(Dir)); MYDEBUG("Verzeichnis: Neu: Anlegen: %s", buffer); cFileInfo *info = new cFileInfo(buffer); if(info->isExists()) { MYDEBUG("Verzeichnis existiert bereits"); OSD_WARNMSG(tr("Directory exists")); FREENULL(buffer); DELETENULL(info); return osContinue; } if(cFileCMD::Mkdir(buffer)) { MYDEBUG("Verzeichnis anlegen erfolgreich"); LastSelDir(buffer); if(!Select) OsdObject->SetState(mmsReInit); } FREENULL(buffer); DELETENULL(info); } case kBack: State = csNone; Build(); return osContinue; break; default: break; } return cOsdMenu::ProcessKey(Key); }
/***************************************************************************** * sout_DeleteInstance: delete a previously allocated instance *****************************************************************************/ void sout_DeleteInstance( sout_instance_t * p_sout ) { /* remove the stream out chain */ sout_StreamChainDelete( p_sout->p_stream, NULL ); /* *** free all string *** */ FREENULL( p_sout->psz_sout ); vlc_mutex_destroy( &p_sout->lock ); /* *** free structure *** */ vlc_object_release( p_sout ); }
eOSState cCMDDir::Edit(eKeys Key) { switch(Key) { case kOk: if(!isempty(Dir)) { char *buffer = NULL; asprintf(&buffer, "%s/%s", CurrentDir(), stripspace(Dir)); MYDEBUG("Verzeichnis: Edit: OK: %s", buffer); cFileInfo *info = new cFileInfo(buffer); if(info->isExists()) { MYDEBUG("Verzeichnis: Edit: Existiert schon"); OSD_WARNMSG(tr("Directory exists")); FREENULL(buffer); DELETENULL(info); return osUnknown; } if(cFileCMD::Rn(LastSelDir(), buffer)) { MYDEBUG("Verzeichnis: Edit: Rename OK"); LastSelDir(buffer); OsdObject->SetState(mmsReInit); } FREENULL(buffer); DELETENULL(info); } case kBack: State = csNone; Build(); return osContinue; break; default: break; } return cOsdMenu::ProcessKey(Key); }
/* Destroy a "stream_out" module */ static void sout_StreamDelete( sout_stream_t *p_stream ) { msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name ); if( p_stream->p_module ) module_unneed( p_stream, p_stream->p_module ); FREENULL( p_stream->psz_name ); config_ChainDestroy( p_stream->p_cfg ); msg_Dbg( p_stream, "destroying chain done" ); vlc_object_release( p_stream ); }
static void cancelDoFingerprint( void *p_arg ) { fingerprinter_sys_t *p_sys = ( fingerprinter_sys_t * ) p_arg; if ( p_sys->p_input ) { input_Stop( p_sys->p_input, true ); input_Close( p_sys->p_input ); } /* cleanup temporary result */ if ( p_sys->chroma_fingerprint.psz_fingerprint ) FREENULL( p_sys->chroma_fingerprint.psz_fingerprint ); if ( p_sys->p_item ) input_item_Release( p_sys->p_item ); }