From 1f57cd4e5150eb916b30f5183deb3449a0d6795d Mon Sep 17 00:00:00 2001 From: russell Date: Tue, 17 Feb 2009 20:41:24 +0000 Subject: Merge a large set of updates to the Asterisk indications API. This patch includes a number of changes to the indications API. The primary motivation for this work was to improve stability. The object management in this API was significantly flawed, and a number of trivial situations could cause crashes. The changes included are: 1) Remove the module res_indications. This included the critical functionality that actually loaded the indications configuration. I have seen many people have Asterisk problems because they accidentally did not have an indications.conf present and loaded. Now, this code is in the core, and Asterisk will fail to start without indications configuration. There was one part of res_indications, the dialplan applications, which did belong in a module, and have been moved to a new module, app_playtones. 2) Object management has been significantly changed. Tone zones are now managed using astobj2, and it is no longer possible to crash Asterisk by issuing a reload that destroys tone zones while they are in use. 3) The API documentation has been filled out. 4) The API has been updated to follow our naming conventions. 5) Various bits of code throughout the tree have been updated to account for the API update. 6) Configuration parsing has been mostly re-written. 7) "Code cleanup" The code is from svn/asterisk/team/russell/indications/. Review: http://reviewboard.digium.com/r/149/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@176627 f38db490-d61c-443f-a65b-d21fe96a405b --- res/snmp/agent.c | 60 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'res/snmp') diff --git a/res/snmp/agent.c b/res/snmp/agent.c index 0a47879cf..f7e08220d 100644 --- a/res/snmp/agent.c +++ b/res/snmp/agent.c @@ -644,23 +644,34 @@ static u_char *ast_var_indications(struct variable *vp, oid *name, size_t *lengt int exact, size_t *var_len, WriteMethod **write_method) { static unsigned long long_ret; - struct tone_zone *tz = NULL; + static char ret_buf[128]; + struct ast_tone_zone *tz = NULL; if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; switch (vp->magic) { case ASTINDCOUNT: + { + struct ao2_iterator i; + long_ret = 0; - while ( (tz = ast_walk_indications(tz)) ) + + i = ast_tone_zone_iterator_init(); + while ((tz = ao2_iterator_next(&i))) { + tz = ast_tone_zone_unref(tz); long_ret++; + } - return (u_char *)&long_ret; + return (u_char *) &long_ret; + } case ASTINDCURRENT: tz = ast_get_indication_zone(NULL); if (tz) { - *var_len = strlen(tz->country); - return (u_char *)tz->country; + ast_copy_string(ret_buf, tz->country, sizeof(ret_buf)); + *var_len = strlen(ret_buf); + tz = ast_tone_zone_unref(tz); + return (u_char *) ret_buf; } *var_len = 0; return NULL; @@ -674,34 +685,47 @@ static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t int exact, size_t *var_len, WriteMethod **write_method) { static unsigned long long_ret; - struct tone_zone *tz = NULL; + static char ret_buf[256]; + struct ast_tone_zone *tz = NULL; int i; + struct ao2_iterator iter; - if (header_simple_table(vp, name, length, exact, var_len, write_method, -1)) + if (header_simple_table(vp, name, length, exact, var_len, write_method, -1)) { return NULL; + } i = name[*length - 1] - 1; - while ( (tz = ast_walk_indications(tz)) && i ) - i--; - if (tz == NULL) + + iter = ast_tone_zone_iterator_init(); + + while ((tz = ao2_iterator_next(&iter)) && i) { + tz = ast_tone_zone_unref(tz); + i--; + } + + if (tz == NULL) { return NULL; + } switch (vp->magic) { case ASTINDINDEX: long_ret = name[*length - 1]; return (u_char *)&long_ret; case ASTINDCOUNTRY: - *var_len = strlen(tz->country); - return (u_char *)tz->country; + ast_copy_string(ret_buf, tz->country, sizeof(ret_buf)); + tz = ast_tone_zone_unref(tz); + *var_len = strlen(ret_buf); + return (u_char *) ret_buf; case ASTINDALIAS: - if (tz->alias) { - *var_len = strlen(tz->alias); - return (u_char *)tz->alias; - } + /* No longer exists */ return NULL; case ASTINDDESCRIPTION: - *var_len = strlen(tz->description); - return (u_char *)tz->description; + ast_tone_zone_lock(tz); + ast_copy_string(ret_buf, tz->description, sizeof(ret_buf)); + ast_tone_zone_unlock(tz); + tz = ast_tone_zone_unref(tz); + *var_len = strlen(ret_buf); + return (u_char *) ret_buf; default: break; } -- cgit v1.2.3