[Asterisk-Dev] Misbehaviour in ast_variable_browse

Luis Vazquez luis at teledata.com.uy
Tue Feb 22 04:27:52 MST 2005


Sorry, there is obviously an error in my previous mail argumentation.

I we were to use the same "next" approach with ast_category_browse() as 
suggested with ast_variable_browse(), the prototype would suffix to be:

struct  ast_category *ast_category_browse(struct ast_config *config) ;

and would be used like this:

cat = ast_category_browse(cfg);
while(cat) {
   /* do our thinng */
   cat = cat->next;
}

It's not done that way (for whatever reason) so the same criterium 
should apply to ast_variable_browse.

bye,
Luis


Luis Vazquez wrote:

> Hello again Brian.
> It seem now you have readed my email to the end ;)
> Ok, you are right.
> Anybody could do it that way, even that was the first way I solved the 
> problem ...
> but I don't think that's good programming practice.
> What if tomorrow anybody changes the way the variables list is 
> implemented?  This way in the application I would be mixing the 
> application api with the private implementation code (v->next?)
> If not what is the reason we have the current definition of 
> ast_category_browse() :
>
> char *ast_category_browse(struct ast_config *config, char *prev)
>
> to be used with this semantic:
>
> cat = ast_category_browse(cfg, NULL);
> while(cat) {
>     ...
>    cat = ast_category_browse(cfg, cat);
> }
>
> to be consistent with the same approach you apply to 
> ast_variable_browse, the definition of ast_category_browse() should be:
> struct  ast_category *ast_category_browse(struct ast_config *config, 
> struct  ast_category *prev)
>
> an you could do this:
>
> cat = ast_category_browse(cfg, NULL);
> while(cat) {
>    /* do our thinng */
>    cat = cat->next;
> }
>
>
> So to resume my statement is not
> "it is not possible to do this with the current implementation"
> but
> "I think the way it's implemented now is not correct by two reasons:
>
> 1) is not consistent con ast_category_browse()´s semantic
> 2) to solve a simple problem (traverse all the vars in a config 
> category) you must break the data encapsulation and depend on the 
> internal implementation of the var list.
>
> Not a problem for me, only wanting to contribute to get a better 
> asterisk api even in a minor point like this.
> Best regards,
> Luis
>
>
>
> Brian West wrote:
>
>> Also on more thinking you can do this too(and reading this again):
>>
>> v = ast_variable_browse(cfg, "mystuff");
>> while(v) {
>>     /* do our thinng */
>>     v = v->next;
>> }
>>
>> You could also do:
>>
>> for (v = ast_variable_browse(config, "mystuff"); v; v = v->next) {
>>     /* do our thing here */
>> }
>>
>> /b
>>




More information about the asterisk-dev mailing list