Merge branch 'tizen_2.2' into tizen
authorAnas Nashif <anas.nashif@intel.com>
Tue, 24 Sep 2013 04:10:50 +0000 (00:10 -0400)
committerAnas Nashif <anas.nashif@intel.com>
Tue, 24 Sep 2013 04:10:50 +0000 (00:10 -0400)
Conflicts:
packaging/ail.spec

1  2 
packaging/ail.spec
src/ail_db.c
src/ail_desktop.c

diff --combined packaging/ail.spec
@@@ -1,12 -1,11 +1,11 @@@
--#sbs-git:slp/pkgs/a/ail ail 0.2.22 29ac1f2c98453cad647cca6a92abc7da3dbb047b
  Name:       ail
  Summary:    Application Information Library
- Version:    0.2.68
+ Version:    0.2.73
  Release:    1
  Group:      System/Libraries
  License:    Apache License, Version 2.0
  Source0:    %{name}-%{version}.tar.gz
 +Source1001:   ail.manifest
  Requires(post): /sbin/ldconfig
  Requires(postun): /sbin/ldconfig
  BuildRequires:  cmake
@@@ -30,7 -29,6 +29,7 @@@ Application Information Library (devel
  
  %prep
  %setup -q
 +cp %{SOURCE1001} .
  
  %build
  CFLAGS+=" -fpic"
@@@ -41,13 -39,9 +40,13 @@@ make %{?jobs:-j%jobs
  %install
  %make_install
  
 +mkdir -p %{buildroot}/opt/dbspace/
 +mkdir -p %{buildroot}/opt/share/applications/
 +
  %post
- vconftool set -t string db/ail/ail_info "0" -f
- vconftool set -t string db/menuscreen/desktop "0" -f
- vconftool set -t string db/menu_widget/language "en_US.utf8" -f
+ vconftool set -t string db/ail/ail_info "0" -f -s system::vconf_inhouse
+ vconftool set -t string db/menuscreen/desktop "0" -f -s system::vconf_inhouse
++vconftool set -t string db/menu_widget/language "en_US.utf8" -f -s system::vconf_inhouse
  
  CHDBGID="6010"
  
@@@ -66,26 -60,22 +65,25 @@@ update_DAC_for_db_file(
                  echo "Failed to change the perms of $@"
          fi
  }
 -mkdir -p /opt/dbspace/
  ail_initdb
  update_DAC_for_db_file /opt/dbspace/.app_info.db
  update_DAC_for_db_file /opt/dbspace/.app_info.db-journal
 -chsmack -a 'ail::db' /opt/dbspace/.app_info.db*
  
  %postun
 +if [ $1 == 0 ]; then
 +rm -f /opt/dbspace/.app_info.db*
 +fi
  
  %files
 -%manifest ail.manifest
 +%manifest %{name}.manifest
  %{_libdir}/libail.so.0
  %{_libdir}/libail.so.0.1.0
- /opt/dbspace
 +/opt/share/applications
  /usr/bin/ail_initdb
  /usr/share/install-info/*
  
  %files devel
 +%manifest %{name}.manifest
  /usr/include/ail.h
  %{_libdir}/libail.so
  %{_libdir}/pkgconfig/ail.pc
diff --combined src/ail_db.c
@@@ -46,23 -46,6 +46,23 @@@ static __thread struct 
        .dbrw = NULL
  };
  
 +
 +static ail_error_e db_do_prepare(sqlite3 *db, const char *query, sqlite3_stmt **stmt)
 +{
 +      int ret;
 +
 +      retv_if(!query, AIL_ERROR_INVALID_PARAMETER);
 +      retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
 +      retv_if(!db, AIL_ERROR_DB_FAILED);
 +
 +      ret = sqlite3_prepare_v2(db, query, strlen(query), stmt, NULL);
 +      if (ret != SQLITE_OK) {
 +              _E("%s\n", sqlite3_errmsg(db));
 +              return AIL_ERROR_DB_FAILED;
 +      } else
 +              return AIL_ERROR_OK;
 +}
 +
  ail_error_e db_open(db_open_mode mode)
  {
        int ret;
@@@ -71,7 -54,6 +71,6 @@@
        if(mode & DB_OPEN_RO) {
                if (!db_info.dbro) {
                        ret = db_util_open_with_options(APP_INFO_DB, &db_info.dbro, SQLITE_OPEN_READONLY, NULL);
-                       _E("db_open_ro ret=%d", ret);
                        retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
                }
        }
@@@ -79,7 -61,6 +78,6 @@@
        if(mode & DB_OPEN_RW) {
                if (!db_info.dbrw) {
                        ret = db_util_open(APP_INFO_DB, &db_info.dbrw, DB_UTIL_REGISTER_HOOK_METHOD);
-                       _E("db_open_rw ret=%d", ret);
                        retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
                }
        }
        return AIL_ERROR_OK;
  }
  
 -
 -
  ail_error_e db_prepare(const char *query, sqlite3_stmt **stmt)
  {
 -      int ret;
 -
 -      retv_if(!query, AIL_ERROR_INVALID_PARAMETER);
 -      retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
 -      retv_if(!db_info.dbro, AIL_ERROR_DB_FAILED);
 +      return db_do_prepare(db_info.dbro, query, stmt);
 +}
  
 -      ret = sqlite3_prepare_v2(db_info.dbro, query, strlen(query), stmt, NULL);
 -      if (ret != SQLITE_OK) {
 -              _E("%s\n", sqlite3_errmsg(db_info.dbro));
 -              return AIL_ERROR_DB_FAILED;
 -      } else 
 -              return AIL_ERROR_OK;
 +ail_error_e db_prepare_rw(const char *query, sqlite3_stmt **stmt)
 +{
 +      return db_do_prepare(db_info.dbrw, query, stmt);
  }
  
  
@@@ -124,17 -113,6 +122,17 @@@ ail_error_e db_bind_int(sqlite3_stmt *s
        return AIL_ERROR_OK;
  }
  
 +ail_error_e db_bind_text(sqlite3_stmt *stmt, int idx, char* value)
 +{
 +      int ret;
 +
 +      retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
 +
 +      ret = sqlite3_bind_text(stmt, idx, value, strlen(value), 0);
 +      retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
 +
 +      return AIL_ERROR_OK;
 +}
  
  
  ail_error_e db_step(sqlite3_stmt *stmt)
diff --combined src/ail_desktop.c
  #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  #define argsdelimiter " \t"
  
 +#define SQL_INSERT_LOCALNAME_STR "insert into localname (package, locale, name) values "
 +#define SQL_INSERT_LOCALNAME_STR_LEN (sizeof(SQL_INSERT_LOCALNAME_STR)-1)
 +
 +#define SQL_INSERT_LOCALNAME_INIT_STR  SQL_INSERT_LOCALNAME_STR"( ?, ?, ?) "
 +
 +#define SQL_LOCALNAME_TRIPLET_STR  ", ( ?, ?, ?)"
 +#define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR)-1)
 +
  typedef enum {
        NOTI_ADD,
        NOTI_UPDATE,
@@@ -757,97 -749,7 +757,97 @@@ char *_pkgname_to_desktop(const char *p
        return desktop;
  }
  
 +static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt)
 +{
 +      int ret = 0;
 +      unsigned long i = 0;
 +      struct name_item *item;
 +      GSList* localname;
 +      retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
 +      retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
 +      retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
 +      localname = info->localname;
 +      while (localname) {
 +              item = (struct name_item *)     localname->data;
 +              if (item && item->locale && item->name) {
 +                      // Bind values for a triplet : package, locale, name
 +                      retv_if(db_bind_text(stmt, i+1, info->package) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
 +                      retv_if(db_bind_text(stmt, i+2, item->locale) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
 +                      retv_if(db_bind_text(stmt, i+3, item->name) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
 +                      i += 3;
 +              }
 +              localname = g_slist_next(localname);
 +      }
 +      return AIL_ERROR_OK;
 +}
 +
 +
 +static inline int _len_local_info(desktop_info_s* info)
 +{
 +      int len = 0;
 +      struct name_item *item;
 +      GSList* localname;
 +      retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
 +      if(info->localname)     {
 +              localname = info->localname;
 +              while (localname) {
 +                      item = (struct name_item *)     localname->data;
 +                      if (item && item->locale && item->name)
 +                              len ++;
 +                      localname = g_slist_next(localname);
 +              }
 +      }
 +      return len;
 +}
 +
 +
 +static inline int _insert_local_info(desktop_info_s* info)
 +{
 +      int len_query = SQL_INSERT_LOCALNAME_STR_LEN;
 +      int nb_locale_args;
 +      char *query;
 +      int ret = AIL_ERROR_OK;
 +      sqlite3_stmt *stmt = NULL;
 +      int i = 0;
 +      retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
 +      retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
  
 +      nb_locale_args = _len_local_info(info);
 +
 +      retv_if(!nb_locale_args, AIL_ERROR_INVALID_PARAMETER);
 +
 +      len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args +1;
 +
 +      query = (char *) malloc(len_query);
 +      retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
 +      stpncpy(query, SQL_INSERT_LOCALNAME_INIT_STR, len_query);
 +      for (i = 0; i <  nb_locale_args - 1; i++)
 +              strcat(query, SQL_LOCALNAME_TRIPLET_STR);
 +
 +      do {
 +              ret = db_prepare_rw(query, &stmt);
 +              if (ret < 0) break;
 +
 +              ret = _bind_local_info(info, stmt);
 +              if (ret < 0) {
 +                      _E("Can't bind locale information to this query - %s. ",query);
 +                      db_finalize(stmt);
 +                      break;
 +              }
 +              ret = db_step(stmt);
 +              if (ret != AIL_ERROR_NO_DATA) {
 +                      /* Insert Request doesn't return any data.
 +                       * db_step should returns AIL_ERROR_NO_DATA in this case. */
 +                      _E("Can't execute this query - %s. ",query);
 +                      db_finalize(stmt);
 +                      break;
 +              }
 +              ret = db_finalize(stmt);
 +      } while(0);
 +
 +      free(query);
 +      return ret;
 +}
  
  static inline int _strlen_desktop_info(desktop_info_s* info)
  {
@@@ -1199,7 -1101,9 +1199,9 @@@ static ail_error_e _create_table(void
                "desktop TEXT UNIQUE NOT NULL);",
                "CREATE TABLE localname (package TEXT NOT NULL, "
                "locale TEXT NOT NULL, "
-               "name TEXT NOT NULL, PRIMARY KEY (package, locale));",
+               "name TEXT NOT NULL, "
+               "x_slp_pkgid TEXT NOT NULL, PRIMARY KEY (package, locale));",
                NULL
        };
  
@@@ -1222,9 -1126,9 +1224,9 @@@ static inline void _insert_localname(gp
        struct name_item *item = (struct name_item *)data;
        desktop_info_s *info = (desktop_info_s *)user_data;
  
-       snprintf(query, sizeof(query), "insert into localname (package, locale, name) "
-                       "values ('%s', '%s', '%s');", 
-                       info->package, item->locale, item->name);
+       snprintf(query, sizeof(query), "insert into localname (package, locale, name, x_slp_pkgid) "
+                       "values ('%s', '%s', '%s', '%s');",
+                       info->package, item->locale, item->name, info->x_slp_pkgid);
        if (db_exec(query) < 0)
                _E("Failed to insert local name of package[%s]",info->package);
  }
@@@ -1311,11 -1215,10 +1313,11 @@@ static ail_error_e _insert_desktop_info
        }
  
        ret = db_exec(query);
 +      free(query);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
  
        if (info->localname)
 -              g_slist_foreach(info->localname, _insert_localname, info);
 +              _insert_local_info(info);
  
        _D("Add (%s).", info->package);
  
