upload tizen1.0 source
authorKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 07:59:50 +0000 (16:59 +0900)
committerKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 07:59:50 +0000 (16:59 +0900)
debian/changelog
include/bundle.h
packaging/bundle.spec
src/bundle.c
src/keyval_array.c
test/TC_bundle.c

index 131df17c214db1f3ad125eb117500dcc0180c94c..5a4a19fbbc9141160f87398b169aa76bc3e7eb2e 100644 (file)
@@ -1,7 +1,7 @@
-bundle (0.1.21) unstable; urgency=low
+bundle (0.1.22) unstable; urgency=low
 
   * Initial release.
   * Git: pkgs/b/bundle
-  * Tag: bundle_0.1.21
+  * Tag: bundle_0.1.22
 
- -- Sewook Park <sewook7.park@samsung.com>  Wed, 07 Dec 2011 12:55:49 +0900
+ -- Jaeho Lee <jaeho81.lee@samsung.com>  Fri, 17 Feb 2012 16:45:12 +0900
index 61c567923ae5a9c58363593deabab954fdbe4009..d12cd06da754d476ab9503e87d576f418edc7ba7 100755 (executable)
@@ -54,7 +54,8 @@ extern "C" {
 # endif
 
 #define API    __attribute__((visibility("default")))
-
+#define likely(x) __builtin_expect(x,1)
+#define unlikely(x) __builtin_expect(x,0)
 
 /**
  * bundle is an opaque type pointing a bundle object
index 76b961c2adef1c53520f558f04aea55ff68830dd..a199a38c5f8ae3f60aa1919ce01ca9b8e8d3d5fc 100644 (file)
@@ -1,9 +1,9 @@
 Name:       bundle
 Summary:    String key-val dictionary ADT
-Version:    0.1.16
-Release:    1.1
-Group:      TO_BE/FILLED_IN
-License:    TO BE FILLED IN
+Version:    0.1.22
+Release:    1
+Group:      System/Libraries
+License:    Apache License, Version 2.0
 Source0:    bundle-%{version}.tar.bz2
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index b605607757c819a0a1f96a7768178c6c3cc1c360..53df434762b510b4a6ec427d8c995e7de685b9dc 100755 (executable)
 #include "keyval_array.h"
 #include "keyval_type.h"
 #include "bundle_log.h"
-#include <glib/gbase64.h>
+#include <glib.h>
 
 #include <stdlib.h>            /* calloc, free */
 #include <string.h>            /* strdup */
 #include <errno.h>
 
-
+#define CHECKSUM_LENGTH 32
+#define TAG_IMPORT_EXPORT_CHECK "`zaybxcwdveuftgsh`"
 /* ADT */
 struct _bundle_t
 {
@@ -390,6 +391,11 @@ int
 bundle_encode(bundle *b, bundle_raw **r, int *len)
 {
        keyval_t *kv;
+       unsigned char *m;
+       unsigned char *p_m;
+       unsigned char *byte;
+       size_t byte_len;
+       gchar *chksum_val;
 
        if(NULL == b) {
                errno = EINVAL;
@@ -404,13 +410,10 @@ bundle_encode(bundle *b, bundle_raw **r, int *len)
                msize += kv->method->get_encoded_size(kv);
                kv = kv->next;
        }
-       unsigned char *m = calloc(msize, sizeof(unsigned char));
-       if ( NULL == m )  { errno = ENOMEM; return -1; }
+       m = calloc(msize+CHECKSUM_LENGTH, sizeof(unsigned char));
+       if(unlikely(NULL == m ))  { errno = ENOMEM; return -1; }
 
-       unsigned char *p_m = m; /* temporary pointer */
-
-       unsigned char *byte;
-       size_t byte_len;
+       p_m = m+CHECKSUM_LENGTH;        /* temporary pointer */
 
        kv = b->kv_head;
        while(kv != NULL) {
@@ -426,11 +429,17 @@ bundle_encode(bundle *b, bundle_raw **r, int *len)
                free(byte);
        }
 
+       /*compute checksum from the data*/
+       chksum_val = g_compute_checksum_for_string(G_CHECKSUM_MD5,m+CHECKSUM_LENGTH,msize);
+       /*prefix checksum to the data */
+       memcpy(m,chksum_val,CHECKSUM_LENGTH);
        if ( NULL != r ) {
-               *r =(unsigned char*)g_base64_encode(m, msize);
+               /*base64 encode for whole string checksum and data*/
+               *r =(unsigned char*)g_base64_encode(m,msize+CHECKSUM_LENGTH);
                if ( NULL != len ) *len = strlen((char*)*r);
        }
        free(m);
+       g_free(chksum_val);/*free checksum string */
 
        return 0;
 }
@@ -450,15 +459,40 @@ bundle_decode(const bundle_raw *r, const int data_size)
 {
        bundle *b;
        bundle_raw *p_r;
+       unsigned char *d_str;
+       unsigned int d_len_raw;
+       unsigned char *d_r;
+       unsigned int d_len;
+       char *extract_cksum;
+       gchar* compute_cksum;
 
        if(NULL == r) {
                errno = EINVAL;
                return NULL;
        }
 
-       unsigned char *d_r;
-       unsigned int d_len;
-       d_r = g_base64_decode((char*)r, &d_len);
+       extract_cksum = calloc(CHECKSUM_LENGTH+1, sizeof(char));
+       if(unlikely(NULL== extract_cksum))
+       {
+               errno = ENOMEM;
+               return NULL;
+       }
+
+       /* base 64 decode of input string*/
+       d_str = g_base64_decode((char*)r, &d_len_raw);
+       /*extract checksum from the received string */
+       strncpy(extract_cksum,d_str,CHECKSUM_LENGTH);
+       /* compute checksum for the data */
+       compute_cksum = g_compute_checksum_for_string(G_CHECKSUM_MD5,d_str+CHECKSUM_LENGTH,d_len_raw-CHECKSUM_LENGTH);
+       /*compare checksum values- extracted from the received string and computed from the data */
+       if(strcmp(extract_cksum,compute_cksum)!=0)
+       {
+               free(extract_cksum);
+               g_free(compute_cksum);
+               return NULL;
+       }
+       d_r = d_str+CHECKSUM_LENGTH;
+       d_len= d_len_raw-CHECKSUM_LENGTH;
 
        /* re-construct bundle */
        b = bundle_create();
@@ -472,7 +506,7 @@ bundle_decode(const bundle_raw *r, const int data_size)
                kv = NULL;      // To get a new kv
 
                // Find type, and use decode function according to type
-               int type = keyval_get_type_from_encoded_byte(p_r);      
+               int type = keyval_get_type_from_encoded_byte(p_r);
 
                if(keyval_type_is_array(type)) {
                        bytes_read = keyval_array_decode(p_r, (keyval_array_t **) &kv);
@@ -486,9 +520,11 @@ bundle_decode(const bundle_raw *r, const int data_size)
                p_r += bytes_read;
        }
 
-       free(d_r);
+       free(extract_cksum);
+       g_free(compute_cksum);
+       free(d_str);
 
-       return b; 
+       return b;
 }
 
 struct _argv_idx {
@@ -541,7 +577,7 @@ bundle_export_to_argv(bundle *b, char ***argv)
        vi.argc = argc;
        vi.argv = *argv;
        vi.idx = 2;                      /* start from index 2*/
-       vi.argv[1]="`zaybxcwdveuftgsh`";                /* set argv[1] as encoded*/
+       vi.argv[1]=TAG_IMPORT_EXPORT_CHECK;             /* set argv[1] as encoded*/
        /*BUNDLE_LOG_PRINT("\nargument 1 is %s",vi.argv[1]);*/
 
        bundle_foreach(b, _iter_export_to_argv, &vi);
@@ -579,7 +615,7 @@ bundle_import_from_argv(int argc, char **argv)
        }
        */
 
-       if(!argv[1]||strcmp(argv[1],"`zaybxcwdveuftgsh`"))
+       if(!argv[1]||strcmp(argv[1],TAG_IMPORT_EXPORT_CHECK))
        {
        /*BUNDLE_LOG_PRINT("\nit is not encoded");*/
                int idx;
index cd8f31d81444501c2bfa82f30446ff7a0cfe8ad1..af2aa12a6add68ea801db49b85efc5f893be97dd 100755 (executable)
@@ -51,9 +51,9 @@ keyval_array_new(keyval_array_t *kva, const char *key, const int type, const voi
        int must_free_obj;
        must_free_obj = kva ? 0 : 1;
 
-       if(!kva) {      
+       if(!kva) {
                kva = calloc(1, sizeof(keyval_array_t));
-               if(!kva) {
+               if(unlikely(NULL==kva)) {
                        errno = ENOMEM;
                        return NULL;
                }
@@ -61,6 +61,12 @@ keyval_array_new(keyval_array_t *kva, const char *key, const int type, const voi
 
        // keyval setting
        keyval_t *kv = keyval_new((keyval_t *)kva, key, type, NULL, 0);
+       if(unlikely(NULL==kv))
+       {
+                       errno = ENOMEM;
+                       return NULL;
+       }
+
        kv->type = kv->type | BUNDLE_TYPE_ARRAY;
 
        kva->len = len;
@@ -85,14 +91,14 @@ keyval_array_new(keyval_array_t *kva, const char *key, const int type, const voi
                return NULL;
        }
        // If avaliable, copy array val
-       if(array_val 
-               && keyval_type_is_measurable(type) 
-               && keyval_type_get_measure_size_func(type)) {   
+       if(array_val
+               && keyval_type_is_measurable(type)
+               && keyval_type_get_measure_size_func(type)) {
                // array_val have original data array. copy it!
 
-               if(keyval_array_copy_array((keyval_array_t*)kv, 
-                                       (void**)array_val, 
-                                       len, 
+               if(keyval_array_copy_array((keyval_array_t*)kv,
+                                       (void**)array_val,
+                                       len,
                                        keyval_type_get_measure_size_func(type))
                                ) {
                        keyval_array_free(kva, 1);
index de74db56a2f6d097714fe6d3058eeae4bbebac28..03e0c268dc7abb5043d5e7a81ccf1412584734e8 100755 (executable)
@@ -1061,11 +1061,11 @@ int TC_bundle_decode()
        dec_b=bundle_decode(bundle_data,len);
        assert(NULL == dec_b);
        assert(EINVAL == errno);
-/*TODO:invalid bundle_data and len values- not encoded-any random string passed -sigsegv */
-//     dec_b=bundle_decode("not_encodeddata",len);
-//     assert(NULL == dec_b);
+/*invalid bundle_data and len values- not encoded-any random string passed -FIXED */
+       dec_b=bundle_decode("not_encodeddata",len);
+       assert(NULL == dec_b);
 //     assert(EINVAL == errno);
-/*encode- decode but incorrect value for length  TODO:it should fail but succeeding*/
+/*encode- decode but incorrect value for length  */
        b=bundle_create();
        assert(NULL != b);
        assert(0 == bundle_add(b, "k1", "val1"));