static void DumpStructure (vlc_object_internals_t *priv, unsigned i_level, char *psz_foo) { char i_back = psz_foo[i_level]; psz_foo[i_level] = '\0'; PrintObject (priv, psz_foo); psz_foo[i_level] = i_back; if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH ) { msg_Warn( vlc_externals(priv), "structure tree is too deep" ); return; } for (priv = priv->first; priv != NULL; priv = priv->next) { if( i_level ) { psz_foo[i_level-1] = ' '; if( psz_foo[i_level-2] == '`' ) { psz_foo[i_level-2] = ' '; } } psz_foo[i_level] = priv->next ? '|' : '`'; psz_foo[i_level+1] = '-'; psz_foo[i_level+2] = '\0'; DumpStructure (priv, i_level + 2, psz_foo); } }
void DumpStructure ( std::ostream & out, const char *title, const mime_part &mp, std::string prefix ) { std::string content_type = mp.get_content_type (); if ( NULL != title ) out << prefix << "Data from: " << title << std::endl; out << prefix << "Content-Type: " << content_type << std::endl; out << prefix << "There are " << std::distance ( mp.header_begin (), mp.header_end ()) << " headers" << std::endl; size_t subpart_count = std::distance ( mp.subpart_begin (), mp.subpart_end ()); switch ( mp.get_part_kind ()) { case mime_part::simple_part: if ( subpart_count != 0 ) out << str ( boost::format ( "%s ### %d subparts on a simple (%s) type!" ) % prefix % subpart_count % content_type ) << std::endl; out << prefix << "The body is " << mp.body_size () << " bytes long" << std::endl; DumpContainer ( out, prefix, *mp.body ()); break; case mime_part::multi_part: break; case mime_part::message_part: if ( boost::iequals ( content_type, "message/delivery-status" )) out << prefix << "The body is " << mp.body_size () << " bytes long" << std::endl; else if ( 1 != subpart_count ) out << str ( boost::format ( "%s ### %d subparts on a message (%s) type!" ) % subpart_count % prefix % content_type ) << std::endl; break; } if ( subpart_count != 0 ) { out << prefix << "There are " << std::distance ( mp.subpart_begin (), mp.subpart_end ()) << " sub parts" << std::endl; for ( mime_part::constPartIter iter = mp.subpart_begin (); iter != mp.subpart_end (); ++iter ) DumpStructure ( out, NULL, **iter, prefix + " " ); } }
/***************************************************************************** * DumpCommand: print the current vlc structure ***************************************************************************** * This function prints either an ASCII tree showing the connections between * vlc objects, and additional information such as their refcount, thread ID, * etc. (command "tree"), or the same data as a simple list (command "list"). *****************************************************************************/ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { (void)oldval; (void)p_data; vlc_object_t *p_object = NULL; if( *newval.psz_string ) { /* try using the object's name to find it */ p_object = vlc_object_find_name( p_this, newval.psz_string, FIND_ANYWHERE ); if( !p_object ) { return VLC_ENOOBJ; } } libvlc_lock (p_this->p_libvlc); if( *psz_cmd == 't' ) { char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1]; if( !p_object ) p_object = VLC_OBJECT(p_this->p_libvlc); psz_foo[0] = '|'; DumpStructure( vlc_internals(p_object), 0, psz_foo ); } else if( *psz_cmd == 'v' ) { if( !p_object ) p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this; PrintObject( vlc_internals(p_object), "" ); vlc_mutex_lock( &vlc_internals( p_object )->var_lock ); if( vlc_internals( p_object )->var_root == NULL ) puts( " `-o No variables" ); else twalk( vlc_internals( p_object )->var_root, DumpVariable ); vlc_mutex_unlock( &vlc_internals( p_object )->var_lock ); } libvlc_unlock (p_this->p_libvlc); if( *newval.psz_string ) { vlc_object_release( p_object ); } return VLC_SUCCESS; }
/** * Prints the VLC object tree * * This function prints either an ASCII tree showing the connections between * vlc objects, and additional information such as their refcount, thread ID, * etc. (command "tree"), or the same data as a simple list (command "list"). */ static int TreeCommand (vlc_object_t *obj, char const *cmd, vlc_value_t oldval, vlc_value_t newval, void *data) { (void) cmd; (void) oldval; (void) newval; (void) data; if (cmd[0] == 't') { char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1]; psz_foo[0] = '|'; DumpStructure (obj, 0, psz_foo); } return VLC_SUCCESS; }
int main ( int argc, char * argv[] ) { if ( argc == 1 ) std::cerr << "Usage: basic_parsing <files-to-parse>" << std::endl; for ( int i = 1; i < argc; ++i ) { boost::shared_ptr<mime_part> rmp; try { std::ifstream in ( argv[i] ); if ( !in ) { std::cerr << "Can't open file " << argv[i] << std::endl; continue; } in >> std::noskipws; std::cout << "**********************************" << std::endl; rmp = mime_part::parse_mime ( in ); } catch ( const boost::mime::mime_parsing_error &err ) { std::cout << "Caught an error parsing '" << argv[i] << "'" << std::endl; std::cout << " " << err.what () << std::endl; continue; } catch ( const boost::exception &berr ) { std::cout << "Caught an boost error parsing '" << argv[i] << "'" << std::endl; // std::cout << " " << berr.what () << std::endl; continue; } try { DumpStructure ( std::cout, argv[i], *rmp, std::string ()); // std::ofstream out ( (std::string ( argv[i] ) + "-Results").c_str (), std::ios::binary ); // out << rmp; } catch ( const std::runtime_error &err ) { std::cout << "Caught an error writing '" << argv[i] << "'" << std::endl; std::cout << " " << err.what () << std::endl; continue; } } return 0; }
static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo ) { int i; char i_back = psz_foo[i_level]; psz_foo[i_level] = '\0'; PrintObject( p_this, psz_foo ); psz_foo[i_level] = i_back; if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH ) { msg_Warn( p_this, "structure tree is too deep" ); return; } for( i = 0 ; i < p_this->i_children ; i++ ) { if( i_level ) { psz_foo[i_level-1] = ' '; if( psz_foo[i_level-2] == '`' ) { psz_foo[i_level-2] = ' '; } } if( i == p_this->i_children - 1 ) { psz_foo[i_level] = '`'; } else { psz_foo[i_level] = '|'; } psz_foo[i_level+1] = '-'; psz_foo[i_level+2] = '\0'; DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo ); } }
static void DumpStructure (vlc_object_t *obj, unsigned level, char *psz_foo) { char back = psz_foo[level]; psz_foo[level] = '\0'; PrintObject (obj, psz_foo); psz_foo[level] = back; if (level / 2 >= MAX_DUMPSTRUCTURE_DEPTH) { msg_Warn (obj, "structure tree is too deep"); return; } vlc_object_internals_t *priv = vlc_internals(obj); /* NOTE: nested locking here (due to recursive call) */ vlc_mutex_lock (&vlc_internals(obj)->tree_lock); for (priv = priv->first; priv != NULL; priv = priv->next) { if (level > 0) { assert(level >= 2); psz_foo[level - 1] = ' '; if (psz_foo[level - 2] == '`') psz_foo[level - 2] = ' '; } psz_foo[level] = priv->next ? '|' : '`'; psz_foo[level + 1] = '-'; psz_foo[level + 2] = '\0'; DumpStructure (vlc_externals(priv), level + 2, psz_foo); } vlc_mutex_unlock (&vlc_internals(obj)->tree_lock); }
/***************************************************************************** * DumpCommand: print the current vlc structure ***************************************************************************** * This function prints either an ASCII tree showing the connections between * vlc objects, and additional information such as their refcount, thread ID, * etc. (command "tree"), or the same data as a simple list (command "list"). *****************************************************************************/ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { if( *psz_cmd == 't' ) { char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1]; vlc_object_t *p_object; if( *newval.psz_string ) { p_object = vlc_object_get( p_this, atoi(newval.psz_string) ); if( !p_object ) { return VLC_ENOOBJ; } } else { p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this; } vlc_mutex_lock( &structure_lock ); psz_foo[0] = '|'; DumpStructure( p_object, 0, psz_foo ); vlc_mutex_unlock( &structure_lock ); if( *newval.psz_string ) { vlc_object_release( p_this ); } } else if( *psz_cmd == 'l' ) { vlc_object_t **pp_current, **pp_end; vlc_mutex_lock( &structure_lock ); pp_current = p_this->p_libvlc->pp_objects; pp_end = pp_current + p_this->p_libvlc->i_objects; for( ; pp_current < pp_end ; pp_current++ ) { if( (*pp_current)->b_attached ) { PrintObject( *pp_current, "" ); } else { printf( " o %.8i %s (not attached)\n", (*pp_current)->i_object_id, (*pp_current)->psz_object_type ); } } vlc_mutex_unlock( &structure_lock ); } return VLC_SUCCESS; }