2010-02-14 08:45:14 +00:00
/* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens
Copyright ( c ) 2006 - 2010 Thomas Schmitt < scdbackup @ gmx . net >
Provided under GPL version 2 or later .
*/
2010-05-16 09:07:42 +00:00
# ifdef HAVE_CONFIG_H
# include "../config.h"
# endif
2006-10-30 05:32:33 +00:00
# include <string.h>
/* ts A61008 */
/* #include <a ssert.h> */
# include <stdlib.h>
2009-09-02 13:32:17 +00:00
# include <stdio.h>
2008-09-14 17:45:11 +00:00
/* ts A80914 : This is unneeded. Version info comes from libburn.h.
# include "v ersion.h"
*/
2006-10-30 05:32:33 +00:00
# include "util.h"
# include "libburn.h"
char * burn_strdup ( char * s )
{
char * ret ;
int l ;
/* ts A61008 */
/* a ssert(s); */
if ( s = = NULL )
return NULL ;
l = strlen ( s ) + 1 ;
2010-07-12 19:37:31 +00:00
ret = calloc ( 1 , l ) ;
2006-10-30 05:32:33 +00:00
memcpy ( ret , s , l ) ;
return ret ;
}
char * burn_strndup ( char * s , int n )
{
char * ret ;
int l ;
/* ts A61008 */
/* a ssert(s); */
/* a ssert(n > 0); */
if ( s = = NULL | | n < = 0 )
return NULL ;
l = strlen ( s ) ;
2010-07-12 19:37:31 +00:00
ret = calloc ( 1 , l < n ? l : n ) ;
2006-10-30 05:32:33 +00:00
memcpy ( ret , s , l < n - 1 ? l : n - 1 ) ;
ret [ n - 1 ] = ' \0 ' ;
return ret ;
}
void burn_version ( int * major , int * minor , int * micro )
{
2008-04-08 13:35:43 +00:00
/* ts A80408 : switched from configure.ac versioning to libburn.h versioning */
2008-09-14 17:45:11 +00:00
* major = burn_header_version_major ;
* minor = burn_header_version_minor ;
* micro = burn_header_version_micro ;
2006-10-30 05:32:33 +00:00
}
2009-09-02 13:32:17 +00:00
2009-09-04 20:21:55 +00:00
struct cd_mid_record {
2009-09-02 13:32:17 +00:00
char * manufacturer ;
int m_li ;
int s_li ;
int f_li ;
int m_lo ;
int s_lo ;
int f_lo ;
char * other_brands ;
} ;
2009-09-04 20:21:55 +00:00
typedef struct cd_mid_record cd_mid_record_t ;
2009-09-02 13:32:17 +00:00
/* ts A90902 */
/** API
@ param flag Bitfield for control purposes ,
bit0 = append " (aka %s) " , other_brands to reply
*/
char * burn_guess_cd_manufacturer ( int m_li , int s_li , int f_li ,
int m_lo , int s_lo , int f_lo , int flag )
{
2009-09-04 20:21:55 +00:00
static cd_mid_record_t mid_list [ ] = {
2009-09-02 13:32:17 +00:00
{ " SKC " , 96 , 40 , 0 , 0 , 0 , 0 , " " } ,
{ " Ritek Corp " , 96 , 43 , 30 , 0 , 0 , 0 , " " } ,
{ " TDK / Ritek " , 97 , 10 , 0 , 0 , 0 , 0 , " TRAXDATA " } ,
{ " TDK Corporation " , 97 , 15 , 0 , 0 , 0 , 0 , " " } ,
{ " Ritek Corp " , 97 , 15 , 10 , 0 , 0 , 0 , " 7-plus, Aopen, PONY, Power Source, TDK, TRAXDATA, HiCO, PHILIPS, Primdisc, Victor.JVC, OPTI STORAGE, Samsung " } ,
{ " Mitsubishi Chemical Corporation " , 97 , 15 , 20 , 0 , 0 , 0 , " " } ,
{ " Nan-Ya Plastics Corporation " , 97 , 15 , 30 , 0 , 0 , 0 , " Hatron, MMore, Acer, LITEON " } ,
{ " Delphi " , 97 , 15 , 50 , 0 , 0 , 0 , " " } ,
{ " Shenzhen SG&SAST " , 97 , 16 , 20 , 0 , 0 , 0 , " " } ,
{ " Moser Baer India Limited " , 97 , 17 , 0 , 0 , 0 , 0 , " EMTEC, Intenso, YAKUMO, PLATINUM, Silver Circle " } ,
{ " SKY media Manufacturing SA " , 97 , 17 , 10 , 0 , 0 , 0 , " " } ,
{ " Wing " , 97 , 18 , 10 , 0 , 0 , 0 , " " } ,
{ " DDT " , 97 , 18 , 20 , 0 , 0 , 0 , " " } ,
{ " Daxon Technology Inc. / Acer " , 97 , 22 , 60 , 0 , 0 , 0 , " Maxmax, Diamond Data, BenQ, gold, SONY " } ,
{ " Taiyo Yuden Company Limited " , 97 , 24 , 0 , 0 , 0 , 0 , " Maxell, FUJIFILM, SONY " } ,
{ " Sony Corporation " , 97 , 24 , 10 , 0 , 0 , 0 , " LeadData, Imation " } ,
{ " Computer Support Italcard s.r.l " , 97 , 24 , 20 , 0 , 0 , 0 , " " } ,
{ " Unitech Japan Inc. " , 97 , 24 , 30 , 0 , 0 , 0 , " " } ,
2009-09-04 20:21:55 +00:00
{ " MPO, France " , 97 , 25 , 0 , 0 , 0 , 0 , " TDK " } ,
2009-09-02 13:32:17 +00:00
{ " Hitachi Maxell Ltd. " , 97 , 25 , 20 , 0 , 0 , 0 , " " } ,
{ " Infodisc Technology Co,Ltd. " , 97 , 25 , 30 , 0 , 0 , 0 , " MEMOREX, SPEEDA, Lead data " } ,
{ " Xcitec " , 97 , 25 , 60 , 0 , 0 , 0 , " " } ,
{ " Fornet International Pte Ltd " , 97 , 26 , 0 , 0 , 0 , 0 , " COMPUSA, Cdhouse " } ,
{ " Postech Corporation " , 97 , 26 , 10 , 0 , 0 , 0 , " Mr.Platinum " } ,
{ " SKC Co Ltd. " , 97 , 26 , 20 , 0 , 0 , 0 , " Infinite " } ,
{ " Fuji Photo Film Co,Ltd. " , 97 , 26 , 40 , 0 , 0 , 0 , " " } ,
{ " Lead Data Inc. " , 97 , 26 , 50 , 0 , 0 , 0 , " SONY, Gigastorage, MIRAGE " } ,
{ " CMC Magnetics Corporation " , 97 , 26 , 60 , 0 , 0 , 0 , " Daxon, Verbatim, Memorex, Bi-Winner, PLEXTOR, YAMAHA, Melody, Office DEPOT, Philips, eMARK, imation, HyperMedia, Samsung, Shintaro, Techworks " } ,
{ " Ricoh Company Limited " , 97 , 27 , 0 , 0 , 0 , 0 , " Sony, Digital Storage, Csita " } ,
{ " Plasmon Data Systems Ltd " , 97 , 27 , 10 , 0 , 0 , 0 , " Ritek, TDK, EMTEC, ALPHAPET, MANIA " } ,
{ " Princo Corporation " , 97 , 27 , 20 , 0 , 0 , 0 , " " } ,
{ " Pioneer " , 97 , 27 , 30 , 0 , 0 , 0 , " " } ,
{ " Eastman Kodak Company " , 97 , 27 , 40 , 0 , 0 , 0 , " " } ,
{ " Mitsui Chemicals Inc. " , 97 , 27 , 50 , 0 , 0 , 0 , " MAM-A, TDK " } ,
{ " Ricoh Company Limited " , 97 , 27 , 60 , 0 , 0 , 0 , " Ritek " } ,
{ " Gigastorage Corporation " , 97 , 28 , 10 , 0 , 0 , 0 , " MaxMax, Nan-Ya " } ,
{ " Multi Media Masters&Machinary SA " , 97 , 28 , 20 , 0 , 0 , 0 , " King, Mmirex " } ,
{ " Ritek Corp " , 97 , 31 , 0 , 0 , 0 , 0 , " TDK " } ,
{ " Grand Advance Technology Sdn. Bhd. " , 97 , 31 , 30 , 0 , 0 , 0 , " " } ,
{ " TDK Corporation " , 97 , 32 , 00 , 0 , 0 , 0 , " " } ,
{ " Prodisc Technology Inc. " , 97 , 32 , 10 , 0 , 0 , 0 , " Smartbuy, Mitsubishi, Digmaster, LG, Media Market " } ,
{ " Mitsubishi Chemical Corporation " , 97 , 34 , 20 , 0 , 0 , 0 , " YAMAHA, Verbatim " } ,
2009-09-04 20:21:55 +00:00
{ " Mitsui Chemicals Inc. " , 97 , 48 , 50 , 0 , 0 , 0 , " " } ,
{ " TDK Corporation " , 97 , 49 , 0 , 0 , 0 , 0 , " " } ,
2009-09-02 13:32:17 +00:00
{ " " , 0 , 0 , 0 , 0 , 0 , 0 , " " }
} ;
int i , f_li_0 ;
char buf [ 1024 ] ;
char * result = NULL ;
2010-05-01 08:29:28 +00:00
if ( m_li = = 0 & & s_li = = 2 & & f_li = = 0 ) {
result = strdup ( " (no manufacturer code) " ) ;
return result ;
}
2009-09-02 13:32:17 +00:00
f_li_0 = f_li - ( f_li % 10 ) ;
for ( i = 0 ; mid_list [ i ] . manufacturer [ 0 ] ; i + + ) {
if ( m_li = = mid_list [ i ] . m_li & &
s_li = = mid_list [ i ] . s_li & &
( f_li_0 = = mid_list [ i ] . f_li | | f_li = = mid_list [ i ] . f_li ) )
break ;
}
if ( mid_list [ i ] . manufacturer [ 0 ] = = 0 ) {
2009-09-04 20:21:55 +00:00
sprintf ( buf , " Unknown CD manufacturer. Please report code '%2.2dm%2.2ds%2.2df/%2.2dm%2.2ds%2.2df', the human readable brand, size, and speed to scdbackup@gmx.net. " , m_li , s_li , f_li , m_lo , s_lo , f_lo ) ;
2009-09-02 13:32:17 +00:00
result = strdup ( buf ) ;
return result ;
}
/* Compose, allocate and copy result */
if ( ( flag & 1 ) & & mid_list [ i ] . other_brands [ 0 ] ) {
sprintf ( buf , " %s (aka %s) " ,
mid_list [ i ] . manufacturer , mid_list [ i ] . other_brands ) ;
result = strdup ( buf ) ;
} else
result = strdup ( mid_list [ i ] . manufacturer ) ;
return result ;
}
2009-09-04 20:21:55 +00:00
/* ts A90904 */
struct dvd_mid_record {
char * mc1 ;
char * mc2 ;
int mc1_sig_len ;
char * manufacturer ;
} ;
typedef struct dvd_mid_record dvd_mid_record_t ;
/* ts A90904 */
char * burn_guess_manufacturer ( int prf ,
char * media_code1 , char * media_code2 , int flag )
{
int i , l = 0 , m_li , s_li , f_li , m_lo , s_lo , f_lo ;
char buf [ 1024 ] ;
char * result = NULL , * cpt ;
2009-09-05 11:29:44 +00:00
/* Important Note: media_code1 and media_code2 are supposed to be
encoded by burn_util_make_printable_word ( ) .
Especially : ' ' - > ' _ ' , { " _%/ " unprintables - > % XY )
*/
2009-09-04 20:21:55 +00:00
static dvd_mid_record_t mid_list [ ] = {
{ " AML " , " " , 8 , " UML " } ,
{ " BeAll " , " " , 5 , " BeAll Developers, Inc. " } ,
{ " CMC " , " " , 3 , " CMC Magnetics Corporation " } ,
{ " DAXON " , " " , 5 , " Daxon Technology Inc. / Acer " } ,
{ " Daxon " , " " , 5 , " Daxon Technology Inc. / Acer " } ,
{ " FUJI " , " " , 4 , " Fujifilm Holdings Corporation " } ,
{ " INFODISC " , " " , 8 , " New Star Digital Co., Ltd. " } ,
{ " INFOME " , " " , 6 , " InfoMedia Inc. " } ,
{ " ISMMBD " , " " , 6 , " Info Source Multi Media Ltd. " } ,
{ " JVC " , " " , 3 , " JVC Limited " } ,
{ " KIC01RG " , " " , 7 , " AMC " } ,
{ " LD " , " " , 8 , " Lead Data Inc. " } ,
{ " LGE " , " " , 3 , " LG Electronics " } ,
{ " MAM " , " " , 8 , " Mitsui Advanced Media, Inc. Europe " } ,
{ " MAXELL " , " " , 6 , " Hitachi Maxell Ltd. " } ,
{ " MBI " , " " , 3 , " Moser Baer India Limited " } ,
{ " MCC " , " " , 8 , " Mitsubishi Chemical Corporation " } ,
{ " MCI " , " " , 8 , " Mitsui Chemicals Inc. " } ,
{ " MEI " , " " , 3 , " Panasonic Corporation " } ,
{ " MKM " , " " , 3 , " Mitsubishi Kagaku Media Co. " } ,
{ " MMC " , " " , 8 , " Mitsubishi Kagaku Media Co. " } ,
{ " MXL " , " " , 8 , " Hitachi Maxell Ltd. " } ,
{ " NANYA " , " " , 5 , " Nan-Ya Plastics Corporation " } ,
{ " NSD " , " " , 8 , " NESA International Inc. " } ,
{ " OPTODISC " , " " , 8 , " Optodisc Technology Corporation " } ,
{ " OTCBDR " , " " , 8 , " Optodisc Technology Corporation " } ,
{ " PHILIP " , " " , 8 , " Moser Baer India Limited " } ,
{ " PHILIPS " , " " , 8 , " Philips " } ,
{ " PRINCO " , " " , 6 , " Princo Corporation " } ,
{ " PRODISC " , " " , 7 , " Prodisc Technology Inc. " } ,
{ " Prodisc " , " " , 7 , " Prodisc Technology Inc. " } ,
{ " PVC " , " " , 3 , " Pioneer " } ,
{ " RICOHJPN " , " " , 8 , " Ricoh Company Limited " } ,
{ " RITEK " , " " , 5 , " Ritek Corp " } ,
{ " SONY " , " " , 4 , " Sony Corporation " } ,
{ " TDK " , " " , 3 , " TDK Corporation " } ,
{ " TT " , " " , 8 , " TDK Corporation " } ,
{ " TY " , " " , 8 , " Taiyo Yuden Company Limited " } ,
{ " TYG " , " " , 3 , " Taiyo Yuden Company Limited " } ,
{ " UTJR001 " , " " , 7 , " Unifino Inc. " } ,
{ " VERBAT " , " " , 5 , " Mitsubishi Kagaku Media Co. " } ,
{ " YUDEN " , " " , 5 , " Taiyo Yuden Company Limited " } ,
{ " " , " " , 0 , " " }
} ;
if ( media_code2 ! = NULL & &
( prf = = - 1 | | prf = = 0x09 | | prf = = 0x0A ) ) {
2009-09-06 09:22:26 +00:00
if ( strlen ( media_code2 ) = = 9 & & media_code1 [ 0 ] = = ' 9 ' & &
media_code1 [ 2 ] = = ' m ' & & media_code1 [ 5 ] = = ' s ' & &
media_code1 [ 8 ] = = ' f ' & &
strchr ( media_code1 , ' % ' ) = = NULL ) {
2009-09-04 20:21:55 +00:00
sscanf ( media_code1 , " %dm%ds%df " , & m_li , & s_li , & f_li ) ;
sscanf ( media_code2 , " %dm%ds%df " , & m_lo , & s_lo , & f_lo ) ;
if ( m_li > = 96 & & m_li < = 97 & & m_lo > 0 ) {
result = burn_guess_cd_manufacturer (
m_li , s_li , f_li , m_lo , s_lo , f_lo , 0 ) ;
return result ;
}
}
}
/* DVD-R do not keep manufacturer id apart from media id.
2009-09-05 11:29:44 +00:00
Some manufacturers use a blank as separator which would now be ' _ ' .
2009-09-04 20:21:55 +00:00
*/
2009-09-05 11:29:44 +00:00
cpt = strchr ( media_code1 , ' _ ' ) ;
2009-09-04 20:21:55 +00:00
if ( cpt ! = NULL & & ( prf = = - 1 | | prf = = 0x11 | | prf = = 0x13 | |
prf = = 0x14 | | prf = = 0x15 ) )
l = cpt - media_code1 ;
for ( i = 0 ; mid_list [ i ] . mc1 [ 0 ] ; i + + ) {
if ( strncmp ( mid_list [ i ] . mc1 , media_code1 ,
mid_list [ i ] . mc1_sig_len ) = = 0 )
break ;
if ( l > 0 )
if ( strncmp ( mid_list [ i ] . mc1 , media_code1 , l ) = = 0 )
break ;
}
if ( mid_list [ i ] . mc1 [ 0 ] = = 0 ) {
sprintf ( buf , " Unknown DVD/BD manufacturer. Please report code '%s/%s', the human readable brand, size, and speed to scdbackup@gmx.net. " ,
media_code1 , media_code2 ) ;
result = strdup ( buf ) ;
return result ;
}
result = strdup ( mid_list [ i ] . manufacturer ) ;
return result ;
}
2009-09-05 11:29:44 +00:00
/* ts A90905 */
2009-09-06 09:22:26 +00:00
/* Make *text a single printable word */
2009-09-05 11:29:44 +00:00
/* IMPORTANT: text must be freeable memory !
@ param flag bit0 = escape ' / ' too
2009-09-06 09:22:26 +00:00
bit1 = ( overrides bit0 ) do not escape " _/ "
2009-09-05 11:29:44 +00:00
*/
int burn_util_make_printable_word ( char * * text , int flag )
{
int i , esc_add = 0 , ret ;
char * wpt , * rpt , * new_text = NULL ;
2009-09-06 09:22:26 +00:00
if ( flag & 2 )
flag & = ~ 1 ;
2009-09-05 11:29:44 +00:00
for ( i = 0 ; ( * text ) [ i ] ; i + + ) {
rpt = ( * text ) + i ;
2009-09-06 09:22:26 +00:00
if ( * rpt < 32 | | * rpt > 126 | | * rpt = = 96 | |
( ( * rpt = = ' _ ' | | * rpt = = ' % ' ) & & ( ! ( flag & 2 ) ) ) | |
( * rpt = = ' / ' & & ( flag & 1 ) ) )
2009-09-05 11:29:44 +00:00
esc_add + = 2 ;
}
if ( esc_add ) {
new_text = calloc ( strlen ( * text ) + esc_add + 1 , 1 ) ;
if ( new_text = = NULL ) {
ret = - 1 ;
goto ex ;
}
wpt = new_text ;
for ( i = 0 ; ( * text ) [ i ] ; i + + ) {
rpt = ( * text ) + i ;
2009-09-06 09:22:26 +00:00
if ( * rpt < 32 | | * rpt > 126 | | * rpt = = 96 | |
( ( * rpt = = ' _ ' | | * rpt = = ' % ' ) & & ( ! ( flag & 2 ) ) ) | |
( * rpt = = ' / ' & & ( flag & 1 ) ) ) {
2009-09-05 11:29:44 +00:00
sprintf ( wpt , " %%%2.2X " ,
( unsigned int ) * ( ( unsigned char * ) rpt ) ) ;
wpt + = 3 ;
} else
* ( wpt + + ) = * rpt ;
}
* wpt = 0 ;
free ( * text ) ;
* text = new_text ;
}
2009-09-06 09:22:26 +00:00
if ( ! ( flag & 2 ) )
for ( i = 0 ; ( * text ) [ i ] ; i + + )
if ( ( * text ) [ i ] = = ' ' )
( * text ) [ i ] = ' _ ' ;
2009-09-05 11:29:44 +00:00
ret = 1 ;
ex :
return ret ;
}