@@@ -1408,7 -1311,7 +1410,7 @@@ static ail_error_e _update_desktop_info
        }
  
        if (info->localname)
 -              g_slist_foreach(info->localname, _insert_localname, info);
 +              _insert_local_info(info);
  
        _D("Update (%s).", info->package);
  
@@@ -1455,6 -1358,41 +1457,41 @@@ static ail_error_e _remove_package(cons
        return AIL_ERROR_OK;
  }
  
+ static ail_error_e _clean_pkgid_data(const char* pkgid)
+ {
+       char *query;
+       int size;
+       retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
+       if (db_open(DB_OPEN_RW) < 0) {
+               return AIL_ERROR_DB_FAILED;
+       }
+       size = strlen(pkgid) + (0x01 << 10);
+       query = calloc(1, size);
+       retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
+       snprintf(query, size, "delete from app_info where x_slp_pkgid = '%s'", pkgid);
+       if (db_exec(query) < 0) {
+               free(query);
+               return AIL_ERROR_DB_FAILED;
+       }
+       snprintf(query, size, "delete from localname where x_slp_pkgid = '%s'", pkgid);
+       _D("query=%s",query);
+       if (db_exec(query) < 0) {
+               free(query);
+               return AIL_ERROR_DB_FAILED;
+       }
+       _D("Clean pkgid data (%s).", pkgid);
+       free(query);
+       return AIL_ERROR_OK;
+ }
  
  
  static ail_error_e _send_db_done_noti(noti_type type, const char *package)
@@@ -1632,6 -1570,24 +1669,24 @@@ EXPORT_API ail_error_e ail_desktop_remo
        return AIL_ERROR_OK;
  }
  
+ EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
+ {
+       ail_error_e ret;
+       retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
+       if (!__is_authorized()) {
+               _E("You are not an authorized user on removing!\n");
+               return -1;
+       }
+       _D("ail_desktop_clean=%s",pkgid);
+       ret = _clean_pkgid_data(pkgid);
+       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       return AIL_ERROR_OK;
+ }
  
  EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
                                                             const char *property,