2018-02-16 07:53:15 +03:00
# include "replace.h"
# include "util_str_hex.h"
2021-01-24 11:15:29 +03:00
# include "lib/util/data_blob.h"
# include "librpc/gen_ndr/misc.h"
2018-02-16 07:53:15 +03:00
2021-01-24 11:15:29 +03:00
static bool hex_uint16 ( const char * in , uint16_t * out )
2018-02-16 07:53:15 +03:00
{
2021-01-24 11:15:29 +03:00
uint8_t hi = 0 , lo = 0 ;
bool ok = hex_byte ( in , & hi ) & & hex_byte ( in + 2 , & lo ) ;
* out = ( ( ( uint16_t ) hi ) < < 8 ) + lo ;
return ok ;
2018-02-16 07:53:15 +03:00
}
2021-01-24 11:15:29 +03:00
bool hex_uint32 ( const char * in , uint32_t * out )
{
uint16_t hi = 0 , lo = 0 ;
bool ok = hex_uint16 ( in , & hi ) & & hex_uint16 ( in + 4 , & lo ) ;
* out = ( ( ( uint32_t ) hi ) < < 16 ) + lo ;
return ok ;
}
2018-02-16 07:53:15 +03:00
2021-01-24 11:15:29 +03:00
bool parse_guid_string ( const char * s , struct GUID * guid )
2018-02-16 07:53:15 +03:00
{
2021-01-24 11:15:29 +03:00
bool ok ;
2018-02-16 07:53:15 +03:00
int i ;
/* "e12b56b6-0a95-11d1-adbb-00c04fd8d5cd"
| | | | |
| | | | \ node [ 6 ]
| | | \ _____ clock_seq [ 2 ]
| | \ __________ time_hi_and_version
| \ _______________ time_mid
\ _____________________ time_low
*/
2021-01-24 11:15:29 +03:00
ok = hex_uint32 ( s , & guid - > time_low ) ;
if ( ! ok | | ( s [ 8 ] ! = ' - ' ) ) {
return false ;
2018-02-16 07:53:15 +03:00
}
s + = 9 ;
2021-01-24 11:15:29 +03:00
ok = hex_uint16 ( s , & guid - > time_mid ) ;
if ( ! ok | | ( s [ 4 ] ! = ' - ' ) ) {
return false ;
2018-02-16 07:53:15 +03:00
}
s + = 5 ;
2021-01-24 11:15:29 +03:00
ok = hex_uint16 ( s , & guid - > time_hi_and_version ) ;
if ( ! ok | | ( s [ 4 ] ! = ' - ' ) ) {
return false ;
2018-02-16 07:53:15 +03:00
}
s + = 5 ;
2021-01-24 11:15:29 +03:00
ok = hex_byte ( s , & guid - > clock_seq [ 0 ] ) & &
hex_byte ( s + 2 , & guid - > clock_seq [ 1 ] ) ;
if ( ! ok | | ( s [ 4 ] ! = ' - ' ) ) {
return false ;
2018-02-16 07:53:15 +03:00
}
2021-01-24 11:15:29 +03:00
s + = 5 ;
2018-02-16 07:53:15 +03:00
for ( i = 0 ; i < 6 ; i + + ) {
2021-01-24 11:15:29 +03:00
ok = hex_byte ( s , & guid - > node [ i ] ) ;
if ( ! ok ) {
return false ;
2018-02-16 07:53:15 +03:00
}
s + = 2 ;
}
2021-01-24 11:15:29 +03:00
return true ;
2018-02-16 07:53:15 +03:00
}