Andrew Baumann wrote:
> On Sunday 10 September 2006 20:04, Armin Bauer wrote:
>> Lets say we write a "categories" filter, which only allows changes whi=
>> match a given category. So a module registers this filter with the nam=
>> "categories". Then a user decides, he wants to use this filter. So in
>> the member config, there should be a entry:
>> Information about how the filter should be applied (which objtypes,=
>> direction etc)
>> This entry tell opensync to use the categories filter, look at the rul=
>> to see if a object matches, and if it matches it calls the filter with=
>> the config given. If the filter returns TRUE (=3D=3D filter matches), =
>> action is executed.
> Ok, that sounds fair enough. But do you really want the filter function=
> parsing the configuration string each time? I would expect that filters=
> other plugins, get their configuration data once at load time, parse it=
> some internal format, and then get invoked with that each time. The cos=
> parsing a configuration string that could be XML or whatever seems too =
> to be doing it on every filter invocation.
ok. then we would need to have some sort of initialize_filter and
finalize_filter functions. Sounds like a good idea.
>> Andrew Baumann wrote:
>> This is most likely a bug. Lets look at the categories filter from
>> above. We would probably register this filter for the format
>> "xml-contact" since we need to look at the xml tree to see the
>> categories. If a object gets passed to use with a different format, t=
>> filter would probably crash.
> Well, the format is specified again later in osync_filter_add_custom, a=
> one is used.=20
>> So that NULL works for you is probably luck and not intended. :)
>> again, see the categories example. the config needs to be a string to =
>> able to save it in the member config.
>> As i understand you, you want to pass around a pointer to a object. I
>> think for this we can add a user_data pointer. do you think this would=
>> work for you?
> Yes, that would be fine for me. However I'd also need to get a callback=
> the filter is removed to be able to free the pointer, unless opensync=20
> requires that only the plugin/member that installed a filter will remov=
this could be done in finalize_filter
>> Maybe it could work like this:
>> in the python module, opensync calls initialize. then the module loads=
>> all python scripts using the register_plugin function. I think this
>> should be changed so that it either registers a plugin or optionally a=
>> filter (using a get_filter function in the python script).
> That sounds good, except I'd want to allow a module to register a plugi=
> multiple filters.
> Let me explain where I'm coming from: in moto-sync there are some entri=
> we can't store on the phone, for example a lot of recurring events can'=
> represented with the correct recurrence. I want to have a filter to rem=
> these so that opensync doesn't try to write them to the phone. This fil=
> wouldn't be configured separately to moto-sync, and it's not really=20
> optional -- it would always be installed by the moto-sync plugin.
> I could implement the same thing in the plugin directly (ie. just ignor=
> objects that can't be handled), but this will confuse opensync the next=
> we sync and that object is gone. I was hoping/expecting that by using a=
> filter, opensync would remember that the object had been filtered out, =
> not expect to see it on the next run. Is that actually true? Is there a=
> of reporting the same thing to opensync from within the plugin's=20
> commit_change method? In that case I wouldn't need to bother with filte=
when exactly would opensync expect this object the next time?
in the case of a fast-sync, you just dont report the object anymore.
in the case of a slow-sync, opensync would not be able to read the
object. so it would try to write it again, which would again be filtered.=
>> The name of the filter should not be set to "python filter wrapper"
>> since this would only allow a single filter in python to be registered=
>> The name has to be set by the python script.
> No, that's not true. I'm running multiple python filters through the si=
> wrapper function. I call osync_env_register_filter_function once to reg=
> the wrapper function with that name, and then later I can call=20
> osync_filter_add_custom as many times as I like, and give each instance=
> the "python filter wrapper" a different config string.
> Maybe this isn't what you intended, but it's what the code does at the =
> As I said, it doesn't make a lot of sense to me that we first register =
> filter function by name, and then later create multiple filters for tha=
> function using its name.
Ok. i see that i can work like this. but this is really not what i
the name is just used so that we can save the name in the member config
and later know again which filter to instanciate.
>> So the initialize process of the filter should be similar to the plugi=
>> (if we add the user_data pointer to env_register_filter_function).
> See above -- I think the filter should be given its config string (if o=
> exists) and be able to parse it into a user_data pointer. This should h=
> only once when the filter is installed/registered/whatever.
>> maybe we should seperate the matching filters and the actions. So that=
>> you can register a filter which returns TRUE or FALSE by looking at th=
>> data and actions. There would be default actions coming with opensync
>> like ALLOW, DROP, etc. But if you want to modify the data through the
>> filter, you can write your own action.
> Hmm, what is an action, if not just a change to the contents of the ch=
> object? On IRC you told me:
> <abauer> abtronic: you need to write a custom filter which triggers on=
> changes going to your plugin. then you need to check the recurrence
> <abauer> abtronic: if it should be deleted, you need to replace the ch=
> with a deleted change
> If a filter can do this already (replace the change), I'm not sure ther=
> need for separate actions. Of course it would probably be good for code=
> if the actions gets more complicated, I don't mind if you want to do th=
The idea is just to seperate the detection and the action. For example:
you would require a filter to detect if the change has a recurrence.
Your action would be to delete (or drop) it on the device (not on all
devices!). The action will probably also be useful to other people as
well, so it could be provided with opensync itself.
> I think the cleanest model would be something where filters are a more =
> fundamental part of opensync like plugins. Let's say that each filter i=
> registered with a couple of functions (the names/variables are somewhat=
> arbitrary here, I'm just trying to give you the idea):
> void osync_filter_set_userdata(OSyncFilter *filter, void *data);
> void osync_filter_get_userdata(OSyncFilter *filter, void *data);
> void osync_filter_set_config(OSyncFilter *filter, const char *data);
> void osync_filter_get_config(OSyncFilter *filter, const char *data);
> typedef OSyncFilterAction (*OSyncFilterFunction)(OSyncFilter*, OSyncCha=
> typedef void (*OSyncFilterParseConfig)(OSyncFilter *);
> typedef void (*OSyncFilterCleanup)(OSyncFilter *);
> osync_bool osync_filter_register_function(const char *name,=20
> OSyncFilterFunction, OSyncFilterParseConfig, OSyncFilterCleanup);
> OSyncFilter *osync_filter_add_custom(OSyncGroup *group,
> OSyncMember *sourcemember, OSyncMember *destmember,
> const char *sourceobjtype, const char *destobjtype,
> const char *detectobjtype, const char *function_name);
> The OSyncFilterParseConfig functions would be expected to parse the con=
> call the osync_filter_set_userdata function on the filter. Because the =
> object itself is passed to the filter function, we could store other th=
> in there that might be useful (like the config data pointer, or the=20
> OSyncPlugin that loaded it).
> If opensync was loading a filter automatically because the user had it =
> configured for that sync group, it would do a call to osync_filter_add_=
> followed by osync_filter_set_config (which would call the=20
> OSyncFilterParseConfig function if one was registered for that function=
> If I (as a plugin writer) need to load a special filter as part of my p=
> I'd do something like:
> osync_filter_register_function("some name", function, NULL, cleanup_fun=
> f =3D osync_filter_add_custom(mygroup, NULL, mymember, NULL, myobjtype,=
> NULL, "some name");
> osync_filter_set_userdata(f, my data pointer);
> ... so it's desirable that osync_filter_register_function be able to be=
> later than plugin load time.
> Does this make sense? Do you understand where I'm coming from? Maybe fi=
> aren't even the right thing for what I want to do, but I think the curr=
> API isn't ideal. IMHO you don't want filter functions parsing textual c=
> strings each time they're invoked, and the current setup requires this.=
agreed. yes i think i understand what your trying to accomplish. The
only part im not yet sure about is: Your plugin always requires this
filter to be present to be working. So i have to give a option to tell
opensync during initialize, which filters should be loaded (together
with a optional config string).