1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 Antoine Cellerier <dionoea -at- videolan -dot- org>
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 static const struct plugin_api
*rb
;
27 MEM_FUNCTION_WRAPPERS(rb
);
32 static int hash( char *string
, const char *path
)
37 int in
= rb
->open( path
, O_RDONLY
);
38 if( in
< 0 ) return -1;
41 while( ( len
= rb
->read( in
, buffer
, 512 ) ) > 0 )
42 AddMD5( &md5
, buffer
, len
);
45 psz_md5_hash( string
, &md5
);
51 static void hash_file( int out
, const char *path
)
57 char string
[MD5_STRING_LENGTH
+1];
59 rb
->splash( 0, "%d / %d : %s", done
, count
, path
);
60 if( hash( string
, path
) )
61 rb
->write( out
, "error", 5 );
63 rb
->write( out
, string
, MD5_STRING_LENGTH
);
64 rb
->write( out
, " ", 2 );
65 rb
->write( out
, path
, rb
->strlen( path
) );
66 rb
->write( out
, "\n", 1 );
70 static void hash_dir( int out
, const char *path
);
71 static void hash_dir( int out
, const char *path
)
76 dir
= rb
->opendir( path
);
79 while( ( entry
= rb
->readdir( dir
) ) )
81 char childpath
[MAX_PATH
];
82 rb
->snprintf( childpath
, MAX_PATH
, "%s/%s",
83 path
, entry
->d_name
);
84 if( entry
->attribute
& ATTR_DIRECTORY
)
86 if( rb
->strcmp( entry
->d_name
, "." )
87 && rb
->strcmp( entry
->d_name
, ".." ) )
89 /* Got a sub directory */
90 hash_dir( out
, childpath
);
96 hash_file( out
, childpath
);
103 static void hash_list( int out
, const char *path
)
105 int list
= rb
->open( path
, O_RDONLY
);
106 char newpath
[MAX_PATH
];
107 if( list
< 0 ) return;
109 while( rb
->read_line( list
, newpath
, MAX_PATH
) > 0 )
111 DIR *dir
= rb
->opendir( newpath
);
115 hash_dir( out
, newpath
);
119 hash_file( out
, newpath
);
126 static void hash_check( int out
, const char *path
)
128 int list
= rb
->open( path
, O_RDONLY
);
129 char line
[MD5_STRING_LENGTH
+1+MAX_PATH
+1];
131 if( list
< 0 ) return;
133 while( ( len
= rb
->read_line( list
, line
, MD5_STRING_LENGTH
+1+MAX_PATH
+1 ) ) > 0 )
139 const char *filename
= rb
->strchr( line
, ' ' );
141 rb
->splash( 0, "%d / %d : %s", done
, count
, filename
);
142 if( !filename
|| len
< MD5_STRING_LENGTH
+ 2 )
144 const char error
[] = "Malformed input line ... skipping";
145 rb
->write( out
, error
, rb
->strlen( error
) );
149 char string
[MD5_STRING_LENGTH
+1];
150 while( *filename
== ' ' )
152 rb
->write( out
, filename
, rb
->strlen( filename
) );
153 rb
->write( out
, ": ", 2 );
154 if( hash( string
, filename
) )
155 rb
->write( out
, "FAILED open or read", 19 );
156 else if( rb
->strncasecmp( line
, string
, MD5_STRING_LENGTH
) )
157 rb
->write( out
, "FAILED", 6 );
159 rb
->write( out
, "OK", 2 );
161 rb
->write( out
, "\n", 1 );
168 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
170 const char *arg
= (const char *)parameter
; /* input file name, if any */
171 int out
= -1; /* output file descriptor */
172 char filename
[MAX_PATH
]; /* output file name */
174 void (*action
)( int, const char * ) = NULL
;
178 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
179 rb
->cpu_boost( true );
184 const char *ext
= rb
->strrchr( arg
, '.' );
186 rb
->snprintf( filename
, MAX_PATH
, "%s.md5sum", arg
);
190 if( !rb
->strcmp( ext
, ".md5" ) || !rb
->strcmp( ext
, ".md5sum" ) )
192 rb
->snprintf( filename
+ ( ext
- arg
),
193 MAX_PATH
+ rb
->strlen( ext
) - rb
->strlen( arg
),
195 /* Lets check the sums */
198 else if( !rb
->strcmp( ext
, ".md5list" ) ) /* ugly */
200 /* Hash listed files */
207 dir
= rb
->opendir( arg
);
210 api
->closedir( dir
);
212 /* Hash the directory's content recursively */
224 rb
->snprintf( filename
, MAX_PATH
, "/everything.md5sum" );
225 /* Hash the whole filesystem */
230 rb
->lcd_puts( 0, 1, "Output file:" );
231 rb
->lcd_puts( 0, 2, filename
);
237 out
= rb
->open( filename
, O_WRONLY
|O_CREAT
);
238 if( out
< 0 ) return PLUGIN_ERROR
;
241 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
242 rb
->cpu_boost( false );