summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/eiotas_particle.c36
-rw-r--r--tests/particle.c3
2 files changed, 28 insertions, 11 deletions
diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c
index 5f302cf..a72d55f 100644
--- a/src/lib/eiotas_particle.c
+++ b/src/lib/eiotas_particle.c
@@ -20,6 +20,7 @@
#include "eiotas_private.h"
static void update_link_value(Eiotas_Particle *particle, const char *field);
+static Eina_Bool add_destination(Eiotas_Particle *particle, const char *dst, int l);
Eiotas_Particle* eiotas_particle_alloc()
{
@@ -100,29 +101,44 @@ EAPI Eina_Bool eiotas_particle_has_dst(Eiotas_Particle *particle)
EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char* destinations)
{
- int n;
char *dst, *sep;
- Eina_Stringshare *s;
dst = (char*)destinations;
for(; *dst;) {
for(; *dst==' '; dst++) /* eat leading spaces */;
sep = dst;
for(; (*sep && *sep!=EIOTAS_FIELDS_SEP && *sep!=' '); sep++) /* search destination end */;
- n = (sep-dst);
- if(n==0) {
- ERR("ignore empty destination");
- } else {
- s = eina_stringshare_add_length(dst,n);
- eina_array_push(particle->dsts,s);
- DBG("add dst >%s<",s);
- }
+ add_destination(particle,dst,(sep-dst));
for(; (*sep && *sep!=EIOTAS_FIELDS_SEP); sep++) /* eat whatever following */;
if(!*sep) return;
dst = sep+1;
}
}
+static Eina_Bool add_destination(Eiotas_Particle *particle, const char *dst, int n)
+{
+ Eina_Stringshare *s;
+
+ if(n==0) {
+ ERR("ignore empty destination");
+ return EINA_FALSE;
+ }
+ if(*dst==EIOTAS_ACTION_SEP || *dst==EIOTAS_PATH_SEP ) {
+ ERR("ignore destination starting with '%c' ",*dst);
+ return EINA_FALSE;
+ }
+ if(dst[n-1]==EIOTAS_ACTION_SEP || dst[n-1]==EIOTAS_PATH_SEP ) {
+ ERR("ignore destination ending with '%c' ",dst[n-1]);
+ return EINA_FALSE;
+ }
+
+ s = eina_stringshare_add_length(dst,n);
+ eina_array_push(particle->dsts,s);
+ DBG("add dst >%s<",s);
+
+ return EINA_TRUE;
+}
+
EAPI void eiotas_particle_link_fields_set(Eiotas_Particle *particle, const char *link_fields)
{
int n;
diff --git a/tests/particle.c b/tests/particle.c
index 2734eff..b6ba450 100644
--- a/tests/particle.c
+++ b/tests/particle.c
@@ -19,7 +19,8 @@ void test_particle()
eiotas_particle_destinations_add(p0," dom0/room0/door0?get ");
eiotas_particle_destinations_add(p0,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get");
eiotas_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get , dom0/room0/door0?get ");
- eiotas_particle_destinations_add(p0," , , dom0/room0/room1/doorx?get,door?get ,, dom0/room0/door0?get ");
+ eiotas_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get, dom0/room0/door0?get ");
+ eiotas_particle_destinations_add(p0," /suffix, ?suffix, prefix/ , prefix? , ,, ");
acc = eina_array_accessor_new(p0->dsts);
eina_accessor_data_get(acc,0,&p);