const char *fbfile;
const char *content;
const char *title;
+ const char *safe_file;
struct livebox *handler;
int lb_w;
int lb_h;
double priority;
int ret;
- ret = packet_get(packet, "sssiidss",
+ ret = packet_get(packet, "sssiidsss",
&pkgname, &id,
&fbfile, &lb_w, &lb_h,
- &priority, &content, &title);
- if (ret != 8) {
+ &priority, &content, &title,
+ &safe_file);
+ if (ret != 9) {
ErrPrint("Invalid argument\n");
goto out;
}
lb_set_content(handler, content);
lb_set_title(handler, title);
lb_set_size(handler, lb_w, lb_h);
+ lb_set_filename(handler, safe_file);
if (lb_text_lb(handler)) {
(void)parse_desc(handler, livebox_filename(handler), 0);
#include <stdlib.h> /* malloc */
#include <string.h> /* strdup */
#include <math.h>
+#include <unistd.h>
#include <aul.h>
#include <dlog.h>
return NULL;
}
-static inline char *get_file_kept_in_safe(const char *id)
-{
- const char *path;
- char *new_path;
- int len;
- int base_idx;
-
- path = util_uri_to_path(id);
- if (!path) {
- ErrPrint("Invalid URI(%s)\n", id);
- return NULL;
- }
-
- /*!
- * \TODO: REMOVE ME
- */
- if (s_info.prevent_overwrite) {
- new_path = strdup(path);
- if (!new_path) {
- ErrPrint("Heap: %s\n", strerror(errno));
- }
-
- return new_path;
- }
-
-
- len = strlen(path);
- base_idx = len - 1;
-
- while (base_idx > 0 && path[base_idx] != '/') base_idx--;
- base_idx += (path[base_idx] == '/');
-
- new_path = malloc(len + 10);
- if (!new_path) {
- ErrPrint("Heap: %s\n", strerror(errno));
- return NULL;
- }
-
- strncpy(new_path, path, base_idx);
- snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
- return new_path;
-}
-
struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
{
struct livebox *handler;
return NULL;
}
- handler->filename = get_file_kept_in_safe(id);
- if (!handler->filename) {
- handler->filename = strdup(util_uri_to_path(id));
- if (!handler->filename) {
- ErrPrint("Error: %s\n", strerror(errno));
- }
- }
-
handler->timestamp = timestamp;
handler->lb.type = _LB_TYPE_FILE;
handler->pd.type = _PD_TYPE_SCRIPT;
if (!handler->id) {
ErrPrint("Error: %s\n", strerror(errno));
}
+}
+void lb_set_filename(struct livebox *handler, const char *filename)
+{
if (handler->filename) {
+ if (unlink(handler->filename) < 0) {
+ ErrPrint("unlink: %s\n", strerror(errno));
+ }
+
free(handler->filename);
}
- handler->filename = get_file_kept_in_safe(id);
+ handler->filename = strdup(filename);
if (!handler->filename) {
- handler->filename = strdup(util_uri_to_path(id));
- if (!handler->filename) {
- ErrPrint("Error: %s\n", strerror(errno));
- }
+ ErrPrint("Heap: %s\n", strerror(errno));
+ return;
}
}
}
if (handler->filename) {
- util_unlink(handler->filename);
+ (void)util_unlink(handler->filename);
}
dlist_remove_data(s_info.livebox_list, handler);