extern int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *lbid, int is_prime, void *data), void *data);
/*!
- * \brief Get the name(appid or pkgname) of a primary livebox.
- * \param[in] appid
+ * \brief Get the pkgname of a primary livebox using given lbid or pkgid.
+ * \param[in] id Livebox Id or Package Id
* \return pkgname String which is allocated on the heap
*/
-extern char *livebox_service_pkgname(const char *appid);
+extern char *livebox_service_pkgname(const char *id);
+/*!
+ * \brief Check the pirmary flag of given livebox Id.
+ * \param[in] lbid Livebox Id
+ * \return int 0 if is not a primary or 1
+ */
+extern int livebox_service_is_primary(const char *lbid);
/*!
* \brief Get the name of a livebox (provider name == livebox appid), you have to release the return value after use it
extern char *livebox_service_provider_name(const char *lbid);
/*!
- * \brief Get the setup app ID
+ * \brief Get the appId of setup app which is specified by given livebox Id's manifest.
* \param[in] Livebox AppId
* \return Setup AppId if exists or NULL
*/
#include "debug.h"
#include "livebox-service.h"
+#define SAMSUNG_PREFIX "com.samsung."
#define EAPI __attribute__((visibility("default")))
#define DEFAULT_TIMEOUT 2.0
#define MAX_COLUMN 80
lbid = livebox_service_pkgname(pkgid);
if (!lbid) {
ErrPrint("Invalid appid (%s)\n", pkgid);
- ret = -EINVAL;
+ ret = 0;
goto out;
}
}
ret = sqlite3_step(stmt);
- if (ret == SQLITE_ROW)
+ if (ret == SQLITE_ROW) {
ret = !!sqlite3_column_int(stmt, 0);
- else
- ret = 1;
+ } else {
+ ret = 1; /*!< Default true: In this case the DB is corrupted. */
+ ErrPrint("There is no result\n");
+ }
out:
sqlite3_reset(stmt);
lbid = livebox_service_pkgname(pkgid);
if (!lbid) {
ErrPrint("Failed to get lbid: %s\n", pkgid);
- ret = -EINVAL;
+ ret = 0;
goto out;
}
}
ret = sqlite3_step(stmt);
- if (ret == SQLITE_ROW)
+ if (ret == SQLITE_ROW) {
ret = !!sqlite3_column_int(stmt, 0);
- else
- ret = 0;
+ } else {
+ ret = 0; /*!< Default is false, In this case the DB is corrupted */
+ ErrPrint("There is no result.\n");
+ }
out:
sqlite3_reset(stmt);
int stage = 0;
int seq = 0;
int idx = 0;
- char *str = "com.samsung.";
+ char *str = SAMSUNG_PREFIX;
if (!lbid)
return NULL;
*/
}
+EAPI int livebox_service_is_primary(const char *lbid)
+{
+ sqlite3_stmt *stmt;
+ sqlite3 *handle;
+ int ret = 0;
+
+ if (!lbid)
+ return 0;
+
+ handle = open_db();
+ if (!handle)
+ return 0;
+
+ ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+ close_db(handle);
+ return 0;
+ }
+
+ ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
+ if (ret != SQLITE_OK) {
+ ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+ goto out;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+ goto out;
+ }
+
+ ret = sqlite3_column_int(stmt, 1);
+
+out:
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ close_db(handle);
+ return ret;
+}
+
/*!
* appid == Package ID
* pkgid == Livebox ID