evas/cserve2: Fix NULL vs. empty string

Server side: Some strings were NULL, some other were empty.
Client side was looking for NULL, but the shared index contained
empty key.
This commit is contained in:
Jean-Philippe Andre 2013-08-27 09:56:50 +09:00
parent 7bf4394198
commit 74d399ab81
3 changed files with 29 additions and 20 deletions

View File

@ -197,7 +197,6 @@ _entry_load_reused(Entry *e)
#endif #endif
} }
static int static int
_shm_object_id_cmp_cb(const void *data1, const void *data2) _shm_object_id_cmp_cb(const void *data1, const void *data2)
{ {
@ -545,7 +544,7 @@ _font_loaded_send(Client *client, unsigned int rid)
static void * static void *
_open_request_build(Entry *entry, int *bufsize) _open_request_build(Entry *entry, int *bufsize)
{ {
const char *loader_data; const char *loader_data, *key, *path;
char *buf; char *buf;
int size, pathlen, keylen, loaderlen; int size, pathlen, keylen, loaderlen;
Slave_Msg_Image_Open msg; Slave_Msg_Image_Open msg;
@ -561,8 +560,12 @@ _open_request_build(Entry *entry, int *bufsize)
return NULL; return NULL;
} }
pathlen = strlen(cserve2_shared_string_get(fd->path)) + 1; path = cserve2_shared_string_get(fd->path);
keylen = strlen(cserve2_shared_string_get(fd->key)) + 1; key = cserve2_shared_string_get(fd->key);
if (!path) path = "";
if (!key) key = "";
pathlen = strlen(path) + 1;
keylen = strlen(key) + 1;
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
loader_data = cserve2_shared_string_get(fd->loader_data); loader_data = cserve2_shared_string_get(fd->loader_data);
@ -574,8 +577,8 @@ _open_request_build(Entry *entry, int *bufsize)
if (!buf) return NULL; if (!buf) return NULL;
memcpy(buf, &msg, sizeof(msg)); memcpy(buf, &msg, sizeof(msg));
memcpy(buf + sizeof(msg), cserve2_shared_string_get(fd->path), pathlen); memcpy(buf + sizeof(msg), path, pathlen);
memcpy(buf + sizeof(msg) + pathlen, cserve2_shared_string_get(fd->key), keylen); memcpy(buf + sizeof(msg) + pathlen, key, keylen);
if (msg.has_loader_data) if (msg.has_loader_data)
memcpy(buf + sizeof(msg) + pathlen + keylen, loader_data, loaderlen); memcpy(buf + sizeof(msg) + pathlen + keylen, loader_data, loaderlen);
@ -661,7 +664,7 @@ static void *
_load_request_build(Image_Entry *ientry, int *bufsize) _load_request_build(Image_Entry *ientry, int *bufsize)
{ {
char *buf, *ptr; char *buf, *ptr;
const char *shmpath, *loader_data; const char *shmpath, *loader_data, *path, *key;
int size; int size;
int shmlen, filelen, keylen, loaderlen; int shmlen, filelen, keylen, loaderlen;
Slave_Msg_Image_Load msg; Slave_Msg_Image_Load msg;
@ -686,8 +689,12 @@ _load_request_build(Image_Entry *ientry, int *bufsize)
shmpath = cserve2_shm_name_get(ientry->shm); shmpath = cserve2_shm_name_get(ientry->shm);
shmlen = strlen(shmpath) + 1; shmlen = strlen(shmpath) + 1;
filelen = strlen(cserve2_shared_string_get(fd->path)) + 1; path = cserve2_shared_string_get(fd->path);
keylen = strlen(cserve2_shared_string_get(fd->key)) + 1; key = cserve2_shared_string_get(fd->key);
if (!path) path = "";
if (!key) key = "";
filelen = strlen(path) + 1;
keylen = strlen(key) + 1;
loader_data = cserve2_shared_string_get(fd->loader_data); loader_data = cserve2_shared_string_get(fd->loader_data);
if (loader_data) if (loader_data)
loaderlen = strlen(loader_data) + 1; loaderlen = strlen(loader_data) + 1;
@ -724,11 +731,12 @@ _load_request_build(Image_Entry *ientry, int *bufsize)
memcpy(ptr, shmpath, shmlen); memcpy(ptr, shmpath, shmlen);
ptr += shmlen; ptr += shmlen;
memcpy(ptr, cserve2_shared_string_get(fd->path), filelen); memcpy(ptr, path, filelen);
ptr += filelen; ptr += filelen;
memcpy(ptr, cserve2_shared_string_get(fd->key), keylen); memcpy(ptr, key, keylen);
ptr += keylen; ptr += keylen;
if (loaderlen > 0) memcpy(ptr, cserve2_shared_string_get(fd->loader_data), loaderlen); if (loaderlen > 0)
memcpy(ptr, loader_data, loaderlen);
*bufsize = size; *bufsize = size;

View File

@ -921,7 +921,7 @@ cserve2_shared_string_add(const char *str)
char *data; char *data;
int len, id; int len, id;
if (!str) return -1; if (!str) return 0;
// Find in known strings // Find in known strings
id = (int) (intptr_t) eina_hash_find(_string_entries, str); id = (int) (intptr_t) eina_hash_find(_string_entries, str);
@ -945,7 +945,7 @@ new_entry:
if (!ie) if (!ie)
{ {
ERR("Could not store new string in shm"); ERR("Could not store new string in shm");
return -1; return 0;
} }
data = _string_mempool->ds->data + ie->offset; data = _string_mempool->ds->data + ie->offset;
@ -957,7 +957,7 @@ new_entry:
int int
cserve2_shared_string_ref(int id) cserve2_shared_string_ref(int id)
{ {
if (!id) return 0; if (id <= 0) return 0;
return cserve2_shared_mempool_buffer_ref(_string_mempool, id); return cserve2_shared_mempool_buffer_ref(_string_mempool, id);
} }
@ -966,7 +966,7 @@ cserve2_shared_string_del(int id)
{ {
const char *data; const char *data;
if (!id) return; if (id <= 0) return;
if ((data = _shared_mempool_buffer_del(_string_mempool, id)) != NULL) if ((data = _shared_mempool_buffer_del(_string_mempool, id)) != NULL)
{ {
if (!eina_hash_del_by_key(_string_entries, data)) if (!eina_hash_del_by_key(_string_entries, data))
@ -980,7 +980,7 @@ cserve2_shared_string_del(int id)
const char * const char *
cserve2_shared_string_get(int id) cserve2_shared_string_get(int id)
{ {
if (!id) return NULL; if (id <= 0) return NULL;
return cserve2_shared_mempool_buffer_get(_string_mempool, id); return cserve2_shared_mempool_buffer_get(_string_mempool, id);
} }

View File

@ -135,15 +135,17 @@ static void
_cserve2_client_open(Client *client) _cserve2_client_open(Client *client)
{ {
Msg_Open *msg = (Msg_Open *)client->msg.buf; Msg_Open *msg = (Msg_Open *)client->msg.buf;
const char *path, *key; const char *path, *key, *end;
path = ((const char *)msg) + sizeof(*msg) + msg->path_offset; path = ((const char *)msg) + sizeof(*msg) + msg->path_offset;
key = ((const char *)msg) + sizeof(*msg) + msg->key_offset; key = ((const char *)msg) + sizeof(*msg) + msg->key_offset;
end = key + strlen(key) + 1;
INF("Received OPEN command: RID=%d", msg->base.rid); INF("Received OPEN command: RID=%d", msg->base.rid);
INF("File_ID: %d, path=\"%s\", key=\"%s\", has_load_opts=%d", INF("File_ID: %d, path=\"%s\", key=\"%s\", has_load_opts=%d",
msg->file_id, path, key, (int) msg->has_load_opts); msg->file_id, path, key, (int) msg->has_load_opts);
if (!key[0]) key = NULL;
cserve2_cache_file_open(client, msg->file_id, path, key, msg->base.rid); cserve2_cache_file_open(client, msg->file_id, path, key, msg->base.rid);
if (!msg->has_load_opts) if (!msg->has_load_opts)
@ -152,8 +154,7 @@ _cserve2_client_open(Client *client)
else else
{ {
// FIXME: Check message size first? // FIXME: Check message size first?
Evas_Image_Load_Opts *opts = Evas_Image_Load_Opts *opts = (Evas_Image_Load_Opts *) end;
(Evas_Image_Load_Opts*) (key + strlen(key) + 1);
DBG("Load Options:"); DBG("Load Options:");
DBG("\tdpi: %03.1f", opts->dpi); DBG("\tdpi: %03.1f", opts->dpi);