aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/misc.c34
-rw-r--r--lib/misc.h3
-rw-r--r--lib/rc4.c2
3 files changed, 38 insertions, 1 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 784d80d6..17599946 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -485,3 +485,37 @@ void random_bytes( unsigned char *buf, int count )
buf[i] = rand() & 0xff;
}
}
+
+int is_bool( char *value )
+{
+ if( *value == 0 )
+ return 0;
+
+ if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
+ return 1;
+ if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
+ return 1;
+
+ while( *value )
+ if( !isdigit( *value ) )
+ return 0;
+ else
+ value ++;
+
+ return 1;
+}
+
+int bool2int( char *value )
+{
+ int i;
+
+ if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
+ return 1;
+ if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
+ return 0;
+
+ if( sscanf( value, "%d", &i ) == 1 )
+ return i;
+
+ return 0;
+}
diff --git a/lib/misc.h b/lib/misc.h
index 57ff3e37..b021e642 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -50,4 +50,7 @@ G_MODULE_EXPORT signed int do_iconv( char *from_cs, char *to_cs, char *src, char
G_MODULE_EXPORT void random_bytes( unsigned char *buf, int count );
+G_MODULE_EXPORT int is_bool( char *value );
+G_MODULE_EXPORT int bool2int( char *value );
+
#endif
diff --git a/lib/rc4.c b/lib/rc4.c
index 86b74ef5..5e334507 100644
--- a/lib/rc4.c
+++ b/lib/rc4.c
@@ -164,7 +164,7 @@ int rc4_decode( unsigned char *crypt, int crypt_len, unsigned char **clear, char
if( clear_len < 0 )
{
- *clear = g_strdup( "" );
+ *clear = (unsigned char*) g_strdup( "" );
return 0;
}