summaryrefslogtreecommitdiffstats
path: root/tinySAK/src
diff options
context:
space:
mode:
Diffstat (limited to 'tinySAK/src')
-rwxr-xr-xtinySAK/src/tinysak_config.h20
-rwxr-xr-xtinySAK/src/tsk.c48
-rwxr-xr-xtinySAK/src/tsk.h6
-rwxr-xr-xtinySAK/src/tsk_base64.c279
-rwxr-xr-xtinySAK/src/tsk_base64.h6
-rwxr-xr-xtinySAK/src/tsk_binaryutils.c6
-rwxr-xr-xtinySAK/src/tsk_binaryutils.h84
-rwxr-xr-xtinySAK/src/tsk_buffer.c375
-rwxr-xr-xtinySAK/src/tsk_buffer.h15
-rwxr-xr-xtinySAK/src/tsk_common.h6
-rwxr-xr-xtinySAK/src/tsk_condwait.c273
-rwxr-xr-xtinySAK/src/tsk_condwait.h6
-rwxr-xr-xtinySAK/src/tsk_debug.c72
-rwxr-xr-xtinySAK/src/tsk_debug.h14
-rwxr-xr-xtinySAK/src/tsk_errno.h6
-rwxr-xr-xtinySAK/src/tsk_fsm.c411
-rwxr-xr-xtinySAK/src/tsk_fsm.h44
-rwxr-xr-xtinySAK/src/tsk_hmac.c224
-rwxr-xr-xtinySAK/src/tsk_hmac.h6
-rwxr-xr-xtinySAK/src/tsk_list.c742
-rwxr-xr-xtinySAK/src/tsk_list.h30
-rwxr-xr-xtinySAK/src/tsk_md5.c55
-rwxr-xr-xtinySAK/src/tsk_md5.h15
-rwxr-xr-xtinySAK/src/tsk_memory.c120
-rwxr-xr-xtinySAK/src/tsk_memory.h6
-rwxr-xr-xtinySAK/src/tsk_mutex.c139
-rwxr-xr-xtinySAK/src/tsk_mutex.h6
-rwxr-xr-xtinySAK/src/tsk_object.c224
-rwxr-xr-xtinySAK/src/tsk_object.h45
-rwxr-xr-xtinySAK/src/tsk_options.c163
-rwxr-xr-xtinySAK/src/tsk_options.h21
-rwxr-xr-xtinySAK/src/tsk_params.c345
-rwxr-xr-xtinySAK/src/tsk_params.h21
-rwxr-xr-xtinySAK/src/tsk_plugin.c254
-rwxr-xr-xtinySAK/src/tsk_plugin.h44
-rwxr-xr-xtinySAK/src/tsk_ppfcs16.c81
-rwxr-xr-xtinySAK/src/tsk_ppfcs16.h6
-rwxr-xr-xtinySAK/src/tsk_ppfcs32.c147
-rwxr-xr-xtinySAK/src/tsk_ppfcs32.h6
-rwxr-xr-xtinySAK/src/tsk_ragel_state.c12
-rwxr-xr-xtinySAK/src/tsk_ragel_state.h19
-rwxr-xr-xtinySAK/src/tsk_runnable.c341
-rwxr-xr-xtinySAK/src/tsk_runnable.h66
-rwxr-xr-xtinySAK/src/tsk_safeobj.c6
-rwxr-xr-xtinySAK/src/tsk_safeobj.h6
-rwxr-xr-xtinySAK/src/tsk_semaphore.c148
-rwxr-xr-xtinySAK/src/tsk_semaphore.h6
-rwxr-xr-xtinySAK/src/tsk_sha1.c186
-rwxr-xr-xtinySAK/src/tsk_sha1.h16
-rwxr-xr-xtinySAK/src/tsk_string.c529
-rwxr-xr-xtinySAK/src/tsk_string.h15
-rwxr-xr-xtinySAK/src/tsk_thread.c140
-rwxr-xr-xtinySAK/src/tsk_thread.h10
-rwxr-xr-xtinySAK/src/tsk_time.c184
-rwxr-xr-xtinySAK/src/tsk_time.h6
-rwxr-xr-xtinySAK/src/tsk_timer.c596
-rwxr-xr-xtinySAK/src/tsk_timer.h6
-rwxr-xr-xtinySAK/src/tsk_url.c78
-rwxr-xr-xtinySAK/src/tsk_url.h6
-rwxr-xr-xtinySAK/src/tsk_uuid.c74
-rwxr-xr-xtinySAK/src/tsk_uuid.h6
-rwxr-xr-xtinySAK/src/tsk_xml.c306
-rwxr-xr-xtinySAK/src/tsk_xml.h100
63 files changed, 3614 insertions, 3619 deletions
diff --git a/tinySAK/src/tinysak_config.h b/tinySAK/src/tinysak_config.h
index 4e40556..629dc07 100755
--- a/tinySAK/src/tinysak_config.h
+++ b/tinySAK/src/tinysak_config.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -88,7 +88,7 @@
# define TSK_BEGIN_DECLS extern "C" {
# define TSK_END_DECLS }
#else
-# define TSK_BEGIN_DECLS
+# define TSK_BEGIN_DECLS
# define TSK_END_DECLS
#endif
@@ -97,7 +97,7 @@
#elif defined(__GNUC__) && !defined(__APPLE__)
# define TSK_INLINE __inline
#else
-# define TSK_INLINE
+# define TSK_INLINE
#endif
@@ -111,11 +111,11 @@
/* Features */
#if !defined (HAVE_GETTIMEOFDAY)
- #if TSK_UNDER_WINDOWS
- # define HAVE_GETTIMEOFDAY 0
- #else
- # define HAVE_GETTIMEOFDAY 1
- #endif
+#if TSK_UNDER_WINDOWS
+# define HAVE_GETTIMEOFDAY 0
+#else
+# define HAVE_GETTIMEOFDAY 1
+#endif
#endif /* HAVE_GETTIMEOFDAY */
#if ANDROID
diff --git a/tinySAK/src/tsk.c b/tinySAK/src/tsk.c
index 195ec96..672cf2d 100755
--- a/tinySAK/src/tsk.c
+++ b/tinySAK/src/tsk.c
@@ -5,19 +5,19 @@
*
* @section LICENSE
*
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -79,14 +79,14 @@ tsk_object_def_t;
* Below, an example of how to declare an object definition:<br>
* @code
* //(Object defnition)
- static const tsk_object_def_t person_def_t =
+ static const tsk_object_def_t person_def_t =
{
sizeof(person_t),
person_ctor,
person_dtor,
person_cmp
};
-* @endcode
+* @endcode
* <h2>6.2 Constructor</h2>
* The constructor is only responsible for the initialization and won’t allocate the object. When passed to the constructor, the object is already allocated.<br>
* Here is an example:<br>
@@ -100,14 +100,14 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
}
return self;
}
-* @endcode
+* @endcode
* <h2>6.3 Destructor</h2>
* The destructor will free the object’s members and won’t destroy the object itself (Phase 1). The destructor function must return a pointer to itself to allow the caller to perform the second phase.<br>
* Here is an example:<br>
* @code
// (destructor)
static tsk_object_t * person_dtor(tsk_object_t * self)
- {
+ {
person_t *person = self;
if(person){
TSK_FREE(person->name);
@@ -115,7 +115,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
}
return self;
}
-* @endcode
+* @endcode
* <h2>6.4 Comparator</h2>
* The comparator function is used to compare two well-defined objects. The objects to compare shall have the same definition (or type). <br>
* Here is an example:<br>
@@ -126,7 +126,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2)
const person_t *p1 = _p1;
const person_t *p1 = _p2;
int ret;
-
+
// do they have the same name?
if((ret = tsk_stricmp(p1->name, p2->name))){
return ret;
@@ -135,7 +135,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2)
if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))){
return ret;
}
-
+
// they are the same
return 0;
}
@@ -144,7 +144,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2)
* Reference counting is used to emulate garbage collection. Each well-defined object contains a reference counter field which indicates how many object have a reference to the actual object.<br>
* When an object is created (see below) the counter value is initialized to 1; this is automatically done and you have nothing to do. The counter is incremented by 1 when you call @ref tsk_object_ref() and decremented (by 1) when you call @ref tsk_object_unref().<br>
* When the counter value reaches zero, then the object is garbaged (freed).<br>
-*
+*
* <h2>6.6 Inheritence</h2>
* As you expect, inheritance is not supported in ANSI-C. <br>
* As any C Structure could be casted to a pointer to its first element, inheritance could be achieved like this:<br>
@@ -163,7 +163,7 @@ student_t* s = tsk_null;
//....
((person_t*)s)->name = tsk_strdup("bob");
* @endcode
-*
+*
* As @code person_t is a well-defined object, then @code student_t is also well-defined.<br>
* <h2>6.7 Usage</h2>
* Once the object’s definition is declared and all its mandatory functions implemented, it is used like this:<br>
@@ -180,7 +180,7 @@ tsk_object_unref(bob);
// create a person
#define PERSON_CREATE(name) tsk_object_new(&person_def_t, (const char*)name)
* @endcode
-*
+*
* As the destructor has fixed parameters, there is a common macro to destroy all kind of well-defined objects. <br>
* TSK_OBJECT_SAFE_FREE() is used to destroy any object. <br>
* The object will be freed only if; when decremented by 1 the reference count of the object is equal to zero. In all case (freed or not) the pointer value will be set to NULL.<br>
@@ -200,7 +200,7 @@ TSK_OBJECT_SAFE_FREE(bob);
*
* <h2>7 Threading</h2>
* The framework provides an operating system agnostic threading functions for both WIN32 and Unix-like systems.<br>
-*
+*
* <h2>7.1 Threads</h2>
* You don’t need thousands of functions to manage threads. In the Framework we only need to create, pause and destroy threads.<br>
* Threads can be created using @ref tsk_thread_create() and joined using @ref tsk_thread_join().<br>
@@ -218,7 +218,7 @@ void test_threads()
{
void* tid[1] = {tsk_null}; // thread id
int arg = 112; // arg to pass to the function
-
+
// creates the thread
tsk_thread_create(&tid[0], MyThreadFunction, &arg);
@@ -226,7 +226,7 @@ void test_threads()
tsk_thread_join(&(tid[0]));
}
* @endcode
-*
+*
* <h2>7.2 Mutexes</h2>
* Mutexes (Mutual exclusion) are used to protect a portion of code or function against concurrent access. Concurrent access happens when two or several threads try to execute the same portion of code at nearly the same time.<br>
* @code
@@ -234,7 +234,7 @@ void test_threads()
// create the mutext
tsk_mutex_handle_t *mutex = tsk_mutex_create();
-
+
tsk_mutex_lock(mutex);
// ...portion of code to protect
tsk_mutex_unlock(mutex);
@@ -243,12 +243,12 @@ tsk_mutex_unlock(mutex);
tsk_mutex_destroy(&mutex);
* @endcode
* Mutexes are not well-defined objects; you should use @ref tsk_mutex_destroy instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br>
-*
+*
* <h2>7.3 Thread-Safe Objects</h2>
-*
+*
* Any C Structure could be declared as thread-safe using @ref TSK_DECLARE_SAFEOBJ macro. It’s not mandatory for the object to be well-defined.<br>
* A thread-safe object is initialized using @ref tsk_safeobj_init() and deinitilized using @ref tsk_safeobj_deinit(). To lock and unlock a portion of code which accesses the object you should use @ref tsk_safeobj_lock() and @ref tsk_safeobj_unlock() respectively.<br>
-*
+*
* <h2>7.4 Semaphores</h2>
* Only counting semaphores are supported by the framework.
* Counting semaphores are used to control the access to a portion of code which might be executed by multiple threads. A thread will have rights to execute the portion of code only if the semaphore’s internal counter value is different than zero. Before executing the code to control, a thread should decrement the counter to check if it has permit.<br>
@@ -266,19 +266,19 @@ tsk_semaphore_destroy(&sem);
* @endcode
* Semaphores are not well-defined objects; you should use @ref tsk_semaphore_destroy instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br>
* Mutexes are binary semaphores (counter value is always equals to 1 or 0).<br>
-*
+*
* <h2>7.5 Condition Variables</h2>
* Condition variables are used to control the access to a portion of code which might be executed by multiple threads. Each thread will block until a certain condition is signaled or ms milliseconds have passed.<br>
* @ref tsk_condwait_create is used to create a condition variable, @ref tsk_condwait_wait() to wait indefinitely until the condition is signaled and @ref tsk_condwait_timedwait() to wait until the condition is signaled or ms milliseconds have passed.<br>
* @ref tsk_condwait_signal() is used to alert the first waiting thread that the condition is now true and @ref tsk_condwait_broadcast() is used to alert all waiting threads.<br>
* Condition variables are not well-defined objects; you should use @ref tsk_condwait_destroy() instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br>
-*
+*
* <h2>7.6 Runnable</h2>
* A <i>runnable</i> object is a well-defined object and is declared using @ref TSK_DECLARE_RUNNABLE() macro.<br>
* A <i>runnable</i> object must be explicitly started using @ref tsk_runnable_start() and is implicitly stopped when destroyed. You can explicitly stop the object by calling @ref tsk_runnable_stop().<br>
-*
+*
* <h2>8 Final Sate Machine</h2>
-*
+*
* <h2>9 Timer Manager</h2>
*
*/
diff --git a/tinySAK/src/tsk.h b/tinySAK/src/tsk.h
index 93e7e1b..2cd0c19 100755
--- a/tinySAK/src/tsk.h
+++ b/tinySAK/src/tsk.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_base64.c b/tinySAK/src/tsk_base64.c
index b10fac0..5c06b4a 100755
--- a/tinySAK/src/tsk_base64.c
+++ b/tinySAK/src/tsk_base64.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -70,7 +70,7 @@
* Encodes arbitrary data into base64 format.
* @param input The input data to encode in base64 format.
* @param input_size The size of the @a input data.
-* @param output A pointer where to copy the encoded data.
+* @param output A pointer where to copy the encoded data.
* If you don't know what will be the size of the output result then set the pointer value to NULL to let the function allocate it of you.
* In all case it is up to you to free the @a ouput.
* You can also use @ref TSK_BASE64_ENCODE_LEN to allocate the buffer before calling this method.
@@ -79,72 +79,72 @@
*/
tsk_size_t tsk_base64_encode(const uint8_t* input, tsk_size_t input_size, char **output)
{
- static const char* TSK_BASE64_ENCODE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
- /*=================================================================================
- content T S K
- ASCII 0x54 0x53 0x4B
- Binary 0101 0100 0101 0011 0100 1011
- ------------------------------------------------------------------------------
- ------------------------------------------------------------------------------
- Packs of 6bits 010101 000101 001101 001011
- Indexes 21 5 13 11
- Base64 encoded V F N L <=== HERE IS THE RESULT OF tsk_base64_encode("TSK")
- */
-
- tsk_size_t i = 0;
- tsk_size_t output_size = 0;
-
- /* Caller provided his own buffer? */
- if (!*output) {
- *output = (char*)tsk_calloc((TSK_BASE64_ENCODE_LEN(input_size) + 1), sizeof(char));
- }
-
- /* Too short? */
- if (input_size < TSK_BASE64_ENCODE_BLOCK_SIZE) {
- goto quantum;
- }
-
- do {
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i]<<4) | (input[i+1]>>4)) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i+1]<<2) | (input[i+2]>>6)) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ input[i+2] & 0x3F ];
-
- i += TSK_BASE64_ENCODE_BLOCK_SIZE;
- }
- while (( i + TSK_BASE64_ENCODE_BLOCK_SIZE) <= input_size);
+ static const char* TSK_BASE64_ENCODE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ /*=================================================================================
+ content T S K
+ ASCII 0x54 0x53 0x4B
+ Binary 0101 0100 0101 0011 0100 1011
+ ------------------------------------------------------------------------------
+ ------------------------------------------------------------------------------
+ Packs of 6bits 010101 000101 001101 001011
+ Indexes 21 5 13 11
+ Base64 encoded V F N L <=== HERE IS THE RESULT OF tsk_base64_encode("TSK")
+ */
+
+ tsk_size_t i = 0;
+ tsk_size_t output_size = 0;
+
+ /* Caller provided his own buffer? */
+ if (!*output) {
+ *output = (char*)tsk_calloc((TSK_BASE64_ENCODE_LEN(input_size) + 1), sizeof(char));
+ }
+
+ /* Too short? */
+ if (input_size < TSK_BASE64_ENCODE_BLOCK_SIZE) {
+ goto quantum;
+ }
+
+ do {
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i]<<4) | (input[i+1]>>4)) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i+1]<<2) | (input[i+2]>>6)) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ input[i+2] & 0x3F ];
+
+ i += TSK_BASE64_ENCODE_BLOCK_SIZE;
+ }
+ while (( i + TSK_BASE64_ENCODE_BLOCK_SIZE) <= input_size);
quantum:
-
- if ((input_size - i) == 1) {
- /* The final quantum of encoding input is exactly 8 bits; here, the
- final unit of encoded output will be two characters followed by
- two "=" padding characters.
- */
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]<<4) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_PAD, *(*output + output_size++) = TSK_BASE64_PAD;
- }
- else if ((input_size - i) == 2) {
- /* The final quantum of encoding input is exactly 16 bits; here, the
- final unit of encoded output will be three characters followed by
- one "=" padding character.
- */
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i]<<4) | (input[i+1]>>4)) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i+1]<<2) | (input[i+2]>>6)) & 0x3F ];
- *(*output + output_size++) = TSK_BASE64_PAD;
- }
-
- return output_size;
+
+ if ((input_size - i) == 1) {
+ /* The final quantum of encoding input is exactly 8 bits; here, the
+ final unit of encoded output will be two characters followed by
+ two "=" padding characters.
+ */
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]<<4) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_PAD, *(*output + output_size++) = TSK_BASE64_PAD;
+ }
+ else if ((input_size - i) == 2) {
+ /* The final quantum of encoding input is exactly 16 bits; here, the
+ final unit of encoded output will be three characters followed by
+ one "=" padding character.
+ */
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ (input[i]>> 2) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i]<<4) | (input[i+1]>>4)) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_ENCODE_ALPHABET [ ((input[i+1]<<2) | (input[i+2]>>6)) & 0x3F ];
+ *(*output + output_size++) = TSK_BASE64_PAD;
+ }
+
+ return output_size;
}
/**@ingroup tsk_base64_group
* Decodes arbitrary base64 data.
* @param input The input base64 data to decode.
* @param input_size The size of the @a input data.
-* @param output A pointer where to copy the decoded data.
+* @param output A pointer where to copy the decoded data.
* If you don't know what will be the size of the output result then set the pointer value to NULL to let the function allocate it of you.
* In all case it is up to you to free the @a ouput.
* You can also use @ref TSK_BASE64_DECODE_LEN to allocate the buffer before calling this method.
@@ -153,84 +153,83 @@ quantum:
*/
tsk_size_t tsk_base64_decode(const uint8_t* input, tsk_size_t input_size, char **output)
{
- static const uint8_t TSK_BASE64_DECODE_ALPHABET[256] =
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1,
- 62,
- -1, -1, -1,
- 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
- -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
- -1, -1, -1, -1, -1, -1,
- 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1,
- };
-
- tsk_size_t i, pay_size;
- tsk_size_t output_size = 0;
-
- /* Caller provided his own buffer? */
- if(!*output){
- *output = (char*)tsk_calloc(1, (TSK_BASE64_DECODE_LEN(input_size)+1));
- }
-
- /* Count pads and remove them from the base64 string */
- for(i = input_size, pay_size = input_size; i > 0; i--){
- if(input[i-1] == TSK_BASE64_PAD) {
- pay_size--;
- }
- else{
- break;
- }
- }
-
- /* Reset i */
- i = 0;
-
- if(pay_size < TSK_BASE64_DECODE_BLOCK_SIZE){
- goto quantum;
- }
-
- do{
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
- | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]<< 4
- | TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]>>2);
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]<<6
- | TSK_BASE64_DECODE_ALPHABET [ input[i+3] ]);
-
- i += TSK_BASE64_DECODE_BLOCK_SIZE;
- }
- while(( i+ TSK_BASE64_DECODE_BLOCK_SIZE) <= pay_size);
+ static const uint8_t TSK_BASE64_DECODE_ALPHABET[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1,
+ 62,
+ -1, -1, -1,
+ 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+ -1, -1, -1, -1, -1, -1, -1,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+ -1, -1, -1, -1, -1, -1,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1,
+ };
+
+ tsk_size_t i, pay_size;
+ tsk_size_t output_size = 0;
+
+ /* Caller provided his own buffer? */
+ if(!*output) {
+ *output = (char*)tsk_calloc(1, (TSK_BASE64_DECODE_LEN(input_size)+1));
+ }
+
+ /* Count pads and remove them from the base64 string */
+ for(i = input_size, pay_size = input_size; i > 0; i--) {
+ if(input[i-1] == TSK_BASE64_PAD) {
+ pay_size--;
+ }
+ else {
+ break;
+ }
+ }
+
+ /* Reset i */
+ i = 0;
+
+ if(pay_size < TSK_BASE64_DECODE_BLOCK_SIZE) {
+ goto quantum;
+ }
+
+ do {
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]<< 4
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]>>2);
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]<<6
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+3] ]);
+
+ i += TSK_BASE64_DECODE_BLOCK_SIZE;
+ }
+ while(( i+ TSK_BASE64_DECODE_BLOCK_SIZE) <= pay_size);
quantum:
-
- if((input_size - pay_size) == 1){
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
- | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]<< 4
- | TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]>>2);
- }
- else if((input_size-pay_size) == 2){
- *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
- | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
- }
-
- return output_size;
+
+ if((input_size - pay_size) == 1) {
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]<< 4
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+2] ]>>2);
+ }
+ else if((input_size-pay_size) == 2) {
+ *(*output + output_size++) = (TSK_BASE64_DECODE_ALPHABET [ input[i] ]<< 2
+ | TSK_BASE64_DECODE_ALPHABET [ input[i+1] ]>>4);
+ }
+
+ return output_size;
}
diff --git a/tinySAK/src/tsk_base64.h b/tinySAK/src/tsk_base64.h
index 6c22c5f..60f49b1 100755
--- a/tinySAK/src/tsk_base64.h
+++ b/tinySAK/src/tsk_base64.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_binaryutils.c b/tinySAK/src/tsk_binaryutils.c
index 0600efe..f4053d0 100755
--- a/tinySAK/src/tsk_binaryutils.c
+++ b/tinySAK/src/tsk_binaryutils.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_binaryutils.h b/tinySAK/src/tsk_binaryutils.h
index 1d09cd1..711e2c8 100755
--- a/tinySAK/src/tsk_binaryutils.h
+++ b/tinySAK/src/tsk_binaryutils.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -58,7 +58,7 @@ static uint16_t TSK_LSB_2_MSB( void const * buffer )
{
const uint8_t* dummy = (const uint8_t*)buffer;
return ( ((uint16_t)dummy[0] << 8) | dummy[1] );
-}
+}
/**@ingroup tsk_binaryutils_group
* @def TSK_BINARY_GET_2BYTES
@@ -87,68 +87,66 @@ static uint16_t TSK_LSB_2_MSB( void const * buffer )
// RFC 3320 - 7.3. Uploading UDVM bytecode
static const uint16_t sigcomp_encoding_destination[]
-= { 0, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024 };
+ = { 0, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024 };
// RFC 3320 - 7.2. Accessing Stored State
static const uint8_t sigcomp_encoding_partial_id_length[]
-= { 0, 6, 9, 12 };
+ = { 0, 6, 9, 12 };
// RFC 3320 - 3.3.1. Memory Size and UDVM Cycles
static const uint8_t sigcomp_encoding_cycles_per_bit[]
-= { 16, 32, 64, 128 };
+ = { 16, 32, 64, 128 };
static const uint32_t sigcomp_encoding_state_memory_size[]
-= { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 };
+ = { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 };
static const uint32_t sigcomp_encoding_decompression_memory_size[]
-= { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 }; // the bit pattern 000 cannot be used.
+ = { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 }; // the bit pattern 000 cannot be used.
// 3.3.1. Memory Size and UDVM Cycles
// 3.3. SigComp Parameters
static const uint8_t sigcomp_encoding_cpb[]
-= { 16, 32, 64, 128 };
+ = { 16, 32, 64, 128 };
static const uint32_t sigcomp_encoding_sms[]
-= { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 };
+ = { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 };
static const uint32_t sigcomp_encoding_dms[]
-= { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 }; // the bit pattern 000 cannot be used.
+ = { 0, 2048, 4096, 8192, 16384, 32768, 65536, 131072 }; // the bit pattern 000 cannot be used.
// RFC 3320: Figure 10: Bytecode for a multitype (%) operand
-static const int8_t operand_multitype_indexes [256] =
-{
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-9,
-10,
--1, -1, -1, -1,
-3, 3,
-4, 4, 4, 4, 4, 4, 4, 4,
-6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
+static const int8_t operand_multitype_indexes [256] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 9,
+ 10,
+ -1, -1, -1, -1,
+ 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};
// Used LSB<->MSB bits reverse/swap
/**@ingroup tsk_binaryutils_group
* Lookup table for bit reversing.
*/
-static const unsigned char Tsk_BitReverseTable256[] =
-{
- 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
- 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
- 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
- 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
- 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
- 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
- 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
- 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
- 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
- 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
- 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
- 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
- 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
- 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
- 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
- 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
+static const unsigned char Tsk_BitReverseTable256[] = {
+ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
+ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
+ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
+ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
+ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
+ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
+ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
+ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
+ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
+ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
+ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
+ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
+ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
+ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
+ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
TSK_END_DECLS
diff --git a/tinySAK/src/tsk_buffer.c b/tinySAK/src/tsk_buffer.c
index 80ee02d..5cd7f49 100755
--- a/tinySAK/src/tsk_buffer.c
+++ b/tinySAK/src/tsk_buffer.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -56,7 +56,7 @@
*/
tsk_buffer_t* tsk_buffer_create(const void* data, tsk_size_t size)
{
- return (tsk_buffer_t*)tsk_object_new(tsk_buffer_def_t, data, size);
+ return (tsk_buffer_t*)tsk_object_new(tsk_buffer_def_t, data, size);
}
/**@ingroup tsk_buffer_group
@@ -66,7 +66,7 @@ tsk_buffer_t* tsk_buffer_create(const void* data, tsk_size_t size)
*/
tsk_buffer_t* tsk_buffer_create_null()
{
- return tsk_buffer_create(tsk_null, 0);
+ return tsk_buffer_create(tsk_null, 0);
}
/**@ingroup tsk_buffer_group
@@ -86,62 +86,62 @@ tsk_buffer_t* tsk_buffer_create_null()
*/
int tsk_buffer_append_2(tsk_buffer_t* self, const char* format, ...)
{
- /*
- * I suppose that sizeof(char) = 1-byte
- */
- int len = 0;
- va_list ap;
- char *buffer;
- tsk_size_t oldsize;
+ /*
+ * I suppose that sizeof(char) = 1-byte
+ */
+ int len = 0;
+ va_list ap;
+ char *buffer;
+ tsk_size_t oldsize;
va_list ap2;
- if(!self){
- return -1;
- }
-
- oldsize = self->size;
- buffer = (char*)TSK_BUFFER_DATA(self);
-
- /* initialize variable arguments (needed for 64bit platforms where vsnprintf will change the va_list) */
- va_start(ap, format);
- va_start(ap2, format);
-
- /* compute destination len for windows mobile
- */
+ if(!self) {
+ return -1;
+ }
+
+ oldsize = self->size;
+ buffer = (char*)TSK_BUFFER_DATA(self);
+
+ /* initialize variable arguments (needed for 64bit platforms where vsnprintf will change the va_list) */
+ va_start(ap, format);
+ va_start(ap2, format);
+
+ /* compute destination len for windows mobile
+ */
#if defined(_WIN32_WCE)
- {
- int n;
- len = (tsk_strlen(format)*2);
- buffer = (char*)tsk_realloc(buffer, (oldsize+len));
- for(;;){
- if( (n = vsnprintf((char*)(buffer + oldsize), len, format, ap)) >= 0 && (n<=len) ){
- len = n;
- break;
- }
- else{
- len += 10;
- buffer = (char*)tsk_realloc(buffer, (oldsize+len));
- }
- }
- }
+ {
+ int n;
+ len = (tsk_strlen(format)*2);
+ buffer = (char*)tsk_realloc(buffer, (oldsize+len));
+ for(;;) {
+ if( (n = vsnprintf((char*)(buffer + oldsize), len, format, ap)) >= 0 && (n<=len) ) {
+ len = n;
+ break;
+ }
+ else {
+ len += 10;
+ buffer = (char*)tsk_realloc(buffer, (oldsize+len));
+ }
+ }
+ }
#else
len = vsnprintf(tsk_null, 0, format, ap);
buffer = (char*)tsk_realloc(buffer, oldsize+len+1);
vsnprintf((buffer + oldsize), len
#if !defined(_MSC_VER) || defined(__GNUC__)
- +1
+ +1
#endif
- , format, ap2);
+ , format, ap2);
#endif
-
- /* reset variable arguments */
- va_end(ap);
- va_end(ap2);
-
- self->data = buffer;
- self->size = (oldsize+len);
-
- return 0;
+
+ /* reset variable arguments */
+ va_end(ap);
+ va_end(ap2);
+
+ self->data = buffer;
+ self->size = (oldsize+len);
+
+ return 0;
}
/**@ingroup tsk_buffer_group
@@ -161,29 +161,29 @@ int tsk_buffer_append_2(tsk_buffer_t* self, const char* format, ...)
*/
int tsk_buffer_append(tsk_buffer_t* self, const void* data, tsk_size_t size)
{
- if(self && size){
- tsk_size_t oldsize = self->size;
- tsk_size_t newsize = oldsize + size;
-
- if(oldsize){
- self->data = tsk_realloc(self->data, newsize);
- }
- else{
- self->data = tsk_calloc(size, sizeof(uint8_t));
- }
-
- if(self->data){
- if(data){
- memcpy((void*)(TSK_BUFFER_TO_U8(self) + oldsize), data, size);
- }
- self->size = newsize;
- return 0;
- }
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- }
- return -1;
+ if(self && size) {
+ tsk_size_t oldsize = self->size;
+ tsk_size_t newsize = oldsize + size;
+
+ if(oldsize) {
+ self->data = tsk_realloc(self->data, newsize);
+ }
+ else {
+ self->data = tsk_calloc(size, sizeof(uint8_t));
+ }
+
+ if(self->data) {
+ if(data) {
+ memcpy((void*)(TSK_BUFFER_TO_U8(self) + oldsize), data, size);
+ }
+ self->size = newsize;
+ return 0;
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
+ return -1;
}
/**@ingroup tsk_buffer_group
@@ -194,23 +194,22 @@ int tsk_buffer_append(tsk_buffer_t* self, const void* data, tsk_size_t size)
*/
int tsk_buffer_realloc(tsk_buffer_t* self, tsk_size_t size)
{
- if(self)
- {
- if(size == 0){
- return tsk_buffer_cleanup(self);
- }
-
- if(self->size == 0){ // first time?
- self->data = tsk_calloc(size, sizeof(uint8_t));
- }
- else if(self->size != size){ // only realloc if different sizes
- self->data = tsk_realloc(self->data, size);
- }
-
- self->size = size;
- return 0;
- }
- return -1;
+ if(self) {
+ if(size == 0) {
+ return tsk_buffer_cleanup(self);
+ }
+
+ if(self->size == 0) { // first time?
+ self->data = tsk_calloc(size, sizeof(uint8_t));
+ }
+ else if(self->size != size) { // only realloc if different sizes
+ self->data = tsk_realloc(self->data, size);
+ }
+
+ self->size = size;
+ return 0;
+ }
+ return -1;
}
/**@ingroup tsk_buffer_group
@@ -222,17 +221,17 @@ int tsk_buffer_realloc(tsk_buffer_t* self, tsk_size_t size)
*/
int tsk_buffer_remove(tsk_buffer_t* self, tsk_size_t position, tsk_size_t size)
{
- if(self && self->data && size){
- if((position == 0) && ((position + size) >= self->size)){ /* Very common case. */
- return tsk_buffer_cleanup(self);
- }
- else if((position + size) < self->size){
- memcpy(((uint8_t*)self->data) + position, ((uint8_t*)self->data) + position + size,
- self->size-(position+size));
- return tsk_buffer_realloc(self, (self->size-size));
- }
- }
- return -1;
+ if(self && self->data && size) {
+ if((position == 0) && ((position + size) >= self->size)) { /* Very common case. */
+ return tsk_buffer_cleanup(self);
+ }
+ else if((position + size) < self->size) {
+ memcpy(((uint8_t*)self->data) + position, ((uint8_t*)self->data) + position + size,
+ self->size-(position+size));
+ return tsk_buffer_realloc(self, (self->size-size));
+ }
+ }
+ return -1;
}
/**@ingroup tsk_buffer_group
@@ -245,53 +244,52 @@ int tsk_buffer_remove(tsk_buffer_t* self, tsk_size_t position, tsk_size_t size)
*/
int tsk_buffer_insert(tsk_buffer_t* self, tsk_size_t position, const void* data, tsk_size_t size)
{
- if(self && size)
- {
- int ret;
- tsk_size_t tomove;
-
- if(position > self->size){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -2;
- }
-
- tomove = (self->size - position);
-
- if((ret = tsk_buffer_realloc(self, (self->size + size)))){
- return ret;
- }
- memmove(((uint8_t*)self->data) + position + size, ((uint8_t*)self->data) + position,
- tomove/*self->size - (position + size)*/);
-
-
- if(data){
- memcpy(((uint8_t*)self->data) + position, data, size);
- }
- else{
- memset(((uint8_t*)self->data) + position, 0, size);
- }
-
- return 0;
- }
- return -1;
+ if(self && size) {
+ int ret;
+ tsk_size_t tomove;
+
+ if(position > self->size) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -2;
+ }
+
+ tomove = (self->size - position);
+
+ if((ret = tsk_buffer_realloc(self, (self->size + size)))) {
+ return ret;
+ }
+ memmove(((uint8_t*)self->data) + position + size, ((uint8_t*)self->data) + position,
+ tomove/*self->size - (position + size)*/);
+
+
+ if(data) {
+ memcpy(((uint8_t*)self->data) + position, data, size);
+ }
+ else {
+ memset(((uint8_t*)self->data) + position, 0, size);
+ }
+
+ return 0;
+ }
+ return -1;
}
int tsk_buffer_copy(tsk_buffer_t* self, tsk_size_t start, const void* data, tsk_size_t size)
{
- int ret = 0;
- if(!self || !data || !size){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- // realloc the buffer to match the overral size
- if(self->size != (start + size) && (ret = tsk_buffer_realloc(self, (start + size)))){
- TSK_DEBUG_ERROR("failed to realloc the buffer");
- return ret;
- }
-
- memcpy(((uint8_t*)self->data) + start, data, size);
- return ret;
+ int ret = 0;
+ if(!self || !data || !size) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ // realloc the buffer to match the overral size
+ if(self->size != (start + size) && (ret = tsk_buffer_realloc(self, (start + size)))) {
+ TSK_DEBUG_ERROR("failed to realloc the buffer");
+ return ret;
+ }
+
+ memcpy(((uint8_t*)self->data) + start, data, size);
+ return ret;
}
/**@ingroup tsk_buffer_group
@@ -301,11 +299,11 @@ int tsk_buffer_copy(tsk_buffer_t* self, tsk_size_t start, const void* data, tsk_
*/
int tsk_buffer_cleanup(tsk_buffer_t* self)
{
- if(self && self->data){
- tsk_free(&(self->data));
- self->size = 0;
- }
- return 0;
+ if(self && self->data) {
+ tsk_free(&(self->data));
+ self->size = 0;
+ }
+ return 0;
}
/**@ingroup tsk_buffer_group
@@ -318,19 +316,19 @@ int tsk_buffer_cleanup(tsk_buffer_t* self)
*/
int tsk_buffer_takeownership(tsk_buffer_t* self, void** data, tsk_size_t size)
{
- if(!self || !data || !*data || !size){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- if(self->data){
- tsk_free(&(self->data));
- }
- self->data = *data;
- self->size = size;
- *data = tsk_null;
-
- return 0;
+ if(!self || !data || !*data || !size) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ if(self->data) {
+ tsk_free(&(self->data));
+ }
+ self->data = *data;
+ self->size = size;
+ *data = tsk_null;
+
+ return 0;
}
@@ -349,37 +347,36 @@ int tsk_buffer_takeownership(tsk_buffer_t* self, void** data, tsk_size_t size)
//
static tsk_object_t* tsk_buffer_ctor(tsk_object_t * self, va_list * app)
{
- tsk_buffer_t *buffer = (tsk_buffer_t *)self;
- const void *data = va_arg(*app, const void *);
- tsk_size_t size = va_arg(*app, tsk_size_t);
-
- if (size) {
- buffer->data = tsk_calloc((size+1), sizeof(uint8_t));
- if (data) {
- memcpy(buffer->data, data, size);
- }
- buffer->size = size;
- }
- return self;
+ tsk_buffer_t *buffer = (tsk_buffer_t *)self;
+ const void *data = va_arg(*app, const void *);
+ tsk_size_t size = va_arg(*app, tsk_size_t);
+
+ if (size) {
+ buffer->data = tsk_calloc((size+1), sizeof(uint8_t));
+ if (data) {
+ memcpy(buffer->data, data, size);
+ }
+ buffer->size = size;
+ }
+ return self;
}
static tsk_object_t* tsk_buffer_dtor(tsk_object_t * self)
-{
- tsk_buffer_t *buffer = (tsk_buffer_t *)self;
- if(buffer){
- TSK_FREE(buffer->data);
- buffer->size = 0;
- }
-
- return self;
+{
+ tsk_buffer_t *buffer = (tsk_buffer_t *)self;
+ if(buffer) {
+ TSK_FREE(buffer->data);
+ buffer->size = 0;
+ }
+
+ return self;
}
-static const tsk_object_def_t tsk_buffer_def_s =
-{
- sizeof(tsk_buffer_t),
- tsk_buffer_ctor,
- tsk_buffer_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_buffer_def_s = {
+ sizeof(tsk_buffer_t),
+ tsk_buffer_ctor,
+ tsk_buffer_dtor,
+ tsk_null,
};
const tsk_object_def_t *tsk_buffer_def_t = &tsk_buffer_def_s;
diff --git a/tinySAK/src/tsk_buffer.h b/tinySAK/src/tsk_buffer.h
index 8afb526..8977238 100755
--- a/tinySAK/src/tsk_buffer.h
+++ b/tinySAK/src/tsk_buffer.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -72,12 +72,11 @@ TSK_BEGIN_DECLS
/**@ingroup tsk_buffer_group
* Buffer object.
*/
-typedef struct tsk_buffer_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_buffer_s {
+ TSK_DECLARE_OBJECT;
- void *data; /**< Interanl data. */
- tsk_size_t size; /**< The size of the internal data. */
+ void *data; /**< Interanl data. */
+ tsk_size_t size; /**< The size of the internal data. */
}
tsk_buffer_t;
diff --git a/tinySAK/src/tsk_common.h b/tinySAK/src/tsk_common.h
index e5ba5d2..35c952a 100755
--- a/tinySAK/src/tsk_common.h
+++ b/tinySAK/src/tsk_common.h
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2010-2015 Mamadou DIOP.
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_condwait.c b/tinySAK/src/tsk_condwait.c
index 74b6389..f361c2c 100755
--- a/tinySAK/src/tsk_condwait.c
+++ b/tinySAK/src/tsk_condwait.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -38,13 +38,13 @@
# include <windows.h>
# include "tsk_errno.h"
# define CONDWAIT_S void
- typedef HANDLE CONDWAIT_T;
+typedef HANDLE CONDWAIT_T;
# define TIMED_OUT WAIT_TIMEOUT
#else
# include <sys/time.h>
# include <pthread.h>
# define CONDWAIT_S pthread_cond_t
- typedef CONDWAIT_S* CONDWAIT_T;
+typedef CONDWAIT_S* CONDWAIT_T;
# define TIMED_OUT ETIMEDOUT
#endif
@@ -79,11 +79,10 @@
/**@ingroup tsk_condwait_group
* Represents both PThread an Windows condwait object.
*/
-typedef struct tsk_condwait_s
-{
- CONDWAIT_T pcond; /**< Pthread handle pointing to the internal condwait object. */
+typedef struct tsk_condwait_s {
+ CONDWAIT_T pcond; /**< Pthread handle pointing to the internal condwait object. */
#if !TSK_UNDER_WINDOWS
- tsk_mutex_handle_t* mutex; /**< Locker. */
+ tsk_mutex_handle_t* mutex; /**< Locker. */
#endif
}
tsk_condwait_t;
@@ -95,82 +94,76 @@ tsk_condwait_t;
*/
tsk_condwait_handle_t* tsk_condwait_create()
{
- tsk_condwait_t *condwait = (tsk_condwait_t*)tsk_calloc(1, sizeof(tsk_condwait_t));
+ tsk_condwait_t *condwait = (tsk_condwait_t*)tsk_calloc(1, sizeof(tsk_condwait_t));
- if(condwait)
- {
+ if(condwait) {
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- condwait->pcond = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
- #else
- condwait->pcond = CreateEvent(NULL, TRUE, FALSE, NULL);
+ condwait->pcond = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
+#else
+ condwait->pcond = CreateEvent(NULL, TRUE, FALSE, NULL);
# endif
- if(!condwait->pcond)
- {
- TSK_FREE(condwait);
- }
+ if(!condwait->pcond) {
+ TSK_FREE(condwait);
+ }
#else
- condwait->pcond = (CONDWAIT_T)tsk_calloc(1, sizeof(CONDWAIT_S));
- if(pthread_cond_init(condwait->pcond, 0))
- {
- TSK_DEBUG_ERROR("Failed to initialize the new conwait.");
- }
+ condwait->pcond = (CONDWAIT_T)tsk_calloc(1, sizeof(CONDWAIT_S));
+ if(pthread_cond_init(condwait->pcond, 0)) {
+ TSK_DEBUG_ERROR("Failed to initialize the new conwait.");
+ }
- if(!(condwait->mutex = tsk_mutex_create()))
- {
- pthread_cond_destroy(condwait->pcond);
+ if(!(condwait->mutex = tsk_mutex_create())) {
+ pthread_cond_destroy(condwait->pcond);
- TSK_FREE(condwait);
- TSK_DEBUG_ERROR("Failed to initialize the internal mutex.");
- }
+ TSK_FREE(condwait);
+ TSK_DEBUG_ERROR("Failed to initialize the internal mutex.");
+ }
#endif
- }
+ }
- if(!condwait)
- {
- TSK_DEBUG_ERROR("Failed to create new conwait.");
- }
- return condwait;
+ if(!condwait) {
+ TSK_DEBUG_ERROR("Failed to create new conwait.");
+ }
+ return condwait;
}
/**@ingroup tsk_condwait_group
-* Block the current thread until the condition is opened.
+* Block the current thread until the condition is opened.
* @param handle CondWait handle created using @ref tsk_condwait_create.
* @retval Zero if succeed and non-zero otherwise.
* @sa @ref tsk_condwait_timedwait.
*/
int tsk_condwait_wait(tsk_condwait_handle_t* handle)
{
- int ret = EINVAL;
- tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
- if(!condwait){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ int ret = EINVAL;
+ tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
+ if(!condwait) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- if((ret = (WaitForSingleObjectEx(condwait->pcond, INFINITE, TRUE) == WAIT_FAILED) ? -1 : 0)){
+ if((ret = (WaitForSingleObjectEx(condwait->pcond, INFINITE, TRUE) == WAIT_FAILED) ? -1 : 0)) {
# else
- if((ret = (WaitForSingleObject(condwait->pcond, INFINITE) == WAIT_FAILED) ? -1 : 0)){
+ if((ret = (WaitForSingleObject(condwait->pcond, INFINITE) == WAIT_FAILED) ? -1 : 0)) {
#endif
- TSK_DEBUG_ERROR("WaitForSingleObject function failed: %d", ret);
- }
+ TSK_DEBUG_ERROR("WaitForSingleObject function failed: %d", ret);
+ }
#else
- if(condwait && condwait->mutex){
- tsk_mutex_lock(condwait->mutex);
- if((ret = pthread_cond_wait(condwait->pcond, (pthread_mutex_t*)condwait->mutex)))
- {
- TSK_DEBUG_ERROR("pthread_cond_wait function failed: %d", ret);
- }
- tsk_mutex_unlock(condwait->mutex);
- }
+ if(condwait && condwait->mutex) {
+ tsk_mutex_lock(condwait->mutex);
+ if((ret = pthread_cond_wait(condwait->pcond, (pthread_mutex_t*)condwait->mutex))) {
+ TSK_DEBUG_ERROR("pthread_cond_wait function failed: %d", ret);
+ }
+ tsk_mutex_unlock(condwait->mutex);
+ }
#endif
- return ret;
+ return ret;
}
/**@ingroup tsk_condwait_group
-* Block the current thread until the condition is opened or until @a ms milliseconds have passed.
+* Block the current thread until the condition is opened or until @a ms milliseconds have passed.
* @param handle condwait handle created using @ref tsk_condwait_create.
* @param ms The number of milliseconds to wait for a given condition.
* @retval Zero if succeed and non-zero error code otherwise.
@@ -179,53 +172,55 @@ int tsk_condwait_wait(tsk_condwait_handle_t* handle)
int tsk_condwait_timedwait(tsk_condwait_handle_t* handle, uint64_t ms)
{
#if TSK_UNDER_WINDOWS
- DWORD ret = WAIT_FAILED;
+ DWORD ret = WAIT_FAILED;
#else
- int ret = EINVAL;
+ int ret = EINVAL;
#endif
- tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
+ tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- if((ret = WaitForSingleObjectEx(condwait->pcond, (DWORD)ms, TRUE)) != WAIT_OBJECT_0){
+ if((ret = WaitForSingleObjectEx(condwait->pcond, (DWORD)ms, TRUE)) != WAIT_OBJECT_0) {
# else
- if((ret = WaitForSingleObject(condwait->pcond, (DWORD)ms)) != WAIT_OBJECT_0){
+ if((ret = WaitForSingleObject(condwait->pcond, (DWORD)ms)) != WAIT_OBJECT_0) {
#endif
- if(ret == TIMED_OUT){
- /* TSK_DEBUG_INFO("WaitForSingleObject function timedout: %d", ret); */
- }
- else{
- TSK_DEBUG_ERROR("WaitForSingleObject function failed: %d", ret);
- }
- return ((ret == TIMED_OUT) ? 0 : ret);
- }
+ if(ret == TIMED_OUT) {
+ /* TSK_DEBUG_INFO("WaitForSingleObject function timedout: %d", ret); */
+ }
+ else {
+ TSK_DEBUG_ERROR("WaitForSingleObject function failed: %d", ret);
+ }
+ return ((ret == TIMED_OUT) ? 0 : ret);
+ }
#else
- if(condwait && condwait->mutex){
- struct timespec ts = {0, 0};
- struct timeval tv = {0, 0};
- /*int rc =*/ tsk_gettimeofday(&tv, 0);
+ if(condwait && condwait->mutex) {
+ struct timespec ts = {0, 0};
+ struct timeval tv = {0, 0};
+ /*int rc =*/ tsk_gettimeofday(&tv, 0);
+
+ ts.tv_sec = ( tv.tv_sec + ((long)ms/1000) );
+ ts.tv_nsec += ( (tv.tv_usec * 1000) + ((long)ms % 1000 * 1000000) );
+ if(ts.tv_nsec > 999999999) {
+ ts.tv_sec+=1, ts.tv_nsec = ts.tv_nsec % 1000000000;
+ }
- ts.tv_sec = ( tv.tv_sec + ((long)ms/1000) );
- ts.tv_nsec += ( (tv.tv_usec * 1000) + ((long)ms % 1000 * 1000000) );
- if(ts.tv_nsec > 999999999) ts.tv_sec+=1, ts.tv_nsec = ts.tv_nsec % 1000000000;
-
- tsk_mutex_lock(condwait->mutex);
- if((ret = pthread_cond_timedwait(condwait->pcond, (pthread_mutex_t*)condwait->mutex, &ts))){
- if(ret == TIMED_OUT){
- /* TSK_DEBUG_INFO("pthread_cond_timedwait function timedout: %d", ret); */
- }
- else{
- TSK_DEBUG_ERROR("pthread_cond_timedwait function failed: %d", ret);
- }
- }
+ tsk_mutex_lock(condwait->mutex);
+ if((ret = pthread_cond_timedwait(condwait->pcond, (pthread_mutex_t*)condwait->mutex, &ts))) {
+ if(ret == TIMED_OUT) {
+ /* TSK_DEBUG_INFO("pthread_cond_timedwait function timedout: %d", ret); */
+ }
+ else {
+ TSK_DEBUG_ERROR("pthread_cond_timedwait function failed: %d", ret);
+ }
+ }
- tsk_mutex_unlock(condwait->mutex);
+ tsk_mutex_unlock(condwait->mutex);
- return ((ret == TIMED_OUT) ? 0 : ret);
- }
+ return ((ret == TIMED_OUT) ? 0 : ret);
+ }
#endif
- return ret;
+ return ret;
}
/**@ingroup tsk_condwait_group
@@ -236,29 +231,29 @@ int tsk_condwait_timedwait(tsk_condwait_handle_t* handle, uint64_t ms)
*/
int tsk_condwait_signal(tsk_condwait_handle_t* handle)
{
- int ret = EINVAL;
- tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
- if(!condwait){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ int ret = EINVAL;
+ tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
+ if(!condwait) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
#if TSK_UNDER_WINDOWS
- if(ret = ((SetEvent(condwait->pcond) && ResetEvent(condwait->pcond)) ? 0 : -1)){
- ret = GetLastError();
- TSK_DEBUG_ERROR("SetEvent/ResetEvent function failed: %d", ret);
- }
+ if(ret = ((SetEvent(condwait->pcond) && ResetEvent(condwait->pcond)) ? 0 : -1)) {
+ ret = GetLastError();
+ TSK_DEBUG_ERROR("SetEvent/ResetEvent function failed: %d", ret);
+ }
#else
- if(condwait && condwait->mutex){
- tsk_mutex_lock(condwait->mutex);
+ if(condwait && condwait->mutex) {
+ tsk_mutex_lock(condwait->mutex);
- if((ret = pthread_cond_signal(condwait->pcond))){
- TSK_DEBUG_ERROR("pthread_cond_signal function failed: %d", ret);
- }
- tsk_mutex_unlock(condwait->mutex);
- }
+ if((ret = pthread_cond_signal(condwait->pcond))) {
+ TSK_DEBUG_ERROR("pthread_cond_signal function failed: %d", ret);
+ }
+ tsk_mutex_unlock(condwait->mutex);
+ }
#endif
- return ret;
+ return ret;
}
@@ -270,29 +265,29 @@ int tsk_condwait_signal(tsk_condwait_handle_t* handle)
*/
int tsk_condwait_broadcast(tsk_condwait_handle_t* handle)
{
- int ret = EINVAL;
- tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
- if(!condwait){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ int ret = EINVAL;
+ tsk_condwait_t *condwait = (tsk_condwait_t*)handle;
+ if(!condwait) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
#if TSK_UNDER_WINDOWS
- if(ret = ((SetEvent(condwait->pcond) && ResetEvent(condwait->pcond)) ? 0 : -1)){
- ret = GetLastError();
- TSK_DEBUG_ERROR("SetEvent function failed: %d", ret);
- }
+ if(ret = ((SetEvent(condwait->pcond) && ResetEvent(condwait->pcond)) ? 0 : -1)) {
+ ret = GetLastError();
+ TSK_DEBUG_ERROR("SetEvent function failed: %d", ret);
+ }
#else
- if(condwait && condwait->mutex){
- tsk_mutex_lock(condwait->mutex);
- if((ret = pthread_cond_broadcast(condwait->pcond))){
- TSK_DEBUG_ERROR("pthread_cond_broadcast function failed: %d", ret);
- }
- tsk_mutex_unlock(condwait->mutex);
- }
+ if(condwait && condwait->mutex) {
+ tsk_mutex_lock(condwait->mutex);
+ if((ret = pthread_cond_broadcast(condwait->pcond))) {
+ TSK_DEBUG_ERROR("pthread_cond_broadcast function failed: %d", ret);
+ }
+ tsk_mutex_unlock(condwait->mutex);
+ }
#endif
- return ret;
+ return ret;
}
/**@ingroup tsk_condwait_group
@@ -302,20 +297,20 @@ int tsk_condwait_broadcast(tsk_condwait_handle_t* handle)
*/
void tsk_condwait_destroy(tsk_condwait_handle_t** handle)
{
- tsk_condwait_t **condwait = (tsk_condwait_t**)handle;
-
- if(condwait && *condwait){
+ tsk_condwait_t **condwait = (tsk_condwait_t**)handle;
+
+ if(condwait && *condwait) {
#if TSK_UNDER_WINDOWS
- CloseHandle((*condwait)->pcond);
+ CloseHandle((*condwait)->pcond);
#else
- tsk_mutex_destroy(&((*condwait)->mutex));
- pthread_cond_destroy((*condwait)->pcond);
- TSK_FREE((*condwait)->pcond);
+ tsk_mutex_destroy(&((*condwait)->mutex));
+ pthread_cond_destroy((*condwait)->pcond);
+ TSK_FREE((*condwait)->pcond);
#endif
- tsk_free((void**)condwait);
- }
- else{
- TSK_DEBUG_WARN("Cannot free an uninitialized condwait object");
- }
+ tsk_free((void**)condwait);
+ }
+ else {
+ TSK_DEBUG_WARN("Cannot free an uninitialized condwait object");
+ }
}
diff --git a/tinySAK/src/tsk_condwait.h b/tinySAK/src/tsk_condwait.h
index 5d5c550..3194ded 100755
--- a/tinySAK/src/tsk_condwait.h
+++ b/tinySAK/src/tsk_condwait.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_debug.c b/tinySAK/src/tsk_debug.c
index e1cf28a..cb84549 100755
--- a/tinySAK/src/tsk_debug.c
+++ b/tinySAK/src/tsk_debug.c
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -41,92 +41,104 @@ static int tsk_debug_level = DEBUG_LEVEL;
* @param arg_data The callback data.
* @sa @ref tsk_debug_get_arg_data()
*/
-void tsk_debug_set_arg_data(const void* arg_data){
- tsk_debug_arg_data = arg_data;
+void tsk_debug_set_arg_data(const void* arg_data)
+{
+ tsk_debug_arg_data = arg_data;
}
/**@ingroup tsk_debug_group
* Gets the callback data passed to the framework using @ref tsk_debug_set_arg_data().
* @retval The callback data.
* @sa @ref tsk_debug_set_arg_data()
*/
-const void* tsk_debug_get_arg_data(){
- return tsk_debug_arg_data;
+const void* tsk_debug_get_arg_data()
+{
+ return tsk_debug_arg_data;
}
/**@ingroup tsk_debug_group
* Sets the callback function to call when @ref TSK_DEBUG_INFO() is internally used.
* @param cb A pointer to the callback function.
* @sa @ref tsk_debug_set_warn_cb() @ref tsk_debug_set_error_cb() @ref tsk_debug_set_fatal_cb().
*/
-void tsk_debug_set_info_cb(tsk_debug_f cb){
- tsk_debug_info_cb = cb;
+void tsk_debug_set_info_cb(tsk_debug_f cb)
+{
+ tsk_debug_info_cb = cb;
}
/**@ingroup tsk_debug_group
* Gets the callback function defined using @ref tsk_debug_set_info_cb().
* @retval A pointer to the callback function.
*/
-tsk_debug_f tsk_debug_get_info_cb(){
- return tsk_debug_info_cb;
+tsk_debug_f tsk_debug_get_info_cb()
+{
+ return tsk_debug_info_cb;
}
/**@ingroup tsk_debug_group
* Sets the callback function to call when @ref TSK_DEBUG_WARN() is internally used.
* @param cb A pointer to the callback function.
* @sa @ref tsk_debug_set_info_cb() @ref tsk_debug_set_error_cb() @ref tsk_debug_set_fatal_cb().
*/
-void tsk_debug_set_warn_cb(tsk_debug_f cb){
- tsk_debug_warn_cb = cb;
+void tsk_debug_set_warn_cb(tsk_debug_f cb)
+{
+ tsk_debug_warn_cb = cb;
}
/**@ingroup tsk_debug_group
* Gets the callback function defined using @ref tsk_debug_set_warn_cb().
* @retval A pointer to the callback function.
*/
-tsk_debug_f tsk_debug_get_warn_cb(){
- return tsk_debug_warn_cb;
+tsk_debug_f tsk_debug_get_warn_cb()
+{
+ return tsk_debug_warn_cb;
}
/**@ingroup tsk_debug_group
* Sets the callback function to call when @ref TSK_DEBUG_ERROR() is internally used.
* @param cb A pointer to the callback function.
* @sa @ref tsk_debug_set_info_cb() @ref tsk_debug_set_warn_cb() @ref tsk_debug_set_fatal_cb().
*/
-void tsk_debug_set_error_cb(tsk_debug_f cb){
- tsk_debug_error_cb = cb;
+void tsk_debug_set_error_cb(tsk_debug_f cb)
+{
+ tsk_debug_error_cb = cb;
}
/**@ingroup tsk_debug_group
* Gets the callback function defined using @ref tsk_debug_set_error_cb().
* @retval A pointer to the callback function.
*/
-tsk_debug_f tsk_debug_get_error_cb(){
- return tsk_debug_error_cb;
+tsk_debug_f tsk_debug_get_error_cb()
+{
+ return tsk_debug_error_cb;
}
/**@ingroup tsk_debug_group
* Sets the callback function to call when @ref TSK_DEBUG_FATAL() is internally used.
* @param cb A pointer to the callback function.
* @sa @ref tsk_debug_set_info_cb() @ref tsk_debug_set_warn_cb() @ref tsk_debug_set_error_cb().
*/
-void tsk_debug_set_fatal_cb(tsk_debug_f cb){
- tsk_debug_fatal_cb = cb;
+void tsk_debug_set_fatal_cb(tsk_debug_f cb)
+{
+ tsk_debug_fatal_cb = cb;
}
/**@ingroup tsk_debug_group
* Gets the callback function defined using @ref tsk_debug_set_fatal_cb().
* @retval A pointer to the callback function.
*/
-tsk_debug_f tsk_debug_get_fatal_cb(){
- return tsk_debug_fatal_cb;
+tsk_debug_f tsk_debug_get_fatal_cb()
+{
+ return tsk_debug_fatal_cb;
}
/**@ingroup tsk_debug_group
* Gets the debug level defined using @ref tsk_debug_set_level.
* @retval The debug level. <b>Must be</b>: @ref DEBUG_LEVEL_INFO, @ref DEBUG_LEVEL_WARN, @ref DEBUG_LEVEL_ERROR or @ref DEBUG_LEVEL_FATAL.
* @sa @ref tsk_debug_set_level()
*/
-int tsk_debug_get_level(){
- return tsk_debug_level;
+int tsk_debug_get_level()
+{
+ return tsk_debug_level;
}
/**@ingroup tsk_debug_group
* Sets the debug level.
* @param level The debug level. <b>Must be</b>: @ref DEBUG_LEVEL_INFO, @ref DEBUG_LEVEL_WARN, @ref DEBUG_LEVEL_ERROR or @ref DEBUG_LEVEL_FATAL.
* @sa @ref tsk_debug_get_level()
*/
-void tsk_debug_set_level(int level){
- tsk_debug_level = level;
+void tsk_debug_set_level(int level)
+{
+ tsk_debug_level = level;
}
#endif /* TSK_HAVE_DEBUG_H */
@@ -147,7 +159,7 @@ void tsk_debug_set_level(int level){
* - @ref DEBUG_LEVEL_INFO is the minimum value. Used to log user information, application progress, configuration ...
* - @ref DEBUG_LEVEL_WARN signals that something that could change the normal process happened. This type of error should not block the application.
* - @ref DEBUG_LEVEL_ERROR is the <b>default</b> minimum value. Signals that the current operation has failed. If the operation was critical (e.g. thread creation) then, this will badly change the application behavior, otherwise (e.g. sending data over network) the application will continue to behave as expected.
-* - @ref DEBUG_LEVEL_FATAL is the maximum value. This kind of errors are signaled just before the application crashes or enters in a state from which it's impossible to recover from.
+* - @ref DEBUG_LEVEL_FATAL is the maximum value. This kind of errors are signaled just before the application crashes or enters in a state from which it's impossible to recover from.
*
* At any time you can change the debug level using @ref tsk_debug_set_level().
*
@@ -183,7 +195,7 @@ FILE* file = fopen("logs.txt", "w+"); // do not forget to close the file using f
fputs(msg, file);
TSK_FREE(msg);
va_end(ap);
-
+
return 0;
}
// optional: set callback data (will be passed to _debug_info_write_to_file() as "arg" parameter)
@@ -194,14 +206,14 @@ tsk_debug_set_info_cb(_debug_info_write_to_file);
* @endcode
* Anywhere in Doubango code when @ref TSK_DEBUG_INFO() is called then, your callback function will be called to write the message to a file. <br />
* This is the best way to use custom loggers such as @a log4j, @a log4net or @a logfile.
-*
+*
* <h3>@anchor _Anchor_TinySAK_Debugging_Custom_Debug_Header Custom debug header</h3>
* This is an ANSI-C header file (<b>*.h</b>) overriding the macros used to print the debug messages. <br />
* This file:
* - must be named @a my_debug.h and in the same folder as @a tsk_debug.h.
* - must contain your own definitions of @ref TSK_DEBUG_INFO(), @ref TSK_DEBUG_WARN(), @ref TSK_DEBUG_ERROR() and @ref TSK_DEBUG_FATAL().
* - and you must add <i>-DTSK_HAVE_DEBUG_H=1</i> in your <i>CFLAGS</i> before building @a tinySAK project.
-*
+*
* <h2>@anchor _Anchor_TinySAK_Debugging_Public_Fuctions Public functions </h2>
* - @ref tsk_debug_get_arg_data
* - @ref tsk_debug_get_error_cb
diff --git a/tinySAK/src/tsk_debug.h b/tinySAK/src/tsk_debug.h
index e4538fa..6e29d67 100755
--- a/tinySAK/src/tsk_debug.h
+++ b/tinySAK/src/tsk_debug.h
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -103,9 +103,9 @@ TSK_BEGIN_DECLS
#if TSK_HAVE_DEBUG_H
# include <my_debug.h>
#else
- typedef int (*tsk_debug_f)(const void* arg, const char* fmt, ...);
+typedef int (*tsk_debug_f)(const void* arg, const char* fmt, ...);
- /* INFO */
+/* INFO */
#define TSK_DEBUG_INFO(FMT, ...) \
if(tsk_debug_get_level() >= DEBUG_LEVEL_INFO){ \
if(tsk_debug_get_info_cb()) \
@@ -115,7 +115,7 @@ TSK_BEGIN_DECLS
}
- /* WARN */
+/* WARN */
#define TSK_DEBUG_WARN(FMT, ...) \
if(tsk_debug_get_level() >= DEBUG_LEVEL_WARN){ \
if(tsk_debug_get_warn_cb()) \
@@ -124,7 +124,7 @@ TSK_BEGIN_DECLS
fprintf(stderr, "**[DOUBANGO WARN]: function: \"%s()\" \nfile: \"%s\" \nline: \"%u\" \nMSG: " FMT "\n", __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
}
- /* ERROR */
+/* ERROR */
#define TSK_DEBUG_ERROR(FMT, ...) \
if(tsk_debug_get_level() >= DEBUG_LEVEL_ERROR){ \
if(tsk_debug_get_error_cb()) \
@@ -134,7 +134,7 @@ TSK_BEGIN_DECLS
}
- /* FATAL */
+/* FATAL */
#define TSK_DEBUG_FATAL(FMT, ...) \
if(tsk_debug_get_level() >= DEBUG_LEVEL_FATAL){ \
if(tsk_debug_get_fatal_cb()) \
diff --git a/tinySAK/src/tsk_errno.h b/tinySAK/src/tsk_errno.h
index 5435d8e..8f3f488 100755
--- a/tinySAK/src/tsk_errno.h
+++ b/tinySAK/src/tsk_errno.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_fsm.c b/tinySAK/src/tsk_fsm.c
index ba1324b..4768b0a 100755
--- a/tinySAK/src/tsk_fsm.c
+++ b/tinySAK/src/tsk_fsm.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -35,57 +35,63 @@
/**@defgroup tsk_fsm_group Finite-state machine (FSM) implementation.
*/
-int tsk_fsm_exec_nothing(va_list *app){ return 0/*success*/; }
-tsk_bool_t tsk_fsm_cond_always(const void* data1, const void* data2) { return tsk_true; }
+int tsk_fsm_exec_nothing(va_list *app)
+{
+ return 0/*success*/;
+}
+tsk_bool_t tsk_fsm_cond_always(const void* data1, const void* data2)
+{
+ return tsk_true;
+}
/**@ingroup tsk_fsm_group
*/
tsk_fsm_t* tsk_fsm_create(tsk_fsm_state_id state_curr, tsk_fsm_state_id state_term)
{
- return (tsk_fsm_t*)tsk_object_new(tsk_fsm_def_t, state_curr, state_term);
+ return (tsk_fsm_t*)tsk_object_new(tsk_fsm_def_t, state_curr, state_term);
}
/**@ingroup tsk_fsm_group
*/
tsk_fsm_entry_t* tsk_fsm_entry_create()
{
- return (tsk_fsm_entry_t*)tsk_object_new(tsk_fsm_entry_def_t);
+ return (tsk_fsm_entry_t*)tsk_object_new(tsk_fsm_entry_def_t);
}
/**@ingroup tsk_fsm_group
* Add entries (states) to the FSM.
* @param self The FSM.
-* @param ... One of these helper macros: @b TSK_FSM_ADD_*. MUST end with
+* @param ... One of these helper macros: @b TSK_FSM_ADD_*. MUST end with
* @b TSK_FSM_ADD_NULL.
* @retval Zero if succeed and non-zero error code otherwise.
*/
int tsk_fsm_set(tsk_fsm_t* self, ...)
{
- va_list args;
- int guard;
-
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- va_start(args, self);
- while((guard = va_arg(args, int)) == 1){
- tsk_fsm_entry_t* entry;
- if((entry = tsk_fsm_entry_create())){
- entry->from = va_arg(args, tsk_fsm_state_id);
- entry->action = va_arg(args, tsk_fsm_action_id);
- entry->cond = va_arg(args, tsk_fsm_cond);
- entry->to = va_arg(args, tsk_fsm_state_id);
- entry->exec = va_arg(args, tsk_fsm_exec);
- entry->desc = va_arg(args, const char*);
-
- tsk_list_push_descending_data(self->entries, (void**)&entry);
- }
- }
- va_end(args);
-
- return 0;
+ va_list args;
+ int guard;
+
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ va_start(args, self);
+ while((guard = va_arg(args, int)) == 1) {
+ tsk_fsm_entry_t* entry;
+ if((entry = tsk_fsm_entry_create())) {
+ entry->from = va_arg(args, tsk_fsm_state_id);
+ entry->action = va_arg(args, tsk_fsm_action_id);
+ entry->cond = va_arg(args, tsk_fsm_cond);
+ entry->to = va_arg(args, tsk_fsm_state_id);
+ entry->exec = va_arg(args, tsk_fsm_exec);
+ entry->desc = va_arg(args, const char*);
+
+ tsk_list_push_descending_data(self->entries, (void**)&entry);
+ }
+ }
+ va_end(args);
+
+ return 0;
}
/**@ingroup tsk_fsm_group
@@ -97,15 +103,15 @@ int tsk_fsm_set(tsk_fsm_t* self, ...)
*/
int tsk_fsm_set_callback_terminated(tsk_fsm_t* self, tsk_fsm_onterminated_f callback, const void* callbackdata)
{
- if(self){
- self->callback_term = callback;
- self->callback_data = callbackdata;
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(self) {
+ self->callback_term = callback;
+ self->callback_data = callbackdata;
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_fsm_group
@@ -119,108 +125,107 @@ int tsk_fsm_set_callback_terminated(tsk_fsm_t* self, tsk_fsm_onterminated_f call
*/
int tsk_fsm_act(tsk_fsm_t* self, tsk_fsm_action_id action, const void* cond_data1, const void* cond_data2, ...)
{
- tsk_list_item_t *item;
- va_list ap;
- tsk_bool_t found = tsk_false;
- tsk_bool_t terminates = tsk_false; /* thread-safeness -> DO NOT REMOVE THIS VARIABLE */
- int ret_exec = 0; /* success */
-
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- if(tsk_fsm_terminated(self)){
- TSK_DEBUG_WARN("The FSM is in the final state.");
- return -2;
- }
-
- // lock
- tsk_safeobj_lock(self);
-
- va_start(ap, cond_data2);
- tsk_list_foreach(item, self->entries)
- {
- tsk_fsm_entry_t* entry = (tsk_fsm_entry_t*)item->data;
- if(((entry->from != tsk_fsm_state_any) && (entry->from != tsk_fsm_state_current)) && (entry->from != self->current)){
- continue;
- }
-
- if((entry->action != tsk_fsm_action_any) && (entry->action != action)){
- continue;
- }
-
- // check condition
- if(entry->cond(cond_data1, cond_data2)){
- // For debug information
- if(self->debug){
- TSK_DEBUG_INFO("State machine: %s", entry->desc);
- }
-
- if(entry->to != tsk_fsm_state_any && entry->to != tsk_fsm_state_current){ /* Stay at the current state if destination state is Any or Current */
- self->current = entry->to;
- }
-
- if(entry->exec){
- if((ret_exec = entry->exec(&ap))){
- TSK_DEBUG_INFO("State machine: Exec function failed. Moving to terminal state.");
- }
- }
- else{ /* Nothing to execute */
- ret_exec = 0;
- }
-
- terminates = (ret_exec || (self->current == self->term));
- found = tsk_true;
- break;
- }
- }
- va_end(ap);
-
- // unlock
- tsk_safeobj_unlock(self);
-
- /* Only call the callback function after unlock. */
- if(terminates){
- self->current = self->term;
- if(self->callback_term){
- self->callback_term(self->callback_data);
- }
- }
- if(!found){
- TSK_DEBUG_INFO("State machine: No matching state found.");
- }
-
- return ret_exec;
+ tsk_list_item_t *item;
+ va_list ap;
+ tsk_bool_t found = tsk_false;
+ tsk_bool_t terminates = tsk_false; /* thread-safeness -> DO NOT REMOVE THIS VARIABLE */
+ int ret_exec = 0; /* success */
+
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ if(tsk_fsm_terminated(self)) {
+ TSK_DEBUG_WARN("The FSM is in the final state.");
+ return -2;
+ }
+
+ // lock
+ tsk_safeobj_lock(self);
+
+ va_start(ap, cond_data2);
+ tsk_list_foreach(item, self->entries) {
+ tsk_fsm_entry_t* entry = (tsk_fsm_entry_t*)item->data;
+ if(((entry->from != tsk_fsm_state_any) && (entry->from != tsk_fsm_state_current)) && (entry->from != self->current)) {
+ continue;
+ }
+
+ if((entry->action != tsk_fsm_action_any) && (entry->action != action)) {
+ continue;
+ }
+
+ // check condition
+ if(entry->cond(cond_data1, cond_data2)) {
+ // For debug information
+ if(self->debug) {
+ TSK_DEBUG_INFO("State machine: %s", entry->desc);
+ }
+
+ if(entry->to != tsk_fsm_state_any && entry->to != tsk_fsm_state_current) { /* Stay at the current state if destination state is Any or Current */
+ self->current = entry->to;
+ }
+
+ if(entry->exec) {
+ if((ret_exec = entry->exec(&ap))) {
+ TSK_DEBUG_INFO("State machine: Exec function failed. Moving to terminal state.");
+ }
+ }
+ else { /* Nothing to execute */
+ ret_exec = 0;
+ }
+
+ terminates = (ret_exec || (self->current == self->term));
+ found = tsk_true;
+ break;
+ }
+ }
+ va_end(ap);
+
+ // unlock
+ tsk_safeobj_unlock(self);
+
+ /* Only call the callback function after unlock. */
+ if(terminates) {
+ self->current = self->term;
+ if(self->callback_term) {
+ self->callback_term(self->callback_data);
+ }
+ }
+ if(!found) {
+ TSK_DEBUG_INFO("State machine: No matching state found.");
+ }
+
+ return ret_exec;
}
tsk_fsm_state_id tsk_fsm_get_current_state(tsk_fsm_t* self)
{
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_fsm_state_any;
- }
- return self->current;
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_fsm_state_any;
+ }
+ return self->current;
}
int tsk_fsm_set_current_state(tsk_fsm_t* self, tsk_fsm_state_id new_state)
{
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- self->current = new_state;
- return 0;
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ self->current = new_state;
+ return 0;
}
tsk_bool_t tsk_fsm_terminated(tsk_fsm_t* self)
{
- if(self){
- return (self->current == self->term);
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_true;
- }
+ if(self) {
+ return (self->current == self->term);
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_true;
+ }
}
@@ -229,48 +234,47 @@ tsk_bool_t tsk_fsm_terminated(tsk_fsm_t* self)
//
static tsk_object_t* tsk_fsm_ctor(tsk_object_t * self, va_list * app)
{
- tsk_fsm_t *fsm = (tsk_fsm_t*)self;
- if(fsm){
- fsm->current = va_arg(*app, tsk_fsm_state_id);
- fsm->term = va_arg(*app, tsk_fsm_state_id);
+ tsk_fsm_t *fsm = (tsk_fsm_t*)self;
+ if(fsm) {
+ fsm->current = va_arg(*app, tsk_fsm_state_id);
+ fsm->term = va_arg(*app, tsk_fsm_state_id);
- fsm->entries = tsk_list_create();
+ fsm->entries = tsk_list_create();
#if defined(DEBUG) || defined(_DEBUG)
- fsm->debug = 1; /* default value, could be changed at any time */
+ fsm->debug = 1; /* default value, could be changed at any time */
#endif
- tsk_safeobj_init(fsm);
- }
+ tsk_safeobj_init(fsm);
+ }
- return self;
+ return self;
}
static tsk_object_t* tsk_fsm_dtor(tsk_object_t * self)
-{
- tsk_fsm_t *fsm = (tsk_fsm_t*)self;
- if(fsm){
- /* If not in the terminal state ==>do it */
- /*if(fsm->current != fsm->term){
- tsk_safeobj_lock(fsm);
- if(fsm->callback_term){
- fsm->callback_term(fsm->callback_data);
- }
- tsk_safeobj_unlock(fsm);
- }*/
- tsk_safeobj_deinit(fsm);
-
- TSK_OBJECT_SAFE_FREE(fsm->entries);
- }
-
- return self;
+{
+ tsk_fsm_t *fsm = (tsk_fsm_t*)self;
+ if(fsm) {
+ /* If not in the terminal state ==>do it */
+ /*if(fsm->current != fsm->term){
+ tsk_safeobj_lock(fsm);
+ if(fsm->callback_term){
+ fsm->callback_term(fsm->callback_data);
+ }
+ tsk_safeobj_unlock(fsm);
+ }*/
+ tsk_safeobj_deinit(fsm);
+
+ TSK_OBJECT_SAFE_FREE(fsm->entries);
+ }
+
+ return self;
}
-static const tsk_object_def_t tsk_fsm_def_s =
-{
- sizeof(tsk_fsm_t),
- tsk_fsm_ctor,
- tsk_fsm_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_fsm_def_s = {
+ sizeof(tsk_fsm_t),
+ tsk_fsm_ctor,
+ tsk_fsm_dtor,
+ tsk_null,
};
const tsk_object_def_t *tsk_fsm_def_t = &tsk_fsm_def_s;
@@ -279,54 +283,53 @@ const tsk_object_def_t *tsk_fsm_def_t = &tsk_fsm_def_s;
//
static tsk_object_t* tsk_fsm_entry_ctor(tsk_object_t * self, va_list * app)
{
- tsk_fsm_entry_t *fsm_entry = (tsk_fsm_entry_t*)self;
- if(fsm_entry){
- }
+ tsk_fsm_entry_t *fsm_entry = (tsk_fsm_entry_t*)self;
+ if(fsm_entry) {
+ }
- return self;
+ return self;
}
static tsk_object_t* tsk_fsm_entry_dtor(tsk_object_t * self)
-{
- tsk_fsm_entry_t *fsm_entry = (tsk_fsm_entry_t*)self;
- if(fsm_entry){
- /* desc is "const char*" => should not be deleted */
- /* TSK_FREE(fsm_entry->desc); */
- }
-
- return self;
+{
+ tsk_fsm_entry_t *fsm_entry = (tsk_fsm_entry_t*)self;
+ if(fsm_entry) {
+ /* desc is "const char*" => should not be deleted */
+ /* TSK_FREE(fsm_entry->desc); */
+ }
+
+ return self;
}
static int tsk_fsm_entry_cmp(const tsk_object_t *_entry1, const tsk_object_t *_entry2)
{
- const tsk_fsm_entry_t* entry1 = (const tsk_fsm_entry_t*)_entry1;
- const tsk_fsm_entry_t* entry2 = (const tsk_fsm_entry_t*)_entry2;
- if(entry1 && entry2){
- /* Put "Any" states at the bottom (Strong)*/
- if(entry1->from == tsk_fsm_state_any){
- return -20;
- }
- else if(entry2->from == tsk_fsm_state_any){
- return +20;
- }
-
- /* Put "Any" actions at the bottom (Weak)*/
- if(entry1->action == tsk_fsm_action_any){
- return -10;
- }
- else if(entry1->action == tsk_fsm_action_any){
- return +10;
- }
- // put conditions first
- return entry1->cond ? -1 : (entry2->cond ? 1 : 0);
- }
- return 0;
+ const tsk_fsm_entry_t* entry1 = (const tsk_fsm_entry_t*)_entry1;
+ const tsk_fsm_entry_t* entry2 = (const tsk_fsm_entry_t*)_entry2;
+ if(entry1 && entry2) {
+ /* Put "Any" states at the bottom (Strong)*/
+ if(entry1->from == tsk_fsm_state_any) {
+ return -20;
+ }
+ else if(entry2->from == tsk_fsm_state_any) {
+ return +20;
+ }
+
+ /* Put "Any" actions at the bottom (Weak)*/
+ if(entry1->action == tsk_fsm_action_any) {
+ return -10;
+ }
+ else if(entry1->action == tsk_fsm_action_any) {
+ return +10;
+ }
+ // put conditions first
+ return entry1->cond ? -1 : (entry2->cond ? 1 : 0);
+ }
+ return 0;
}
-static const tsk_object_def_t tsk_fsm_entry_def_s =
-{
- sizeof(tsk_fsm_entry_t),
- tsk_fsm_entry_ctor,
- tsk_fsm_entry_dtor,
- tsk_fsm_entry_cmp,
+static const tsk_object_def_t tsk_fsm_entry_def_s = {
+ sizeof(tsk_fsm_entry_t),
+ tsk_fsm_entry_ctor,
+ tsk_fsm_entry_dtor,
+ tsk_fsm_entry_cmp,
};
const tsk_object_def_t *tsk_fsm_entry_def_t = &tsk_fsm_entry_def_s;
diff --git a/tinySAK/src/tsk_fsm.h b/tinySAK/src/tsk_fsm.h
index 1cd754f..1078367 100755
--- a/tinySAK/src/tsk_fsm.h
+++ b/tinySAK/src/tsk_fsm.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -124,40 +124,38 @@ typedef int (*tsk_fsm_onterminated_f)(const void*);
/**@ingroup tsk_fsm_group
* FSM entry.
*/
-typedef struct tsk_fsm_entry_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_fsm_entry_s {
+ TSK_DECLARE_OBJECT;
- tsk_fsm_state_id from;
- tsk_fsm_action_id action;
- tsk_fsm_cond cond;
- tsk_fsm_state_id to;
- tsk_fsm_exec exec;
- const char* desc;
+ tsk_fsm_state_id from;
+ tsk_fsm_action_id action;
+ tsk_fsm_cond cond;
+ tsk_fsm_state_id to;
+ tsk_fsm_exec exec;
+ const char* desc;
}
tsk_fsm_entry_t;
/**@ingroup tsk_fsm_group
-* List of @ref tsk_fsm_entry_t elements.
+* List of @ref tsk_fsm_entry_t elements.
*/
typedef tsk_list_t tsk_fsm_entries_L_t;
/**@ingroup tsk_fsm_group
* FSM.
*/
-typedef struct tsk_fsm_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_fsm_s {
+ TSK_DECLARE_OBJECT;
- unsigned debug:1;
- tsk_fsm_state_id current;
- tsk_fsm_state_id term;
- tsk_fsm_entries_L_t* entries;
+ unsigned debug:1;
+ tsk_fsm_state_id current;
+ tsk_fsm_state_id term;
+ tsk_fsm_entries_L_t* entries;
- tsk_fsm_onterminated_f callback_term;
- const void* callback_data;
+ tsk_fsm_onterminated_f callback_term;
+ const void* callback_data;
- TSK_DECLARE_SAFEOBJ;
+ TSK_DECLARE_SAFEOBJ;
}
tsk_fsm_t;
diff --git a/tinySAK/src/tsk_hmac.c b/tinySAK/src/tsk_hmac.c
index 2d78dc5..b2563df 100755
--- a/tinySAK/src/tsk_hmac.c
+++ b/tinySAK/src/tsk_hmac.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -45,83 +45,85 @@ int tsk_hmac_xxxcompute(const uint8_t* input, tsk_size_t input_size, const char*
{
#define TSK_MAX_BLOCK_SIZE TSK_SHA1_BLOCK_SIZE
- tsk_size_t i, newkey_size;
-
- tsk_size_t block_size = type == md5 ? TSK_MD5_BLOCK_SIZE : TSK_SHA1_BLOCK_SIZE; // Only SHA-1 and MD5 are supported for now
- tsk_size_t digest_size = type == md5 ? TSK_MD5_DIGEST_SIZE : TSK_SHA1_DIGEST_SIZE;
- char hkey [TSK_MAX_BLOCK_SIZE];
-
- uint8_t ipad [TSK_MAX_BLOCK_SIZE];
- uint8_t opad [TSK_MAX_BLOCK_SIZE];
-
-
- memset(ipad, 0, sizeof(ipad));
- memset(opad, 0, sizeof(ipad));
-
- /*
- * H(K XOR opad, H(K XOR ipad, input))
- */
-
- // Check key len
- if (key_size > block_size){
- if(type == md5){
- TSK_MD5_DIGEST_CALC(key, key_size, (uint8_t*)hkey);
- }
- else if(type == sha1){
- TSK_SHA1_DIGEST_CALC((uint8_t*)key, (unsigned int)key_size, (uint8_t*)hkey);
- }
- else return -3;
-
- newkey_size = digest_size;
- }
- else{
- memcpy(hkey, key, key_size);
- newkey_size = key_size;
- }
-
- memcpy(ipad, hkey, newkey_size);
- memcpy(opad, hkey, newkey_size);
-
- /* [K XOR ipad] and [K XOR opad]*/
- for (i=0; i<block_size; i++){
- ipad[i] ^= 0x36;
- opad[i] ^= 0x5c;
- }
-
-
- {
- tsk_buffer_t *passx; // pass1 or pass2
- int pass1_done = 0;
-
- passx = tsk_buffer_create(ipad, block_size); // pass1
- tsk_buffer_append(passx, input, input_size);
+ tsk_size_t i, newkey_size;
+
+ tsk_size_t block_size = type == md5 ? TSK_MD5_BLOCK_SIZE : TSK_SHA1_BLOCK_SIZE; // Only SHA-1 and MD5 are supported for now
+ tsk_size_t digest_size = type == md5 ? TSK_MD5_DIGEST_SIZE : TSK_SHA1_DIGEST_SIZE;
+ char hkey [TSK_MAX_BLOCK_SIZE];
+
+ uint8_t ipad [TSK_MAX_BLOCK_SIZE];
+ uint8_t opad [TSK_MAX_BLOCK_SIZE];
+
+
+ memset(ipad, 0, sizeof(ipad));
+ memset(opad, 0, sizeof(ipad));
+
+ /*
+ * H(K XOR opad, H(K XOR ipad, input))
+ */
+
+ // Check key len
+ if (key_size > block_size) {
+ if(type == md5) {
+ TSK_MD5_DIGEST_CALC(key, key_size, (uint8_t*)hkey);
+ }
+ else if(type == sha1) {
+ TSK_SHA1_DIGEST_CALC((uint8_t*)key, (unsigned int)key_size, (uint8_t*)hkey);
+ }
+ else {
+ return -3;
+ }
+
+ newkey_size = digest_size;
+ }
+ else {
+ memcpy(hkey, key, key_size);
+ newkey_size = key_size;
+ }
+
+ memcpy(ipad, hkey, newkey_size);
+ memcpy(opad, hkey, newkey_size);
+
+ /* [K XOR ipad] and [K XOR opad]*/
+ for (i=0; i<block_size; i++) {
+ ipad[i] ^= 0x36;
+ opad[i] ^= 0x5c;
+ }
+
+
+ {
+ tsk_buffer_t *passx; // pass1 or pass2
+ int pass1_done = 0;
+
+ passx = tsk_buffer_create(ipad, block_size); // pass1
+ tsk_buffer_append(passx, input, input_size);
digest_compute:
- if(type == md5){
- TSK_MD5_DIGEST_CALC(TSK_BUFFER_TO_U8(passx), (unsigned int)TSK_BUFFER_SIZE(passx), digest);
- }
- else{
- TSK_SHA1_DIGEST_CALC(TSK_BUFFER_TO_U8(passx), (unsigned int)TSK_BUFFER_SIZE(passx), digest);
- }
-
- if(pass1_done){
- TSK_OBJECT_SAFE_FREE(passx);
- goto pass1_and_pass2_done;
- }
- else{
- pass1_done = 1;
- }
-
- tsk_buffer_cleanup(passx);
- tsk_buffer_append(passx, opad, block_size); // pass2
- tsk_buffer_append(passx, digest, digest_size);
-
- goto digest_compute;
- }
+ if(type == md5) {
+ TSK_MD5_DIGEST_CALC(TSK_BUFFER_TO_U8(passx), (unsigned int)TSK_BUFFER_SIZE(passx), digest);
+ }
+ else {
+ TSK_SHA1_DIGEST_CALC(TSK_BUFFER_TO_U8(passx), (unsigned int)TSK_BUFFER_SIZE(passx), digest);
+ }
+
+ if(pass1_done) {
+ TSK_OBJECT_SAFE_FREE(passx);
+ goto pass1_and_pass2_done;
+ }
+ else {
+ pass1_done = 1;
+ }
+
+ tsk_buffer_cleanup(passx);
+ tsk_buffer_append(passx, opad, block_size); // pass2
+ tsk_buffer_append(passx, digest, digest_size);
+
+ goto digest_compute;
+ }
pass1_and_pass2_done:
- return 0;
+ return 0;
}
@@ -133,46 +135,46 @@ pass1_and_pass2_done:
* @date 12/29/2009
*
* @param [in,out] input The input data.
- * @param input_size The size of the input.
- * @param [in,out] key The input key.
- * @param key_size The size of the input key.
+ * @param input_size The size of the input.
+ * @param [in,out] key The input key.
+ * @param key_size The size of the input key.
* @param [out] result Pointer to the result.
*
- * @return Zero if succeed and non-zero error code otherwise.
+ * @return Zero if succeed and non-zero error code otherwise.
**/
int hmac_md5_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_md5string_t *result)
{
- tsk_md5digest_t digest;
- int ret;
+ tsk_md5digest_t digest;
+ int ret;
- if((ret = hmac_md5digest_compute(input, input_size, key, key_size, digest))){
- return ret;
- }
- tsk_str_from_hex(digest, TSK_MD5_DIGEST_SIZE, *result);
- (*result)[TSK_MD5_STRING_SIZE] = '\0';
+ if((ret = hmac_md5digest_compute(input, input_size, key, key_size, digest))) {
+ return ret;
+ }
+ tsk_str_from_hex(digest, TSK_MD5_DIGEST_SIZE, *result);
+ (*result)[TSK_MD5_STRING_SIZE] = '\0';
- return 0;
+ return 0;
}
/**@ingroup tsk_hmac_group
*
- * Calculate HMAC-MD5 hash (bytes) as per RFC 2104.
+ * Calculate HMAC-MD5 hash (bytes) as per RFC 2104.
*
* @author Mamadou
* @date 12/29/2009
*
- * @param [in,out] input The input data.
- * @param input_size The Size of the input.
- * @param [in,out] key The input key.
- * @param key_size The size of the input key.
- * @param result Pointer to the result.
+ * @param [in,out] input The input data.
+ * @param input_size The Size of the input.
+ * @param [in,out] key The input key.
+ * @param key_size The size of the input key.
+ * @param result Pointer to the result.
*
* @return Zero if succeed and non-zero error code otherwise.
**/
int hmac_md5digest_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_md5digest_t result)
{
- return tsk_hmac_xxxcompute(input, input_size, key, key_size, md5, result);
+ return tsk_hmac_xxxcompute(input, input_size, key, key_size, md5, result);
}
/**@ingroup tsk_hmac_group
@@ -182,9 +184,9 @@ int hmac_md5digest_compute(const uint8_t* input, tsk_size_t input_size, const ch
* @author Mamadou
* @date 12/29/2009
*
- * @param [in,out] input The input data.
- * @param input_size The Size of the input.
- * @param [in,out] key The input key.
+ * @param [in,out] input The input data.
+ * @param input_size The Size of the input.
+ * @param [in,out] key The input key.
* @param key_size The size of the input key.
* @param [out] result Pointer to the result.
*
@@ -192,16 +194,16 @@ int hmac_md5digest_compute(const uint8_t* input, tsk_size_t input_size, const ch
**/
int hmac_sha1_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_sha1string_t *result)
{
- tsk_sha1digest_t digest;
- int ret;
+ tsk_sha1digest_t digest;
+ int ret;
- if((ret = hmac_sha1digest_compute(input, input_size, key, key_size, digest))){
- return ret;
- }
- tsk_str_from_hex((uint8_t*)digest, TSK_SHA1_DIGEST_SIZE, (char*)*result);
- (*result)[TSK_SHA1_STRING_SIZE] = '\0';
+ if((ret = hmac_sha1digest_compute(input, input_size, key, key_size, digest))) {
+ return ret;
+ }
+ tsk_str_from_hex((uint8_t*)digest, TSK_SHA1_DIGEST_SIZE, (char*)*result);
+ (*result)[TSK_SHA1_STRING_SIZE] = '\0';
- return 0;
+ return 0;
}
/**@ingroup tsk_hmac_group
@@ -211,16 +213,16 @@ int hmac_sha1_compute(const uint8_t* input, tsk_size_t input_size, const char* k
* @author Mamadou
* @date 12/29/2009
*
- * @param [in,out] input If non-null, the input.
- * @param input_size The size of the input.
- * @param [in,out] key The input key.
+ * @param [in,out] input If non-null, the input.
+ * @param input_size The size of the input.
+ * @param [in,out] key The input key.
* @param key_size The size of the input key.
- * @param result Pointer to the result.
+ * @param result Pointer to the result.
*
- * @return Zero if succeed and non-zero error code otherwise.
+ * @return Zero if succeed and non-zero error code otherwise.
**/
int hmac_sha1digest_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_sha1digest_t result)
{
- return tsk_hmac_xxxcompute(input, input_size, key, key_size, sha1, (uint8_t*)result);
+ return tsk_hmac_xxxcompute(input, input_size, key, key_size, sha1, (uint8_t*)result);
}
diff --git a/tinySAK/src/tsk_hmac.h b/tinySAK/src/tsk_hmac.h
index 5bd76b4..c91d7db 100755
--- a/tinySAK/src/tsk_hmac.h
+++ b/tinySAK/src/tsk_hmac.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_list.c b/tinySAK/src/tsk_list.c
index fb59ac7..5726b28 100755
--- a/tinySAK/src/tsk_list.c
+++ b/tinySAK/src/tsk_list.c
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -35,7 +35,7 @@
*/
static int tsk_list_find_by_item(const tsk_list_item_t* item, const void* _item)
{
- return (item == (const tsk_list_item_t*)_item) ? 0 : -1;
+ return (item == (const tsk_list_item_t*)_item) ? 0 : -1;
}
/**@ingroup tsk_list_group
@@ -45,18 +45,18 @@ static int tsk_list_find_by_item(const tsk_list_item_t* item, const void* _item)
*/
tsk_list_t* tsk_list_create()
{
- return (tsk_list_t*)tsk_object_new(tsk_list_def_t);
+ return (tsk_list_t*)tsk_object_new(tsk_list_def_t);
}
/**@ingroup tsk_list_group
-* Create and initialize an item to be added to a @ref tsk_list_t "linked list".
+* Create and initialize an item to be added to a @ref tsk_list_t "linked list".
* You should not need to call this function by yourself. See @ref _Anchor_TinySAK_Linked_List_Add_Remove "here" for more information on how to add items.<br />
* You <b>MUST</b> use @ref TSK_OBJECT_SAFE_FREE() to safely free the returned @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object. <br />
* @return The newly created @ref tsk_list_item_t "item" object.
*/
tsk_list_item_t* tsk_list_item_create()
{
- return (tsk_list_item_t*)tsk_object_new(tsk_list_item_def_t);
+ return (tsk_list_item_t*)tsk_object_new(tsk_list_item_def_t);
}
/**@ingroup tsk_list_group
@@ -68,16 +68,16 @@ tsk_list_item_t* tsk_list_item_create()
*/
int tsk_list_lock(tsk_list_t* list)
{
- if(list){
- if(!list->mutex){
- list->mutex = tsk_mutex_create();
- }
- return tsk_mutex_lock(list->mutex);
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(list) {
+ if(!list->mutex) {
+ list->mutex = tsk_mutex_create();
+ }
+ return tsk_mutex_lock(list->mutex);
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_list_group
@@ -89,13 +89,13 @@ int tsk_list_lock(tsk_list_t* list)
*/
int tsk_list_unlock(tsk_list_t* list)
{
- if(list && list->mutex){
- return tsk_mutex_unlock(list->mutex);
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(list && list->mutex) {
+ return tsk_mutex_unlock(list->mutex);
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_list_group
@@ -107,10 +107,10 @@ int tsk_list_unlock(tsk_list_t* list)
*/
tsk_bool_t tsk_list_remove_item(tsk_list_t* list, tsk_list_item_t* item)
{
- if(item){
- return tsk_list_remove_item_by_pred(list, tsk_list_find_by_item, (const void*)item);
- }
- return tsk_false;
+ if(item) {
+ return tsk_list_remove_item_by_pred(list, tsk_list_find_by_item, (const void*)item);
+ }
+ return tsk_false;
}
/**@ingroup tsk_list_group
@@ -122,42 +122,42 @@ tsk_bool_t tsk_list_remove_item(tsk_list_t* list, tsk_list_item_t* item)
*/
tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const tsk_object_t *tskobj)
{
- if(list){
- tsk_list_item_t *prev = tsk_null;
- tsk_list_item_t *curr = prev = list->head;
-
- while(curr){
- if(!tsk_object_cmp(curr->data, tskobj)){
- if(prev == curr){
- /* Found at first position. */
- if(list->head == list->tail){
- /* There was only one item */
- list->head = list->tail = tsk_null;
- }
- else{
- list->head = curr->next;
- }
- }
- else {
- if(curr == list->tail){
- /* Found at last position */
- list->tail = prev;
- list->tail->next = tsk_null;
- }
- else{
- prev->next = curr->next;
- }
- }
-
- return curr;
- }
-
- prev = curr;
- curr = curr->next;
- }
- }
-
- return tsk_null;
+ if(list) {
+ tsk_list_item_t *prev = tsk_null;
+ tsk_list_item_t *curr = prev = list->head;
+
+ while(curr) {
+ if(!tsk_object_cmp(curr->data, tskobj)) {
+ if(prev == curr) {
+ /* Found at first position. */
+ if(list->head == list->tail) {
+ /* There was only one item */
+ list->head = list->tail = tsk_null;
+ }
+ else {
+ list->head = curr->next;
+ }
+ }
+ else {
+ if(curr == list->tail) {
+ /* Found at last position */
+ list->tail = prev;
+ list->tail->next = tsk_null;
+ }
+ else {
+ prev->next = curr->next;
+ }
+ }
+
+ return curr;
+ }
+
+ prev = curr;
+ curr = curr->next;
+ }
+ }
+
+ return tsk_null;
}
/**@ingroup tsk_list_group
@@ -168,12 +168,12 @@ tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const tsk_object_t
*/
tsk_bool_t tsk_list_remove_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj)
{
- tsk_list_item_t* item;
- if((item = tsk_list_pop_item_by_data(list, tskobj))){
- tsk_object_unref(item);
- return tsk_true;
- }
- return tsk_false;
+ tsk_list_item_t* item;
+ if((item = tsk_list_pop_item_by_data(list, tskobj))) {
+ tsk_object_unref(item);
+ return tsk_true;
+ }
+ return tsk_false;
}
/**@ingroup tsk_list_group
@@ -187,42 +187,42 @@ tsk_bool_t tsk_list_remove_item_by_data(tsk_list_t* list, const tsk_object_t * t
*/
tsk_list_item_t* tsk_list_pop_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data)
{
- if(list){
- tsk_list_item_t *prev = tsk_null;
- tsk_list_item_t *curr = prev = list->head;
-
- while(curr){
- if(!predicate(curr, data)){
- if(prev == curr){
- /* Found at first position. */
- if(list->head == list->tail){
- /* There was only one item */
- list->head = list->tail = tsk_null;
- }
- else{
- list->head = curr->next;
- }
- }
- else {
- if(curr == list->tail){
- /* Found at last position */
- list->tail = prev;
- list->tail->next = tsk_null;
- }
- else{
- prev->next = curr->next;
- }
- }
-
- return curr;
- }
-
- prev = curr;
- curr = curr->next;
- }
- }
-
- return 0;
+ if(list) {
+ tsk_list_item_t *prev = tsk_null;
+ tsk_list_item_t *curr = prev = list->head;
+
+ while(curr) {
+ if(!predicate(curr, data)) {
+ if(prev == curr) {
+ /* Found at first position. */
+ if(list->head == list->tail) {
+ /* There was only one item */
+ list->head = list->tail = tsk_null;
+ }
+ else {
+ list->head = curr->next;
+ }
+ }
+ else {
+ if(curr == list->tail) {
+ /* Found at last position */
+ list->tail = prev;
+ list->tail->next = tsk_null;
+ }
+ else {
+ prev->next = curr->next;
+ }
+ }
+
+ return curr;
+ }
+
+ prev = curr;
+ curr = curr->next;
+ }
+ }
+
+ return 0;
}
/**@ingroup tsk_list_group
@@ -234,12 +234,12 @@ tsk_list_item_t* tsk_list_pop_item_by_pred(tsk_list_t* list, tsk_list_func_predi
*/
tsk_bool_t tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data)
{
- tsk_list_item_t* item;
- if((item = tsk_list_pop_item_by_pred(list, predicate, data))){
- tsk_object_unref(item);
- return tsk_true;
- }
- return tsk_false;
+ tsk_list_item_t* item;
+ if((item = tsk_list_pop_item_by_pred(list, predicate, data))) {
+ tsk_object_unref(item);
+ return tsk_true;
+ }
+ return tsk_false;
}
/**@ingroup tsk_list_group
@@ -248,18 +248,18 @@ tsk_bool_t tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicat
*/
void tsk_list_clear_items(tsk_list_t* list)
{
- if(list){
- tsk_list_item_t* next = tsk_null;
- tsk_list_item_t* curr = list->head;
-
- while(curr){
- next = curr->next;
- tsk_object_unref(curr);
- curr = next;
- }
- list->head = tsk_null;
- list->tail = tsk_null;
- }
+ if(list) {
+ tsk_list_item_t* next = tsk_null;
+ tsk_list_item_t* curr = list->head;
+
+ while(curr) {
+ next = curr->next;
+ tsk_object_unref(curr);
+ curr = next;
+ }
+ list->head = tsk_null;
+ list->tail = tsk_null;
+ }
}
/**@ingroup tsk_list_group
@@ -269,20 +269,20 @@ void tsk_list_clear_items(tsk_list_t* list)
*/
tsk_list_item_t* tsk_list_pop_first_item(tsk_list_t* list)
{
- tsk_list_item_t* item = tsk_null;
- if(list){
- item = list->head;
- if(list->head){
- if(list->head->next){
- list->head = list->head->next;
- }
- else{
- list->head = list->tail = tsk_null;
- }
- }
- }
+ tsk_list_item_t* item = tsk_null;
+ if(list) {
+ item = list->head;
+ if(list->head) {
+ if(list->head->next) {
+ list->head = list->head->next;
+ }
+ else {
+ list->head = list->tail = tsk_null;
+ }
+ }
+ }
- return item;
+ return item;
}
/**@ingroup tsk_list_group
@@ -293,20 +293,20 @@ tsk_list_item_t* tsk_list_pop_first_item(tsk_list_t* list)
*/
void tsk_list_push_item(tsk_list_t* list, tsk_list_item_t** item, tsk_bool_t back)
{
- // do not test
- tsk_bool_t first = !list->head;
-
- if(back && list->tail){
- list->tail->next = *item, list->tail = *item, (*item)->next = tsk_null;
- }
- else {
- (*item)->next = list->head, list->head = *item;
- }
-
- if(first){
- list->tail = list->head = *item, list->tail->next = tsk_null;
- }
- (*item) = tsk_null;
+ // do not test
+ tsk_bool_t first = !list->head;
+
+ if(back && list->tail) {
+ list->tail->next = *item, list->tail = *item, (*item)->next = tsk_null;
+ }
+ else {
+ (*item)->next = list->head, list->head = *item;
+ }
+
+ if(first) {
+ list->tail = list->head = *item, list->tail->next = tsk_null;
+ }
+ (*item) = tsk_null;
}
/**@ingroup tsk_list_group
@@ -318,44 +318,44 @@ void tsk_list_push_item(tsk_list_t* list, tsk_list_item_t** item, tsk_bool_t bac
*/
void tsk_list_push_filtered_item(tsk_list_t* list, tsk_list_item_t** item, tsk_bool_t ascending)
{
- if (list && item && *item) {
- tsk_list_item_t *prev = tsk_null;
- tsk_list_item_t *curr = prev = list->head;
- int diff;
-
- while (curr) {
- diff = tsk_object_cmp((*item), curr);
- if (diff == 0 || (diff </*=*/ 0 && ascending) || (diff >/*=*/0 && !ascending)) {
- int after = (diff == 0); // push_after(match) -> backward compatibility
- int back = (after && (curr == list->tail));
- int front = !back && (curr == list->head);
-
- if (back) {
- tsk_list_push_back_item(list, item);
- }
- else if (front) {
- tsk_list_push_front_item(list, item);
- }
- else {
- if (after) {
- // push_after(match)
- (*item)->next = curr->next;
- curr->next = (*item);
- }
- else {
- // push_before(match)
- (*item)->next = curr;
- prev->next = (*item);
- }
- }
- (*item) = tsk_null;
- return;
- }
- prev = curr;
- curr = curr->next;
- }
- tsk_list_push_back_item(list, item);
- }
+ if (list && item && *item) {
+ tsk_list_item_t *prev = tsk_null;
+ tsk_list_item_t *curr = prev = list->head;
+ int diff;
+
+ while (curr) {
+ diff = tsk_object_cmp((*item), curr);
+ if (diff == 0 || (diff </*=*/ 0 && ascending) || (diff >/*=*/0 && !ascending)) {
+ int after = (diff == 0); // push_after(match) -> backward compatibility
+ int back = (after && (curr == list->tail));
+ int front = !back && (curr == list->head);
+
+ if (back) {
+ tsk_list_push_back_item(list, item);
+ }
+ else if (front) {
+ tsk_list_push_front_item(list, item);
+ }
+ else {
+ if (after) {
+ // push_after(match)
+ (*item)->next = curr->next;
+ curr->next = (*item);
+ }
+ else {
+ // push_before(match)
+ (*item)->next = curr;
+ prev->next = (*item);
+ }
+ }
+ (*item) = tsk_null;
+ return;
+ }
+ prev = curr;
+ curr = curr->next;
+ }
+ tsk_list_push_back_item(list, item);
+ }
}
/**@ingroup tsk_list_group
@@ -367,25 +367,25 @@ void tsk_list_push_filtered_item(tsk_list_t* list, tsk_list_item_t** item, tsk_b
**/
int tsk_list_push_list(tsk_list_t* dest, const tsk_list_t* src, tsk_bool_t back)
{
- const tsk_list_item_t* curr = (src)->head;
- tsk_object_t* copy;
-
- if(!dest || !src){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ const tsk_list_item_t* curr = (src)->head;
+ tsk_object_t* copy;
- while(curr){
- copy = tsk_object_ref(curr->data);
- tsk_list_push_data(dest, (void**)&copy, back);
-
- curr = curr->next;
- }
- return 0;
+ if(!dest || !src) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ while(curr) {
+ copy = tsk_object_ref(curr->data);
+ tsk_list_push_data(dest, (void**)&copy, back);
+
+ curr = curr->next;
+ }
+ return 0;
}
/**@ingroup tsk_list_group
-* Adds a @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object to the @a list.
+* Adds a @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object to the @a list.
* The reference to the @a object will be stolen(set to @ref tsk_null) instead of incrementing its reference counter.
* @param list The destination @a list.
* @param tskobj The @a object to add.
@@ -395,19 +395,19 @@ int tsk_list_push_list(tsk_list_t* dest, const tsk_list_t* src, tsk_bool_t back)
*/
int tsk_list_push_data(tsk_list_t* list, tsk_object_t** tskobj, tsk_bool_t back)
{
- if(list && tskobj && *tskobj){
- tsk_list_item_t *item = tsk_list_item_create();
- item->data = *tskobj; // stolen
-
- tsk_list_push_item(list, &item, back);
- (*tskobj) = tsk_null;
+ if(list && tskobj && *tskobj) {
+ tsk_list_item_t *item = tsk_list_item_create();
+ item->data = *tskobj; // stolen
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ tsk_list_push_item(list, &item, back);
+ (*tskobj) = tsk_null;
+
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_list_group
@@ -420,19 +420,19 @@ int tsk_list_push_data(tsk_list_t* list, tsk_object_t** tskobj, tsk_bool_t back)
*/
int tsk_list_push_filtered_data(tsk_list_t* list, tsk_object_t** tskobj, tsk_bool_t ascending)
{
- if(list && tskobj && *tskobj){
- tsk_list_item_t *item = tsk_list_item_create();
- item->data = *tskobj;
-
- tsk_list_push_filtered_item(list, &item, ascending);
- (*tskobj) = tsk_null;
+ if(list && tskobj && *tskobj) {
+ tsk_list_item_t *item = tsk_list_item_create();
+ item->data = *tskobj;
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ tsk_list_push_filtered_item(list, &item, ascending);
+ (*tskobj) = tsk_null;
+
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_list_group
@@ -446,16 +446,16 @@ int tsk_list_push_filtered_data(tsk_list_t* list, tsk_object_t** tskobj, tsk_boo
*/
const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const tsk_object_t* tskobj)
{
- if(list && tskobj){
- tsk_list_item_t *item;
- tsk_list_foreach(item, list){
- if(!tsk_object_cmp(item->data, tskobj)){
- return item;
- }
- }
- }
-
- return 0;
+ if(list && tskobj) {
+ tsk_list_item_t *item;
+ tsk_list_foreach(item, list) {
+ if(!tsk_object_cmp(item->data, tskobj)) {
+ return item;
+ }
+ }
+ }
+
+ return 0;
}
/**@ingroup tsk_list_group
@@ -470,18 +470,18 @@ const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const
*/
const tsk_list_item_t* tsk_list_find_item_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const void* data)
{
- if(predicate){
- const tsk_list_item_t *item;
- tsk_list_foreach(item, list){
- if(predicate(item, data) == 0){
- return item;
- }
- }
- }
- else{
- TSK_DEBUG_WARN("Cannot use a null predicate function");
- }
- return tsk_null;
+ if(predicate) {
+ const tsk_list_item_t *item;
+ tsk_list_foreach(item, list) {
+ if(predicate(item, data) == 0) {
+ return item;
+ }
+ }
+ }
+ else {
+ TSK_DEBUG_WARN("Cannot use a null predicate function");
+ }
+ return tsk_null;
}
/**@ingroup tsk_list_group
@@ -495,47 +495,47 @@ const tsk_list_item_t* tsk_list_find_item_by_pred(const tsk_list_t* list, tsk_li
*/
const tsk_object_t* tsk_list_find_object_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const void* data)
{
- return tsk_list_find_object_by_pred_at_index(list, predicate, data, 0);
+ return tsk_list_find_object_by_pred_at_index(list, predicate, data, 0);
}
const tsk_object_t* tsk_list_find_object_by_data(const tsk_list_t* list, const tsk_object_t* tskobj)
{
- const tsk_list_item_t* item = tsk_list_find_item_by_data(list, tskobj);
- if(item) {
- return (const tsk_object_t*)item->data;
- }
- return tsk_null;
+ const tsk_list_item_t* item = tsk_list_find_item_by_data(list, tskobj);
+ if(item) {
+ return (const tsk_object_t*)item->data;
+ }
+ return tsk_null;
}
/**@ingroup tsk_list_group */
const tsk_object_t* tsk_list_find_object_by_pred_at_index(const tsk_list_t* list, tsk_list_func_predicate predicate, const void* data, tsk_size_t index)
{
- tsk_size_t pos = 0;
- const tsk_list_item_t *item;
-
- tsk_list_foreach(item, list){
- if((!predicate || predicate(item, data) == 0) && pos++ >= index){
- return item->data;
- }
- }
-
- return tsk_null;
+ tsk_size_t pos = 0;
+ const tsk_list_item_t *item;
+
+ tsk_list_foreach(item, list) {
+ if((!predicate || predicate(item, data) == 0) && pos++ >= index) {
+ return item->data;
+ }
+ }
+
+ return tsk_null;
}
/**@ingroup tsk_list_group */
int tsk_list_find_index_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const void* data)
-{
- if(list && predicate){
- int index = 0;
- const tsk_list_item_t *item;
- tsk_list_foreach(item, list){
- if(predicate(item, data) == 0){
- return index;
- }
- ++index;
- }
- }
- return -1;
+{
+ if(list && predicate) {
+ int index = 0;
+ const tsk_list_item_t *item;
+ tsk_list_foreach(item, list) {
+ if(predicate(item, data) == 0) {
+ return index;
+ }
+ ++index;
+ }
+ }
+ return -1;
}
/**@ingroup tsk_list_group
@@ -547,34 +547,34 @@ int tsk_list_find_index_by_pred(const tsk_list_t* list, tsk_list_func_predicate
*/
tsk_size_t tsk_list_count(const tsk_list_t* list, tsk_list_func_predicate predicate, const void* data)
{
- tsk_size_t count = 0;
- if(list){
- const tsk_list_item_t *item;
- tsk_list_foreach(item, list){
- if(!predicate || (predicate(item, data) == 0)){
- ++count;
- }
- }
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- }
+ tsk_size_t count = 0;
+ if(list) {
+ const tsk_list_item_t *item;
+ tsk_list_foreach(item, list) {
+ if(!predicate || (predicate(item, data) == 0)) {
+ ++count;
+ }
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
- return count;
+ return count;
}
/**@ingroup tsk_list_group
*/
tsk_list_t* tsk_list_clone(const tsk_list_t* list)
{
- if (list) {
- tsk_list_t*clone = tsk_list_create();
- if (clone) {
- tsk_list_pushback_list(clone, list);
- }
- return clone;
- }
- return tsk_null;
+ if (list) {
+ tsk_list_t*clone = tsk_list_create();
+ if (clone) {
+ tsk_list_pushback_list(clone, list);
+ }
+ return clone;
+ }
+ return tsk_null;
}
@@ -590,41 +590,42 @@ tsk_list_t* tsk_list_clone(const tsk_list_t* list)
//
static tsk_object_t* tsk_list_item_ctor(tsk_object_t * self, va_list * app)
{
- tsk_list_item_t *item = (tsk_list_item_t*)self;
- if(item){
- }
- return self;
+ tsk_list_item_t *item = (tsk_list_item_t*)self;
+ if(item) {
+ }
+ return self;
}
static tsk_object_t* tsk_list_item_dtor(tsk_object_t *self)
{
- tsk_list_item_t *item = (tsk_list_item_t*)self;
- if(item){
- item->data = tsk_object_unref(item->data);
- }
- else{
- TSK_DEBUG_WARN("Cannot free an uninitialized item");
- }
- return item;
+ tsk_list_item_t *item = (tsk_list_item_t*)self;
+ if(item) {
+ item->data = tsk_object_unref(item->data);
+ }
+ else {
+ TSK_DEBUG_WARN("Cannot free an uninitialized item");
+ }
+ return item;
}
static int tsk_list_item_cmp(const tsk_object_t *_item1, const tsk_object_t *_item2)
-{
- const tsk_list_item_t* item1 = (const tsk_list_item_t*)_item1;
- const tsk_list_item_t* item2 = (const tsk_list_item_t*)_item2;
-
- if(item1 && item2){
- return tsk_object_cmp(item1->data, item2->data);
- }
- else return -1;
+{
+ const tsk_list_item_t* item1 = (const tsk_list_item_t*)_item1;
+ const tsk_list_item_t* item2 = (const tsk_list_item_t*)_item2;
+
+ if(item1 && item2) {
+ return tsk_object_cmp(item1->data, item2->data);
+ }
+ else {
+ return -1;
+ }
}
-static const tsk_object_def_t tsk_list_item_def_s =
-{
- sizeof(tsk_list_item_t),
- tsk_list_item_ctor,
- tsk_list_item_dtor,
- tsk_list_item_cmp,
+static const tsk_object_def_t tsk_list_item_def_s = {
+ sizeof(tsk_list_item_t),
+ tsk_list_item_ctor,
+ tsk_list_item_dtor,
+ tsk_list_item_cmp,
};
const tsk_object_def_t *tsk_list_item_def_t = &tsk_list_item_def_s;
@@ -633,52 +634,51 @@ const tsk_object_def_t *tsk_list_item_def_t = &tsk_list_item_def_s;
//
static tsk_object_t* tsk_list_ctor(tsk_object_t *self, va_list *app)
{
- tsk_list_t *list = (tsk_list_t *)self;
- if(list){
- }
+ tsk_list_t *list = (tsk_list_t *)self;
+ if(list) {
+ }
- return self;
+ return self;
}
static tsk_object_t* tsk_list_dtor(tsk_object_t *self)
-{
- tsk_list_t *list = (tsk_list_t *)self;
- if(list){
+{
+ tsk_list_t *list = (tsk_list_t *)self;
+ if(list) {
#if 0
- /* Not thread-safe */
- tsk_list_item_t* next = tsk_null;
- tsk_list_item_t* curr = list->head;
-
- while(curr){
- next = curr->next;
- /*curr =*/ tsk_object_unref(curr);
- curr = next;
- }
+ /* Not thread-safe */
+ tsk_list_item_t* next = tsk_null;
+ tsk_list_item_t* curr = list->head;
+
+ while(curr) {
+ next = curr->next;
+ /*curr =*/ tsk_object_unref(curr);
+ curr = next;
+ }
#else
- /* Thread-safe method */
- tsk_list_item_t* item;
- while((item = tsk_list_pop_first_item(list))){
- tsk_object_unref(item);
- }
+ /* Thread-safe method */
+ tsk_list_item_t* item;
+ while((item = tsk_list_pop_first_item(list))) {
+ tsk_object_unref(item);
+ }
#endif
- /* destroy the on-demand mutex */
- if(list->mutex){
- tsk_mutex_destroy(&list->mutex);
- }
- }
- else{
- TSK_DEBUG_WARN("Cannot free an uninitialized list");
- }
- return list;
-}
-
-static const tsk_object_def_t tsk_list_def_s =
-{
- sizeof(tsk_list_t),
- tsk_list_ctor,
- tsk_list_dtor,
- tsk_null,
+ /* destroy the on-demand mutex */
+ if(list->mutex) {
+ tsk_mutex_destroy(&list->mutex);
+ }
+ }
+ else {
+ TSK_DEBUG_WARN("Cannot free an uninitialized list");
+ }
+ return list;
+}
+
+static const tsk_object_def_t tsk_list_def_s = {
+ sizeof(tsk_list_t),
+ tsk_list_ctor,
+ tsk_list_dtor,
+ tsk_null,
};
const tsk_object_def_t *tsk_list_def_t = &tsk_list_def_s;
@@ -701,19 +701,19 @@ const tsk_object_def_t *tsk_list_def_t = &tsk_list_def_s;
*
* A linked-list is a @ref _Page_TinySAK_AnsiC_Object_Programming "well defined" object and must contain only @ref _Page_TinySAK_AnsiC_Object_Programming "well defined" objects. <br />
* A linked-list is a @ref tsk_list_t object and contains @ref tsk_list_item_t objects which holds @ref _Anchor_TinySAK_Linked_List_Well_Defined_Object "our well defined object" in its <i>data</i> field. <br />
-*
+*
* <h2>@anchor _Anchor_TinySAK_Linked_List_Well_Defined_Object Our "well-defined" object</h2>
* Our linked-list will hold a "well defined" object defined like this:
*
*@code
// (well-defined object declaration)
-typedef struct student_s
-{
+typedef struct student_s
+{
TSK_DECLARE_OBJECT;
char *id;
char *name;
-}
+}
student_t;
// (constructor)
@@ -736,7 +736,7 @@ static tsk_object_t* student_dtor(tsk_object_t* self)
// (case insensitive comparator)
static int student_icmp(const tsk_object_t *self, const tsk_object_t *object)
-{
+{
const student_t* student1 = (const tsk_object_t*)self;
const student_t* student2 = (const tsk_object_t*)object;
@@ -750,7 +750,7 @@ static int student_icmp(const tsk_object_t *self, const tsk_object_t *object)
// (well-defined object declaration)
static const tsk_object_def_t student_def_s =
{
- sizeof(student_t),
+ sizeof(student_t),
student_ctor,
student_dtor,
student_icmp
@@ -820,7 +820,7 @@ static int pred_find_student_by_id(const tsk_list_item_t *item, const void *id)
* There are two ways to add items to the list: <br />
* First way:
* @code
-* // create the well-defined object
+* // create the well-defined object
* student_t *student = student_create("0", "student-0");
* // push the object at the end of the list
* tsk_list_push_back_data(list, (void**)&student);
@@ -857,7 +857,7 @@ static int pred_find_student_by_id(const tsk_list_item_t *item, const void *id)
* TSK_DEBUG_INFO("id = %s, name = %s", student->id, student->name);
* }
* @endcode
-*
+*
* <h2>@anchor _Anchor_TinySAK_Linked_List_Sort_Items Sort items</h2>
* You can sort the list in ascending or descending order. The default function used for comparison is the one defined in the well-defined object (see @ref _Anchor_TinySAK_Object_Comparator "here" for more information). <br />
* An item is sorted when it's being added to the list. It's not possible to sort items later once they are added. <br />
@@ -873,7 +873,7 @@ static int pred_find_student_by_id(const tsk_list_item_t *item, const void *id)
*
* <h2>@anchor _Anchor_TinySAK_Linked_List_Find_Items Find items</h2>
* @code
-* // find student with same id
+* // find student with same id
* const student_t* _student = tsk_list_find_object_by_data(list, student);// comparision function will be student_icmp() defined above.
* // find an item containing a student with name equal to "student-2"
* const tsk_list_item_t *item = tsk_list_find_item_by_pred(list, pred_find_student_by_name, "student-2");
diff --git a/tinySAK/src/tsk_list.h b/tinySAK/src/tsk_list.h
index bc0d4d4..184e360 100755
--- a/tinySAK/src/tsk_list.h
+++ b/tinySAK/src/tsk_list.h
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -71,30 +71,28 @@ TSK_BEGIN_DECLS
#define TSK_LIST_LAST_DATA(list) (((list) && (list)->tail) ? (list)->tail->data : tsk_null)
/**@ingroup tsk_list_group
-* Item for @ref tsk_list_t "linked list".
+* Item for @ref tsk_list_t "linked list".
*/
-typedef struct tsk_list_item_s
-{
- TSK_DECLARE_OBJECT;
- void* data; /**< Opaque data. <b>Must</b> be a @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object. */
- struct tsk_list_item_s* next; /**< Next item. */
+typedef struct tsk_list_item_s {
+ TSK_DECLARE_OBJECT;
+ void* data; /**< Opaque data. <b>Must</b> be a @ref _Page_TinySAK_AnsiC_Object_Programming "well-defined" object. */
+ struct tsk_list_item_s* next; /**< Next item. */
}
tsk_list_item_t;
/**@ingroup tsk_list_group
* A @ref _Page_TinySAK_AnsiC_Linked_List "linked-list".
*/
-typedef struct tsk_list_s
-{
- TSK_DECLARE_OBJECT;
-
- tsk_list_item_t* head; /**< The head of the linked list. */
- tsk_list_item_t* tail; /**< The tail of the linked list. */
- tsk_mutex_handle_t* mutex; /**< on-demand mutex. */
+typedef struct tsk_list_s {
+ TSK_DECLARE_OBJECT;
+
+ tsk_list_item_t* head; /**< The head of the linked list. */
+ tsk_list_item_t* tail; /**< The tail of the linked list. */
+ tsk_mutex_handle_t* mutex; /**< on-demand mutex. */
}
tsk_list_t;
-/**@ingroup tsk_list_group
+/**@ingroup tsk_list_group
* Function predicate used to match an item. <br />
* For example, see @ref _Anchor_TinySAK_Linked_List_Find_Items "here" for more information on how to use this function to find items.
* @param item The current item to match.
diff --git a/tinySAK/src/tsk_md5.c b/tinySAK/src/tsk_md5.c
index d7b0251..cdbf14a 100755
--- a/tinySAK/src/tsk_md5.c
+++ b/tinySAK/src/tsk_md5.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -35,7 +35,7 @@
#include <string.h>
/**@defgroup tsk_md5_group MD5 (RFC 1321) utility functions.
- * The code in this file is a modified version of an implementation placed in the public domain by the following persons:
+ * The code in this file is a modified version of an implementation placed in the public domain by the following persons:
* @author Colin Plumb
* @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
*/
@@ -47,7 +47,7 @@ void tsk_byteReverse(uint32_t *buf, unsigned words)
{
uint8_t *p = (uint8_t *)buf;
- do{
+ do {
*buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 |
((unsigned)p[1] << 8 | p[0]);
p += 4;
@@ -84,12 +84,12 @@ void tsk_md5update(tsk_md5context_t *ctx, uint8_t const *buf, tsk_size_t len)
/* Update byte count */
t = ctx->bytes[0];
- if ((ctx->bytes[0] = t + (uint32_t)len) < t)
- ctx->bytes[1]++; /* Carry from low to high */
+ if ((ctx->bytes[0] = t + (uint32_t)len) < t) {
+ ctx->bytes[1]++; /* Carry from low to high */
+ }
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
- if (t > len)
- {
+ if (t > len) {
memcpy((uint8_t *)ctx->in + 64 - t, buf, len);
return ;
}
@@ -101,8 +101,7 @@ void tsk_md5update(tsk_md5context_t *ctx, uint8_t const *buf, tsk_size_t len)
len -= t;
/* Process data in 64-byte chunks */
- while (len >= 64)
- {
+ while (len >= 64) {
memcpy(ctx->in, buf, 64);
tsk_byteReverse(ctx->in, 16);
tsk_md5transform(ctx->buf, ctx->in);
@@ -115,7 +114,7 @@ void tsk_md5update(tsk_md5context_t *ctx, uint8_t const *buf, tsk_size_t len)
}
/**@ingroup tsk_md5_group
- * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void tsk_md5final(tsk_md5digest_t digest, tsk_md5context_t *ctx)
@@ -129,8 +128,8 @@ void tsk_md5final(tsk_md5digest_t digest, tsk_md5context_t *ctx)
/* Bytes of padding needed to make 56 bytes (-8..55) */
count = 56 - 1 - count;
- if (count < 0)
- { /* Padding forces an extra block */
+ if (count < 0) {
+ /* Padding forces an extra block */
memset(p, 0, count + 8);
tsk_byteReverse(ctx->in, 16);
tsk_md5transform(ctx->buf, ctx->in);
@@ -253,24 +252,26 @@ void tsk_md5transform(uint32_t buf[4], uint32_t const in[TSK_MD5_DIGEST_SIZE])
/**@ingroup tsk_md5_group
*
- * @brief Calculate MD5 HASH for @a input data.
+ * @brief Calculate MD5 HASH for @a input data.
*
- * @param input The input data.
- * @param size The size of the input data.
- * @param result MD5 hash result as Hexadecimal string.
+ * @param input The input data.
+ * @param size The size of the input data.
+ * @param result MD5 hash result as Hexadecimal string.
*
- * @return Zero if succeed and non-zero error code otherwise.
+ * @return Zero if succeed and non-zero error code otherwise.
**/
int tsk_md5compute(const char* input, tsk_size_t size, tsk_md5string_t *result)
{
- tsk_md5digest_t digest;
+ tsk_md5digest_t digest;
+
+ if(!result | !*result) {
+ return -1;
+ }
+
+ (*result)[TSK_MD5_STRING_SIZE] = '\0';
- if(!result | !*result) return -1;
-
- (*result)[TSK_MD5_STRING_SIZE] = '\0';
-
- TSK_MD5_DIGEST_CALC(input, size, digest);
- tsk_str_from_hex(digest, TSK_MD5_DIGEST_SIZE, *result);
+ TSK_MD5_DIGEST_CALC(input, size, digest);
+ tsk_str_from_hex(digest, TSK_MD5_DIGEST_SIZE, *result);
- return 0;
+ return 0;
}
diff --git a/tinySAK/src/tsk_md5.h b/tinySAK/src/tsk_md5.h
index 87f711d..d94b626 100755
--- a/tinySAK/src/tsk_md5.h
+++ b/tinySAK/src/tsk_md5.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -74,11 +74,10 @@ typedef uint8_t tsk_md5digest_t[TSK_MD5_DIGEST_SIZE]; /**< MD5 digest bytes. */
tsk_md5final((digest), &ctx); \
}
-typedef struct tsk_md5context_s
-{
- uint32_t buf[4];
- uint32_t bytes[2];
- uint32_t in[16];
+typedef struct tsk_md5context_s {
+ uint32_t buf[4];
+ uint32_t bytes[2];
+ uint32_t in[16];
}
tsk_md5context_t;
diff --git a/tinySAK/src/tsk_memory.c b/tinySAK/src/tsk_memory.c
index 9d72fc0..0d5a62c 100755
--- a/tinySAK/src/tsk_memory.c
+++ b/tinySAK/src/tsk_memory.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -47,24 +47,24 @@
*/
void* tsk_malloc(tsk_size_t size)
{
- void *ret = malloc(size);
- if(!ret){
- TSK_DEBUG_ERROR("Memory allocation failed");
- }
+ void *ret = malloc(size);
+ if(!ret) {
+ TSK_DEBUG_ERROR("Memory allocation failed");
+ }
- return ret;
+ return ret;
}
/**@ingroup tsk_memory_group
* Reallocate memory block.
* In case that ptr is NULL, the function behaves exactly as @a tsk_malloc, assigning a new block of size bytes and returning a pointer to the beginning of it.
-* The function may move the memory block to a new location, in which case the new location is returned. The content of the memory block is preserved up to the lesser of the
+* The function may move the memory block to a new location, in which case the new location is returned. The content of the memory block is preserved up to the lesser of the
* new and old sizes, even if the block is moved. If the new size is larger, the value of the newly allocated portion is indeterminate.
* In case that the size is 0, the memory previously allocated in ptr is deallocated as if a call to free was made, and a NULL pointer is returned.
* @param ptr Pointer to a memory block previously allocated with malloc, calloc or realloc to be reallocated.
* If this is NULL, a new block is allocated and a pointer to it is returned by the function.
* @param size New size for the memory block, in bytes.
-* If it is 0 and ptr points to an existing block of memory, the memory block pointed by ptr is deallocated and a NULL pointer is returned.
+* If it is 0 and ptr points to an existing block of memory, the memory block pointed by ptr is deallocated and a NULL pointer is returned.
* @retval A pointer to the reallocated memory block, which may be either the same as the ptr argument or a new location.
* The type of this pointer is void*, which can be cast to the desired type of data pointer in order to be dereferenceable.
* If the function failed to allocate the requested block of memory, a NULL pointer is returned.
@@ -72,38 +72,38 @@ void* tsk_malloc(tsk_size_t size)
*/
void* tsk_realloc (void* ptr, tsk_size_t size)
{
- void *ret = tsk_null;
-
- if(size) {
- if(ptr){
- if(!(ret = realloc(ptr, size))){
- TSK_DEBUG_ERROR("Memory reallocation failed");
- }
- }
- else{
- if(!(ret = calloc(size, 1))){
- TSK_DEBUG_ERROR("Memory allocation (%u) failed", (unsigned)size);
- }
- }
- }
- else if (ptr) {
- free(ptr);
- }
-
- return ret;
+ void *ret = tsk_null;
+
+ if(size) {
+ if(ptr) {
+ if(!(ret = realloc(ptr, size))) {
+ TSK_DEBUG_ERROR("Memory reallocation failed");
+ }
+ }
+ else {
+ if(!(ret = calloc(size, 1))) {
+ TSK_DEBUG_ERROR("Memory allocation (%u) failed", (unsigned)size);
+ }
+ }
+ }
+ else if (ptr) {
+ free(ptr);
+ }
+
+ return ret;
}
/**@ingroup tsk_memory_group
* Deallocate space in memory.
* @param ptr Pointer to a memory block previously allocated with @a tsk_malloc, @a tsk_calloc or @a tsk_realloc to be deallocated.
-* If a null pointer is passed as argument, no action occurs.
+* If a null pointer is passed as argument, no action occurs.
*/
void tsk_free(void** ptr)
{
- if(ptr && *ptr){
- free(*ptr);
- *ptr = tsk_null;
- }
+ if(ptr && *ptr) {
+ free(*ptr);
+ *ptr = tsk_null;
+ }
}
/**@ingroup tsk_memory_group
@@ -117,60 +117,60 @@ void tsk_free(void** ptr)
*/
void* tsk_calloc(tsk_size_t num, tsk_size_t size)
{
- void* ret = tsk_null;
- if(num && size){
- ret = calloc(num, size);
- if(!ret){
- TSK_DEBUG_ERROR("Memory allocation failed. num=%u and size=%u", (unsigned)num, (unsigned)size);
- }
- }
-
- return ret;
+ void* ret = tsk_null;
+ if(num && size) {
+ ret = calloc(num, size);
+ if(!ret) {
+ TSK_DEBUG_ERROR("Memory allocation failed. num=%u and size=%u", (unsigned)num, (unsigned)size);
+ }
+ }
+
+ return ret;
}
void* tsk_malloc_aligned(tsk_size_t size, tsk_size_t alignment)
{
#if TSK_UNDER_WINDOWS && !TSK_UNDER_WINDOWS_CE && !TSK_UNDER_WINDOWS_RT
- return _aligned_malloc(size, alignment);
+ return _aligned_malloc(size, alignment);
#else
- void* ret = malloc(size + alignment);
+ void* ret = malloc(size + alignment);
if (ret) {
long pad = ((~(long)ret) % alignment) + 1;
ret = ((uint8_t*)ret) + pad; // pad
((uint8_t*)ret)[-1] = (uint8_t)pad; // store the pad for later use
}
- return ret;
+ return ret;
#endif
}
void* tsk_realloc_aligned(void * ptr, tsk_size_t size, tsk_size_t alignment)
{
#if TSK_UNDER_WINDOWS && !TSK_UNDER_WINDOWS_CE && !TSK_UNDER_WINDOWS_RT
- return _aligned_realloc(ptr, size, alignment);
+ return _aligned_realloc(ptr, size, alignment);
#else
- tsk_free_aligned(ptr);
- return tsk_malloc_aligned(size, alignment);
+ tsk_free_aligned(ptr);
+ return tsk_malloc_aligned(size, alignment);
#endif
}
void tsk_free_aligned(void** ptr)
{
- if (ptr && *ptr) {
- void* ptr_ = *ptr;
+ if (ptr && *ptr) {
+ void* ptr_ = *ptr;
#if TSK_UNDER_WINDOWS && !TSK_UNDER_WINDOWS_CE && !TSK_UNDER_WINDOWS_RT
- _aligned_free(ptr_);
+ _aligned_free(ptr_);
#else
- free((((uint8_t*)ptr_) - ((uint8_t*)ptr_)[-1]));
+ free((((uint8_t*)ptr_) - ((uint8_t*)ptr_)[-1]));
#endif
- *ptr = tsk_null;
- }
+ *ptr = tsk_null;
+ }
}
void* tsk_calloc_aligned(tsk_size_t num, tsk_size_t size, tsk_size_t alignment)
{
- void* ptr = tsk_malloc_aligned((size * num), alignment);
- if (ptr) {
- memset(ptr, 0, (size * num));
- }
- return ptr;
+ void* ptr = tsk_malloc_aligned((size * num), alignment);
+ if (ptr) {
+ memset(ptr, 0, (size * num));
+ }
+ return ptr;
}
diff --git a/tinySAK/src/tsk_memory.h b/tinySAK/src/tsk_memory.h
index 2112fae..a260299 100755
--- a/tinySAK/src/tsk_memory.h
+++ b/tinySAK/src/tsk_memory.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_mutex.c b/tinySAK/src/tsk_mutex.c
index d3eb9f8..8bb8d4e 100755
--- a/tinySAK/src/tsk_mutex.c
+++ b/tinySAK/src/tsk_mutex.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -34,13 +34,13 @@
#if TSK_UNDER_WINDOWS
# include <windows.h>
# include "tsk_errno.h"
- typedef HANDLE MUTEX_T;
+typedef HANDLE MUTEX_T;
# define MUTEX_S void
# define TSK_ERROR_NOT_OWNER ERROR_NOT_OWNER
#else
# include <pthread.h>
# define MUTEX_S pthread_mutex_t
- typedef MUTEX_S* MUTEX_T;
+typedef MUTEX_S* MUTEX_T;
# define TSK_ERROR_NOT_OWNER EPERM
# if !defined(TSK_RECURSIVE_MUTEXATTR)
# if defined(PTHREAD_MUTEX_RECURSIVE)
@@ -64,8 +64,8 @@
* @sa @ref tsk_mutex_destroy() @ref tsk_mutex_create_2()
*/
tsk_mutex_handle_t* tsk_mutex_create()
-{
- return tsk_mutex_create_2(tsk_true);
+{
+ return tsk_mutex_create_2(tsk_true);
}
/**@ingroup tsk_mutex_group
@@ -76,40 +76,40 @@ tsk_mutex_handle_t* tsk_mutex_create()
*/
tsk_mutex_handle_t* tsk_mutex_create_2(tsk_bool_t recursive)
{
- MUTEX_T handle = tsk_null;
-
+ MUTEX_T handle = tsk_null;
+
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- handle = CreateMutexEx(NULL, NULL, 0x00000000, MUTEX_ALL_ACCESS);
+ handle = CreateMutexEx(NULL, NULL, 0x00000000, MUTEX_ALL_ACCESS);
# else
- handle = CreateMutex(NULL, FALSE, NULL);
+ handle = CreateMutex(NULL, FALSE, NULL);
# endif
#else
- int ret;
- pthread_mutexattr_t mta;
-
- if((ret = pthread_mutexattr_init(&mta))){
- TSK_DEBUG_ERROR("pthread_mutexattr_init failed with error code %d", ret);
- return tsk_null;
- }
- if(recursive && (ret = pthread_mutexattr_settype(&mta, TSK_RECURSIVE_MUTEXATTR))){
- TSK_DEBUG_ERROR("pthread_mutexattr_settype failed with error code %d", ret);
- pthread_mutexattr_destroy(&mta);
- return tsk_null;
- }
-
- /* if we are here: all is ok */
- handle = tsk_calloc(1, sizeof(MUTEX_S));
- if(pthread_mutex_init((MUTEX_T)handle, &mta)){
- TSK_FREE(handle);
- }
- pthread_mutexattr_destroy(&mta);
+ int ret;
+ pthread_mutexattr_t mta;
+
+ if((ret = pthread_mutexattr_init(&mta))) {
+ TSK_DEBUG_ERROR("pthread_mutexattr_init failed with error code %d", ret);
+ return tsk_null;
+ }
+ if(recursive && (ret = pthread_mutexattr_settype(&mta, TSK_RECURSIVE_MUTEXATTR))) {
+ TSK_DEBUG_ERROR("pthread_mutexattr_settype failed with error code %d", ret);
+ pthread_mutexattr_destroy(&mta);
+ return tsk_null;
+ }
+
+ /* if we are here: all is ok */
+ handle = tsk_calloc(1, sizeof(MUTEX_S));
+ if(pthread_mutex_init((MUTEX_T)handle, &mta)) {
+ TSK_FREE(handle);
+ }
+ pthread_mutexattr_destroy(&mta);
#endif
-
- if(!handle){
- TSK_DEBUG_ERROR("Failed to create new mutex.");
- }
- return handle;
+
+ if(!handle) {
+ TSK_DEBUG_ERROR("Failed to create new mutex.");
+ }
+ return handle;
}
/**@ingroup tsk_mutex_group
@@ -120,24 +120,23 @@ tsk_mutex_handle_t* tsk_mutex_create_2(tsk_bool_t recursive)
*/
int tsk_mutex_lock(tsk_mutex_handle_t* handle)
{
- int ret = EINVAL;
- if(handle)
- {
+ int ret = EINVAL;
+ if(handle) {
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- if((ret = WaitForSingleObjectEx((MUTEX_T)handle, INFINITE, TRUE)) == WAIT_FAILED)
+ if((ret = WaitForSingleObjectEx((MUTEX_T)handle, INFINITE, TRUE)) == WAIT_FAILED)
# else
- if((ret = WaitForSingleObject((MUTEX_T)handle, INFINITE)) == WAIT_FAILED)
+ if((ret = WaitForSingleObject((MUTEX_T)handle, INFINITE)) == WAIT_FAILED)
#endif
#else
- if((ret = pthread_mutex_lock((MUTEX_T)handle)))
+ if((ret = pthread_mutex_lock((MUTEX_T)handle)))
#endif
- {
- TSK_DEBUG_ERROR("Failed to lock the mutex: %d", ret);
- }
- }
- return ret;
+ {
+ TSK_DEBUG_ERROR("Failed to lock the mutex: %d", ret);
+ }
+ }
+ return ret;
}
/**@ingroup tsk_mutex_group
@@ -148,25 +147,23 @@ int tsk_mutex_lock(tsk_mutex_handle_t* handle)
*/
int tsk_mutex_unlock(tsk_mutex_handle_t* handle)
{
- int ret = EINVAL;
- if(handle)
- {
+ int ret = EINVAL;
+ if(handle) {
#if TSK_UNDER_WINDOWS
- if((ret = ReleaseMutex((MUTEX_T)handle) ? 0 : -1)){
- ret = GetLastError();
+ if((ret = ReleaseMutex((MUTEX_T)handle) ? 0 : -1)) {
+ ret = GetLastError();
#else
- if((ret = pthread_mutex_unlock((MUTEX_T)handle)))
- {
+ if((ret = pthread_mutex_unlock((MUTEX_T)handle))) {
#endif
- if(ret == TSK_ERROR_NOT_OWNER){
- TSK_DEBUG_WARN("The calling thread does not own the mutex: %d", ret);
- }
- else{
- TSK_DEBUG_ERROR("Failed to unlock the mutex: %d", ret);
- }
- }
- }
- return ret;
+ if(ret == TSK_ERROR_NOT_OWNER) {
+ TSK_DEBUG_WARN("The calling thread does not own the mutex: %d", ret);
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to unlock the mutex: %d", ret);
+ }
+ }
+ }
+ return ret;
}
/**@ingroup tsk_mutex_group
@@ -176,17 +173,17 @@ int tsk_mutex_unlock(tsk_mutex_handle_t* handle)
*/
void tsk_mutex_destroy(tsk_mutex_handle_t** handle)
{
- if(handle && *handle){
+ if(handle && *handle) {
#if TSK_UNDER_WINDOWS
- CloseHandle((MUTEX_T)*handle);
- *handle = tsk_null;
+ CloseHandle((MUTEX_T)*handle);
+ *handle = tsk_null;
#else
- pthread_mutex_destroy((MUTEX_T)*handle);
- tsk_free(handle);
+ pthread_mutex_destroy((MUTEX_T)*handle);
+ tsk_free(handle);
#endif
- }
- else{
- TSK_DEBUG_WARN("Cannot free an uninitialized mutex");
- }
+ }
+ else {
+ TSK_DEBUG_WARN("Cannot free an uninitialized mutex");
+ }
}
diff --git a/tinySAK/src/tsk_mutex.h b/tinySAK/src/tsk_mutex.h
index c02f7f2..f5c414c 100755
--- a/tinySAK/src/tsk_mutex.h
+++ b/tinySAK/src/tsk_mutex.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_object.c b/tinySAK/src/tsk_object.c
index 30bf1f6..b5769d2 100755
--- a/tinySAK/src/tsk_object.c
+++ b/tinySAK/src/tsk_object.c
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -50,38 +50,38 @@ static int tsk_objects_count = 0;
*/
tsk_object_t* tsk_object_new(const tsk_object_def_t *objdef, ...)
{
- // Do not check "objdef", let the application die if it's null
- tsk_object_t *newobj = tsk_calloc(1, objdef->size);
- if(newobj){
- (*(const tsk_object_def_t **) newobj) = objdef;
- TSK_OBJECT_HEADER(newobj)->refCount = 1;
- if(objdef->constructor){
- va_list ap;
- tsk_object_t * newobj_ = newobj;// save
- va_start(ap, objdef);
- newobj = objdef->constructor(newobj, &ap); // must return new
- va_end(ap);
-
- if(!newobj){ // null if constructor failed to initialized the object
- if(objdef->destructor){
- objdef->destructor(newobj_);
- }
- tsk_free(&newobj_);
- }
+ // Do not check "objdef", let the application die if it's null
+ tsk_object_t *newobj = tsk_calloc(1, objdef->size);
+ if(newobj) {
+ (*(const tsk_object_def_t **) newobj) = objdef;
+ TSK_OBJECT_HEADER(newobj)->refCount = 1;
+ if(objdef->constructor) {
+ va_list ap;
+ tsk_object_t * newobj_ = newobj;// save
+ va_start(ap, objdef);
+ newobj = objdef->constructor(newobj, &ap); // must return new
+ va_end(ap);
+
+ if(!newobj) { // null if constructor failed to initialized the object
+ if(objdef->destructor) {
+ objdef->destructor(newobj_);
+ }
+ tsk_free(&newobj_);
+ }
#if TSK_DEBUG_OBJECTS
- TSK_DEBUG_INFO("N∞ objects:%d", ++tsk_objects_count);
+ TSK_DEBUG_INFO("N∞ objects:%d", ++tsk_objects_count);
#endif
- }
- else{
- TSK_DEBUG_WARN("No constructor found.");
- }
- }
- else{
- TSK_DEBUG_ERROR("Failed to create new tsk_object.");
- }
+ }
+ else {
+ TSK_DEBUG_WARN("No constructor found.");
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to create new tsk_object.");
+ }
- return newobj;
+ return newobj;
}
/**@ingroup tsk_object_group
@@ -93,26 +93,26 @@ tsk_object_t* tsk_object_new(const tsk_object_def_t *objdef, ...)
*/
tsk_object_t* tsk_object_new_2(const tsk_object_def_t *objdef, va_list* ap)
{
- tsk_object_t *newobj = tsk_calloc(1, objdef->size);
- if (newobj) {
- (*(const tsk_object_def_t **) newobj) = objdef;
- TSK_OBJECT_HEADER(newobj)->refCount = 1;
- if (objdef->constructor) {
- newobj = objdef->constructor(newobj, ap);
+ tsk_object_t *newobj = tsk_calloc(1, objdef->size);
+ if (newobj) {
+ (*(const tsk_object_def_t **) newobj) = objdef;
+ TSK_OBJECT_HEADER(newobj)->refCount = 1;
+ if (objdef->constructor) {
+ newobj = objdef->constructor(newobj, ap);
#if TSK_DEBUG_OBJECTS
- TSK_DEBUG_INFO("N∞ objects:%d", ++tsk_objects_count);
+ TSK_DEBUG_INFO("N∞ objects:%d", ++tsk_objects_count);
#endif
- }
- else {
- TSK_DEBUG_WARN("No constructor found.");
- }
- }
- else {
- TSK_DEBUG_ERROR("Failed to create new tsk_object.");
- }
+ }
+ else {
+ TSK_DEBUG_WARN("No constructor found.");
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to create new tsk_object.");
+ }
- return newobj;
+ return newobj;
}
/**@ingroup tsk_object_group
@@ -123,14 +123,14 @@ tsk_object_t* tsk_object_new_2(const tsk_object_def_t *objdef, va_list* ap)
*/
tsk_size_t tsk_object_sizeof(const tsk_object_t *self)
{
- const tsk_object_def_t **objdef = (const tsk_object_def_t **)self;
- if (objdef && *objdef) {
- return (*objdef)->size;
- }
- else {
- TSK_DEBUG_ERROR("NULL object definition.");
- return 0;
- }
+ const tsk_object_def_t **objdef = (const tsk_object_def_t **)self;
+ if (objdef && *objdef) {
+ return (*objdef)->size;
+ }
+ else {
+ TSK_DEBUG_ERROR("NULL object definition.");
+ return 0;
+ }
}
/**@ingroup tsk_object_group
@@ -143,16 +143,16 @@ tsk_size_t tsk_object_sizeof(const tsk_object_t *self)
*/
int tsk_object_cmp(const tsk_object_t *object1, const tsk_object_t *object2)
{
- const tsk_object_def_t **objdef = (const tsk_object_def_t **)object1;
+ const tsk_object_def_t **objdef = (const tsk_object_def_t **)object1;
- if (objdef && *objdef && (*objdef)->comparator) {
- return (*objdef)->comparator(object1, object2);
- }
- else {
- int ret;
- tsk_subsat_int32_ptr(object1, object2, &ret);
- return ret;
- }
+ if (objdef && *objdef && (*objdef)->comparator) {
+ return (*objdef)->comparator(object1, object2);
+ }
+ else {
+ int ret;
+ tsk_subsat_int32_ptr(object1, object2, &ret);
+ return ret;
+ }
}
/**@ingroup tsk_object_group
@@ -165,12 +165,12 @@ int tsk_object_cmp(const tsk_object_t *object1, const tsk_object_t *object2)
*/
tsk_object_t* tsk_object_ref(tsk_object_t *self)
{
- tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self);
- if (objhdr && objhdr->refCount > 0) {
- tsk_atomic_inc(&objhdr->refCount);
- return self;
- }
- return tsk_null;
+ tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self);
+ if (objhdr && objhdr->refCount > 0) {
+ tsk_atomic_inc(&objhdr->refCount);
+ return self;
+ }
+ return tsk_null;
}
/**@ingroup tsk_object_group
@@ -184,20 +184,20 @@ tsk_object_t* tsk_object_ref(tsk_object_t *self)
*/
tsk_object_t* tsk_object_unref(tsk_object_t *self)
{
- if (self) {
- tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self);
- if (objhdr->refCount > 0) { // If refCount is == 0 then, nothing should happen.
- tsk_atomic_dec(&objhdr->refCount);
- if (objhdr->refCount == 0) {
- tsk_object_delete(self);
- return tsk_null;
- }
- }
- else {
- return tsk_null;
- }
- }
- return self;
+ if (self) {
+ tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self);
+ if (objhdr->refCount > 0) { // If refCount is == 0 then, nothing should happen.
+ tsk_atomic_dec(&objhdr->refCount);
+ if (objhdr->refCount == 0) {
+ tsk_object_delete(self);
+ return tsk_null;
+ }
+ }
+ else {
+ return tsk_null;
+ }
+ }
+ return self;
}
/**@ingroup tsk_object_group
@@ -206,7 +206,7 @@ tsk_object_t* tsk_object_unref(tsk_object_t *self)
*/
tsk_size_t tsk_object_get_refcount(tsk_object_t *self)
{
- return self ? TSK_OBJECT_HEADER(self)->refCount : 0;
+ return self ? TSK_OBJECT_HEADER(self)->refCount : 0;
}
/**@ingroup tsk_object_group
@@ -218,26 +218,26 @@ tsk_size_t tsk_object_get_refcount(tsk_object_t *self)
*/
void tsk_object_delete(tsk_object_t *self)
{
- const tsk_object_def_t ** objdef = (const tsk_object_def_t **)self;
- if(self && *objdef){
- if ((*objdef)->destructor) {
- self = (*objdef)->destructor(self);
+ const tsk_object_def_t ** objdef = (const tsk_object_def_t **)self;
+ if(self && *objdef) {
+ if ((*objdef)->destructor) {
+ self = (*objdef)->destructor(self);
#if TSK_DEBUG_OBJECTS
- TSK_DEBUG_INFO("N∞ objects:%d", --tsk_objects_count);
+ TSK_DEBUG_INFO("N∞ objects:%d", --tsk_objects_count);
#endif
- }
- else {
- TSK_DEBUG_WARN("No destructor found.");
- }
- if (self) {
- free(self);
- }
- }
+ }
+ else {
+ TSK_DEBUG_WARN("No destructor found.");
+ }
+ if (self) {
+ free(self);
+ }
+ }
}
/**@page _Page_TinySAK_AnsiC_Object_Programming ANSI-C Object Programming
-*
+*
* - @ref _Anchor_TinySAK_Object_Definition "Object Definition"
* - @ref _Anchor_TinySAK_Object_Constructor "Constructor"
* - @ref _Anchor_TinySAK_Object_Destructor "Destructor"
@@ -297,14 +297,14 @@ tsk_object_def_t;
* Below, an example of how to declare an object definition:<br>
* @code
* //(Object defnition)
- static const tsk_object_def_t person_def_t =
+ static const tsk_object_def_t person_def_t =
{
sizeof(person_t),
person_ctor,
person_dtor,
person_cmp
};
-* @endcode
+* @endcode
* <h2>@anchor _Anchor_TinySAK_Object_Constructor Constructor</h2>
* The constructor is only responsible for the initialization and won’t allocate the object. When passed to the constructor, the object is already allocated.<br>
* Here is an example:<br>
@@ -318,14 +318,14 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
}
return self;
}
-* @endcode
+* @endcode
* <h2>@anchor _Anchor_TinySAK_Object_Destructor Destructor</h2>
* The destructor will free the object’s members and won’t free the object itself (Phase 1). The destructor function must return a pointer to itself to allow the caller to perform the second phase (freeing the object itself).<br>
* Here is an example:<br>
* @code
// (destructor)
static tsk_object_t * person_dtor(tsk_object_t * self)
- {
+ {
person_t *person = (person_t *)self;
if(person){
TSK_FREE(person->name);
@@ -333,7 +333,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
}
return self;
}
-* @endcode
+* @endcode
* <h2>@anchor _Anchor_TinySAK_Object_Comparator Comparator</h2>
* The comparator function is used to compare two <i>"well-defined"</i> objects. The objects to compare shall have the same definition (or type). <br>
* Here is an example:<br>
@@ -344,7 +344,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2)
const person_t *p1 = (const person_t *)_p1;
const person_t *p1 = (const person_t *)_p2;
int ret;
-
+
// do they have the same name?
if((ret = tsk_stricmp(p1->name, p2->name))){
return ret;
@@ -353,7 +353,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2)
if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))){
return ret;
}
-
+
// they are the same
return 0;
}
@@ -365,7 +365,7 @@ The comparator function is also used by the linked-list to sort <i>"well-defined
* When an object is created (see below) the counter value is initialized to 1; this is automatically done and you have nothing to do. The counter is incremented by 1 when you call @ref tsk_object_ref() and decremented (by 1) when you call @ref tsk_object_unref().<br>
* When the counter value reaches zero then, the object is garbaged (freed).<br>
* Calling @ref tsk_object_delete() will destroy an object regardless the value of the reference counter. You should never call @ref tsk_object_delete() but @ref tsk_object_unref() instead.
-*
+*
* <h2>@anchor _Anchor_TinySAK_Object_Inheritence Inheritence</h2>
* As you may expect, inheritance is not supported in ANSI-C. <br>
* As any C Structure could be casted to a pointer to its first element, inheritance could be achieved like this:<br>
@@ -385,7 +385,7 @@ student_t* s = tsk_null;
// then, cast a "student" as "person" to initialize additional fields
((person_t*)s)->name = tsk_strdup("bob");
* @endcode
-*
+*
* As <b>person_t</b> is a well-defined object, then <b>student_t</b> is also well-defined.<br>
*
* <h2>@anchor _Anchor_TinySAK_Object_Basic_Usage Basic usage</h2>
@@ -407,7 +407,7 @@ static person_t* person_create(const char* name)
}
*
* @endcode
-*
+*
* As the destructor has fixed parameters, there is a common macro to destroy all kind of well-defined objects. <br>
* @ref TSK_OBJECT_SAFE_FREE() macro is used to destroy any well-defined object. <br>
* The object will be freed only if; when decremented by 1 the reference count of the object is equal to zero. In all case (freed or not) the pointer value will be set to NULL to avoid trying to free the object again.<br>
@@ -449,7 +449,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
// (destructor)
static tsk_object_t * person_dtor(tsk_object_t * self)
- {
+ {
person_t *person = self;
if(person){
TSK_FREE(person->name);
@@ -464,7 +464,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
const person_t *p1 = (const person_t *)_p1;
const person_t *p1 = (const person_t *)_p2;
int ret;
-
+
// do they have the same name?
if((ret = tsk_stricmp(p1->name, p2->name))){
return ret;
@@ -473,7 +473,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app)
if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))){
return ret;
}
-
+
// they are the same
return 0;
}
@@ -498,7 +498,7 @@ bob = tsk_object_unref(bob); // refcount = 1
bob = tsk_object_unref(bob); // refcount = 0 and destroyed
*
* @endcode
-*
+*
* <h2>@anchor _Anchor_TinySAK_Object_Public_Fuctions Public functions </h2>
* - @ref tsk_object_cmp
* - @ref tsk_object_delete
diff --git a/tinySAK/src/tsk_object.h b/tinySAK/src/tsk_object.h
index 51f892a..61789d9 100755
--- a/tinySAK/src/tsk_object.h
+++ b/tinySAK/src/tsk_object.h
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -40,10 +40,10 @@ typedef void tsk_object_t;
/**@ingroup tsk_object_group
* @def TSK_OBJECT_SAFE_FREE
* Safely free any well-defined object. If the reference count of the object was equal to 1 then this
- * object will be freed otherwise the refrence counter will be decremented.
+ * object will be freed otherwise the refrence counter will be decremented.
* In all case this operation will set the pointer (the object itself) to NULL.<br>
* <b>Very Important</b>: Mutexes, Semaphores and CondVars are not well-defined objects. You should never use this macro to destroy them.
- * @param self The object to free or unref.
+ * @param self The object to free or unref.
**/
#define TSK_OBJECT_SAFE_FREE(self) if((self)) tsk_object_unref((self)), (self) = tsk_null
@@ -86,8 +86,8 @@ typedef void tsk_object_t;
#define TSK_OBJECT_DEF(self) ((const tsk_object_def_t*)self)
/** Object meta-data (definition) */
-typedef struct tsk_object_header_s{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_object_header_s {
+ TSK_DECLARE_OBJECT;
}
tsk_object_header_t;
#define TSK_OBJECT_HEADER(object) ((tsk_object_header_t*)object)
@@ -110,10 +110,10 @@ tsk_object_header_t;
* }
* return self;
* }
-*
+*
* // destructor
* static void* person_destroy(tsk_object_t * self)
-* {
+* {
* person_t *person = self;
* if(person){
* TSK_FREE(person->firstName);
@@ -121,25 +121,25 @@ tsk_object_header_t;
* }
* return self;
* }
-*
+*
* // comparator
* static int person_cmp(const tsk_object_t *object1, const tsk_object_t *object1)
* {
* const person_t *person1 = object1;
* const person_t *person2 = object2;
-*
+*
* return (person1 && person2) ? (person1->id - person2->id) : -1;
* }
*
* // Meta-data (Object defnition)
-* static const tsk_object_def_t person_def_s =
+* static const tsk_object_def_t person_def_s =
* {
* sizeof(person_t),
* person_create,
* person_destroy,
-* person_cmp,
+* person_cmp,
* }person_def_t;
-*
+*
* @endcode
* Now, to create your object:
* @code
@@ -155,16 +155,15 @@ tsk_object_header_t;
* TSK_OBJECT_SAFE_FREE(person); // Will call "person_destroy" function.
* @endcode
*/
-typedef struct tsk_object_def_s
-{
- //! The size of the object.
- tsk_size_t size;
- //! Pointer to the constructor.
- tsk_object_t* (* constructor) (tsk_object_t *, va_list *);
- //! Pointer to the destructor.
- tsk_object_t* (* destructor) (tsk_object_t *);
- //! Pointer to the comparator.
- int (* comparator) (const tsk_object_t *, const tsk_object_t *);
+typedef struct tsk_object_def_s {
+ //! The size of the object.
+ tsk_size_t size;
+ //! Pointer to the constructor.
+ tsk_object_t* (* constructor) (tsk_object_t *, va_list *);
+ //! Pointer to the destructor.
+ tsk_object_t* (* destructor) (tsk_object_t *);
+ //! Pointer to the comparator.
+ int (* comparator) (const tsk_object_t *, const tsk_object_t *);
}
tsk_object_def_t;
diff --git a/tinySAK/src/tsk_options.c b/tinySAK/src/tsk_options.c
index 8ef3358..b3650c2 100755
--- a/tinySAK/src/tsk_options.c
+++ b/tinySAK/src/tsk_options.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -41,25 +41,25 @@
*/
static int pred_find_option_by_id(const tsk_list_item_t *item, const void *id)
{
- if(item && item->data){
- tsk_option_t *option = (tsk_option_t*)item->data;
- return (option->id - *((int*)id));
- }
- return -1;
+ if(item && item->data) {
+ tsk_option_t *option = (tsk_option_t*)item->data;
+ return (option->id - *((int*)id));
+ }
+ return -1;
}
/**@ingroup tsk_options_group
*/
tsk_option_t* tsk_option_create(int id, const char* value)
{
- return (tsk_option_t*)tsk_object_new(TSK_OPTION_VA_ARGS(id, value));
+ return (tsk_option_t*)tsk_object_new(TSK_OPTION_VA_ARGS(id, value));
}
/**@ingroup tsk_options_group
*/
tsk_option_t* tsk_option_create_null()
{
- return tsk_option_create(0, tsk_null);
+ return tsk_option_create(0, tsk_null);
}
@@ -71,12 +71,12 @@ tsk_option_t* tsk_option_create_null()
*/
tsk_bool_t tsk_options_have_option(const tsk_options_L_t *self, int id)
{
- if(self){
- if(tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id)){
- return tsk_true;
- }
- }
- return tsk_false;
+ if(self) {
+ if(tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id)) {
+ return tsk_true;
+ }
+ }
+ return tsk_false;
}
/**@ingroup tsk_options_group
@@ -88,36 +88,36 @@ tsk_bool_t tsk_options_have_option(const tsk_options_L_t *self, int id)
*/
int tsk_options_add_option(tsk_options_L_t **self, int id, const char* value)
{
- tsk_option_t *option;
+ tsk_option_t *option;
- if(!self) {
- return -1;
- }
+ if(!self) {
+ return -1;
+ }
- if(!*self){
- *self = tsk_list_create();
- }
+ if(!*self) {
+ *self = tsk_list_create();
+ }
- if((option = (tsk_option_t*)tsk_options_get_option_by_id(*self, id))){
- tsk_strupdate(&option->value, value); /* Already exist ==> update the value. */
- }
- else{
- option = tsk_option_create(id, value);
- tsk_list_push_back_data(*self, (void**)&option);
- }
+ if((option = (tsk_option_t*)tsk_options_get_option_by_id(*self, id))) {
+ tsk_strupdate(&option->value, value); /* Already exist ==> update the value. */
+ }
+ else {
+ option = tsk_option_create(id, value);
+ tsk_list_push_back_data(*self, (void**)&option);
+ }
- return 0;
+ return 0;
}
int tsk_options_add_option_2(tsk_options_L_t **self, const tsk_option_t* option)
{
- int ret = -1;
- if(!self || !option || !option){
- return ret;
- }
+ int ret = -1;
+ if(!self || !option || !option) {
+ return ret;
+ }
- ret = tsk_options_add_option(self, option->id, option->value);
- return ret;
+ ret = tsk_options_add_option(self, option->id, option->value);
+ return ret;
}
/**@ingroup tsk_options_group
@@ -128,11 +128,11 @@ int tsk_options_add_option_2(tsk_options_L_t **self, const tsk_option_t* option)
*/
int tsk_options_remove_option(tsk_options_L_t *self, int id)
{
- if(self){
- tsk_list_remove_item_by_pred(self, pred_find_option_by_id, &id);
- return 0;
- }
- return -1;
+ if(self) {
+ tsk_list_remove_item_by_pred(self, pred_find_option_by_id, &id);
+ return 0;
+ }
+ return -1;
}
/**@ingroup tsk_options_group
@@ -143,13 +143,13 @@ int tsk_options_remove_option(tsk_options_L_t *self, int id)
*/
const tsk_option_t *tsk_options_get_option_by_id(const tsk_options_L_t *self, int id)
{
- if(self){
- const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id);
- if(item_const){
- return (const tsk_option_t*)item_const->data;
- }
- }
- return 0;
+ if(self) {
+ const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id);
+ if(item_const) {
+ return (const tsk_option_t*)item_const->data;
+ }
+ }
+ return 0;
}
/**@ingroup tsk_options_group
@@ -160,13 +160,13 @@ const tsk_option_t *tsk_options_get_option_by_id(const tsk_options_L_t *self, in
*/
const char *tsk_options_get_option_value(const tsk_options_L_t *self, int id)
{
- if(self){
- const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id);
- if(item_const && item_const->data){
- return ((const tsk_option_t *)item_const->data)->value;
- }
- }
- return tsk_null;
+ if(self) {
+ const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_option_by_id, &id);
+ if(item_const && item_const->data) {
+ return ((const tsk_option_t *)item_const->data)->value;
+ }
+ }
+ return tsk_null;
}
/**@ingroup tsk_options_group
@@ -177,8 +177,8 @@ const char *tsk_options_get_option_value(const tsk_options_L_t *self, int id)
*/
int tsk_options_get_option_value_as_int(const tsk_options_L_t *self, int id)
{
- const char *value = tsk_options_get_option_value(self, id);
- return value ? atoi(value) : -1;
+ const char *value = tsk_options_get_option_value(self, id);
+ return value ? atoi(value) : -1;
}
@@ -207,36 +207,35 @@ int tsk_options_get_option_value_as_int(const tsk_options_L_t *self, int id)
//
static tsk_object_t* tsk_option_ctor(tsk_object_t * self, va_list * app)
{
- tsk_option_t *option = (tsk_option_t*)self;
- if(option){
- int id = va_arg(*app, int);
- const char* value = va_arg(*app, const char *);
-
- option->id = id;
- if(!tsk_strnullORempty(value)) {
- option->value = tsk_strdup(value);
- }
- }
-
- return self;
+ tsk_option_t *option = (tsk_option_t*)self;
+ if(option) {
+ int id = va_arg(*app, int);
+ const char* value = va_arg(*app, const char *);
+
+ option->id = id;
+ if(!tsk_strnullORempty(value)) {
+ option->value = tsk_strdup(value);
+ }
+ }
+
+ return self;
}
static tsk_object_t* tsk_option_dtor(tsk_object_t * self)
-{
- tsk_option_t *option = (tsk_option_t*)self;
- if(option){
- TSK_FREE(option->value);
- }
+{
+ tsk_option_t *option = (tsk_option_t*)self;
+ if(option) {
+ TSK_FREE(option->value);
+ }
- return self;
+ return self;
}
-static const tsk_object_def_t tsk_option_def_s =
-{
- sizeof(tsk_option_t),
- tsk_option_ctor,
- tsk_option_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_option_def_s = {
+ sizeof(tsk_option_t),
+ tsk_option_ctor,
+ tsk_option_dtor,
+ tsk_null,
};
const tsk_object_def_t* tsk_option_def_t = &tsk_option_def_s;
diff --git a/tinySAK/src/tsk_options.h b/tinySAK/src/tsk_options.h
index 6581b60..ab5da7c 100755
--- a/tinySAK/src/tsk_options.h
+++ b/tinySAK/src/tsk_options.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -45,14 +45,13 @@ TSK_BEGIN_DECLS
/**@ingroup tsk_options_group
* Parameter.
*/
-typedef struct tsk_option_s
-{
- TSK_DECLARE_OBJECT;
-
- int id;
- char* value;
-
- tsk_bool_t tag;
+typedef struct tsk_option_s {
+ TSK_DECLARE_OBJECT;
+
+ int id;
+ char* value;
+
+ tsk_bool_t tag;
}
tsk_option_t;
diff --git a/tinySAK/src/tsk_params.c b/tinySAK/src/tsk_params.c
index a5756e8..e47d2ec 100755
--- a/tinySAK/src/tsk_params.c
+++ b/tinySAK/src/tsk_params.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -42,25 +42,25 @@
*/
static int pred_find_param_by_name(const tsk_list_item_t *item, const void *name)
{
- if(item && item->data){
- tsk_param_t *param = (tsk_param_t*)item->data;
- return tsk_stricmp(param->name, (const char*)name);
- }
- return -1;
+ if(item && item->data) {
+ tsk_param_t *param = (tsk_param_t*)item->data;
+ return tsk_stricmp(param->name, (const char*)name);
+ }
+ return -1;
}
/**@ingroup tsk_params_group
*/
tsk_param_t* tsk_param_create(const char* name, const char* value)
{
- return (tsk_param_t*)tsk_object_new(TSK_PARAM_VA_ARGS(name, value));
+ return (tsk_param_t*)tsk_object_new(TSK_PARAM_VA_ARGS(name, value));
}
/**@ingroup tsk_params_group
*/
tsk_param_t* tsk_param_create_null()
{
- return tsk_param_create(tsk_null, tsk_null);
+ return tsk_param_create(tsk_null, tsk_null);
}
/**@ingroup tsk_params_group
@@ -71,30 +71,30 @@ tsk_param_t* tsk_param_create_null()
*/
tsk_param_t *tsk_params_parse_param(const char* line, tsk_size_t size)
{
- if(line && size){
- const char* start = line;
- const char* end = (line + size);
- const char* equal = strstr(line, "=");
- tsk_param_t *param = tsk_param_create_null();
-
- if (param && equal && equal<end) {
- if ((param->name = (char*)tsk_calloc((tsk_size_t)((equal - start) + 1), sizeof(const char)))) {
- memcpy(param->name, start, (equal - start));
- }
-
- if ((param->value = (char*)tsk_calloc((tsk_size_t)((end - equal - 1) + 1), sizeof(const char)))) {
- memcpy(param->value, equal + 1, (end - equal - 1));
- }
- }
- else if (param) {
- if ((param->name = (char*)tsk_calloc((tsk_size_t)((end - start) + 1), sizeof(const char)))) {
- memcpy(param->name, start, (end - start));
- }
- }
-
- return param;
- }
- return tsk_null;
+ if(line && size) {
+ const char* start = line;
+ const char* end = (line + size);
+ const char* equal = strstr(line, "=");
+ tsk_param_t *param = tsk_param_create_null();
+
+ if (param && equal && equal<end) {
+ if ((param->name = (char*)tsk_calloc((tsk_size_t)((equal - start) + 1), sizeof(const char)))) {
+ memcpy(param->name, start, (equal - start));
+ }
+
+ if ((param->value = (char*)tsk_calloc((tsk_size_t)((end - equal - 1) + 1), sizeof(const char)))) {
+ memcpy(param->value, equal + 1, (end - equal - 1));
+ }
+ }
+ else if (param) {
+ if ((param->name = (char*)tsk_calloc((tsk_size_t)((end - start) + 1), sizeof(const char)))) {
+ memcpy(param->name, start, (end - start));
+ }
+ }
+
+ return param;
+ }
+ return tsk_null;
}
/**@ingroup tsk_params_group
* Checks if the supplied list of parameters contains a parameter named @a name (case-insensitive).
@@ -104,15 +104,15 @@ tsk_param_t *tsk_params_parse_param(const char* line, tsk_size_t size)
*/
tsk_bool_t tsk_params_have_param(const tsk_params_L_t *self, const char* name)
{
- if(self){
- if(tsk_list_find_item_by_pred(self, pred_find_param_by_name, name)){
- return tsk_true;
- }
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- }
- return tsk_false;
+ if(self) {
+ if(tsk_list_find_item_by_pred(self, pred_find_param_by_name, name)) {
+ return tsk_true;
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
+ return tsk_false;
}
/**@ingroup tsk_params_group
@@ -124,43 +124,43 @@ tsk_bool_t tsk_params_have_param(const tsk_params_L_t *self, const char* name)
*/
int tsk_params_add_param(tsk_params_L_t **self, const char* name, const char* value)
{
- tsk_param_t *param;
-
- if(!self || !name) {
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
-
- if(!*self){
- *self = tsk_list_create();
- }
-
- if((param = (tsk_param_t*)tsk_params_get_param_by_name(*self, name))){
- tsk_strupdate(&param->value, value); /* Already exist ==> update the value. */
- }
- else{
- param = tsk_param_create(name, value);
- tsk_list_push_back_data(*self, (void**)&param);
- }
-
- return 0;
+ tsk_param_t *param;
+
+ if(!self || !name) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ if(!*self) {
+ *self = tsk_list_create();
+ }
+
+ if((param = (tsk_param_t*)tsk_params_get_param_by_name(*self, name))) {
+ tsk_strupdate(&param->value, value); /* Already exist ==> update the value. */
+ }
+ else {
+ param = tsk_param_create(name, value);
+ tsk_list_push_back_data(*self, (void**)&param);
+ }
+
+ return 0;
}
int tsk_params_add_param_2(tsk_params_L_t **self, const tsk_param_t* param)
{
- if(!self || !param || !param){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!self || !param || !param) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- return tsk_params_add_param(self, param->name, param->value);
+ return tsk_params_add_param(self, param->name, param->value);
}
int tsk_params_add_param_3(tsk_params_L_t **self, const char* name, int64_t value)
{
- tsk_istr_t value_str;
- tsk_itoa(value, &value_str);
- return tsk_params_add_param(self, name, value_str);
+ tsk_istr_t value_str;
+ tsk_itoa(value, &value_str);
+ return tsk_params_add_param(self, name, value_str);
}
/**@ingroup tsk_params_group
@@ -171,14 +171,14 @@ int tsk_params_add_param_3(tsk_params_L_t **self, const char* name, int64_t valu
*/
int tsk_params_remove_param(tsk_params_L_t *self, const char* name)
{
- if(self){
- tsk_list_remove_item_by_pred(self, pred_find_param_by_name, name);
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(self) {
+ tsk_list_remove_item_by_pred(self, pred_find_param_by_name, name);
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_params_group
@@ -189,16 +189,16 @@ int tsk_params_remove_param(tsk_params_L_t *self, const char* name)
*/
const tsk_param_t *tsk_params_get_param_by_name(const tsk_params_L_t *self, const char* name)
{
- if(self){
- const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_param_by_name, name);
- if(item_const){
- return (const tsk_param_t*)item_const->data;
- }
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- }
- return tsk_null;
+ if(self) {
+ const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_param_by_name, name);
+ if(item_const) {
+ return (const tsk_param_t*)item_const->data;
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
+ return tsk_null;
}
/**@ingroup tsk_params_group
@@ -209,16 +209,16 @@ const tsk_param_t *tsk_params_get_param_by_name(const tsk_params_L_t *self, cons
*/
const char *tsk_params_get_param_value(const tsk_params_L_t *self, const char* name)
{
- if(self && name){
- const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_param_by_name, name);
- if(item_const && item_const->data){
- return ((const tsk_param_t *)item_const->data)->value;
- }
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- }
- return tsk_null;
+ if(self && name) {
+ const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(self, pred_find_param_by_name, name);
+ if(item_const && item_const->data) {
+ return ((const tsk_param_t *)item_const->data)->value;
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
+ return tsk_null;
}
/**@ingroup tsk_params_group
@@ -229,8 +229,8 @@ const char *tsk_params_get_param_value(const tsk_params_L_t *self, const char* n
*/
int tsk_params_get_param_value_as_int(const tsk_params_L_t *self, const char* name)
{
- const char *value = tsk_params_get_param_value(self, name);
- return value ? atoi(value) : -1;
+ const char *value = tsk_params_get_param_value(self, name);
+ return value ? atoi(value) : -1;
}
/**@ingroup tsk_params_group
@@ -241,10 +241,10 @@ int tsk_params_get_param_value_as_int(const tsk_params_L_t *self, const char* na
*/
int tsk_params_param_tostring(const tsk_param_t *param, tsk_buffer_t* output)
{
- if(param){
- return tsk_buffer_append_2(output, param->value?"%s=%s":"%s", param->name, param->value);
- }
- return -1;
+ if(param) {
+ return tsk_buffer_append_2(output, param->value?"%s=%s":"%s", param->name, param->value);
+ }
+ return -1;
}
/**@ingroup tsk_params_group
@@ -256,40 +256,40 @@ int tsk_params_param_tostring(const tsk_param_t *param, tsk_buffer_t* output)
*/
int tsk_params_tostring(const tsk_params_L_t *self, const char separator, tsk_buffer_t* output)
{
- int ret = -1;
-
- if(self){
- tsk_list_item_t *item;
- ret = 0; // for empty lists
- tsk_list_foreach(item, self){
- tsk_param_t* param = (tsk_param_t*)item->data;
- //tsk_params_param_tostring(param, output);
- if(TSK_LIST_IS_FIRST(self, item)){
- if((ret = tsk_buffer_append_2(output, param->value?"%s=%s":"%s", param->name, param->value))){
- goto bail;
- }
- }
- else{
- if((ret = tsk_buffer_append_2(output, param->value?"%c%s=%s":"%c%s", separator, param->name, param->value))){
- goto bail;
- }
- }
- }
- }
+ int ret = -1;
+
+ if(self) {
+ tsk_list_item_t *item;
+ ret = 0; // for empty lists
+ tsk_list_foreach(item, self) {
+ tsk_param_t* param = (tsk_param_t*)item->data;
+ //tsk_params_param_tostring(param, output);
+ if(TSK_LIST_IS_FIRST(self, item)) {
+ if((ret = tsk_buffer_append_2(output, param->value?"%s=%s":"%s", param->name, param->value))) {
+ goto bail;
+ }
+ }
+ else {
+ if((ret = tsk_buffer_append_2(output, param->value?"%c%s=%s":"%c%s", separator, param->name, param->value))) {
+ goto bail;
+ }
+ }
+ }
+ }
bail:
- return ret;
+ return ret;
}
/**@ingroup tsk_params_group
*/
tsk_params_L_t* tsk_params_fromstring(const char* string, const char* separator, tsk_bool_t trim)
{
- tsk_params_L_t* params = tsk_null;
- tsk_param_t* param;
+ tsk_params_L_t* params = tsk_null;
+ tsk_param_t* param;
- int i = 0, index;
- tsk_size_t size = tsk_strlen(string);
+ int i = 0, index;
+ tsk_size_t size = tsk_strlen(string);
#define PUSH_PARAM() \
if(!params){ \
@@ -305,21 +305,21 @@ tsk_params_L_t* tsk_params_fromstring(const char* string, const char* separator,
} \
tsk_list_push_back_data(params, (void**)&param);
- while((index = tsk_strindexOf((string + i), (size - i), separator)) != -1){
- if((param = tsk_params_parse_param((string + i), index))){
- PUSH_PARAM();
- }
- i += (index + 1);
- }
-
- // last one
- if(i<(int)size){
- if((param = tsk_params_parse_param((string + i), (size - i)))){
- PUSH_PARAM();
- }
- }
-
- return params;
+ while((index = tsk_strindexOf((string + i), (size - i), separator)) != -1) {
+ if((param = tsk_params_parse_param((string + i), index))) {
+ PUSH_PARAM();
+ }
+ i += (index + 1);
+ }
+
+ // last one
+ if(i<(int)size) {
+ if((param = tsk_params_parse_param((string + i), (size - i)))) {
+ PUSH_PARAM();
+ }
+ }
+
+ return params;
}
@@ -347,39 +347,38 @@ tsk_params_L_t* tsk_params_fromstring(const char* string, const char* separator,
//
static tsk_object_t* tsk_param_ctor(tsk_object_t* self, va_list * app)
{
- tsk_param_t *param = (tsk_param_t*)self;
- if(param){
- const char* name = va_arg(*app, const char *);
- const char* value = va_arg(*app, const char *);
-
- if(!tsk_strnullORempty(name)) {
- param->name = tsk_strdup(name);
- if(!tsk_strnullORempty(value)) {
- param->value = tsk_strdup(value);
- }
- }
- }
-
- return self;
+ tsk_param_t *param = (tsk_param_t*)self;
+ if(param) {
+ const char* name = va_arg(*app, const char *);
+ const char* value = va_arg(*app, const char *);
+
+ if(!tsk_strnullORempty(name)) {
+ param->name = tsk_strdup(name);
+ if(!tsk_strnullORempty(value)) {
+ param->value = tsk_strdup(value);
+ }
+ }
+ }
+
+ return self;
}
static tsk_object_t* tsk_param_dtor(tsk_object_t* self)
-{
- tsk_param_t *param = (tsk_param_t*)self;
- if(param){
- TSK_FREE(param->name);
- TSK_FREE(param->value);
- }
-
- return self;
+{
+ tsk_param_t *param = (tsk_param_t*)self;
+ if(param) {
+ TSK_FREE(param->name);
+ TSK_FREE(param->value);
+ }
+
+ return self;
}
-static const tsk_object_def_t tsk_param_def_s =
-{
- sizeof(tsk_param_t),
- tsk_param_ctor,
- tsk_param_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_param_def_s = {
+ sizeof(tsk_param_t),
+ tsk_param_ctor,
+ tsk_param_dtor,
+ tsk_null,
};
const tsk_object_def_t *tsk_param_def_t = &tsk_param_def_s;
diff --git a/tinySAK/src/tsk_params.h b/tinySAK/src/tsk_params.h
index 2d903f8..29f04cc 100755
--- a/tinySAK/src/tsk_params.h
+++ b/tinySAK/src/tsk_params.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -45,14 +45,13 @@ TSK_BEGIN_DECLS
/**@ingroup tsk_params_group
* Parameter.
*/
-typedef struct tsk_param_s
-{
- TSK_DECLARE_OBJECT;
-
- char *name;/**< The name of the parameter. */
- char *value;/**< The value of the parameter. */
-
- tsk_bool_t tag;/**< tag to be used for any use case (e.g. validity of the parameter, whether to ignore the param., ...). Default value: @ref tsk_false.*/
+typedef struct tsk_param_s {
+ TSK_DECLARE_OBJECT;
+
+ char *name;/**< The name of the parameter. */
+ char *value;/**< The value of the parameter. */
+
+ tsk_bool_t tag;/**< tag to be used for any use case (e.g. validity of the parameter, whether to ignore the param., ...). Default value: @ref tsk_false.*/
}
tsk_param_t;
diff --git a/tinySAK/src/tsk_plugin.c b/tinySAK/src/tsk_plugin.c
index c8453a9..25fd8df 100755
--- a/tinySAK/src/tsk_plugin.c
+++ b/tinySAK/src/tsk_plugin.c
@@ -1,17 +1,17 @@
/* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -48,194 +48,192 @@ static const wchar_t* szFormat = L"%hs";
static int _tsk_plugin_handle_destroy(tsk_plugin_handle_t** self);
static tsk_plugin_symbol_t* _tsk_plugin_handle_get_symbol(tsk_plugin_handle_t* handle, const char* symbol_name);
-typedef struct tsk_plugin_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_plugin_s {
+ TSK_DECLARE_OBJECT;
- tsk_plugin_handle_t* handle;
- int def_count;
- char* path;
+ tsk_plugin_handle_t* handle;
+ int def_count;
+ char* path;
}
tsk_plugin_t;
static tsk_object_t* tsk_plugin_ctor(tsk_object_t * self, va_list * app)
{
- tsk_plugin_t *plugin = (tsk_plugin_t*)self;
- if(plugin){
-
- }
- return self;
+ tsk_plugin_t *plugin = (tsk_plugin_t*)self;
+ if(plugin) {
+
+ }
+ return self;
}
static tsk_object_t* tsk_plugin_dtor(tsk_object_t * self)
-{
- tsk_plugin_t *plugin = (tsk_plugin_t*)self;
- if(plugin){
- TSK_FREE(plugin->path);
- _tsk_plugin_handle_destroy(&plugin->handle);
- }
-
- return self;
-}
-static const tsk_object_def_t tsk_plugin_def_s =
{
- sizeof(tsk_plugin_t),
- tsk_plugin_ctor,
- tsk_plugin_dtor,
- tsk_null,
+ tsk_plugin_t *plugin = (tsk_plugin_t*)self;
+ if(plugin) {
+ TSK_FREE(plugin->path);
+ _tsk_plugin_handle_destroy(&plugin->handle);
+ }
+
+ return self;
+}
+static const tsk_object_def_t tsk_plugin_def_s = {
+ sizeof(tsk_plugin_t),
+ tsk_plugin_ctor,
+ tsk_plugin_dtor,
+ tsk_null,
};
tsk_plugin_t* tsk_plugin_create(const char* path)
{
- tsk_plugin_t* plugin;
- symbol_get_def_count funcptr_get_def_count;
- tsk_plugin_handle_t* handle;
+ tsk_plugin_t* plugin;
+ symbol_get_def_count funcptr_get_def_count;
+ tsk_plugin_handle_t* handle;
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
- swprintf(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
- handle = LoadPackagedLibrary(szPath, 0x00000000);
- TSK_FREE(szPath);
+ wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
+ swprintf(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
+ handle = LoadPackagedLibrary(szPath, 0x00000000);
+ TSK_FREE(szPath);
# else /* Windows desktop/CE */
#if TSK_UNDER_WINDOWS_CE
- wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
- swprintf_s(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
- handle = LoadLibrary(szPath);
- TSK_FREE(szPath);
+ wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
+ swprintf_s(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
+ handle = LoadLibrary(szPath);
+ TSK_FREE(szPath);
#else
- UINT currErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); // save current ErrorMode. GetErrorMode() not supported on XP.
- SetErrorMode(currErrMode | SEM_FAILCRITICALERRORS);
- handle = LoadLibraryA(path);
- SetErrorMode(currErrMode); // restore ErrorMode
+ UINT currErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); // save current ErrorMode. GetErrorMode() not supported on XP.
+ SetErrorMode(currErrMode | SEM_FAILCRITICALERRORS);
+ handle = LoadLibraryA(path);
+ SetErrorMode(currErrMode); // restore ErrorMode
#endif /* !TSK_UNDER_WINDOWS_CE */
# endif /*end-of-else-TSK_UNDER_WINDOWS_RT*/
#else
- handle = dlopen(path, RTLD_NOW);
+ handle = dlopen(path, RTLD_NOW);
#endif
- if(!handle){
- TSK_DEBUG_ERROR("Failed to load library with path=%s", path);
- return tsk_null;
- }
+ if(!handle) {
+ TSK_DEBUG_ERROR("Failed to load library with path=%s", path);
+ return tsk_null;
+ }
- if(!(funcptr_get_def_count = (symbol_get_def_count)_tsk_plugin_handle_get_symbol(handle, TSK_PLUGIN_FUNC_NAME_DEF_COUNT))){
- TSK_DEBUG_ERROR("Cannot find function with name=%s", TSK_PLUGIN_FUNC_NAME_DEF_COUNT);
- _tsk_plugin_handle_destroy(&handle);
- return tsk_null;
- }
+ if(!(funcptr_get_def_count = (symbol_get_def_count)_tsk_plugin_handle_get_symbol(handle, TSK_PLUGIN_FUNC_NAME_DEF_COUNT))) {
+ TSK_DEBUG_ERROR("Cannot find function with name=%s", TSK_PLUGIN_FUNC_NAME_DEF_COUNT);
+ _tsk_plugin_handle_destroy(&handle);
+ return tsk_null;
+ }
- if(!(plugin = (tsk_plugin_t*)tsk_object_new(&tsk_plugin_def_s))){
- TSK_DEBUG_ERROR("Failed to create plugin object");
- _tsk_plugin_handle_destroy(&handle);
- return tsk_null;
- }
+ if(!(plugin = (tsk_plugin_t*)tsk_object_new(&tsk_plugin_def_s))) {
+ TSK_DEBUG_ERROR("Failed to create plugin object");
+ _tsk_plugin_handle_destroy(&handle);
+ return tsk_null;
+ }
- plugin->handle = handle;
- plugin->def_count = funcptr_get_def_count();
- plugin->path = tsk_strdup(path);
+ plugin->handle = handle;
+ plugin->def_count = funcptr_get_def_count();
+ plugin->path = tsk_strdup(path);
- TSK_DEBUG_INFO("Plugin with path=[%s] created with [%d] defs", plugin->path, plugin->def_count);
+ TSK_DEBUG_INFO("Plugin with path=[%s] created with [%d] defs", plugin->path, plugin->def_count);
- return plugin;
+ return plugin;
}
tsk_plugin_def_ptr_const_t tsk_plugin_get_def_2(struct tsk_plugin_s* self, tsk_plugin_def_type_t type, tsk_plugin_def_media_type_t media_type, tsk_size_t index)
{
- tsk_plugin_def_ptr_const_t def_ptr_const;
- symbol_get_def_type_at funcptr_get_def_type_at;
- symbol_get_def_media_type_at funcptr_get_def_media_type_at;
- symbol_get_def_at funcptr_get_def_at;
- int i;
- tsk_size_t _index = 0;
-
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_null;
- }
-
- if(!(funcptr_get_def_type_at = (symbol_get_def_type_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_TYPE_AT))){
- TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_TYPE_AT, self->path);
- return tsk_null;
- }
- if(!(funcptr_get_def_media_type_at = (symbol_get_def_media_type_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_MEDIA_TYPE_AT))){
- TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_MEDIA_TYPE_AT, self->path);
- return tsk_null;
- }
- if(!(funcptr_get_def_at = (symbol_get_def_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_AT))){
- TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_AT, self->path);
- return tsk_null;
- }
-
- for(i = 0; i < self->def_count; ++i){
- if((funcptr_get_def_type_at(i) & type) && (funcptr_get_def_media_type_at(i) & media_type)){
- if((def_ptr_const = funcptr_get_def_at(i))){
- if(_index++ == index){
- return def_ptr_const;
- }
- }
- }
- }
- return tsk_null;
+ tsk_plugin_def_ptr_const_t def_ptr_const;
+ symbol_get_def_type_at funcptr_get_def_type_at;
+ symbol_get_def_media_type_at funcptr_get_def_media_type_at;
+ symbol_get_def_at funcptr_get_def_at;
+ int i;
+ tsk_size_t _index = 0;
+
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+
+ if(!(funcptr_get_def_type_at = (symbol_get_def_type_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_TYPE_AT))) {
+ TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_TYPE_AT, self->path);
+ return tsk_null;
+ }
+ if(!(funcptr_get_def_media_type_at = (symbol_get_def_media_type_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_MEDIA_TYPE_AT))) {
+ TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_MEDIA_TYPE_AT, self->path);
+ return tsk_null;
+ }
+ if(!(funcptr_get_def_at = (symbol_get_def_at)tsk_plugin_get_symbol(self, TSK_PLUGIN_FUNC_NAME_DEF_AT))) {
+ TSK_DEBUG_ERROR("[%s] function not implemented in plugin with path=[%s]", TSK_PLUGIN_FUNC_NAME_DEF_AT, self->path);
+ return tsk_null;
+ }
+
+ for(i = 0; i < self->def_count; ++i) {
+ if((funcptr_get_def_type_at(i) & type) && (funcptr_get_def_media_type_at(i) & media_type)) {
+ if((def_ptr_const = funcptr_get_def_at(i))) {
+ if(_index++ == index) {
+ return def_ptr_const;
+ }
+ }
+ }
+ }
+ return tsk_null;
}
tsk_plugin_def_ptr_const_t tsk_plugin_get_def(tsk_plugin_t* self, tsk_plugin_def_type_t type, tsk_plugin_def_media_type_t media_type)
{
- return tsk_plugin_get_def_2(self, type, media_type, 0);
+ return tsk_plugin_get_def_2(self, type, media_type, 0);
}
tsk_plugin_symbol_t* tsk_plugin_get_symbol(tsk_plugin_t* self, const char* symbol_name)
{
- if(!self || !self->handle || !symbol_name){
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_null;
- }
- return _tsk_plugin_handle_get_symbol(self->handle, symbol_name);
+ if(!self || !self->handle || !symbol_name) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+ return _tsk_plugin_handle_get_symbol(self->handle, symbol_name);
}
tsk_bool_t tsk_plugin_file_exist(const char* path)
{
- if (path) {
+ if (path) {
#if TSK_UNDER_WINDOWS_CE
- wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
- DWORD dwAttrib;
- swprintf_s(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
- dwAttrib = GetFileAttributes(szPath);
- TSK_FREE(szPath);
- return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0);
+ wchar_t* szPath = (wchar_t*)tsk_calloc(tsk_strlen(path) + 1, sizeof(wchar_t));
+ DWORD dwAttrib;
+ swprintf_s(szPath, tsk_strlen(path) * sizeof(wchar_t), szFormat, path);
+ dwAttrib = GetFileAttributes(szPath);
+ TSK_FREE(szPath);
+ return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0);
#else
- struct stat _stat;
- return (stat(path, &_stat) == 0 && _stat.st_size > 0);
+ struct stat _stat;
+ return (stat(path, &_stat) == 0 && _stat.st_size > 0);
#endif /* TSK_UNDER_WINDOWS_CE */
- }
- return tsk_false;
+ }
+ return tsk_false;
}
static tsk_plugin_symbol_t* _tsk_plugin_handle_get_symbol(tsk_plugin_handle_t* handle, const char* symbol_name)
{
- if(!handle || !symbol_name){
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_null;
- }
+ if(!handle || !symbol_name) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_CE
- return (tsk_plugin_symbol_t*)GetProcAddressA((HMODULE)handle, symbol_name);
+ return (tsk_plugin_symbol_t*)GetProcAddressA((HMODULE)handle, symbol_name);
# else
- return (tsk_plugin_symbol_t*)GetProcAddress((HMODULE)handle, symbol_name);
+ return (tsk_plugin_symbol_t*)GetProcAddress((HMODULE)handle, symbol_name);
# endif
#else
- return (tsk_plugin_symbol_t*)dlsym(handle, symbol_name);
+ return (tsk_plugin_symbol_t*)dlsym(handle, symbol_name);
#endif
}
static int _tsk_plugin_handle_destroy(tsk_plugin_handle_t** handle)
{
- if(handle && *handle){
+ if(handle && *handle) {
#if TSK_UNDER_WINDOWS
- FreeLibrary((HMODULE)*handle);
+ FreeLibrary((HMODULE)*handle);
#else
- dlclose(*handle);
+ dlclose(*handle);
#endif
- *handle = tsk_null;
- }
- return 0;
+ *handle = tsk_null;
+ }
+ return 0;
}
diff --git a/tinySAK/src/tsk_plugin.h b/tinySAK/src/tsk_plugin.h
index 82fcfd6..85f0a00 100755
--- a/tinySAK/src/tsk_plugin.h
+++ b/tinySAK/src/tsk_plugin.h
@@ -1,17 +1,17 @@
/* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -25,29 +25,27 @@
TSK_BEGIN_DECLS
-typedef enum tsk_plugin_def_type_e
-{
- tsk_plugin_def_type_none = 0,
- tsk_plugin_def_type_consumer = (1 << 0),
- tsk_plugin_def_type_producer = (1 << 1),
- tsk_plugin_def_type_session = (1 << 2),
- tsk_plugin_def_type_codec = (1 << 3),
- tsk_plugin_def_type_resampler = (1 << 4),
- tsk_plugin_def_type_jb = (1 << 5),
- tsk_plugin_def_type_denoiser = (1 << 6),
- tsk_plugin_def_type_converter = (1 << 7),
- tsk_plugin_def_type_ipsec = (1 << 8),
- tsk_plugin_def_type_all = (~0)
+typedef enum tsk_plugin_def_type_e {
+ tsk_plugin_def_type_none = 0,
+ tsk_plugin_def_type_consumer = (1 << 0),
+ tsk_plugin_def_type_producer = (1 << 1),
+ tsk_plugin_def_type_session = (1 << 2),
+ tsk_plugin_def_type_codec = (1 << 3),
+ tsk_plugin_def_type_resampler = (1 << 4),
+ tsk_plugin_def_type_jb = (1 << 5),
+ tsk_plugin_def_type_denoiser = (1 << 6),
+ tsk_plugin_def_type_converter = (1 << 7),
+ tsk_plugin_def_type_ipsec = (1 << 8),
+ tsk_plugin_def_type_all = (~0)
}
tsk_plugin_def_type_t;
-typedef enum tsk_plugin_def_media_type_e
-{
- tsk_plugin_def_media_type_none = 0,
- tsk_plugin_def_media_type_audio = (1 << 0),
- tsk_plugin_def_media_type_video = (1 << 1),
- tsk_plugin_def_media_type_screencast = (1 << 2),
- tsk_plugin_def_media_type_all = (~0)
+typedef enum tsk_plugin_def_media_type_e {
+ tsk_plugin_def_media_type_none = 0,
+ tsk_plugin_def_media_type_audio = (1 << 0),
+ tsk_plugin_def_media_type_video = (1 << 1),
+ tsk_plugin_def_media_type_screencast = (1 << 2),
+ tsk_plugin_def_media_type_all = (~0)
}
tsk_plugin_def_media_type_t;
diff --git a/tinySAK/src/tsk_ppfcs16.c b/tinySAK/src/tsk_ppfcs16.c
index cc82574..bff369e 100755
--- a/tinySAK/src/tsk_ppfcs16.c
+++ b/tinySAK/src/tsk_ppfcs16.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -33,40 +33,39 @@
/**@defgroup tsk_ppfcs16_group PPP in HDLC-like Framing (RFC 1662).
*/
-static uint16_t fcstab[256] =
-{
- 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
- 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
- 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
- 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
- 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
- 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
- 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
- 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
- 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
- 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
- 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
- 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
- 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
- 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
- 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
- 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
- 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
- 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
- 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
- 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
- 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
- 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
- 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
- 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
- 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
- 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
- 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
- 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
- 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
- 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
- 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
- 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
+static uint16_t fcstab[256] = {
+ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
+ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
+ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
+ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
+ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
+ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
+ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
+ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
+ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
+ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
+ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
+ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
+ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
+ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
+ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
+ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
+ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
+ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
+ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
+ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
+ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
+ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
+ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
+ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
+ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
+ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
+ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
+ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
+ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
+ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
+ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
+ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
/**@ingroup tsk_ppfcs16_group
@@ -74,9 +73,9 @@ static uint16_t fcstab[256] =
*/
uint16_t tsk_pppfcs16(register uint16_t fcs, register const uint8_t* cp, register int32_t len)
{
- while (len--){
- fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
- }
- return (fcs);
+ while (len--) {
+ fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
+ }
+ return (fcs);
}
diff --git a/tinySAK/src/tsk_ppfcs16.h b/tinySAK/src/tsk_ppfcs16.h
index af340d1..5b52fd2 100755
--- a/tinySAK/src/tsk_ppfcs16.h
+++ b/tinySAK/src/tsk_ppfcs16.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_ppfcs32.c b/tinySAK/src/tsk_ppfcs32.c
index 1bb0eac..79e86c9 100755
--- a/tinySAK/src/tsk_ppfcs32.c
+++ b/tinySAK/src/tsk_ppfcs32.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -33,72 +33,71 @@
/**@defgroup tsk_ppfcs32_group PPP in HDLC-like Framing (RFC 1662).
*/
-static uint32_t fcstab_32[256] =
-{
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+static uint32_t fcstab_32[256] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
+ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
+ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
+ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
+ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
+ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
+ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
+ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
+ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
+ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
+ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
+ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
+ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
+ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
+ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
+ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
+ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
+ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
/**@ingroup tsk_ppfcs32_group
@@ -106,11 +105,11 @@ static uint32_t fcstab_32[256] =
*/
uint32_t tsk_pppfcs32(register uint32_t fcs, register const uint8_t* cp, register int32_t len)
{
- int32_t n;
- for(n = 0; n < len; ++n){
- fcs = (fcs >> 8) ^ (fcstab_32[(fcs & 0xff) ^ cp[n]]);
- }
+ int32_t n;
+ for(n = 0; n < len; ++n) {
+ fcs = (fcs >> 8) ^ (fcstab_32[(fcs & 0xff) ^ cp[n]]);
+ }
- return (fcs ^0xffffffff);
+ return (fcs ^0xffffffff);
}
diff --git a/tinySAK/src/tsk_ppfcs32.h b/tinySAK/src/tsk_ppfcs32.h
index f9cff1f..9281110 100755
--- a/tinySAK/src/tsk_ppfcs32.h
+++ b/tinySAK/src/tsk_ppfcs32.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_ragel_state.c b/tinySAK/src/tsk_ragel_state.c
index 840d784..3ec3908 100755
--- a/tinySAK/src/tsk_ragel_state.c
+++ b/tinySAK/src/tsk_ragel_state.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -40,8 +40,8 @@
*/
void tsk_ragel_state_init(tsk_ragel_state_t *state, const char *data, tsk_size_t size)
{
- state->cs = 0;
- state->tag_start = state->p = data;
- state->eoh = state->eof = state->tag_end = state->pe = state->p + size;
+ state->cs = 0;
+ state->tag_start = state->p = data;
+ state->eoh = state->eof = state->tag_end = state->pe = state->p + size;
}
diff --git a/tinySAK/src/tsk_ragel_state.h b/tinySAK/src/tsk_ragel_state.h
index fb0df85..d80aa99 100755
--- a/tinySAK/src/tsk_ragel_state.h
+++ b/tinySAK/src/tsk_ragel_state.h
@@ -165,16 +165,15 @@ TSK_BEGIN_DECLS
/**@ingroup tsk_ragel_state_group
* Ragel state.
*/
-typedef struct tsk_ragel_state_s
-{
- int cs; /**< Ragel current state. */
- const char *p; /**< Data pointing to the buffer to parse. */
- const char *pe; /**< Data end pointer. */
- const char *eof; /**< End of the file (in our case data) pointer. */
- const char *eoh; /**< End of the headers. */
-
- const char* tag_start; /**< Last tag start position set by ragel machine. */
- const char* tag_end; /**< The end of the ragel tag. */
+typedef struct tsk_ragel_state_s {
+ int cs; /**< Ragel current state. */
+ const char *p; /**< Data pointing to the buffer to parse. */
+ const char *pe; /**< Data end pointer. */
+ const char *eof; /**< End of the file (in our case data) pointer. */
+ const char *eoh; /**< End of the headers. */
+
+ const char* tag_start; /**< Last tag start position set by ragel machine. */
+ const char* tag_end; /**< The end of the ragel tag. */
}
tsk_ragel_state_t;
diff --git a/tinySAK/src/tsk_runnable.c b/tinySAK/src/tsk_runnable.c
index 2b0e3fe..0e80776 100755
--- a/tinySAK/src/tsk_runnable.c
+++ b/tinySAK/src/tsk_runnable.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -46,22 +46,22 @@ static void* TSK_STDCALL __async_join(void* self);
*/
tsk_runnable_t* tsk_runnable_create()
{
- return tsk_runnable_create_2(TSK_THREAD_PRIORITY_MEDIUM);
+ return tsk_runnable_create_2(TSK_THREAD_PRIORITY_MEDIUM);
}
/**@ingroup tsk_runnable_group
* Creates new Runnable object.
-* @param priority Thread priority. Possible values: TSK_THREAD_PRIORITY_LOW, TSK_THREAD_PRIORITY_MEDIUM, TSK_THREAD_PRIORITY_HIGH or TSK_THREAD_PRIORITY_TIME_CRITICAL
+* @param priority Thread priority. Possible values: TSK_THREAD_PRIORITY_LOW, TSK_THREAD_PRIORITY_MEDIUM, TSK_THREAD_PRIORITY_HIGH or TSK_THREAD_PRIORITY_TIME_CRITICAL
* @retval @ref tsk_runnable_t.
*/
tsk_runnable_t* tsk_runnable_create_2(int32_t priority)
{
- tsk_runnable_t* runnable;
- if((runnable = (tsk_runnable_t*)tsk_object_new(tsk_runnable_def_t))){
- runnable->priority = priority;
- }
- return runnable;
+ tsk_runnable_t* runnable;
+ if((runnable = (tsk_runnable_t*)tsk_object_new(tsk_runnable_def_t))) {
+ runnable->priority = priority;
+ }
+ return runnable;
}
/**@ingroup tsk_runnable_group
@@ -73,21 +73,21 @@ tsk_runnable_t* tsk_runnable_create_2(int32_t priority)
*/
static int tsk_runnable_init(tsk_runnable_t *self, const tsk_object_def_t *objdef)
{
- if(self && objdef){
- if(self->initialized){
- TSK_DEBUG_ERROR("Already initialized");
- return -2;
- }
-
- self->semaphore = tsk_semaphore_create();
- self->objdef = objdef;
- self->objects = tsk_list_create();
+ if(self && objdef) {
+ if(self->initialized) {
+ TSK_DEBUG_ERROR("Already initialized");
+ return -2;
+ }
+
+ self->semaphore = tsk_semaphore_create();
+ self->objdef = objdef;
+ self->objects = tsk_list_create();
- self->initialized = tsk_true;
- return 0;
- }
- TSK_DEBUG_ERROR("Invalid Parameter");
- return -1;
+ self->initialized = tsk_true;
+ return 0;
+ }
+ TSK_DEBUG_ERROR("Invalid Parameter");
+ return -1;
}
/**@ingroup tsk_runnable_group
@@ -98,24 +98,24 @@ static int tsk_runnable_init(tsk_runnable_t *self, const tsk_object_def_t *objde
*/
static int tsk_runnable_deinit(tsk_runnable_t *self)
{
- if(self){
- if(!self->initialized){
- return 0; /* Already deinitialized */
- }
- else if(self->running){
- TSK_DEBUG_ERROR("Cannot deinit a runnable object while running.");
- return -3;
- }
+ if(self) {
+ if(!self->initialized) {
+ return 0; /* Already deinitialized */
+ }
+ else if(self->running) {
+ TSK_DEBUG_ERROR("Cannot deinit a runnable object while running.");
+ return -3;
+ }
- tsk_semaphore_destroy(&self->semaphore);
- TSK_OBJECT_SAFE_FREE(self->objects);
+ tsk_semaphore_destroy(&self->semaphore);
+ TSK_OBJECT_SAFE_FREE(self->objects);
- self->initialized = tsk_false;
+ self->initialized = tsk_false;
- return 0;
- }
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
+ return 0;
+ }
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
}
/**@ingroup tsk_runnable_group
@@ -127,66 +127,72 @@ static int tsk_runnable_deinit(tsk_runnable_t *self)
*/
int tsk_runnable_start(tsk_runnable_t *self, const tsk_object_def_t *objdef)
{
- if(self){
- int ret = -1;
- if(self->running) return -2;
- else if(!self->run) return -3;
- else if(tsk_runnable_init(self, objdef)) return -4;
+ if(self) {
+ int ret = -1;
+ if(self->running) {
+ return -2;
+ }
+ else if(!self->run) {
+ return -3;
+ }
+ else if(tsk_runnable_init(self, objdef)) {
+ return -4;
+ }
- /* call run() function in new thread. */
- if((ret = tsk_thread_create(&(self->h_thread[0]), self->run, self))){
- TSK_DEBUG_ERROR("Failed to start new thread.");
- return ret;
- }
- /* set priority now that the thread is created */
- if(tsk_runnable_set_priority(self, self->priority)){
- TSK_DEBUG_ERROR("Failed to set thread priority value to %d", self->priority);
- }
- // Do not set "running" to true here
- // Problem: When you try to stop the thread before it start
- // Will be done by "TSK_RUNNABLE_RUN_BEGIN" which is called into the thread
- //self->running = tsk_true;
+ /* call run() function in new thread. */
+ if((ret = tsk_thread_create(&(self->h_thread[0]), self->run, self))) {
+ TSK_DEBUG_ERROR("Failed to start new thread.");
+ return ret;
+ }
+ /* set priority now that the thread is created */
+ if(tsk_runnable_set_priority(self, self->priority)) {
+ TSK_DEBUG_ERROR("Failed to set thread priority value to %d", self->priority);
+ }
+ // Do not set "running" to true here
+ // Problem: When you try to stop the thread before it start
+ // Will be done by "TSK_RUNNABLE_RUN_BEGIN" which is called into the thread
+ //self->running = tsk_true;
- self->started = tsk_true;
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ self->started = tsk_true;
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_runnable_group
* To indicate whether the enqueued data is important or not.
* @param self The runnable object
-* @param important @a tsk_true or @a tsk_false. If set to @a tsk_true, the thread will not be joined
+* @param important @a tsk_true or @a tsk_false. If set to @a tsk_true, the thread will not be joined
* until all data in the queue have been consumed.
*/
int tsk_runnable_set_important(tsk_runnable_t *self, tsk_bool_t important)
{
- if(self){
- self->important = important;
- return 0;
- }
- else{
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(self) {
+ self->important = important;
+ return 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
}
/**@ingroup tsk_runnable_group
*/
int tsk_runnable_set_priority(tsk_runnable_t *self, int32_t priority)
{
- if(!self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- self->priority = priority;
- if(self->h_thread[0]){
- return tsk_thread_set_priority(self->h_thread[0], priority);
- }
- return 0;
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ self->priority = priority;
+ if(self->h_thread[0]) {
+ return tsk_thread_set_priority(self->h_thread[0], priority);
+ }
+ return 0;
}
/**@ingroup tsk_runnable_group
@@ -197,78 +203,78 @@ int tsk_runnable_set_priority(tsk_runnable_t *self, int32_t priority)
*/
int tsk_runnable_stop(tsk_runnable_t *self)
{
- int ret = -1;
- if (self) {
- tsk_thread_id_t id_curr_thread;
- if (!self->initialized) {
- if (!self->running) {
- /* already deinitialized */
- return 0;
- }
- else {
- /* should never happen */
- TSK_DEBUG_ERROR("Not initialized.");
- return -2;
- }
- }
- else if (!self->running) {
+ int ret = -1;
+ if (self) {
+ tsk_thread_id_t id_curr_thread;
+ if (!self->initialized) {
+ if (!self->running) {
+ /* already deinitialized */
+ return 0;
+ }
+ else {
+ /* should never happen */
+ TSK_DEBUG_ERROR("Not initialized.");
+ return -2;
+ }
+ }
+ else if (!self->running) {
- if (self->started) {
- tsk_size_t count = 0;
- /* Thread is started but not running ==> Give it time.*/
- while (++count <= 5) {
- tsk_thread_sleep(count * 200);
- if (self->running) {
- goto stop;
- }
- }
- }
- else{
- return 0; /* already stopped */
- }
- return -3;
- }
+ if (self->started) {
+ tsk_size_t count = 0;
+ /* Thread is started but not running ==> Give it time.*/
+ while (++count <= 5) {
+ tsk_thread_sleep(count * 200);
+ if (self->running) {
+ goto stop;
+ }
+ }
+ }
+ else {
+ return 0; /* already stopped */
+ }
+ return -3;
+ }
stop:
- self->running = tsk_false;
- tsk_semaphore_increment(self->semaphore);
- // To avoid deadlock we don't join() the thread if this funcion is called from the "run()" function
- // setting "self::running" to false is enough to exit the thread after the call to "TSK_RUNNABLE_RUN_BEGIN(self)"
- id_curr_thread = tsk_thread_get_id();
- if (tsk_thread_id_equals(&self->id_thread, &id_curr_thread)) {
- tsk_runnable_t* copy = tsk_object_ref(TSK_OBJECT(self)); // "copy" will be null if this function is called in the "dtor()" because "refCount" is already equal to "zero".
- TSK_DEBUG_INFO("tsk_thread_join(%s) called inside the thread(%lu) itself...delaying", copy ? "NOT null" : "null", (unsigned long)id_curr_thread);
- if (!copy || self->h_thread[1]) {
- if (self->h_thread[1]) { // must never happen
- TSK_DEBUG_ERROR("Join already delayed");
- }
- ret = tsk_thread_destroy(&(self->h_thread[0]));
- tsk_object_unref(TSK_OBJECT(copy));
- }
- else {
- ret = tsk_thread_create(&(self->h_thread[1]), __async_join, copy);
- }
- }
- else if ((ret = tsk_thread_join(&(self->h_thread[0])))) {
- self->running = tsk_true;
- TSK_DEBUG_ERROR("Failed to join the thread.");
- return ret;
- }
- tsk_runnable_deinit(self);
+ self->running = tsk_false;
+ tsk_semaphore_increment(self->semaphore);
+ // To avoid deadlock we don't join() the thread if this funcion is called from the "run()" function
+ // setting "self::running" to false is enough to exit the thread after the call to "TSK_RUNNABLE_RUN_BEGIN(self)"
+ id_curr_thread = tsk_thread_get_id();
+ if (tsk_thread_id_equals(&self->id_thread, &id_curr_thread)) {
+ tsk_runnable_t* copy = tsk_object_ref(TSK_OBJECT(self)); // "copy" will be null if this function is called in the "dtor()" because "refCount" is already equal to "zero".
+ TSK_DEBUG_INFO("tsk_thread_join(%s) called inside the thread(%lu) itself...delaying", copy ? "NOT null" : "null", (unsigned long)id_curr_thread);
+ if (!copy || self->h_thread[1]) {
+ if (self->h_thread[1]) { // must never happen
+ TSK_DEBUG_ERROR("Join already delayed");
+ }
+ ret = tsk_thread_destroy(&(self->h_thread[0]));
+ tsk_object_unref(TSK_OBJECT(copy));
+ }
+ else {
+ ret = tsk_thread_create(&(self->h_thread[1]), __async_join, copy);
+ }
+ }
+ else if ((ret = tsk_thread_join(&(self->h_thread[0])))) {
+ self->running = tsk_true;
+ TSK_DEBUG_ERROR("Failed to join the thread.");
+ return ret;
+ }
+ tsk_runnable_deinit(self);
- self->started = tsk_false;
- }
- return ret;
+ self->started = tsk_false;
+ }
+ return ret;
}
static void* TSK_STDCALL __async_join(void* arg)
{
- tsk_runnable_t *self = (tsk_runnable_t *)arg;
- if (self) {
- tsk_thread_join(&self->h_thread[0]);
- return tsk_object_unref(TSK_OBJECT(self));
- }
- return self;
+ tsk_runnable_t *self = (tsk_runnable_t *)arg;
+ if (self) {
+ tsk_thread_join(&self->h_thread[0]);
+ return tsk_object_unref(TSK_OBJECT(self));
+ }
+ return self;
}
//=================================================================================================
@@ -276,33 +282,32 @@ static void* TSK_STDCALL __async_join(void* arg)
//
static tsk_object_t* tsk_runnable_ctor(tsk_object_t * self, va_list * app)
{
- tsk_runnable_t* runnable = (tsk_runnable_t*)self;
- if (runnable) {
-
- }
- return self;
+ tsk_runnable_t* runnable = (tsk_runnable_t*)self;
+ if (runnable) {
+
+ }
+ return self;
}
static tsk_object_t* tsk_runnable_dtor(tsk_object_t * self)
-{
- tsk_runnable_t* runnable = (tsk_runnable_t*)self;
- if (runnable) {
- /* stops runnable object (if running or started) */
- tsk_runnable_stop(runnable); // join(runnable->h_thread[0])
- if (runnable->h_thread[1]) {
- tsk_thread_destroy(&(runnable->h_thread[1])); // must not be join()
- }
- TSK_DEBUG_INFO("*** tsk_runnable_t destroyed ***");
- }
- return self;
+{
+ tsk_runnable_t* runnable = (tsk_runnable_t*)self;
+ if (runnable) {
+ /* stops runnable object (if running or started) */
+ tsk_runnable_stop(runnable); // join(runnable->h_thread[0])
+ if (runnable->h_thread[1]) {
+ tsk_thread_destroy(&(runnable->h_thread[1])); // must not be join()
+ }
+ TSK_DEBUG_INFO("*** tsk_runnable_t destroyed ***");
+ }
+ return self;
}
-static const tsk_object_def_t tsk_runnable_def_s =
-{
- sizeof(tsk_runnable_t),
- tsk_runnable_ctor,
- tsk_runnable_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_runnable_def_s = {
+ sizeof(tsk_runnable_t),
+ tsk_runnable_ctor,
+ tsk_runnable_dtor,
+ tsk_null,
};
const tsk_object_def_t *tsk_runnable_def_t = &tsk_runnable_def_s;
diff --git a/tinySAK/src/tsk_runnable.h b/tinySAK/src/tsk_runnable.h
index 8aa4ed1..b8a6020 100755
--- a/tinySAK/src/tsk_runnable.h
+++ b/tinySAK/src/tsk_runnable.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -50,29 +50,28 @@ typedef void* (TSK_STDCALL *tsk_runnable_func_run)(void* self);
/**@ingroup tsk_runnable_group
* Runnable.
*/
-typedef struct tsk_runnable_s
-{
- TSK_DECLARE_OBJECT;
-
- const tsk_object_def_t *objdef;
-
- tsk_thread_handle_t* h_thread[2/*0=default,1=delayed*/];
- tsk_runnable_func_run run;
- tsk_thread_id_t id_thread; // no way to get this value from "h_thread" on WINXP
- tsk_semaphore_handle_t *semaphore;
-
- tsk_bool_t running;
- tsk_bool_t started;
- tsk_bool_t initialized;
- /** whether the enqueued data are important or not.
- * if yes, the thread will not be joined until all data in the queue have been consumed.
- * default value: tsk_false
- */
- tsk_bool_t important;
-
- int32_t priority;
-
- tsk_list_t *objects;
+typedef struct tsk_runnable_s {
+ TSK_DECLARE_OBJECT;
+
+ const tsk_object_def_t *objdef;
+
+ tsk_thread_handle_t* h_thread[2/*0=default,1=delayed*/];
+ tsk_runnable_func_run run;
+ tsk_thread_id_t id_thread; // no way to get this value from "h_thread" on WINXP
+ tsk_semaphore_handle_t *semaphore;
+
+ tsk_bool_t running;
+ tsk_bool_t started;
+ tsk_bool_t initialized;
+ /** whether the enqueued data are important or not.
+ * if yes, the thread will not be joined until all data in the queue have been consumed.
+ * default value: tsk_false
+ */
+ tsk_bool_t important;
+
+ int32_t priority;
+
+ tsk_list_t *objects;
}
tsk_runnable_t;
@@ -106,7 +105,7 @@ TINYSAK_GEXTERN const tsk_object_def_t *tsk_runnable_def_t;
if(!TSK_RUNNABLE(self)->running && \
(!TSK_RUNNABLE(self)->important || (TSK_RUNNABLE(self)->important && TSK_LIST_IS_EMPTY(TSK_RUNNABLE(self)->objects)))) \
break;
-
+
#define TSK_RUNNABLE_RUN_END(self) \
} \
@@ -160,12 +159,13 @@ TINYSAK_GEXTERN const tsk_object_def_t *tsk_runnable_def_t;
*/
#define TSK_RUNNABLE_POP_FIRST(self) \
tsk_list_pop_first_item(TSK_RUNNABLE(self)->objects)
-static tsk_list_item_t* TSK_RUNNABLE_POP_FIRST_SAFE(tsk_runnable_t* self){
- tsk_list_item_t* item;
- tsk_list_lock(self->objects);
- item= tsk_list_pop_first_item(self->objects);
- tsk_list_unlock(self->objects);
- return item;
+static tsk_list_item_t* TSK_RUNNABLE_POP_FIRST_SAFE(tsk_runnable_t* self)
+{
+ tsk_list_item_t* item;
+ tsk_list_lock(self->objects);
+ item= tsk_list_pop_first_item(self->objects);
+ tsk_list_unlock(self->objects);
+ return item;
}
TSK_END_DECLS
diff --git a/tinySAK/src/tsk_safeobj.c b/tinySAK/src/tsk_safeobj.c
index fb5f836..85c01de 100755
--- a/tinySAK/src/tsk_safeobj.c
+++ b/tinySAK/src/tsk_safeobj.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_safeobj.h b/tinySAK/src/tsk_safeobj.h
index 6d826b7..5cdf062 100755
--- a/tinySAK/src/tsk_safeobj.h
+++ b/tinySAK/src/tsk_safeobj.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_semaphore.c b/tinySAK/src/tsk_semaphore.c
index ba9149a..1ba85ef 100755
--- a/tinySAK/src/tsk_semaphore.c
+++ b/tinySAK/src/tsk_semaphore.c
@@ -62,8 +62,7 @@ typedef HANDLE SEMAPHORE_T;
# include <fcntl.h> /* O_CREAT */
# include <sys/stat.h> /* S_IRUSR, S_IWUSR*/
-typedef struct named_sem_s
-{
+typedef struct named_sem_s {
sem_t* sem;
char name [NAME_MAX + 1];
} named_sem_t;
@@ -100,7 +99,7 @@ tsk_semaphore_handle_t* tsk_semaphore_create()
tsk_semaphore_handle_t* tsk_semaphore_create_2(int initial_val)
{
SEMAPHORE_T handle = tsk_null;
-
+
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
handle = CreateSemaphoreEx(NULL, initial_val, 0x7FFFFFFF, NULL, 0x00000000, SEMAPHORE_ALL_ACCESS);
@@ -109,101 +108,102 @@ tsk_semaphore_handle_t* tsk_semaphore_create_2(int initial_val)
# endif
#else
handle = tsk_calloc(1, sizeof(SEMAPHORE_S));
-
+
#if TSK_USE_NAMED_SEM
named_sem_t * nsem = (named_sem_t*)handle;
snprintf(nsem->name, (sizeof(nsem->name)/sizeof(nsem->name[0])) - 1, "/sem/%llu/%d.", tsk_time_epoch(), rand() ^ rand());
if ((nsem->sem = sem_open(nsem->name, O_CREAT /*| O_EXCL*/, S_IRUSR | S_IWUSR, initial_val)) == SEM_FAILED) {
#else
- if (sem_init((SEMAPHORE_T)handle, 0, initial_val)) {
+ if (sem_init((SEMAPHORE_T)handle, 0, initial_val)) {
#endif
- TSK_FREE(handle);
- TSK_DEBUG_ERROR("Failed to initialize the new semaphore (errno=%d).", errno);
- }
+ TSK_FREE(handle);
+ TSK_DEBUG_ERROR("Failed to initialize the new semaphore (errno=%d).", errno);
+ }
#endif
- if (!handle) {
- TSK_DEBUG_ERROR("Failed to create new semaphore");
- }
- return handle;
+ if (!handle) {
+ TSK_DEBUG_ERROR("Failed to create new semaphore");
}
-
- /**@ingroup tsk_semaphore_group
- * Increments a semaphore.
- * @param handle The semaphore to increment.
- * @retval Zero if succeed and otherwise the function returns -1 and sets errno to indicate the error.
- * @sa @ref tsk_semaphore_decrement.
- */
- int tsk_semaphore_increment(tsk_semaphore_handle_t* handle)
- {
- int ret = EINVAL;
- if (handle) {
+ return handle;
+}
+
+/**@ingroup tsk_semaphore_group
+ * Increments a semaphore.
+ * @param handle The semaphore to increment.
+ * @retval Zero if succeed and otherwise the function returns -1 and sets errno to indicate the error.
+ * @sa @ref tsk_semaphore_decrement.
+ */
+int tsk_semaphore_increment(tsk_semaphore_handle_t* handle)
+{
+ int ret = EINVAL;
+ if (handle) {
#if TSK_UNDER_WINDOWS
- if((ret = ReleaseSemaphore((SEMAPHORE_T)handle, 1L, NULL) ? 0 : -1))
+ if((ret = ReleaseSemaphore((SEMAPHORE_T)handle, 1L, NULL) ? 0 : -1))
#else
- if((ret = sem_post((SEMAPHORE_T)GET_SEM(handle))))
+ if((ret = sem_post((SEMAPHORE_T)GET_SEM(handle))))
#endif
- {
- TSK_DEBUG_ERROR("sem_post function failed: %d", ret);
- }
+ {
+ TSK_DEBUG_ERROR("sem_post function failed: %d", ret);
}
- return ret;
}
-
- /**@ingroup tsk_semaphore_group
- * Decrements a semaphore.
- * @param handle The semaphore to decrement.
- * @retval Zero if succeed and otherwise the function returns -1 and sets errno to indicate the error.
- * @sa @ref tsk_semaphore_increment.
- */
- int tsk_semaphore_decrement(tsk_semaphore_handle_t* handle)
- {
- int ret = EINVAL;
- if (handle) {
+ return ret;
+}
+
+/**@ingroup tsk_semaphore_group
+ * Decrements a semaphore.
+ * @param handle The semaphore to decrement.
+ * @retval Zero if succeed and otherwise the function returns -1 and sets errno to indicate the error.
+ * @sa @ref tsk_semaphore_increment.
+ */
+int tsk_semaphore_decrement(tsk_semaphore_handle_t* handle)
+{
+ int ret = EINVAL;
+ if (handle) {
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- ret = (WaitForSingleObjectEx((SEMAPHORE_T)handle, INFINITE, TRUE) == WAIT_OBJECT_0) ? 0 : -1;
+ ret = (WaitForSingleObjectEx((SEMAPHORE_T)handle, INFINITE, TRUE) == WAIT_OBJECT_0) ? 0 : -1;
# else
- ret = (WaitForSingleObject((SEMAPHORE_T)handle, INFINITE) == WAIT_OBJECT_0) ? 0 : -1;
+ ret = (WaitForSingleObject((SEMAPHORE_T)handle, INFINITE) == WAIT_OBJECT_0) ? 0 : -1;
#endif
- if (ret) {
- TSK_DEBUG_ERROR("sem_wait function failed: %d", ret);
- }
+ if (ret) {
+ TSK_DEBUG_ERROR("sem_wait function failed: %d", ret);
+ }
#else
- do {
- ret = sem_wait((SEMAPHORE_T)GET_SEM(handle));
- }
- while ( errno == EINTR );
- if(ret) TSK_DEBUG_ERROR("sem_wait function failed: %d", errno);
-#endif
+ do {
+ ret = sem_wait((SEMAPHORE_T)GET_SEM(handle));
}
-
- return ret;
+ while ( errno == EINTR );
+ if(ret) {
+ TSK_DEBUG_ERROR("sem_wait function failed: %d", errno);
+ }
+#endif
}
-
- /**@ingroup tsk_semaphore_group
- * Destroy a semaphore previously created using @ref tsk_semaphore_create.
- * @param handle The semaphore to free.
- * @sa @ref tsk_semaphore_create
- */
- void tsk_semaphore_destroy(tsk_semaphore_handle_t** handle)
- {
- if(handle && *handle)
- {
+
+ return ret;
+}
+
+/**@ingroup tsk_semaphore_group
+ * Destroy a semaphore previously created using @ref tsk_semaphore_create.
+ * @param handle The semaphore to free.
+ * @sa @ref tsk_semaphore_create
+ */
+void tsk_semaphore_destroy(tsk_semaphore_handle_t** handle)
+{
+ if(handle && *handle) {
#if TSK_UNDER_WINDOWS
- CloseHandle((SEMAPHORE_T)*handle);
- *handle = tsk_null;
+ CloseHandle((SEMAPHORE_T)*handle);
+ *handle = tsk_null;
#else
# if TSK_USE_NAMED_SEM
- named_sem_t * nsem = ((named_sem_t*)*handle);
- sem_close(nsem->sem);
+ named_sem_t * nsem = ((named_sem_t*)*handle);
+ sem_close(nsem->sem);
#else
- sem_destroy((SEMAPHORE_T)GET_SEM(*handle));
+ sem_destroy((SEMAPHORE_T)GET_SEM(*handle));
#endif /* TSK_USE_NAMED_SEM */
- tsk_free(handle);
+ tsk_free(handle);
#endif
- }
- else{
- TSK_DEBUG_WARN("Cannot free an uninitialized semaphore object");
- }
}
-
+ else {
+ TSK_DEBUG_WARN("Cannot free an uninitialized semaphore object");
+ }
+}
+
diff --git a/tinySAK/src/tsk_semaphore.h b/tinySAK/src/tsk_semaphore.h
index 205e8c0..50fb729 100755
--- a/tinySAK/src/tsk_semaphore.h
+++ b/tinySAK/src/tsk_semaphore.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_sha1.c b/tinySAK/src/tsk_sha1.c
index 1d972db..3a15b2a 100755
--- a/tinySAK/src/tsk_sha1.c
+++ b/tinySAK/src/tsk_sha1.c
@@ -1,7 +1,7 @@
/*
*
* Based on the RFC 3174
- *
+ *
* Full Copyright Statement
*
* Copyright (C) The Internet Society (2001). All Rights Reserved.
@@ -32,7 +32,7 @@
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
- *
+ *
* Description:
* This file implements the Secure Hashing Algorithm 1 as
* defined in FIPS PUB 180-1 published April 17, 1995.
@@ -65,19 +65,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -108,7 +108,7 @@
* when n is the digest size in bits. Therefore, this
* algorithm can serve as a means of providing a
* "fingerprint" for a message.
- *
+ *
*/
/**@ingroup tsk_sha1_group
@@ -132,7 +132,7 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *);
*/
tsk_sha1_errcode_t tsk_sha1reset(tsk_sha1context_t *context)
{
- if (!context){
+ if (!context) {
return shaNull;
}
@@ -165,17 +165,17 @@ tsk_sha1_errcode_t tsk_sha1result( tsk_sha1context_t *context, tsk_sha1digest_t
{
int32_t i;
- if (!context || !Message_Digest){
+ if (!context || !Message_Digest) {
return shaNull;
}
- if (context->Corrupted){
+ if (context->Corrupted) {
return (tsk_sha1_errcode_t)context->Corrupted;
}
- if (!context->Computed){
+ if (!context->Computed) {
SHA1PadMessage(context);
- for(i=0; i<64; ++i){
+ for(i=0; i<64; ++i) {
/* message may be sensitive, clear it out */
context->Message_Block[i] = 0;
}
@@ -185,7 +185,7 @@ tsk_sha1_errcode_t tsk_sha1result( tsk_sha1context_t *context, tsk_sha1digest_t
}
- for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i){
+ for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i) {
Message_Digest[i] = context->Intermediate_Hash[i>>2]
>> 8 * ( 3 - ( i & 0x03 ) );
}
@@ -203,46 +203,44 @@ tsk_sha1_errcode_t tsk_sha1result( tsk_sha1context_t *context, tsk_sha1digest_t
* @retval @ref tsk_sha1_errcode_t code.
*/
tsk_sha1_errcode_t tsk_sha1input(tsk_sha1context_t *context,
- const uint8_t *message_array,
- unsigned length)
+ const uint8_t *message_array,
+ unsigned length)
{
- if (!length){
+ if (!length) {
return shaSuccess;
}
- if (!context || !message_array){
+ if (!context || !message_array) {
return shaNull;
}
- if (context->Computed){
+ if (context->Computed) {
context->Corrupted = shaStateError;
return shaStateError;
}
- if (context->Corrupted){
- return (tsk_sha1_errcode_t)context->Corrupted;
+ if (context->Corrupted) {
+ return (tsk_sha1_errcode_t)context->Corrupted;
}
- while(length-- && !context->Corrupted)
- {
- context->Message_Block[context->Message_Block_Index++] =
- (*message_array & 0xFF);
-
- context->Length_Low += 8;
- if (context->Length_Low == 0){
- context->Length_High++;
- if (context->Length_High == 0)
- {
- /* Message is too long */
- context->Corrupted = 1;
+ while(length-- && !context->Corrupted) {
+ context->Message_Block[context->Message_Block_Index++] =
+ (*message_array & 0xFF);
+
+ context->Length_Low += 8;
+ if (context->Length_Low == 0) {
+ context->Length_High++;
+ if (context->Length_High == 0) {
+ /* Message is too long */
+ context->Corrupted = 1;
+ }
}
- }
- if (context->Message_Block_Index == 64){
- SHA1ProcessMessageBlock(context);
- }
+ if (context->Message_Block_Index == 64) {
+ SHA1ProcessMessageBlock(context);
+ }
- message_array++;
+ message_array++;
}
return shaSuccess;
@@ -258,17 +256,17 @@ tsk_sha1_errcode_t tsk_sha1input(tsk_sha1context_t *context,
*/
void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
{
- /*
- * Many of the variable names in this code, especially the
- * single character names, were used because those were the
- * names used in the publication.
- */
+ /*
+ * Many of the variable names in this code, especially the
+ * single character names, were used because those were the
+ * names used in the publication.
+ */
const uint32_t K[] = { /* Constants defined in SHA-1 */
- 0x5A827999,
- 0x6ED9EBA1,
- 0x8F1BBCDC,
- 0xCA62C1D6
- };
+ 0x5A827999,
+ 0x6ED9EBA1,
+ 0x8F1BBCDC,
+ 0xCA62C1D6
+ };
int32_t t; /* Loop counter */
uint32_t temp; /* Temporary word value */
uint32_t W[80]; /* Word sequence */
@@ -277,15 +275,15 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
/*
* Initialize the first 16 words in the array W
*/
- for(t = 0; t < 16; t++){
+ for(t = 0; t < 16; t++) {
W[t] = context->Message_Block[t * 4] << 24;
W[t] |= context->Message_Block[t * 4 + 1] << 16;
W[t] |= context->Message_Block[t * 4 + 2] << 8;
W[t] |= context->Message_Block[t * 4 + 3];
}
- for(t = 16; t < 80; t++){
- W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
+ for(t = 16; t < 80; t++) {
+ W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
}
A = context->Intermediate_Hash[0];
@@ -294,7 +292,7 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
D = context->Intermediate_Hash[3];
E = context->Intermediate_Hash[4];
- for(t = 0; t < 20; t++){
+ for(t = 0; t < 20; t++) {
temp = SHA1CircularShift(5,A) +
((B & C) | ((~B) & D)) + E + W[t] + K[0];
E = D;
@@ -305,7 +303,7 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
A = temp;
}
- for(t = 20; t < 40; t++){
+ for(t = 20; t < 40; t++) {
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
E = D;
D = C;
@@ -314,7 +312,7 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
A = temp;
}
- for(t = 40; t < 60; t++){
+ for(t = 40; t < 60; t++) {
temp = SHA1CircularShift(5,A) +
((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
E = D;
@@ -324,7 +322,7 @@ void SHA1ProcessMessageBlock(tsk_sha1context_t *context)
A = temp;
}
- for(t = 60; t < 80; t++){
+ for(t = 60; t < 80; t++) {
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
E = D;
D = C;
@@ -365,21 +363,21 @@ void SHA1PadMessage(tsk_sha1context_t *context)
* block, process it, and then continue padding into a second
* block.
*/
- if (context->Message_Block_Index > 55){
+ if (context->Message_Block_Index > 55) {
context->Message_Block[context->Message_Block_Index++] = 0x80;
- while(context->Message_Block_Index < 64){
+ while(context->Message_Block_Index < 64) {
context->Message_Block[context->Message_Block_Index++] = 0;
}
SHA1ProcessMessageBlock(context);
- while(context->Message_Block_Index < 56){
+ while(context->Message_Block_Index < 56) {
context->Message_Block[context->Message_Block_Index++] = 0;
}
}
- else{
+ else {
context->Message_Block[context->Message_Block_Index++] = 0x80;
- while(context->Message_Block_Index < 56){
+ while(context->Message_Block_Index < 56) {
context->Message_Block[context->Message_Block_Index++] = 0;
}
}
@@ -405,51 +403,51 @@ void SHA1PadMessage(tsk_sha1context_t *context)
* @param context The sha1 context.
*/
void tsk_sha1final(uint8_t *Message_Digest, tsk_sha1context_t *context)
-{
- int32_t i;
-
- SHA1PadMessage(context);
- for(i = 0; i<64; ++i) {
- context->Message_Block[i] = 0;
- }
- context->Length_Low = 0; /* and clear length */
- context->Length_High = 0;
-
- for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i) {
- Message_Digest[i] = context->Intermediate_Hash[i>>2] >> 8*(3-(i&0x03));
- }
+{
+ int32_t i;
+
+ SHA1PadMessage(context);
+ for(i = 0; i<64; ++i) {
+ context->Message_Block[i] = 0;
+ }
+ context->Length_Low = 0; /* and clear length */
+ context->Length_High = 0;
+
+ for(i = 0; i < TSK_SHA1_DIGEST_SIZE; ++i) {
+ Message_Digest[i] = context->Intermediate_Hash[i>>2] >> 8*(3-(i&0x03));
+ }
}
/**@ingroup tsk_sha1_group
- * Calculates sha1 digest result (hexadecimal string).
+ * Calculates sha1 digest result (hexadecimal string).
*
- * @param input The input data for which to calculate the SHA-1 hash.
- * @param size The size of the input data.
- * @param result SHA-1 hash result as a hexadecimal string.
+ * @param input The input data for which to calculate the SHA-1 hash.
+ * @param size The size of the input data.
+ * @param result SHA-1 hash result as a hexadecimal string.
*
* @retval @ref tsk_sha1_errcode_t code.
* @sa @ref TSK_SHA1_DIGEST_CALC
**/
tsk_sha1_errcode_t tsk_sha1compute(const char* input, tsk_size_t size, tsk_sha1string_t *result)
{
- tsk_sha1_errcode_t ret;
- tsk_sha1context_t sha;
- uint8_t digest[TSK_SHA1_DIGEST_SIZE];
-
- (*result)[TSK_SHA1_STRING_SIZE] = '\0';
-
- if( (ret = tsk_sha1reset(&sha)) != shaSuccess ){
- return ret;
- }
- else if ( (ret = tsk_sha1input(&sha, (uint8_t*)input, (unsigned int)size)) != shaSuccess ){
- return ret;
- }
- else if( (ret = tsk_sha1result(&sha, digest)) != shaSuccess ){
- return ret;
- }
-
- tsk_str_from_hex(digest, TSK_SHA1_DIGEST_SIZE, (char*)*result);
-
- return shaSuccess;
+ tsk_sha1_errcode_t ret;
+ tsk_sha1context_t sha;
+ uint8_t digest[TSK_SHA1_DIGEST_SIZE];
+
+ (*result)[TSK_SHA1_STRING_SIZE] = '\0';
+
+ if( (ret = tsk_sha1reset(&sha)) != shaSuccess ) {
+ return ret;
+ }
+ else if ( (ret = tsk_sha1input(&sha, (uint8_t*)input, (unsigned int)size)) != shaSuccess ) {
+ return ret;
+ }
+ else if( (ret = tsk_sha1result(&sha, digest)) != shaSuccess ) {
+ return ret;
+ }
+
+ tsk_str_from_hex(digest, TSK_SHA1_DIGEST_SIZE, (char*)*result);
+
+ return shaSuccess;
}
diff --git a/tinySAK/src/tsk_sha1.h b/tinySAK/src/tsk_sha1.h
index ff1e3d3..7c09005 100755
--- a/tinySAK/src/tsk_sha1.h
+++ b/tinySAK/src/tsk_sha1.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -37,8 +37,7 @@ TSK_BEGIN_DECLS
/**@ingroup tsk_sha1_group
* SHA-1 error codes.
*/
-typedef enum tsk_sha1_errcode_e
-{
+typedef enum tsk_sha1_errcode_e {
shaSuccess = 0, /**< Success */
shaNull, /**< Null pointer parameter */
shaInputTooLong, /**< input data too long */
@@ -90,20 +89,19 @@ typedef uint8_t tsk_sha1digest_t[TSK_SHA1_DIGEST_SIZE]; /**< SHA-1 digest bytes.
* This structure will hold context information for the SHA-1
* hashing SSESSION
*/
-typedef struct tsk_sha1context_s
-{
+typedef struct tsk_sha1context_s {
uint32_t Intermediate_Hash[TSK_SHA1_DIGEST_SIZE/4]; /* Message Digest */
uint32_t Length_Low; /**< Message length in bits */
uint32_t Length_High; /**< Message length in bits */
-
+
int_least16_t Message_Block_Index;/**< Index into message block array */
uint8_t Message_Block[64]; /**< 512-bit message blocks */
int32_t Computed; /**< Is the digest computed? */
int32_t Corrupted; /**< Is the message digest corrupted? */
-}
+}
tsk_sha1context_t;
/*
diff --git a/tinySAK/src/tsk_string.c b/tinySAK/src/tsk_string.c
index 301eed3..2ee5c6d 100755
--- a/tinySAK/src/tsk_string.c
+++ b/tinySAK/src/tsk_string.c
@@ -58,23 +58,23 @@
*/
tsk_string_t* tsk_string_create(const char* str)
{
- return (tsk_string_t*)tsk_object_new(tsk_string_def_t, str);
+ return (tsk_string_t*)tsk_object_new(tsk_string_def_t, str);
}
int tsk_string_pred_icmp(const tsk_list_item_t* item, const void* str)
{
- if (item && str){
- return tsk_stricmp(TSK_STRING_STR(item->data), (const char*)str);
- }
- return -1;
+ if (item && str) {
+ return tsk_stricmp(TSK_STRING_STR(item->data), (const char*)str);
+ }
+ return -1;
}
int tsk_string_pred_cmp(const tsk_list_item_t* item, const void* str)
{
- if (item && str){
- return tsk_strcmp(TSK_STRING_STR(item->data), (const char*)str);
- }
- return -1;
+ if (item && str) {
+ return tsk_strcmp(TSK_STRING_STR(item->data), (const char*)str);
+ }
+ return -1;
}
/**@ingroup tsk_string_group
@@ -84,8 +84,8 @@ int tsk_string_pred_cmp(const tsk_list_item_t* item, const void* str)
*/
char tsk_b10tob16(char c)
{
- static char HEX[] = "0123456789abcdef";
- return HEX[c & 15];
+ static char HEX[] = "0123456789abcdef";
+ return HEX[c & 15];
}
/**@ingroup tsk_string_group
@@ -95,7 +95,7 @@ char tsk_b10tob16(char c)
*/
char tsk_b16tob10(char c)
{
- return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
+ return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
}
/**@ingroup tsk_string_group
@@ -112,10 +112,10 @@ char tsk_b16tob10(char c)
*/
int tsk_stricmp(const char * str1, const char * str2)
{
- return (str1 && str2) ?
- ((tolower(*str1) == tolower(*str2)) ? stricmp(str1, str2) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
- :
- ((!str1 && !str2) ? 0 : -1);
+ return (str1 && str2) ?
+ ((tolower(*str1) == tolower(*str2)) ? stricmp(str1, str2) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
+ :
+ ((!str1 && !str2) ? 0 : -1);
}
/**@ingroup tsk_string_group
@@ -133,20 +133,20 @@ int tsk_stricmp(const char * str1, const char * str2)
*/
int tsk_strnicmp(const char * str1, const char * str2, tsk_size_t n)
{
- return (str1 && str2 && n) ?
- ((tolower(*str1) == tolower(*str2)) ? strnicmp(str1, str2, n) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
- :
- ((!str1 && !str2) ? 0 : -1);
+ return (str1 && str2 && n) ?
+ ((tolower(*str1) == tolower(*str2)) ? strnicmp(str1, str2, n) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
+ :
+ ((!str1 && !str2) ? 0 : -1);
}
/**@ingroup tsk_string_group
*/
int tsk_strcmp(const char * str1, const char * str2)
{
- return (str1 && str2) ?
- ((*str1 == *str2) ? stricmp(str1, str2) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
- :
- ((!str1 && !str2) ? 0 : -1);
+ return (str1 && str2) ?
+ ((*str1 == *str2) ? stricmp(str1, str2) : (*str1 - *str2)) /* Compare first charaters before doing complete comparison */
+ :
+ ((!str1 && !str2) ? 0 : -1);
}
/**@ingroup tsk_string_group
@@ -164,7 +164,7 @@ int tsk_strcmp(const char * str1, const char * str2)
*/
int tsk_strncmp(const char * str1, const char * str2, tsk_size_t n)
{
- return (str1 && str2) ? ((*str1 != *str2) ? -1 : strncmp(str1, str2, n)) : ((!str1 && !str2) ? 0 : -1);
+ return (str1 && str2) ? ((*str1 != *str2) ? -1 : strncmp(str1, str2, n)) : ((!str1 && !str2) ? 0 : -1);
}
/**@ingroup tsk_string_group
@@ -174,10 +174,10 @@ int tsk_strncmp(const char * str1, const char * str2, tsk_size_t n)
*/
char* tsk_strdup(const char *s1)
{
- if (s1){
- return strdup(s1);
- }
- return tsk_null;
+ if (s1) {
+ return strdup(s1);
+ }
+ return tsk_null;
}
/** Duplicates the first @a n chars of @a s1.
@@ -187,18 +187,18 @@ char* tsk_strdup(const char *s1)
**/
char* tsk_strndup(const char *s1, tsk_size_t n)
{
- char *ret = tsk_null;
+ char *ret = tsk_null;
- if (s1 && n){
- tsk_size_t len = tsk_strlen(s1);
- tsk_size_t nret = (n > len) ? (len) : (n);
+ if (s1 && n) {
+ tsk_size_t len = tsk_strlen(s1);
+ tsk_size_t nret = (n > len) ? (len) : (n);
- if ((ret = (char*)tsk_calloc((nret + 1), sizeof(uint8_t)))){
- memcpy(ret, s1, nret);
- }
- }
+ if ((ret = (char*)tsk_calloc((nret + 1), sizeof(uint8_t)))) {
+ memcpy(ret, s1, nret);
+ }
+ }
- return ret;
+ return ret;
}
/**@ingroup tsk_string_group
@@ -210,7 +210,7 @@ char* tsk_strndup(const char *s1, tsk_size_t n)
*/
tsk_bool_t tsk_strcontains(const char * str, tsk_size_t size, const char * substring)
{
- return (tsk_strindexOf(str, size, substring) >= 0);
+ return (tsk_strindexOf(str, size, substring) >= 0);
}
/**@ingroup tsk_string_group
@@ -223,42 +223,42 @@ tsk_bool_t tsk_strcontains(const char * str, tsk_size_t size, const char * subst
*/
int tsk_strindexOf(const char * str, tsk_size_t size, const char * substring)
{
- if (str && substring){
- const char* sub_start = strstr(str, substring);
- if (sub_start && (sub_start < (str + size))) {
- int ret;
- tsk_subsat_int32_ptr(sub_start, str, &ret);
- return ret;
- }
- }
- return -1;
+ if (str && substring) {
+ const char* sub_start = strstr(str, substring);
+ if (sub_start && (sub_start < (str + size))) {
+ int ret;
+ tsk_subsat_int32_ptr(sub_start, str, &ret);
+ return ret;
+ }
+ }
+ return -1;
}
/**@ingroup tsk_string_group
*/
int tsk_strLastIndexOf(const char * str, tsk_size_t size, const char * substring)
{
- if (str && substring){
- tsk_size_t sub_size = tsk_strlen(substring);
- const char* last_sub_start = tsk_null;
- const char* sub_start = strstr(str, substring);
- const char* end = (str + size);
- while (sub_start && (sub_start < end)) {
- last_sub_start = sub_start;
- if ((sub_start + sub_size) < end){
- sub_start = strstr((sub_start + sub_size), substring);
- }
- else {
- break;
- }
- }
- if (last_sub_start) {
- int ret;
- tsk_subsat_int32_ptr(last_sub_start, str, &ret);
- return ret;
- }
- }
- return -1;
+ if (str && substring) {
+ tsk_size_t sub_size = tsk_strlen(substring);
+ const char* last_sub_start = tsk_null;
+ const char* sub_start = strstr(str, substring);
+ const char* end = (str + size);
+ while (sub_start && (sub_start < end)) {
+ last_sub_start = sub_start;
+ if ((sub_start + sub_size) < end) {
+ sub_start = strstr((sub_start + sub_size), substring);
+ }
+ else {
+ break;
+ }
+ }
+ if (last_sub_start) {
+ int ret;
+ tsk_subsat_int32_ptr(last_sub_start, str, &ret);
+ return ret;
+ }
+ }
+ return -1;
}
/**@ingroup tsk_string_group
@@ -270,49 +270,49 @@ int tsk_strLastIndexOf(const char * str, tsk_size_t size, const char * substring
*/
void tsk_strcat(char** destination, const char* source)
{
- tsk_strncat(destination, source, tsk_strlen(source));
+ tsk_strncat(destination, source, tsk_strlen(source));
}
/**@ingroup tsk_string_group
*/
void tsk_strcat_2(char** destination, const char* format, ...)
{
- char* temp = tsk_null;
- int len;
- va_list ap;
+ char* temp = tsk_null;
+ int len;
+ va_list ap;
- /* initialize variable arguments */
- va_start(ap, format);
- /* compute */
- if ((len = tsk_sprintf_2(&temp, format, &ap))){
- tsk_strncat(destination, temp, len);
- }
- /* reset variable arguments */
- va_end(ap);
- TSK_FREE(temp);
+ /* initialize variable arguments */
+ va_start(ap, format);
+ /* compute */
+ if ((len = tsk_sprintf_2(&temp, format, &ap))) {
+ tsk_strncat(destination, temp, len);
+ }
+ /* reset variable arguments */
+ va_end(ap);
+ TSK_FREE(temp);
}
/**@ingroup tsk_string_group
*/
void tsk_strncat(char** destination, const char* source, tsk_size_t n)
{
- tsk_size_t index = 0;
- tsk_size_t tsk_size_to_cat = (n > tsk_strlen(source)) ? tsk_strlen(source) : n;
+ tsk_size_t index = 0;
+ tsk_size_t tsk_size_to_cat = (n > tsk_strlen(source)) ? tsk_strlen(source) : n;
- if (!source || !n) {
- return;
- }
+ if (!source || !n) {
+ return;
+ }
- if (!*destination) {
- *destination = (char*)tsk_malloc(tsk_size_to_cat + 1);
- strncpy(*destination, source, tsk_size_to_cat + 1);
- }
- else {
- index = tsk_strlen(*destination);
- *destination = (char*)tsk_realloc(*destination, index + tsk_size_to_cat + 1);
- strncpy(((*destination) + index), source, tsk_size_to_cat + 1);
- }
- (*destination)[index + tsk_size_to_cat] = '\0';
+ if (!*destination) {
+ *destination = (char*)tsk_malloc(tsk_size_to_cat + 1);
+ strncpy(*destination, source, tsk_size_to_cat + 1);
+ }
+ else {
+ index = tsk_strlen(*destination);
+ *destination = (char*)tsk_realloc(*destination, index + tsk_size_to_cat + 1);
+ strncpy(((*destination) + index), source, tsk_size_to_cat + 1);
+ }
+ (*destination)[index + tsk_size_to_cat] = '\0';
}
/**@ingroup tsk_string_group
@@ -329,68 +329,68 @@ void tsk_strncat(char** destination, const char* source, tsk_size_t n)
*/
int tsk_sprintf(char** str, const char* format, ...)
{
- int len;
- va_list ap;
+ int len;
+ va_list ap;
- /* initialize variable arguments */
- va_start(ap, format);
- /* compute */
- len = tsk_sprintf_2(str, format, &ap);
- /* reset variable arguments */
- va_end(ap);
+ /* initialize variable arguments */
+ va_start(ap, format);
+ /* compute */
+ len = tsk_sprintf_2(str, format, &ap);
+ /* reset variable arguments */
+ va_end(ap);
- return len;
+ return len;
}
/**@ingroup tsk_string_group
*/
int tsk_sprintf_2(char** str, const char* format, va_list* ap)
{
- int len = 0;
- va_list ap2;
+ int len = 0;
+ va_list ap2;
- /* free previous value */
- if (*str){
- tsk_free((void**)str);
- }
+ /* free previous value */
+ if (*str) {
+ tsk_free((void**)str);
+ }
- /* needed for 64bit platforms where vsnprintf will change the va_list */
- tsk_va_copy(ap2, *ap);
+ /* needed for 64bit platforms where vsnprintf will change the va_list */
+ tsk_va_copy(ap2, *ap);
- /* compute destination len for windows mobile
- */
+ /* compute destination len for windows mobile
+ */
#if defined(_WIN32_WCE)
- {
- int n;
- len = (tsk_strlen(format) * 2);
- *str = (char*)tsk_calloc(1, len+1);
- for(;;){
- if( (n = vsnprintf(*str, len, format, *ap)) >= 0 && (n<len) ){
- len = n;
- goto done;
- }
- else{
- len += 10;
- *str = (char*)tsk_realloc(*str, len+1);
- }
- }
- done:
- (*str)[len] = '\0';
- }
+ {
+ int n;
+ len = (tsk_strlen(format) * 2);
+ *str = (char*)tsk_calloc(1, len+1);
+ for(;;) {
+ if( (n = vsnprintf(*str, len, format, *ap)) >= 0 && (n<len) ) {
+ len = n;
+ goto done;
+ }
+ else {
+ len += 10;
+ *str = (char*)tsk_realloc(*str, len+1);
+ }
+ }
+done:
+ (*str)[len] = '\0';
+ }
#else
- len = vsnprintf(0, 0, format, *ap);
- *str = (char*)tsk_calloc(1, len + 1);
- vsnprintf(*str, len
+ len = vsnprintf(0, 0, format, *ap);
+ *str = (char*)tsk_calloc(1, len + 1);
+ vsnprintf(*str, len
#if !defined(_MSC_VER) || defined(__GNUC__)
- +1
+ +1
#endif
- , format, ap2);
+ , format, ap2);
#endif
- va_end(ap2);
+ va_end(ap2);
- return len;
- }
+ return len;
+}
/**@ingroup tsk_string_group
* Updates the value of @a str.
@@ -399,17 +399,17 @@ int tsk_sprintf_2(char** str, const char* format, va_list* ap)
*/
void tsk_strupdate(char** str, const char* newval)
{
- if (str && *str != newval){ // do nothing if same memory address
- // use realloc() to keep same memory address
- tsk_size_t length = tsk_strlen(newval);
- if (!length) {
- tsk_free((void**)str);
- }
- else if ((*str = (char*)tsk_realloc(*str, length + 1))){
- memcpy(*str, newval, length);
- (*str)[length] = '\0';
- }
- }
+ if (str && *str != newval) { // do nothing if same memory address
+ // use realloc() to keep same memory address
+ tsk_size_t length = tsk_strlen(newval);
+ if (!length) {
+ tsk_free((void**)str);
+ }
+ else if ((*str = (char*)tsk_realloc(*str, length + 1))) {
+ memcpy(*str, newval, length);
+ (*str)[length] = '\0';
+ }
+ }
}
@@ -419,15 +419,17 @@ void tsk_strupdate(char** str, const char* newval)
*/
void tsk_strtrim_left(char **str)
{
- if (str && *str) {
- tsk_size_t count = 0;
- while (isspace(*((*str) + count))) count++;
- if (count) {
- tsk_size_t len = tsk_strlen((*str));
- memmove((*str), (*str) + count, (len - count));
- (*str)[len - count] = '\0';
- }
- }
+ if (str && *str) {
+ tsk_size_t count = 0;
+ while (isspace(*((*str) + count))) {
+ count++;
+ }
+ if (count) {
+ tsk_size_t len = tsk_strlen((*str));
+ memmove((*str), (*str) + count, (len - count));
+ (*str)[len - count] = '\0';
+ }
+ }
}
/**@ingroup tsk_string_group
@@ -436,13 +438,15 @@ void tsk_strtrim_left(char **str)
*/
void tsk_strtrim_right(char **str)
{
- if (str && *str){
- tsk_size_t size;
- if ((size = tsk_strlen(*str))){
- while (isspace(*((*str) + size - 1))) size--;
- *(*str + size) = '\0';
- }
- }
+ if (str && *str) {
+ tsk_size_t size;
+ if ((size = tsk_strlen(*str))) {
+ while (isspace(*((*str) + size - 1))) {
+ size--;
+ }
+ *(*str + size) = '\0';
+ }
+ }
}
/**@ingroup tsk_string_group
* Removes all occurrences of white space characters from the beginning and end of @a str.
@@ -450,10 +454,10 @@ void tsk_strtrim_right(char **str)
*/
void tsk_strtrim(char **str)
{
- // left
- tsk_strtrim_left(str);
- // right
- tsk_strtrim_right(str);
+ // left
+ tsk_strtrim_left(str);
+ // right
+ tsk_strtrim_right(str);
}
/**@ingroup tsk_string_group
@@ -463,7 +467,7 @@ void tsk_strtrim(char **str)
*/
void tsk_strquote(char **str)
{
- tsk_strquote_2(str, '"', '"');
+ tsk_strquote_2(str, '"', '"');
}
/**@ingroup tsk_string_group
@@ -474,12 +478,12 @@ void tsk_strquote(char **str)
*/
void tsk_strquote_2(char **str, char lquote, char rquote)
{
- if (str && *str){
- char *result = tsk_null;
- tsk_sprintf(&result, "%c%s%c", lquote, *str, rquote);
- tsk_free((void**)str);
- *str = result;
- }
+ if (str && *str) {
+ char *result = tsk_null;
+ tsk_sprintf(&result, "%c%s%c", lquote, *str, rquote);
+ tsk_free((void**)str);
+ *str = result;
+ }
}
/**@ingroup tsk_string_group
@@ -489,7 +493,7 @@ void tsk_strquote_2(char **str, char lquote, char rquote)
*/
void tsk_strunquote(char **str)
{
- tsk_strunquote_2(str, '"', '"');
+ tsk_strunquote_2(str, '"', '"');
}
/**@ingroup tsk_string_group
@@ -501,13 +505,13 @@ void tsk_strunquote(char **str)
*/
void tsk_strunquote_2(char **str, char lquote, char rquote)
{
- if (str && *str) {
- tsk_size_t size = tsk_strlen(*str);
- if (size >= 2 && **str == lquote && *((*str) + size - 1) == rquote){
- memmove((*str), (*str) + 1, (size - 2));
- *((*str) + size - 2) = '\0';
- }
- }
+ if (str && *str) {
+ tsk_size_t size = tsk_strlen(*str);
+ if (size >= 2 && **str == lquote && *((*str) + size - 1) == rquote) {
+ memmove((*str), (*str) + 1, (size - 2));
+ *((*str) + size - 2) = '\0';
+ }
+ }
}
/**@ingroup tsk_string_group
@@ -517,36 +521,36 @@ void tsk_strunquote_2(char **str, char lquote, char rquote)
*/
void tsk_itoa(int64_t i, tsk_istr_t *result)
{
- memset(result, 0, sizeof(*result));
- sprintf(*result, "%lld", i);
+ memset(result, 0, sizeof(*result));
+ sprintf(*result, "%lld", i);
}
/**@ingroup tsk_string_group
*/
int64_t tsk_atoll(const char* str)
{
- // FIXME: use HAVE_ATOLL and use macro instead of function
- if (str){
+ // FIXME: use HAVE_ATOLL and use macro instead of function
+ if (str) {
#if defined(_MSC_VER)
- return _atoi64(str);
+ return _atoi64(str);
#elif defined(__GNUC__)
- return atoll(str);
+ return atoll(str);
#else
- return atol(str);
+ return atol(str);
#endif
- }
- return 0;
+ }
+ return 0;
}
/**@ingroup tsk_string_group
*/
long tsk_atox(const char* str)
{
- long ret = 0;
- if (str){
- sscanf(str, "%lx", &ret);
- }
- return ret;
+ long ret = 0;
+ if (str) {
+ sscanf(str, "%lx", &ret);
+ }
+ return ret;
}
/**@ingroup tsk_string_group
@@ -556,8 +560,8 @@ long tsk_atox(const char* str)
**/
void tsk_strrandom(tsk_istr_t *result)
{
- static uint64_t __counter = 1;
- tsk_itoa((tsk_time_now() ^ (rand())) ^ ++__counter, result);
+ static uint64_t __counter = 1;
+ tsk_itoa((tsk_time_now() ^ (rand())) ^ ++__counter, result);
}
/**@ingroup tsk_string_group
@@ -572,13 +576,13 @@ void tsk_strrandom(tsk_istr_t *result)
**/
void tsk_str_from_hex(const uint8_t *hex, tsk_size_t size, char* str)
{
- static const char *TSK_HEXA_VALUES = { "0123456789abcdef" };
- tsk_size_t i;
+ static const char *TSK_HEXA_VALUES = { "0123456789abcdef" };
+ tsk_size_t i;
- for (i = 0; i < size; i++){
- str[2 * i] = TSK_HEXA_VALUES[(*(hex + i) & 0xf0) >> 4];
- str[(2 * i) + 1] = TSK_HEXA_VALUES[(*(hex + i) & 0x0f)];
- }
+ for (i = 0; i < size; i++) {
+ str[2 * i] = TSK_HEXA_VALUES[(*(hex + i) & 0xf0) >> 4];
+ str[(2 * i) + 1] = TSK_HEXA_VALUES[(*(hex + i) & 0x0f)];
+ }
}
/**@ingroup tsk_string_group
@@ -590,8 +594,8 @@ void tsk_str_from_hex(const uint8_t *hex, tsk_size_t size, char* str)
**/
void tsk_str_to_hex(const char *str, tsk_size_t size, uint8_t* hex)
{
- // to avoid SIGBUS error when memory is misaligned do not use sscanf("%2x")
- TSK_DEBUG_FATAL("Not implemented.");
+ // to avoid SIGBUS error when memory is misaligned do not use sscanf("%2x")
+ TSK_DEBUG_FATAL("Not implemented.");
}
@@ -600,36 +604,30 @@ void tsk_str_to_hex(const char *str, tsk_size_t size, uint8_t* hex)
TINYSAK_API std::vector<char> rt_tsk_str_to_native(Platform::String^ str)
{
- if(str != nullptr && !str->IsEmpty())
- {
- int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str->Data(), str->Length(), nullptr, 0, nullptr, nullptr);
- if (len > 0)
- {
- std::vector<char> vec(len + 1);
- if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str->Data(), str->Length(), vec.data(), len, nullptr, nullptr) == len)
- {
- return std::move(vec);
- }
- }
- }
- return std::move(std::vector<char>(0));
+ if(str != nullptr && !str->IsEmpty()) {
+ int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str->Data(), str->Length(), nullptr, 0, nullptr, nullptr);
+ if (len > 0) {
+ std::vector<char> vec(len + 1);
+ if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str->Data(), str->Length(), vec.data(), len, nullptr, nullptr) == len) {
+ return std::move(vec);
+ }
+ }
+ }
+ return std::move(std::vector<char>(0));
}
TINYSAK_API Platform::String^ rt_tsk_str_to_managed(char const* str)
{
- if(str)
- {
- int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, nullptr, 0);
- if (len > 0)
- {
- std::vector<wchar_t> vec(len);
- if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, vec.data(), len) == len)
- {
- return ref new Platform::String(vec.data());
- }
- }
- }
- return nullptr;
+ if(str) {
+ int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, nullptr, 0);
+ if (len > 0) {
+ std::vector<wchar_t> vec(len);
+ if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, vec.data(), len) == len) {
+ return ref new Platform::String(vec.data());
+ }
+ }
+ }
+ return nullptr;
}
#endif /* TSK_UNDER_WINDOWS_RT */
@@ -644,42 +642,45 @@ TINYSAK_API Platform::String^ rt_tsk_str_to_managed(char const* str)
//
static tsk_object_t* tsk_string_ctor(tsk_object_t * self, va_list * app)
{
- tsk_string_t *string = (tsk_string_t*)self;
- const char *value = va_arg(*app, const char *);
- if (value){
- string->value = tsk_strdup(value);
- }
- return self;
+ tsk_string_t *string = (tsk_string_t*)self;
+ const char *value = va_arg(*app, const char *);
+ if (value) {
+ string->value = tsk_strdup(value);
+ }
+ return self;
}
static tsk_object_t* tsk_string_dtor(tsk_object_t * self)
{
- tsk_string_t *string = (tsk_string_t*)self;
- if (string){
- TSK_FREE(string->value);
- }
+ tsk_string_t *string = (tsk_string_t*)self;
+ if (string) {
+ TSK_FREE(string->value);
+ }
- return self;
+ return self;
}
static int tsk_string_cmp(const tsk_object_t *_s1, const tsk_object_t *_s2)
{
- const tsk_string_t *s1 = (const tsk_string_t *)_s1;
- const tsk_string_t *s2 = (const tsk_string_t *)_s2;
-
- if (s1 && s2){
- return tsk_stricmp(s1->value, s2->value);
- }
- else if (!s1 && !s2) return 0;
- else return -1;
-}
-
-static const tsk_object_def_t tsk_string_def_s =
-{
- sizeof(tsk_string_t),
- tsk_string_ctor,
- tsk_string_dtor,
- tsk_string_cmp,
+ const tsk_string_t *s1 = (const tsk_string_t *)_s1;
+ const tsk_string_t *s2 = (const tsk_string_t *)_s2;
+
+ if (s1 && s2) {
+ return tsk_stricmp(s1->value, s2->value);
+ }
+ else if (!s1 && !s2) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+static const tsk_object_def_t tsk_string_def_s = {
+ sizeof(tsk_string_t),
+ tsk_string_ctor,
+ tsk_string_dtor,
+ tsk_string_cmp,
};
const tsk_object_def_t *tsk_string_def_t = &tsk_string_def_s;
diff --git a/tinySAK/src/tsk_string.h b/tinySAK/src/tsk_string.h
index b941012..e3d7749 100755
--- a/tinySAK/src/tsk_string.h
+++ b/tinySAK/src/tsk_string.h
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2010-2015 Mamadou DIOP.
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -31,7 +31,7 @@
/**@ingroup tsk_string_group
* @def TSK_STRING_STR
-* Gets the internal string pointer.
+* Gets the internal string pointer.
*/
TSK_BEGIN_DECLS
@@ -114,11 +114,10 @@ TINYSAK_API void tsk_str_to_hex(const char *str, tsk_size_t size, uint8_t* hex);
/**@ingroup tsk_string_group
* String object.
*/
-typedef struct tsk_string_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_string_s {
+ TSK_DECLARE_OBJECT;
- char *value; /**< The value of the string object. */
+ char *value; /**< The value of the string object. */
}
tsk_string_t;
diff --git a/tinySAK/src/tsk_thread.c b/tinySAK/src/tsk_thread.c
index ff2e2c0..5538d42 100755
--- a/tinySAK/src/tsk_thread.c
+++ b/tinySAK/src/tsk_thread.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -36,7 +36,7 @@
#endif
#if TSK_UNDER_WINDOWS_RT
# include "../winrt/ThreadEmulation.h"
- using namespace ThreadEmulation;
+using namespace ThreadEmulation;
#endif
#include <string.h>
@@ -49,31 +49,31 @@
void tsk_thread_sleep(uint64_t ms)
{
#if TSK_UNDER_WINDOWS
- Sleep((DWORD)ms);
+ Sleep((DWORD)ms);
#else
- struct timespec interval;
+ struct timespec interval;
- interval.tv_sec = (long)(ms/1000);
- interval.tv_nsec = (long)(ms%1000) * 1000000;
- nanosleep(&interval, 0);
-#endif
+ interval.tv_sec = (long)(ms/1000);
+ interval.tv_nsec = (long)(ms%1000) * 1000000;
+ nanosleep(&interval, 0);
+#endif
}
/**@ingroup tsk_thread_group
* Creates a new thread.
* @param handle Handle id of the newly created thread. The returned handle should be destroyed using @ref tsk_thread_join()
-* @param start The function to be run as the new thread's start routine
-* @param arg An address for the argument for the thread's start routine
+* @param start The function to be run as the new thread's start routine
+* @param arg An address for the argument for the thread's start routine
* @retval If successful, returns zero. Otherwise, an error number is returned to indicate the error
*/
int tsk_thread_create(tsk_thread_handle_t** handle, void *(TSK_STDCALL *start) (void *), void *arg)
{
#if TSK_UNDER_WINDOWS
- *((HANDLE*)handle) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start, arg, 0, NULL);
- return *((HANDLE*)handle) ? 0 : -1;
+ *((HANDLE*)handle) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start, arg, 0, NULL);
+ return *((HANDLE*)handle) ? 0 : -1;
#else
- *handle = tsk_calloc(1, sizeof(pthread_t));
- return pthread_create((pthread_t*)*handle, 0, start, arg);
+ *handle = tsk_calloc(1, sizeof(pthread_t));
+ return pthread_create((pthread_t*)*handle, 0, start, arg);
#endif
}
@@ -81,25 +81,25 @@ int tsk_thread_create(tsk_thread_handle_t** handle, void *(TSK_STDCALL *start) (
*/
int tsk_thread_set_priority(tsk_thread_handle_t* handle, int32_t priority)
{
- if(!handle){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
+ if(!handle) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
#if TSK_UNDER_WINDOWS
- {
- int ret = SetThreadPriority(handle, priority) ? 0 : -1;
+ {
+ int ret = SetThreadPriority(handle, priority) ? 0 : -1;
#if TSK_UNDER_WINDOWS_RT
- // It's not possible to set priority on WP8 when thread is not in suspended state -> do nothing and don't bother us
- if(ret){
- TSK_DEBUG_INFO("SetThreadPriority() failed but nothing to worry about");
- ret = 0;
- }
+ // It's not possible to set priority on WP8 when thread is not in suspended state -> do nothing and don't bother us
+ if(ret) {
+ TSK_DEBUG_INFO("SetThreadPriority() failed but nothing to worry about");
+ ret = 0;
+ }
#endif
- return ret;
- }
+ return ret;
+ }
#else
- struct sched_param sp;
- int ret;
+ struct sched_param sp;
+ int ret;
memset(&sp, 0, sizeof(struct sched_param));
sp.sched_priority = priority;
if ((ret = pthread_setschedparam(*((pthread_t*)handle), SCHED_OTHER, &sp))) {
@@ -115,82 +115,82 @@ int tsk_thread_set_priority(tsk_thread_handle_t* handle, int32_t priority)
int tsk_thread_set_priority_2(int32_t priority)
{
#if TSK_UNDER_WINDOWS
- TSK_DEBUG_ERROR("Not implemented");
- return -1;
+ TSK_DEBUG_ERROR("Not implemented");
+ return -1;
#else
- pthread_t thread = pthread_self();
- return tsk_thread_set_priority(&thread, priority);
+ pthread_t thread = pthread_self();
+ return tsk_thread_set_priority(&thread, priority);
#endif
}
tsk_thread_id_t tsk_thread_get_id()
{
#if TSK_UNDER_WINDOWS
- return GetCurrentThreadId();
+ return GetCurrentThreadId();
#else
- return pthread_self();
+ return pthread_self();
#endif
}
tsk_bool_t tsk_thread_id_equals(tsk_thread_id_t* id_1, tsk_thread_id_t *id_2)
{
- if(!id_1 || !id_2){
- TSK_DEBUG_ERROR("Invalid parameter");
- return tsk_false;
- }
+ if(!id_1 || !id_2) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_false;
+ }
#if TSK_UNDER_WINDOWS
- return (*id_1 == *id_2);
+ return (*id_1 == *id_2);
#else
- return (pthread_equal(*id_1, *id_2) != 0);
+ return (pthread_equal(*id_1, *id_2) != 0);
#endif
}
/**@ingroup tsk_thread_group
* Join a thread.
* @param handle Pthread handle to the target thread.
-* @retval If successful, returns zero. Otherwise, an error number is returned to indicate the error.
+* @retval If successful, returns zero. Otherwise, an error number is returned to indicate the error.
*/
int tsk_thread_join(tsk_thread_handle_t** handle)
{
- int ret;
-
- if(!handle){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- if(!*handle){
- TSK_DEBUG_WARN("Cannot join NULL handle");
- return 0;
- }
-
+ int ret;
+
+ if(!handle) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ if(!*handle) {
+ TSK_DEBUG_WARN("Cannot join NULL handle");
+ return 0;
+ }
+
#if TSK_UNDER_WINDOWS
# if TSK_UNDER_WINDOWS_RT
- ret = (WaitForSingleObjectEx(*((HANDLE*)handle), INFINITE, TRUE) == WAIT_FAILED) ? -1 : 0;
+ ret = (WaitForSingleObjectEx(*((HANDLE*)handle), INFINITE, TRUE) == WAIT_FAILED) ? -1 : 0;
# else
- ret = (WaitForSingleObject(*((HANDLE*)handle), INFINITE) == WAIT_FAILED) ? -1 : 0;
+ ret = (WaitForSingleObject(*((HANDLE*)handle), INFINITE) == WAIT_FAILED) ? -1 : 0;
#endif
- if(ret == 0){
- ret = tsk_thread_destroy(handle);
- }
+ if(ret == 0) {
+ ret = tsk_thread_destroy(handle);
+ }
#else
- if((ret = pthread_join(*((pthread_t*)*handle), 0)) == 0){
- ret = tsk_thread_destroy(handle);
- }
+ if((ret = pthread_join(*((pthread_t*)*handle), 0)) == 0) {
+ ret = tsk_thread_destroy(handle);
+ }
#endif
- return ret;
+ return ret;
}
int tsk_thread_destroy(tsk_thread_handle_t** handle)
{
- if(handle && *handle){
+ if(handle && *handle) {
#if TSK_UNDER_WINDOWS
- CloseHandle(*((HANDLE*)handle));
- *handle = tsk_null;
+ CloseHandle(*((HANDLE*)handle));
+ *handle = tsk_null;
#else
- tsk_free(handle);
+ tsk_free(handle);
#endif
- }
- return 0;
+ }
+ return 0;
}
diff --git a/tinySAK/src/tsk_thread.h b/tinySAK/src/tsk_thread.h
index ebab601..e5d1361 100755
--- a/tinySAK/src/tsk_thread.h
+++ b/tinySAK/src/tsk_thread.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -34,7 +34,7 @@
typedef void tsk_thread_handle_t;
#if TSK_UNDER_WINDOWS
- typedef unsigned long tsk_thread_id_t;
+typedef unsigned long tsk_thread_id_t;
# define TSK_THREAD_PRIORITY_LOW THREAD_PRIORITY_LOWEST
# define TSK_THREAD_PRIORITY_MEDIUM THREAD_PRIORITY_NORMAL
# define TSK_THREAD_PRIORITY_HIGH THREAD_PRIORITY_HIGHEST
@@ -42,7 +42,7 @@ typedef void tsk_thread_handle_t;
#else
# include <pthread.h>
# include <sched.h>
- typedef pthread_t tsk_thread_id_t;
+typedef pthread_t tsk_thread_id_t;
# define TSK_THREAD_PRIORITY_LOW sched_get_priority_min(SCHED_OTHER)
# define TSK_THREAD_PRIORITY_TIME_CRITICAL sched_get_priority_max(SCHED_OTHER)
# define TSK_THREAD_PRIORITY_MEDIUM ((TSK_THREAD_PRIORITY_TIME_CRITICAL - TSK_THREAD_PRIORITY_LOW) >> 1)
diff --git a/tinySAK/src/tsk_time.c b/tinySAK/src/tsk_time.c
index 0f93df8..5202c29 100755
--- a/tinySAK/src/tsk_time.c
+++ b/tinySAK/src/tsk_time.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -38,7 +38,7 @@
# include <sys/time.h>
# endif
#elif defined(__SYMBIAN32__)
-# include <_timeval.h>
+# include <_timeval.h>
#else
# include <sys/time.h>
#endif
@@ -63,55 +63,53 @@
#endif
#if TSK_UNDER_WINDOWS_CE
-#endif
+#endif
-struct timezone
-{
- int tz_minuteswest; // minutes W of Greenwich
- int tz_dsttime; // type of dst correction
+struct timezone {
+ int tz_minuteswest; // minutes W of Greenwich
+ int tz_dsttime; // type of dst correction
};
-static int gettimeofday(struct timeval *tv, struct timezone *tz)
-{
- FILETIME ft;
- uint64_t tmpres = 0;
- static int tzflag = 0;
+static int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ uint64_t tmpres = 0;
+ static int tzflag = 0;
- if(tv)
- {
+ if(tv) {
#if TSK_UNDER_WINDOWS_CE
- SYSTEMTIME st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &ft);
#else
- GetSystemTimeAsFileTime(&ft);
+ GetSystemTimeAsFileTime(&ft);
#endif /* TSK_UNDER_WINDOWS_CE */
- tmpres |= ft.dwHighDateTime;
- tmpres <<= 32;
- tmpres |= ft.dwLowDateTime;
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
- /*converting file time to unix epoch*/
- tmpres /= 10; /*convert into microseconds*/
- tmpres -= DELTA_EPOCH_IN_MICROSECS;
- tv->tv_sec = (long)(tmpres / 1000000UL);
- tv->tv_usec = (long)(tmpres % 1000000UL);
- }
+ /*converting file time to unix epoch*/
+ tmpres /= 10; /*convert into microseconds*/
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
#if !TSK_UNDER_WINDOWS_CE
- if (tz){
- if (!tzflag){
+ if (tz) {
+ if (!tzflag) {
#if !TSK_UNDER_WINDOWS_RT
- _tzset();
+ _tzset();
#endif /* TSK_UNDER_WINDOWS_RT */
- tzflag++;
- }
- tz->tz_minuteswest = _timezone / 60;
- tz->tz_dsttime = _daylight;
- }
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
#endif /* TSK_UNDER_WINDOWS_CE */
- return 0;
+ return 0;
}
#else
@@ -121,7 +119,7 @@ static int gettimeofday(struct timeval *tv, struct timezone *tz)
#endif /* !HAVE_GETTIMEOFDAY */
/**@ingroup tsk_time_group
-* The tsk_gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since EPOCH (00:00:00 UTC on 1 January 1970).
+* The tsk_gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since EPOCH (00:00:00 UTC on 1 January 1970).
* The resolution of the system clock is unspecified.
* @param tv The current time, expressed as seconds and microseconds since EPOCH(00:00:00 UTC on 1 January 1970).
* @param tz The timezone.
@@ -129,16 +127,16 @@ static int gettimeofday(struct timeval *tv, struct timezone *tz)
*/
int tsk_gettimeofday(struct timeval *tv, struct timezone *tz)
{
- return gettimeofday(tv, tz);
+ return gettimeofday(tv, tz);
}
/**@ingroup tsk_time_group
*/
uint64_t tsk_gettimeofday_ms()
{
- struct timeval tv;
- tsk_gettimeofday(&tv, tsk_null);
- return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
+ struct timeval tv;
+ tsk_gettimeofday(&tv, tsk_null);
+ return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
}
/**@ingroup tsk_time_group
@@ -147,11 +145,11 @@ uint64_t tsk_gettimeofday_ms()
*/
uint64_t tsk_time_get_ms(const struct timeval* tv)
{
- if(!tv){
- TSK_DEBUG_ERROR("Invalid parameter");
- return 0;
- }
- return (((uint64_t)tv->tv_sec)*(uint64_t)1000) + (((uint64_t)tv->tv_usec)/(uint64_t)1000);
+ if(!tv) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return 0;
+ }
+ return (((uint64_t)tv->tv_sec)*(uint64_t)1000) + (((uint64_t)tv->tv_usec)/(uint64_t)1000);
}
/**@ingroup tsk_time_group
@@ -160,9 +158,9 @@ uint64_t tsk_time_get_ms(const struct timeval* tv)
*/
uint64_t tsk_time_epoch()
{
- struct timeval tv;
- gettimeofday(&tv, (struct timezone *)tsk_null);
- return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
+ struct timeval tv;
+ gettimeofday(&tv, (struct timezone *)tsk_null);
+ return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
}
// /!\ NOT CURRENT TIME
@@ -170,36 +168,36 @@ uint64_t tsk_time_epoch()
uint64_t tsk_time_now()
{
#if TSK_UNDER_WINDOWS
- static int __cpu_count = 0;
- if(__cpu_count == 0){
- SYSTEM_INFO SystemInfo;
+ static int __cpu_count = 0;
+ if(__cpu_count == 0) {
+ SYSTEM_INFO SystemInfo;
# if TSK_UNDER_WINDOWS_RT
- GetNativeSystemInfo(&SystemInfo);
+ GetNativeSystemInfo(&SystemInfo);
# else
- GetSystemInfo(&SystemInfo);
+ GetSystemInfo(&SystemInfo);
# endif
- __cpu_count = SystemInfo.dwNumberOfProcessors;
- }
- if(__cpu_count == 1){
- static LARGE_INTEGER __liFrequency = {0};
- LARGE_INTEGER liPerformanceCount;
- if(!__liFrequency.QuadPart){
- QueryPerformanceFrequency(&__liFrequency);
- }
- QueryPerformanceCounter(&liPerformanceCount);
- return (uint64_t)(((double)liPerformanceCount.QuadPart/(double)__liFrequency.QuadPart)*1000.0);
- }
- else{
+ __cpu_count = SystemInfo.dwNumberOfProcessors;
+ }
+ if(__cpu_count == 1) {
+ static LARGE_INTEGER __liFrequency = {0};
+ LARGE_INTEGER liPerformanceCount;
+ if(!__liFrequency.QuadPart) {
+ QueryPerformanceFrequency(&__liFrequency);
+ }
+ QueryPerformanceCounter(&liPerformanceCount);
+ return (uint64_t)(((double)liPerformanceCount.QuadPart/(double)__liFrequency.QuadPart)*1000.0);
+ }
+ else {
# if TSK_UNDER_WINDOWS_RT
- return tsk_time_epoch();
+ return tsk_time_epoch();
# else
- return timeGetTime();
+ return timeGetTime();
# endif
- }
+ }
#elif HAVE_CLOCK_GETTIME || _POSIX_TIMERS > 0
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- return (((uint64_t)ts.tv_sec)*(uint64_t)1000) + (((uint64_t)ts.tv_nsec)/(uint64_t)1000000);
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (((uint64_t)ts.tv_sec)*(uint64_t)1000) + (((uint64_t)ts.tv_nsec)/(uint64_t)1000000);
#elif defined(__APPLE__)
static mach_timebase_info_data_t __apple_timebase_info = {0, 0};
if (__apple_timebase_info.denom == 0) {
@@ -207,39 +205,39 @@ uint64_t tsk_time_now()
}
return (uint64_t)((mach_absolute_time() * __apple_timebase_info.numer) / (1e+6 * __apple_timebase_info.denom));
#else
- struct timeval tv;
- gettimeofday(&tv, tsk_null);
- return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
+ struct timeval tv;
+ gettimeofday(&tv, tsk_null);
+ return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
#endif
}
// http://en.wikipedia.org/wiki/Network_Time_Protocol
uint64_t tsk_time_ntp()
{
- struct timeval tv;
- gettimeofday(&tv, (struct timezone *)tsk_null);
- return tsk_time_get_ntp_ms(&tv);
+ struct timeval tv;
+ gettimeofday(&tv, (struct timezone *)tsk_null);
+ return tsk_time_get_ntp_ms(&tv);
}
uint64_t tsk_time_get_ntp_ms(const struct timeval *tv)
{
- static const unsigned long __epoch = 2208988800UL;
- static const double __ntp_scale_frac = 4294967295.0;
+ static const unsigned long __epoch = 2208988800UL;
+ static const double __ntp_scale_frac = 4294967295.0;
- uint64_t tv_ntp;
- uint64_t tv_usecs;
+ uint64_t tv_ntp;
+ uint64_t tv_usecs;
- if(!tv){
- TSK_DEBUG_ERROR("Invalid parameter");
- return 0;
- }
+ if(!tv) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return 0;
+ }
- tv_ntp = tv->tv_sec + __epoch;
+ tv_ntp = tv->tv_sec + __epoch;
#if 0 // ARM floating point calc issue (__aeabi_d2uiz)
- tv_usecs = (tv->tv_usec * 1e-6) * __ntp_scale_frac;
- return ((tv_ntp << 32) | (uint32_t)tv_usecs);
+ tv_usecs = (tv->tv_usec * 1e-6) * __ntp_scale_frac;
+ return ((tv_ntp << 32) | (uint32_t)tv_usecs);
#else
- tv_usecs = ((uint64_t)tv->tv_usec * (uint64_t)__ntp_scale_frac) / (uint64_t)1000000;
- return ((((uint64_t)tv_ntp) << 32) | (uint32_t)tv_usecs);
+ tv_usecs = ((uint64_t)tv->tv_usec * (uint64_t)__ntp_scale_frac) / (uint64_t)1000000;
+ return ((((uint64_t)tv_ntp) << 32) | (uint32_t)tv_usecs);
#endif
} \ No newline at end of file
diff --git a/tinySAK/src/tsk_time.h b/tinySAK/src/tsk_time.h
index 512d59e..9a1f051 100755
--- a/tinySAK/src/tsk_time.h
+++ b/tinySAK/src/tsk_time.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_timer.c b/tinySAK/src/tsk_timer.c
index f449675..fbdb989 100755
--- a/tinySAK/src/tsk_timer.c
+++ b/tinySAK/src/tsk_timer.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -52,16 +52,15 @@
* @struct tsk_timer_s
* @brief Timer.
**/
-typedef struct tsk_timer_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_timer_s {
+ TSK_DECLARE_OBJECT;
- tsk_timer_id_t id; /**< Unique timer identifier. */
- const void *arg; /**< Opaque data to return with the callback function. */
- uint64_t timeout; /**< When the timer will timeout(as EPOCH time). */
- tsk_timer_callback_f callback; /**< The callback function to call after @ref timeout milliseconds. */
+ tsk_timer_id_t id; /**< Unique timer identifier. */
+ const void *arg; /**< Opaque data to return with the callback function. */
+ uint64_t timeout; /**< When the timer will timeout(as EPOCH time). */
+ tsk_timer_callback_f callback; /**< The callback function to call after @ref timeout milliseconds. */
- unsigned canceled:1;
+ unsigned canceled:1;
}
tsk_timer_t;
typedef tsk_list_t tsk_timers_L_t; /**< List of @ref tsk_timer_t elements. */
@@ -71,22 +70,21 @@ typedef tsk_list_t tsk_timers_L_t; /**< List of @ref tsk_timer_t elements. */
*
* @brief Timer manager.
**/
-typedef struct tsk_timer_manager_s
-{
- TSK_DECLARE_RUNNABLE;
+typedef struct tsk_timer_manager_s {
+ TSK_DECLARE_RUNNABLE;
- void* mainThreadId[1];
- tsk_condwait_handle_t *condwait;
- tsk_mutex_handle_t *mutex;
- tsk_semaphore_handle_t *sem;
+ void* mainThreadId[1];
+ tsk_condwait_handle_t *condwait;
+ tsk_mutex_handle_t *mutex;
+ tsk_semaphore_handle_t *sem;
- tsk_timers_L_t *timers;
+ tsk_timers_L_t *timers;
}
tsk_timer_manager_t;
typedef tsk_list_t tsk_timer_manager_L_t; /**< List of @ref tsk_timer_manager_t elements. */
/*== Definitions */
-static void* TSK_STDCALL __tsk_timer_manager_mainthread(void *param);
+static void* TSK_STDCALL __tsk_timer_manager_mainthread(void *param);
static int __tsk_pred_find_timer_by_id(const tsk_list_item_t *item, const void *id);
static void __tsk_timer_manager_raise(tsk_timer_t *timer);
static void* TSK_STDCALL run(void* self);
@@ -95,7 +93,7 @@ static void* TSK_STDCALL run(void* self);
*/
tsk_timer_manager_handle_t* tsk_timer_manager_create()
{
- return tsk_object_new(tsk_timer_manager_def_t);
+ return tsk_object_new(tsk_timer_manager_def_t);
}
/**@ingroup tsk_timer_group
@@ -103,33 +101,33 @@ tsk_timer_manager_handle_t* tsk_timer_manager_create()
*/
int tsk_timer_manager_start(tsk_timer_manager_handle_t *self)
{
- int err = -1;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
-
- TSK_DEBUG_INFO("tsk_timer_manager_start");
-
- if(!manager){
- return -1;
- }
-
- tsk_mutex_lock(manager->mutex);
-
- if(!TSK_RUNNABLE(manager)->running && !TSK_RUNNABLE(manager)->started){
- TSK_RUNNABLE(manager)->run = run;
- if((err = tsk_runnable_start(TSK_RUNNABLE(manager), tsk_timer_def_t))){
- //TSK_OBJECT_SAFE_FREE(manager);
- goto bail;
- }
- }
- else{
- TSK_DEBUG_INFO("Timer manager already running");
- err = 0;
- }
+ int err = -1;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+
+ TSK_DEBUG_INFO("tsk_timer_manager_start");
+
+ if(!manager) {
+ return -1;
+ }
+
+ tsk_mutex_lock(manager->mutex);
+
+ if(!TSK_RUNNABLE(manager)->running && !TSK_RUNNABLE(manager)->started) {
+ TSK_RUNNABLE(manager)->run = run;
+ if((err = tsk_runnable_start(TSK_RUNNABLE(manager), tsk_timer_def_t))) {
+ //TSK_OBJECT_SAFE_FREE(manager);
+ goto bail;
+ }
+ }
+ else {
+ TSK_DEBUG_INFO("Timer manager already running");
+ err = 0;
+ }
bail:
- tsk_mutex_unlock(manager->mutex);
+ tsk_mutex_unlock(manager->mutex);
- return err;
+ return err;
}
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
@@ -137,20 +135,20 @@ bail:
*/
void tsk_timer_manager_debug(tsk_timer_manager_handle_t *self)
{
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
- if(manager){
- //int index = 0;
- tsk_list_item_t *item = tsk_null;
-
- tsk_mutex_lock(manager->mutex);
-
- tsk_list_foreach(item, manager->timers){
- tsk_timer_t* timer = (tsk_timer_t*)item->data;
- TSK_DEBUG_INFO("timer [%llu]- %llu, %llu", timer->id, timer->timeout, tsk_time_now());
- }
-
- tsk_mutex_unlock(manager->mutex);
- }
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+ if(manager) {
+ //int index = 0;
+ tsk_list_item_t *item = tsk_null;
+
+ tsk_mutex_lock(manager->mutex);
+
+ tsk_list_foreach(item, manager->timers) {
+ tsk_timer_t* timer = (tsk_timer_t*)item->data;
+ TSK_DEBUG_INFO("timer [%llu]- %llu, %llu", timer->id, timer->timeout, tsk_time_now());
+ }
+
+ tsk_mutex_unlock(manager->mutex);
+ }
}
#endif
@@ -158,203 +156,203 @@ void tsk_timer_manager_debug(tsk_timer_manager_handle_t *self)
*/
int tsk_timer_manager_stop(tsk_timer_manager_handle_t *self)
{
- int ret = -1;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
-
- if(!manager){
- TSK_DEBUG_ERROR("Invalid paramater");
- return -1;
- }
-
- // all functions called below are thread-safe ==> do not lock
- // "mainthread" uses manager->mutex and runs in a separate thread ==> deadlock
-
- if(TSK_RUNNABLE(manager)->running){
- if((ret = tsk_runnable_stop(TSK_RUNNABLE(manager)))){
- goto bail;
- }
-
- tsk_semaphore_increment(manager->sem);
- tsk_condwait_signal(manager->condwait);
-
- ret = tsk_thread_join(manager->mainThreadId);
- goto bail;
- }
- else{
- ret = 0; /* already running. */
- goto bail;
- }
+ int ret = -1;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+
+ if(!manager) {
+ TSK_DEBUG_ERROR("Invalid paramater");
+ return -1;
+ }
+
+ // all functions called below are thread-safe ==> do not lock
+ // "mainthread" uses manager->mutex and runs in a separate thread ==> deadlock
+
+ if(TSK_RUNNABLE(manager)->running) {
+ if((ret = tsk_runnable_stop(TSK_RUNNABLE(manager)))) {
+ goto bail;
+ }
+
+ tsk_semaphore_increment(manager->sem);
+ tsk_condwait_signal(manager->condwait);
+
+ ret = tsk_thread_join(manager->mainThreadId);
+ goto bail;
+ }
+ else {
+ ret = 0; /* already running. */
+ goto bail;
+ }
bail:
- tsk_list_clear_items(manager->timers);
- return ret;
+ tsk_list_clear_items(manager->timers);
+ return ret;
}
/**@ingroup tsk_timer_group
*/
tsk_timer_id_t tsk_timer_manager_schedule(tsk_timer_manager_handle_t *self, uint64_t timeout, tsk_timer_callback_f callback, const void *arg)
{
- tsk_timer_id_t timer_id = TSK_INVALID_TIMER_ID;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+ tsk_timer_id_t timer_id = TSK_INVALID_TIMER_ID;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
- if(manager && (TSK_RUNNABLE(manager)->running || TSK_RUNNABLE(manager)->started)){
- tsk_timer_t *timer;
+ if(manager && (TSK_RUNNABLE(manager)->running || TSK_RUNNABLE(manager)->started)) {
+ tsk_timer_t *timer;
- timer = (tsk_timer_t*)TSK_TIMER_CREATE(timeout, callback, arg);
- timer_id = timer->id;
- tsk_mutex_lock(manager->mutex);
- tsk_list_push_ascending_data(manager->timers, ((void**) &timer));
- tsk_mutex_unlock(manager->mutex);
-
- // tsk_timer_manager_debug(self);
+ timer = (tsk_timer_t*)TSK_TIMER_CREATE(timeout, callback, arg);
+ timer_id = timer->id;
+ tsk_mutex_lock(manager->mutex);
+ tsk_list_push_ascending_data(manager->timers, ((void**) &timer));
+ tsk_mutex_unlock(manager->mutex);
- tsk_condwait_signal(manager->condwait);
- tsk_semaphore_increment(manager->sem);
- }
+ // tsk_timer_manager_debug(self);
+
+ tsk_condwait_signal(manager->condwait);
+ tsk_semaphore_increment(manager->sem);
+ }
- return timer_id;
+ return timer_id;
}
/**@ingroup tsk_timer_group
*/
int tsk_timer_manager_cancel(tsk_timer_manager_handle_t *self, tsk_timer_id_t id)
{
- int ret = -1;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
-
- /* Check validity. */
- if(!TSK_TIMER_ID_IS_VALID(id)){ /* Very common. */
- return 0;
- }
-
- if(!TSK_LIST_IS_EMPTY(manager->timers) && TSK_RUNNABLE(manager)->running){
- const tsk_list_item_t *item;
- tsk_mutex_lock(manager->mutex);
- item = tsk_list_find_item_by_pred(manager->timers, __tsk_pred_find_timer_by_id, &id);
- if(item && item->data){
- tsk_timer_t *timer = (tsk_timer_t*)item->data;
- timer->canceled = 1;
- timer->callback = tsk_null;
-
- if(item == manager->timers->head){
- /* The timer we are waiting on ? ==> remove it now. */
- tsk_condwait_signal(manager->condwait);
- }
-
- ret = 0;
- }
- tsk_mutex_unlock(manager->mutex);
- }
- return ret;
+ int ret = -1;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+
+ /* Check validity. */
+ if(!TSK_TIMER_ID_IS_VALID(id)) { /* Very common. */
+ return 0;
+ }
+
+ if(!TSK_LIST_IS_EMPTY(manager->timers) && TSK_RUNNABLE(manager)->running) {
+ const tsk_list_item_t *item;
+ tsk_mutex_lock(manager->mutex);
+ item = tsk_list_find_item_by_pred(manager->timers, __tsk_pred_find_timer_by_id, &id);
+ if(item && item->data) {
+ tsk_timer_t *timer = (tsk_timer_t*)item->data;
+ timer->canceled = 1;
+ timer->callback = tsk_null;
+
+ if(item == manager->timers->head) {
+ /* The timer we are waiting on ? ==> remove it now. */
+ tsk_condwait_signal(manager->condwait);
+ }
+
+ ret = 0;
+ }
+ tsk_mutex_unlock(manager->mutex);
+ }
+ return ret;
}
int tsk_timer_manager_destroy(tsk_timer_manager_handle_t **self)
{
- if(!self || !*self){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- TSK_OBJECT_SAFE_FREE(*self);
- return 0;
+ if(!self || !*self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ TSK_OBJECT_SAFE_FREE(*self);
+ return 0;
}
static void* TSK_STDCALL run(void* self)
{
- int ret;
- tsk_list_item_t *curr;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+ int ret;
+ tsk_list_item_t *curr;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
- TSK_RUNNABLE(manager)->running = tsk_true; // VERY IMPORTANT --> needed by the main thread
+ TSK_RUNNABLE(manager)->running = tsk_true; // VERY IMPORTANT --> needed by the main thread
- /* create main thread */
- if((ret = tsk_thread_create(&(manager->mainThreadId[0]), __tsk_timer_manager_mainthread, manager))){
- TSK_DEBUG_FATAL("Failed to create mainthread: %d\n", ret);
- return tsk_null;
- }
+ /* create main thread */
+ if((ret = tsk_thread_create(&(manager->mainThreadId[0]), __tsk_timer_manager_mainthread, manager))) {
+ TSK_DEBUG_FATAL("Failed to create mainthread: %d\n", ret);
+ return tsk_null;
+ }
- TSK_DEBUG_INFO("Timer manager run()::enter");
+ TSK_DEBUG_INFO("Timer manager run()::enter");
- TSK_RUNNABLE_RUN_BEGIN(manager);
+ TSK_RUNNABLE_RUN_BEGIN(manager);
- if((curr = TSK_RUNNABLE_POP_FIRST_SAFE(TSK_RUNNABLE(manager)))){
- tsk_timer_t *timer = (tsk_timer_t *)curr->data;
- if(timer->callback){
- timer->callback(timer->arg, timer->id);
- }
- tsk_object_unref(curr);
- }
+ if((curr = TSK_RUNNABLE_POP_FIRST_SAFE(TSK_RUNNABLE(manager)))) {
+ tsk_timer_t *timer = (tsk_timer_t *)curr->data;
+ if(timer->callback) {
+ timer->callback(timer->arg, timer->id);
+ }
+ tsk_object_unref(curr);
+ }
- TSK_RUNNABLE_RUN_END(manager);
+ TSK_RUNNABLE_RUN_END(manager);
- TSK_DEBUG_INFO("Timer manager run()::exit");
+ TSK_DEBUG_INFO("Timer manager run()::exit");
- return tsk_null;
+ return tsk_null;
}
static int __tsk_pred_find_timer_by_id(const tsk_list_item_t *item, const void *id)
{
- tsk_timer_t *timer;
- if(item && item->data){
- timer = (tsk_timer_t*)item->data;
- return (int)(timer->id - *((tsk_timer_id_t*)id));
- }
- return -1;
+ tsk_timer_t *timer;
+ if(item && item->data) {
+ timer = (tsk_timer_t*)item->data;
+ return (int)(timer->id - *((tsk_timer_id_t*)id));
+ }
+ return -1;
}
static void* TSK_STDCALL __tsk_timer_manager_mainthread(void *param)
{
- int ret;
- tsk_timer_t *curr;
- uint64_t now;
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)param;
+ int ret;
+ tsk_timer_t *curr;
+ uint64_t now;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)param;
- TSK_DEBUG_INFO("TIMER MANAGER -- START");
+ TSK_DEBUG_INFO("TIMER MANAGER -- START");
- while(TSK_RUNNABLE(manager)->running){
- tsk_semaphore_decrement(manager->sem);
+ while(TSK_RUNNABLE(manager)->running) {
+ tsk_semaphore_decrement(manager->sem);
peek_first:
- if(!TSK_RUNNABLE(manager)->running){
- break;
- }
-
- tsk_mutex_lock(manager->mutex);
- curr = TSK_TIMER_GET_FIRST();
- tsk_mutex_unlock(manager->mutex);
-
- if (curr && !curr->canceled) {
- now = tsk_time_now();
- if (now >= curr->timeout) {
- tsk_timer_t *timer = (tsk_timer_t*)tsk_object_ref(curr);
- //TSK_DEBUG_INFO("Timer raise %llu", timer->id);
-
- tsk_mutex_lock(manager->mutex); // must lock() before enqueue()
- TSK_RUNNABLE_ENQUEUE_OBJECT_SAFE(TSK_RUNNABLE(manager), timer);
- tsk_list_remove_item_by_data(manager->timers, curr);
- tsk_mutex_unlock(manager->mutex);
- TSK_OBJECT_SAFE_FREE(timer);
- }
- else{
- if((ret = tsk_condwait_timedwait(manager->condwait, (curr->timeout - now)))){
- TSK_DEBUG_ERROR("CONWAIT for timer manager failed [%d]", ret);
- break;
- }
- else{
- goto peek_first;
- }
- }
- }
- else if(curr) {
- tsk_mutex_lock(manager->mutex);
- /* TSK_DEBUG_INFO("Timer canceled %llu", curr->id); */
- tsk_list_remove_item_by_data(manager->timers, curr);
- tsk_mutex_unlock(manager->mutex);
- }
- } /* while() */
-
- TSK_DEBUG_INFO("TIMER MANAGER -- STOP");
-
- return tsk_null;
+ if(!TSK_RUNNABLE(manager)->running) {
+ break;
+ }
+
+ tsk_mutex_lock(manager->mutex);
+ curr = TSK_TIMER_GET_FIRST();
+ tsk_mutex_unlock(manager->mutex);
+
+ if (curr && !curr->canceled) {
+ now = tsk_time_now();
+ if (now >= curr->timeout) {
+ tsk_timer_t *timer = (tsk_timer_t*)tsk_object_ref(curr);
+ //TSK_DEBUG_INFO("Timer raise %llu", timer->id);
+
+ tsk_mutex_lock(manager->mutex); // must lock() before enqueue()
+ TSK_RUNNABLE_ENQUEUE_OBJECT_SAFE(TSK_RUNNABLE(manager), timer);
+ tsk_list_remove_item_by_data(manager->timers, curr);
+ tsk_mutex_unlock(manager->mutex);
+ TSK_OBJECT_SAFE_FREE(timer);
+ }
+ else {
+ if((ret = tsk_condwait_timedwait(manager->condwait, (curr->timeout - now)))) {
+ TSK_DEBUG_ERROR("CONWAIT for timer manager failed [%d]", ret);
+ break;
+ }
+ else {
+ goto peek_first;
+ }
+ }
+ }
+ else if(curr) {
+ tsk_mutex_lock(manager->mutex);
+ /* TSK_DEBUG_INFO("Timer canceled %llu", curr->id); */
+ tsk_list_remove_item_by_data(manager->timers, curr);
+ tsk_mutex_unlock(manager->mutex);
+ }
+ } /* while() */
+
+ TSK_DEBUG_INFO("TIMER MANAGER -- STOP");
+
+ return tsk_null;
}
@@ -367,26 +365,26 @@ static tsk_timer_manager_t* __timer_mgr = tsk_null;
tsk_timer_manager_handle_t* tsk_timer_mgr_global_ref()
{
- if(!__timer_mgr){
- __timer_mgr = (tsk_timer_manager_t*)tsk_timer_manager_create();
- }
- else{
- __timer_mgr = (tsk_timer_manager_t*)tsk_object_ref(__timer_mgr);
- }
- return __timer_mgr;
+ if(!__timer_mgr) {
+ __timer_mgr = (tsk_timer_manager_t*)tsk_timer_manager_create();
+ }
+ else {
+ __timer_mgr = (tsk_timer_manager_t*)tsk_object_ref(__timer_mgr);
+ }
+ return __timer_mgr;
}
int tsk_timer_mgr_global_start()
{
int ret = 0;
- if(!__timer_mgr){
- TSK_DEBUG_ERROR("No global Timer manager could be found");
- return -1;
+ if(!__timer_mgr) {
+ TSK_DEBUG_ERROR("No global Timer manager could be found");
+ return -1;
}
- if(!TSK_RUNNABLE(__timer_mgr)->running && !TSK_RUNNABLE(__timer_mgr)->started){
- if((ret = tsk_timer_manager_start(__timer_mgr))){
- return ret;
- }
+ if(!TSK_RUNNABLE(__timer_mgr)->running && !TSK_RUNNABLE(__timer_mgr)->started) {
+ if((ret = tsk_timer_manager_start(__timer_mgr))) {
+ return ret;
+ }
}
tsk_mutex_lock(__timer_mgr->mutex);
tsk_mutex_unlock(__timer_mgr->mutex);
@@ -395,34 +393,34 @@ int tsk_timer_mgr_global_start()
tsk_timer_id_t tsk_timer_mgr_global_schedule(uint64_t timeout, tsk_timer_callback_f callback, const void *arg)
{
- if(!__timer_mgr){
- TSK_DEBUG_ERROR("No global Timer manager could be found");
- return TSK_INVALID_TIMER_ID;
+ if(!__timer_mgr) {
+ TSK_DEBUG_ERROR("No global Timer manager could be found");
+ return TSK_INVALID_TIMER_ID;
}
return tsk_timer_manager_schedule(__timer_mgr, timeout, callback, arg);
}
int tsk_timer_mgr_global_cancel(tsk_timer_id_t id)
{
- if(!__timer_mgr){
- TSK_DEBUG_ERROR("No global Timer manager could be found");
- return -1;
+ if(!__timer_mgr) {
+ TSK_DEBUG_ERROR("No global Timer manager could be found");
+ return -1;
}
return tsk_timer_manager_cancel(__timer_mgr, id);
}
int tsk_timer_mgr_global_unref(tsk_timer_manager_handle_t** mgr_global)
{
- if(!mgr_global || !*mgr_global){
- return 0;
- }
- if((*mgr_global != __timer_mgr)){
- TSK_DEBUG_ERROR("Invalid parameter");
- return -1;
- }
- __timer_mgr = (tsk_timer_manager_t*)tsk_object_unref(TSK_OBJECT(*mgr_global));
- *mgr_global = tsk_null;
- return 0;
+ if(!mgr_global || !*mgr_global) {
+ return 0;
+ }
+ if((*mgr_global != __timer_mgr)) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ __timer_mgr = (tsk_timer_manager_t*)tsk_object_unref(TSK_OBJECT(*mgr_global));
+ *mgr_global = tsk_null;
+ return 0;
}
@@ -436,38 +434,37 @@ int tsk_timer_mgr_global_unref(tsk_timer_manager_handle_t** mgr_global)
//
static tsk_object_t* tsk_timer_manager_ctor(tsk_object_t * self, va_list * app)
{
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
- if(manager){
- manager->timers = tsk_list_create();
- manager->sem = tsk_semaphore_create();
- manager->condwait = tsk_condwait_create();
- manager->mutex = tsk_mutex_create();
- }
- return self;
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+ if(manager) {
+ manager->timers = tsk_list_create();
+ manager->sem = tsk_semaphore_create();
+ manager->condwait = tsk_condwait_create();
+ manager->mutex = tsk_mutex_create();
+ }
+ return self;
}
static tsk_object_t* tsk_timer_manager_dtor(tsk_object_t * self)
-{
- tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
-
- if(manager){
- tsk_timer_manager_stop(manager);
-
- tsk_semaphore_destroy(&manager->sem);
- tsk_condwait_destroy(&manager->condwait);
- tsk_mutex_destroy(&manager->mutex);
- TSK_OBJECT_SAFE_FREE(manager->timers);
- }
-
- return self;
+{
+ tsk_timer_manager_t *manager = (tsk_timer_manager_t*)self;
+
+ if(manager) {
+ tsk_timer_manager_stop(manager);
+
+ tsk_semaphore_destroy(&manager->sem);
+ tsk_condwait_destroy(&manager->condwait);
+ tsk_mutex_destroy(&manager->mutex);
+ TSK_OBJECT_SAFE_FREE(manager->timers);
+ }
+
+ return self;
}
-static const tsk_object_def_t tsk_timer_manager_def_s =
-{
- sizeof(tsk_timer_manager_t),
- tsk_timer_manager_ctor,
- tsk_timer_manager_dtor,
- tsk_null,
+static const tsk_object_def_t tsk_timer_manager_def_s = {
+ sizeof(tsk_timer_manager_t),
+ tsk_timer_manager_ctor,
+ tsk_timer_manager_dtor,
+ tsk_null,
};
const tsk_object_def_t * tsk_timer_manager_def_t = &tsk_timer_manager_def_s;
@@ -481,47 +478,50 @@ const tsk_object_def_t * tsk_timer_manager_def_t = &tsk_timer_manager_def_s;
//
static tsk_object_t* tsk_timer_ctor(tsk_object_t * self, va_list * app)
{
- static volatile tsk_timer_id_t __tsk_unique_timer_id = 0;
- tsk_timer_t *timer = (tsk_timer_t*)self;
- if(timer){
- tsk_atomic_inc(&__tsk_unique_timer_id);
- timer->id = __tsk_unique_timer_id;
- timer->timeout = va_arg(*app, uint64_t);
- timer->callback = va_arg(*app, tsk_timer_callback_f);
- timer->arg = va_arg(*app, const void *);
-
- timer->timeout += tsk_time_now();
- }
- return self;
+ static volatile tsk_timer_id_t __tsk_unique_timer_id = 0;
+ tsk_timer_t *timer = (tsk_timer_t*)self;
+ if(timer) {
+ tsk_atomic_inc(&__tsk_unique_timer_id);
+ timer->id = __tsk_unique_timer_id;
+ timer->timeout = va_arg(*app, uint64_t);
+ timer->callback = va_arg(*app, tsk_timer_callback_f);
+ timer->arg = va_arg(*app, const void *);
+
+ timer->timeout += tsk_time_now();
+ }
+ return self;
}
static tsk_object_t* tsk_timer_dtor(tsk_object_t * self)
-{
- tsk_timer_t *timer = (tsk_timer_t*)self;
- if(timer){
- }
+{
+ tsk_timer_t *timer = (tsk_timer_t*)self;
+ if(timer) {
+ }
- return self;
+ return self;
}
static int tsk_timer_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2)
{
- const tsk_timer_t *t1 = (const tsk_timer_t *)obj1;
- const tsk_timer_t *t2 = (const tsk_timer_t *)obj2;
-
- if(t1 && t2){
- return (int)(t1->timeout - t2->timeout);
- }
- else if(!t1 && !t2) return 0;
- else return -1;
+ const tsk_timer_t *t1 = (const tsk_timer_t *)obj1;
+ const tsk_timer_t *t2 = (const tsk_timer_t *)obj2;
+
+ if(t1 && t2) {
+ return (int)(t1->timeout - t2->timeout);
+ }
+ else if(!t1 && !t2) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
-static const tsk_object_def_t tsk_timer_def_s =
-{
- sizeof(tsk_timer_t),
- tsk_timer_ctor,
- tsk_timer_dtor,
- tsk_timer_cmp,
+static const tsk_object_def_t tsk_timer_def_s = {
+ sizeof(tsk_timer_t),
+ tsk_timer_ctor,
+ tsk_timer_dtor,
+ tsk_timer_cmp,
};
const tsk_object_def_t * tsk_timer_def_t = &tsk_timer_def_s;
diff --git a/tinySAK/src/tsk_timer.h b/tinySAK/src/tsk_timer.h
index fe05d98..e79933f 100755
--- a/tinySAK/src/tsk_timer.h
+++ b/tinySAK/src/tsk_timer.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_url.c b/tinySAK/src/tsk_url.c
index 8734ab6..cf4417b 100755
--- a/tinySAK/src/tsk_url.c
+++ b/tinySAK/src/tsk_url.c
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2010-2015 Mamadou DIOP.
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -41,22 +41,23 @@
* @sa tsk_url_decode
*
*/
-char* tsk_url_encode(const char* url) {
- char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) * 3 + 1), *pbuf = buf;
- while (*purl) {
- if (isalnum(*purl) || *purl == '-' || *purl == '_' || *purl == '.' || *purl == '~'){
- *pbuf++ = *purl;
- }
- else if (*purl == ' '){
- *pbuf++ = '+';
- }
- else{
- *pbuf++ = '%', *pbuf++ = tsk_b10tob16(*purl >> 4), *pbuf++ = tsk_b10tob16(*purl & 15);
- }
- purl++;
- }
- *pbuf = '\0';
- return buf;
+char* tsk_url_encode(const char* url)
+{
+ char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) * 3 + 1), *pbuf = buf;
+ while (*purl) {
+ if (isalnum(*purl) || *purl == '-' || *purl == '_' || *purl == '.' || *purl == '~') {
+ *pbuf++ = *purl;
+ }
+ else if (*purl == ' ') {
+ *pbuf++ = '+';
+ }
+ else {
+ *pbuf++ = '%', *pbuf++ = tsk_b10tob16(*purl >> 4), *pbuf++ = tsk_b10tob16(*purl & 15);
+ }
+ purl++;
+ }
+ *pbuf = '\0';
+ return buf;
}
/**@ingroup tsk_url_group
@@ -66,24 +67,25 @@ char* tsk_url_encode(const char* url) {
*
* @sa tsk_url_encode
*/
-char* tsk_url_decode(const char* url) {
- char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) + 1), *pbuf = buf;
- while (*purl) {
- if (*purl == '%') {
- if (purl[1] && purl[2]) {
- *pbuf++ = tsk_b16tob10(purl[1]) << 4 | tsk_b16tob10(purl[2]);
- purl += 2;
- }
- }
- else if (*purl == '+') {
- *pbuf++ = ' ';
- }
- else {
- *pbuf++ = *purl;
- }
- purl++;
- }
- *pbuf = '\0';
- return buf;
+char* tsk_url_decode(const char* url)
+{
+ char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) + 1), *pbuf = buf;
+ while (*purl) {
+ if (*purl == '%') {
+ if (purl[1] && purl[2]) {
+ *pbuf++ = tsk_b16tob10(purl[1]) << 4 | tsk_b16tob10(purl[2]);
+ purl += 2;
+ }
+ }
+ else if (*purl == '+') {
+ *pbuf++ = ' ';
+ }
+ else {
+ *pbuf++ = *purl;
+ }
+ purl++;
+ }
+ *pbuf = '\0';
+ return buf;
}
diff --git a/tinySAK/src/tsk_url.h b/tinySAK/src/tsk_url.h
index 7071613..3b88d77 100755
--- a/tinySAK/src/tsk_url.h
+++ b/tinySAK/src/tsk_url.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_uuid.c b/tinySAK/src/tsk_uuid.c
index 61fbe0c..fa5a8f1 100755
--- a/tinySAK/src/tsk_uuid.c
+++ b/tinySAK/src/tsk_uuid.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -44,49 +44,49 @@
*/
int tsk_uuidgenerate(tsk_uuidstring_t *result)
{
- /* From wikipedia
- * Version 5 UUIDs use a scheme with SHA-1 hashing, otherwise it is the same idea as in version 3.
- * RFC 4122 states that version 5 is preferred over version 3 name based UUIDs.
- * Note that the 160 bit SHA-1 hash is truncated to 128 bits to make the length work out.
- */
- tsk_sha1string_t sha1result;
- tsk_istr_t now;
- unsigned i, k;
- static char HEX[] = "0123456789abcdef";
+ /* From wikipedia
+ * Version 5 UUIDs use a scheme with SHA-1 hashing, otherwise it is the same idea as in version 3.
+ * RFC 4122 states that version 5 is preferred over version 3 name based UUIDs.
+ * Note that the 160 bit SHA-1 hash is truncated to 128 bits to make the length work out.
+ */
+ tsk_sha1string_t sha1result;
+ tsk_istr_t now;
+ unsigned i, k;
+ static char HEX[] = "0123456789abcdef";
- tsk_itoa(tsk_time_now(), &now);
- tsk_sha1compute(now, sizeof(now), &sha1result);
+ tsk_itoa(tsk_time_now(), &now);
+ tsk_sha1compute(now, sizeof(now), &sha1result);
- /* XOR the SHA-1 result with random numbers. */
- for(i=0; i<(TSK_UUID_DIGEST_SIZE*2); i+=4){
+ /* XOR the SHA-1 result with random numbers. */
+ for(i=0; i<(TSK_UUID_DIGEST_SIZE*2); i+=4) {
#if 0
- *((uint32_t*)&sha1result[i]) ^= rand();
+ *((uint32_t*)&sha1result[i]) ^= rand();
#else
- k = rand();
- sha1result[i] ^= k, sha1result[i + 1] ^= k,
- sha1result[i + 2] ^= k, sha1result[i + 3] ^= k;
+ k = rand();
+ sha1result[i] ^= k, sha1result[i + 1] ^= k,
+ sha1result[i + 2] ^= k, sha1result[i + 3] ^= k;
#endif
-
- for(k=0; k<sizeof(uint32_t); k++){
- sha1result[i+k] = HEX[sha1result[i+k] & 0x0F]; /* To hexa. */
- }
- }
- /* f47ac10b-58cc-4372-a567-0e02b2c3d479 */
- memcpy(&(*result)[0], &sha1result[0], 8);
- (*result)[8] = '-';
+ for(k=0; k<sizeof(uint32_t); k++) {
+ sha1result[i+k] = HEX[sha1result[i+k] & 0x0F]; /* To hexa. */
+ }
+ }
+
+ /* f47ac10b-58cc-4372-a567-0e02b2c3d479 */
+ memcpy(&(*result)[0], &sha1result[0], 8);
+ (*result)[8] = '-';
- memcpy(&(*result)[9], &sha1result[8], 4);
- (*result)[13] = '-';
+ memcpy(&(*result)[9], &sha1result[8], 4);
+ (*result)[13] = '-';
- memcpy(&(*result)[14], &sha1result[12], 4);
- (*result)[18] = '-';
+ memcpy(&(*result)[14], &sha1result[12], 4);
+ (*result)[18] = '-';
- memcpy(&(*result)[19], &sha1result[16], 4);
- (*result)[23] = '-';
+ memcpy(&(*result)[19], &sha1result[16], 4);
+ (*result)[23] = '-';
- memcpy(&(*result)[24], &sha1result[20], 12);
- (*result)[36] = '\0';
+ memcpy(&(*result)[24], &sha1result[20], 12);
+ (*result)[36] = '\0';
- return 0;
+ return 0;
}
diff --git a/tinySAK/src/tsk_uuid.h b/tinySAK/src/tsk_uuid.h
index 3ec300e..a196826 100755
--- a/tinySAK/src/tsk_uuid.h
+++ b/tinySAK/src/tsk_uuid.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
diff --git a/tinySAK/src/tsk_xml.c b/tinySAK/src/tsk_xml.c
index 2e581da..40089bb 100755
--- a/tinySAK/src/tsk_xml.c
+++ b/tinySAK/src/tsk_xml.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -80,13 +80,13 @@
*/
void tsk_xml_element_init_set(tsk_xml_element_t** element, const char* name, const char* value, tsk_xml_type_t type)
{
- TSK_XML_ELEMENT_CREATE((*element));
- (*element)->elements = TSK_LIST_CREATE();
- (*element)->attributes = TSK_LIST_CREATE();
- (*element)->namespaces = TSK_LIST_CREATE();
- (*element)->name = tsk_strdup(name);
- (*element)->value = tsk_strdup(value);
- (*element)->type = type;
+ TSK_XML_ELEMENT_CREATE((*element));
+ (*element)->elements = TSK_LIST_CREATE();
+ (*element)->attributes = TSK_LIST_CREATE();
+ (*element)->namespaces = TSK_LIST_CREATE();
+ (*element)->name = tsk_strdup(name);
+ (*element)->value = tsk_strdup(value);
+ (*element)->type = type;
}
/**@ingroup tsk_xml_group
@@ -135,14 +135,17 @@ void tsk_xml_element_init_set(tsk_xml_element_t** element, const char* name, con
*/
xmlNsPtr tsk_xml_get_namespace(xmlDocPtr docPtr, xmlNodePtr node, const char *href)
{
- xmlNs *ns = *xmlGetNsList(docPtr, node);
- while (ns)
- {
- if (tsk_striequals(ns->href, href)) return ns;
- else ns = ns->next;
- }
-
- return 0;
+ xmlNs *ns = *xmlGetNsList(docPtr, node);
+ while (ns) {
+ if (tsk_striequals(ns->href, href)) {
+ return ns;
+ }
+ else {
+ ns = ns->next;
+ }
+ }
+
+ return 0;
}
/**@ingroup tsk_xml_group
@@ -154,29 +157,37 @@ xmlNsPtr tsk_xml_get_namespace(xmlDocPtr docPtr, xmlNodePtr node, const char *hr
*/
xmlNodePtr tsk_xml_find_node(const xmlNodePtr curr, const char* name, tsk_xml_node_find_type_t ftype)
{
- xmlNodePtr node = curr;
-
- while(node)
- {
- switch(ftype)
- {
- case nft_none: return (tsk_striequals(node->name, name))? node : 0;
- case nft_children: node = node->children; break;
- case nft_parent: node = node->parent; break;
- case nft_next: node = node->next; break;
- case nft_prev: node = node->prev; break;
- default: return 0;
- } /* switch */
-
- /* check and return value if match */
- if( node && (!name || tsk_striequals(node->name, name)) )
- //if( node && (name == 0 || !tsk_stricmp((const char*)node->name, name)) )
- {
- return node;
- }
- }
-
- return 0;
+ xmlNodePtr node = curr;
+
+ while(node) {
+ switch(ftype) {
+ case nft_none:
+ return (tsk_striequals(node->name, name))? node : 0;
+ case nft_children:
+ node = node->children;
+ break;
+ case nft_parent:
+ node = node->parent;
+ break;
+ case nft_next:
+ node = node->next;
+ break;
+ case nft_prev:
+ node = node->prev;
+ break;
+ default:
+ return 0;
+ } /* switch */
+
+ /* check and return value if match */
+ if( node && (!name || tsk_striequals(node->name, name)) )
+ //if( node && (name == 0 || !tsk_stricmp((const char*)node->name, name)) )
+ {
+ return node;
+ }
+ }
+
+ return 0;
}
/**@ingroup tsk_xml_group
@@ -185,111 +196,114 @@ xmlNodePtr tsk_xml_find_node(const xmlNodePtr curr, const char* name, tsk_xml_no
*/
xmlNodePtr tsk_xml_select_node(const xmlNodePtr root, ...)
{
- va_list list;
- int step;
- char* root_name = 0;
- xmlNodePtr node = root;
-
- if(!node || !(node->name)) return 0;
-
- /* initialize variable arguments */
- va_start(list, root);
-
- while( node && (step=va_arg(list, tsk_xml_node_select_type_t)) != nst_end)
- {
- switch(step)
- {
- case nst_by_name:
- { /* name */
- const char* qname = va_arg(list, const char*);
- if(tsk_striequals(root->name, qname)){
- node = tsk_xml_find_node(node, 0, nft_children);
- }
- else{
- if(!tsk_striequals(node->name, qname))
- { /* do not match */
- node = tsk_xml_find_node(node, qname, nft_next);
- }
- else
- { /* already match */
- node = node->children;
- }
- }
- break;
- }
-
- case nst_content:
- { /**/
- node = tsk_xml_find_node(node, 0, nft_children);
- break;
- }
-
- case nst_att_value:
- { /* qname, att_name */
- xmlAttrPtr attrPtr = 0;
- int found = 0;
- const char* qname = va_arg(list, const char*);
- const char* att_name = va_arg(list, const char*);
- node = tsk_xml_find_node(node, qname, nft_none);
- while( node && !found )
- {
- attrPtr = node->properties;
- while(attrPtr)
- {
- if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children)
- {
- if( tsk_striequals(attrPtr->name, att_name) ){
- node = attrPtr->children;
- found = 1;
- }
- }
- attrPtr = attrPtr->next;
- }
- if(!found) node = tsk_xml_find_node(node, 0, nft_next);
- }
- break;
- }
-
- case nst_by_att:
- { /* qname att_name att_value */
- xmlAttrPtr attrPtr = 0;
- int found = 0;
- const char* qname = va_arg(list, const char*);
- const char* att_name = va_arg(list, const char*);
- const char* att_value = va_arg(list, const char*);
- node = tsk_xml_find_node(node, qname, nft_none);
- while( node && !found )
- {
- attrPtr = node->properties;
- while(attrPtr)
- {
- if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children)
- {
- if( tsk_striequals(attrPtr->name, att_name)
- && ( (attrPtr->children->content && tsk_striequals(attrPtr->children->content, att_value)) || !att_value )
- ){
- found = 1;
- }
- }
- attrPtr = attrPtr->next;
- }
- if(!found) node = tsk_xml_find_node(node, 0, nft_next);
- }
-
- if(found && node) break;
- else return 0;
-
- break;
- }
- default: return 0;
- } /* switch */
-
- /* skip all comments */
- TSK_XML_NODE_SKIP_COMMENTS(node);
-
- } /* while*/
-
- return node;
+ va_list list;
+ int step;
+ char* root_name = 0;
+ xmlNodePtr node = root;
+
+ if(!node || !(node->name)) {
+ return 0;
+ }
+
+ /* initialize variable arguments */
+ va_start(list, root);
+
+ while( node && (step=va_arg(list, tsk_xml_node_select_type_t)) != nst_end) {
+ switch(step) {
+ case nst_by_name: {
+ /* name */
+ const char* qname = va_arg(list, const char*);
+ if(tsk_striequals(root->name, qname)) {
+ node = tsk_xml_find_node(node, 0, nft_children);
+ }
+ else {
+ if(!tsk_striequals(node->name, qname)) {
+ /* do not match */
+ node = tsk_xml_find_node(node, qname, nft_next);
+ }
+ else {
+ /* already match */
+ node = node->children;
+ }
+ }
+ break;
+ }
+
+ case nst_content: {
+ /**/
+ node = tsk_xml_find_node(node, 0, nft_children);
+ break;
+ }
+
+ case nst_att_value: {
+ /* qname, att_name */
+ xmlAttrPtr attrPtr = 0;
+ int found = 0;
+ const char* qname = va_arg(list, const char*);
+ const char* att_name = va_arg(list, const char*);
+ node = tsk_xml_find_node(node, qname, nft_none);
+ while( node && !found ) {
+ attrPtr = node->properties;
+ while(attrPtr) {
+ if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children) {
+ if( tsk_striequals(attrPtr->name, att_name) ) {
+ node = attrPtr->children;
+ found = 1;
+ }
+ }
+ attrPtr = attrPtr->next;
+ }
+ if(!found) {
+ node = tsk_xml_find_node(node, 0, nft_next);
+ }
+ }
+ break;
+ }
+
+ case nst_by_att: {
+ /* qname att_name att_value */
+ xmlAttrPtr attrPtr = 0;
+ int found = 0;
+ const char* qname = va_arg(list, const char*);
+ const char* att_name = va_arg(list, const char*);
+ const char* att_value = va_arg(list, const char*);
+ node = tsk_xml_find_node(node, qname, nft_none);
+ while( node && !found ) {
+ attrPtr = node->properties;
+ while(attrPtr) {
+ if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children) {
+ if( tsk_striequals(attrPtr->name, att_name)
+ && ( (attrPtr->children->content && tsk_striequals(attrPtr->children->content, att_value)) || !att_value )
+ ) {
+ found = 1;
+ }
+ }
+ attrPtr = attrPtr->next;
+ }
+ if(!found) {
+ node = tsk_xml_find_node(node, 0, nft_next);
+ }
+ }
+
+ if(found && node) {
+ break;
+ }
+ else {
+ return 0;
+ }
+
+ break;
+ }
+ default:
+ return 0;
+ } /* switch */
+
+ /* skip all comments */
+ TSK_XML_NODE_SKIP_COMMENTS(node);
+
+ } /* while*/
+
+ return node;
}
#endif /* HAVE_LIBXML2_H */
diff --git a/tinySAK/src/tsk_xml.h b/tinySAK/src/tsk_xml.h
index 8af6fa3..aac3c59 100755
--- a/tinySAK/src/tsk_xml.h
+++ b/tinySAK/src/tsk_xml.h
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
-*
+*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
@@ -39,7 +39,7 @@
#define TSK_XML_NODE_IS_TEXTVALUE(node) (node && node->type==XML_TEXT_NODE)
#define TSK_XML_NODE_SAFE_GET_TEXTVALUE(node) (const char*)(TSK_XML_NODE_IS_TEXTVALUE(node)?(node->content):0)
#define TSK_XML_NODE_SKIP_COMMENTS(node) while(node && (node->type==XML_COMMENT_NODE)) node = tsk_xml_find_node(node, 0, nft_next);
-
+
#define TSK_XML_NODE_SELECT_BY_NAME(qname) nst_by_name, qname
#define TSK_XML_NODE_SELECT_BY_ATT(qname, att_name, att_value) nst_by_att, qname, att_name, att_value
@@ -61,77 +61,71 @@
else tsk_strupdate(&result, "");
/** C and XML Schema mapping */
-typedef enum tsk_xml_type_e
-{
- xt_none,
- xt_string, /* xsd:string */
- xt_byte, /* xsd:byte */
- xt_unsignedByte, /* xsd:unsignedByte */
- xt_short, /* xsd:short */
- xt_unsignedShort, /* xsd:unsignedShort */
- xt_int, /* xsd:int */
- xt_unsignedInt, /* xsd:unsignedInt */
- xt_long, /* xsd:long */
- xt_boolean, /* xsd:boolean */
- xt_float, /* xsd:float */
- xt_double /* xsd:double */
+typedef enum tsk_xml_type_e {
+ xt_none,
+ xt_string, /* xsd:string */
+ xt_byte, /* xsd:byte */
+ xt_unsignedByte, /* xsd:unsignedByte */
+ xt_short, /* xsd:short */
+ xt_unsignedShort, /* xsd:unsignedShort */
+ xt_int, /* xsd:int */
+ xt_unsignedInt, /* xsd:unsignedInt */
+ xt_long, /* xsd:long */
+ xt_boolean, /* xsd:boolean */
+ xt_float, /* xsd:float */
+ xt_double /* xsd:double */
}
tsk_xml_type_t;
/** Node finding types */
-typedef enum tsk_xml_node_find_type_s
-{
- nft_none,
- nft_children,
- nft_parent,
- nft_next,
- nft_prev
+typedef enum tsk_xml_node_find_type_s {
+ nft_none,
+ nft_children,
+ nft_parent,
+ nft_next,
+ nft_prev
}
tsk_xml_node_find_type_t;
/** Element selection types */
-typedef enum tsk_xml_node_select_type_s
-{
- nst_by_name,
- nst_by_att,
- nst_att_value,
- nst_content,
- nst_end
+typedef enum tsk_xml_node_select_type_s {
+ nst_by_name,
+ nst_by_att,
+ nst_att_value,
+ nst_content,
+ nst_end
}
tsk_xml_node_select_type_t;
/** XML namespace */
-typedef struct tsk_xml_namespace_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_xml_namespace_s {
+ TSK_DECLARE_OBJECT;
- char* prefix;
- char* value;
+ char* prefix;
+ char* value;
}
tsk_xml_namespace_t;
/** XML attribute */
-typedef struct tsk_xml_attribute_s
-{
- TSK_DECLARE_OBJECT;
+typedef struct tsk_xml_attribute_s {
+ TSK_DECLARE_OBJECT;
- char* name;
- void* value;
- tsk_xml_type_t type;
+ char* name;
+ void* value;
+ tsk_xml_type_t type;
}
tsk_xml_attribute_t;
/** XML element */
-typedef struct tsk_xml_element_s
-{
- TSK_DECLARE_OBJECT;
-
- char* name;
- void* value;
- tsk_list_t* elements;
- tsk_list_t* attributes;
- tsk_list_t* namespaces;
- tsk_xml_type_t type;
+typedef struct tsk_xml_element_s {
+ TSK_DECLARE_OBJECT;
+
+ char* name;
+ void* value;
+ tsk_list_t* elements;
+ tsk_list_t* attributes;
+ tsk_list_t* namespaces;
+ tsk_xml_type_t type;
}
tsk_xml_element_t;
OpenPOWER on IntegriCloud