farsightsec / nmsg

network message encapsulation library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

need way to get maximum val_idx for a field

vschryver opened this issue · comments

This is the only current way to get all instances of a field:

for (val_idx = 0; ; ++val_idx)  {
    res = nmsg_message_get_field_by_idx(...val_idx...)
    if (res != nmsg_res_success)
         break;

Robert said "There ought to be a better way (maybe some new function) ..."
I added "Another tolerable way might be a new error value for val_idx>max, but that would be less convenient and might be slower than a function that simply returns the maximum.

nmsg_message_get_num_field_values and $1_by_idx were removed in 5d2905c. @edmonds is there a reason not to revert it?

That commit is from 2010, I kind of doubt it can be textually reverted, or if it can, whether it would still compile or work.

I also can't remember if there was a specific reason I removed those functions (maybe it simplified something else), or if I just removed them because they didn't look particularly useful (e.g. the Python bindings didn't really need them: b51f489).

For context, the nmsg_message_get_*() and nmsg_message_set_*() interfaces weren't in the original libnmsg API; they were specifically added later so that pynmsg could benefit from the "virtual field" stuff, I think.

Anyway, I don't have any particularly strong objection to adding new functions with the same names and prototypes and behavior as the original ones, but it's possible the implementation might need to be updated to keep up with post-2010 libnmsg changes.