[asterisk-commits] tilghman: branch group/manager_http_auth r187876 - /team/group/manager_http_a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 10 15:19:09 CDT 2009
Author: tilghman
Date: Fri Apr 10 15:19:04 2009
New Revision: 187876
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=187876
Log:
28 Crashes Later...
Modified:
team/group/manager_http_auth/main/astobj2.c
team/group/manager_http_auth/main/manager.c
Modified: team/group/manager_http_auth/main/astobj2.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/main/astobj2.c?view=diff&rev=187876&r1=187875&r2=187876
==============================================================================
--- team/group/manager_http_auth/main/astobj2.c (original)
+++ team/group/manager_http_auth/main/astobj2.c Fri Apr 10 15:19:04 2009
@@ -113,7 +113,17 @@
p = (struct astobj2 *) ((char *) user_data - sizeof(*p));
if (AO2_MAGIC != (p->priv_data.magic) ) {
+ unsigned char *a;
+ int i = 0;
+ char data[sizeof(p->priv_data) * 3 + 1] = "";
+ for (a = (unsigned char *)&p->priv_data; a < (unsigned char *)&p->priv_data + sizeof(p->priv_data); a++) {
+ unsigned char n1 = *a >> 4, n2 = *a & 0xf;
+ data[i++] = n1 < 10 ? '0' + n1 : 'A' + n1 - 10;
+ data[i++] = n2 < 10 ? '0' + n2 : 'A' + n2 - 10;
+ data[i++] = ' ';
+ }
ast_log(LOG_ERROR, "bad magic number 0x%x for %p\n", p->priv_data.magic, p);
+ ast_log(LOG_ERROR, "Raw privdata dump: %s\n", data);
p = NULL;
}
@@ -236,7 +246,9 @@
if (delta != 0) {
FILE *refo = fopen(REF_FILE,"a");
- fprintf(refo, "%p %s%d %s:%d:%s (%s) [@%d]\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag, obj->priv_data.ref_counter);
+ fprintf(refo, "%p %s%d %s:%d:%s (%s)\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag);
+ fflush(refo);
+ fprintf(refo, "%p %s%d %s:%d:%s (%s) [@%d]\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag, obj ? obj->priv_data.ref_counter : -1);
fclose(refo);
}
if (obj->priv_data.ref_counter + delta == 0 && obj->priv_data.destructor_fn != NULL) { /* this isn't protected with lock; just for o/p */
@@ -428,7 +440,7 @@
return NULL;
c->version = 1; /* 0 is a reserved value here */
- c->n_buckets = n_buckets;
+ c->n_buckets = hash_fn ? n_buckets : 1;
c->hash_fn = hash_fn ? hash_fn : hash_zero;
c->cmp_fn = cmp_fn;
@@ -444,10 +456,11 @@
{
/* XXX maybe consistency check on arguments ? */
/* compute the container size */
- size_t container_size = sizeof(struct ao2_container) + n_buckets * sizeof(struct bucket);
+ const unsigned int num_buckets = hash_fn ? n_buckets : 1;
+ size_t container_size = sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
struct ao2_container *c = __ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname);
- return internal_ao2_container_alloc(c, n_buckets, hash_fn, cmp_fn);
+ return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn);
}
struct ao2_container *__ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn,
@@ -456,10 +469,11 @@
/* XXX maybe consistency check on arguments ? */
/* compute the container size */
- size_t container_size = sizeof(struct ao2_container) + n_buckets * sizeof(struct bucket);
+ const unsigned int num_buckets = hash_fn ? n_buckets : 1;
+ size_t container_size = sizeof(struct ao2_container) + num_buckets * sizeof(struct bucket);
struct ao2_container *c = __ao2_alloc(container_size, container_destruct);
- return internal_ao2_container_alloc(c, n_buckets, hash_fn, cmp_fn);
+ return internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn);
}
/*!
Modified: team/group/manager_http_auth/main/manager.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/manager_http_auth/main/manager.c?view=diff&rev=187876&r1=187875&r2=187876
==============================================================================
--- team/group/manager_http_auth/main/manager.c (original)
+++ team/group/manager_http_auth/main/manager.c Fri Apr 10 15:19:04 2009
@@ -51,6 +51,8 @@
#include <sys/time.h>
#include <signal.h>
#include <sys/mman.h>
+
+#define REF_DEBUG 1
#include "asterisk/channel.h"
#include "asterisk/file.h"
@@ -228,7 +230,7 @@
int fd;
};
-static struct ao2_container *sessions;
+static struct ao2_container *sessions = NULL;
#define NEW_EVENT(m) (AST_LIST_NEXT(m->session->last_ev, eq_next))
@@ -3143,7 +3145,6 @@
int (*call_func)(struct mansession *s, const struct message *m) = NULL;
ast_copy_string(action, __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY), sizeof(action));
- ast_debug(1, "Manager received command '%s'\n", action);
if (ast_strlen_zero(action)) {
ao2_lock(s);
@@ -3176,16 +3177,18 @@
continue;
}
if (s->session->writeperm & tmp->authority || tmp->authority == 0) {
- ret = tmp->func(s, m);
+ call_func = tmp->func;
} else {
astman_send_error(s, m, "Permission denied");
+ tmp = NULL;
}
break;
}
AST_RWLIST_UNLOCK(&actions);
- if (tmp) {
+ if (tmp && call_func) {
/* call AMI function after actions list are unlocked */
+ ast_debug(1, "Running action '%s'\n", tmp->action);
ret = call_func(s, m);
} else {
char buf[512];
@@ -3413,7 +3416,7 @@
session->username, ast_inet_ntoa(session->sin.sin_addr));
}
ao2_unlock(session);
- /* session_destroy(session); */
+ session_destroy(session);
n_max--;
} else {
ao2_unlock(session);
@@ -4085,15 +4088,15 @@
s.session = session;
s.fd = mkstemp(template); /* create a temporary file for command output */
unlink(template);
- if (session->fd <= -1) {
+ if (s.fd <= -1) {
ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n");
goto generic_callback_out;
}
- session->f = fdopen(session->fd, "w+");
- if (!session->f) {
+ s.f = fdopen(s.fd, "w+");
+ if (!s.f) {
ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n");
- close(session->fd);
+ close(s.fd);
goto generic_callback_out;
}
@@ -4246,7 +4249,7 @@
struct ast_variable *v, *params = get_params;
char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */
struct ast_str *http_header = NULL, *out = NULL;
- size_t result_size = 0;
+ size_t result_size = 512;
struct message m = { 0 };
unsigned int x;
size_t hdrlen;
@@ -4435,17 +4438,18 @@
session->sessiontimeout = time(NULL) + (httptimeout > 5 ? httptimeout : 5);
ao2_unlock(session);
- session->fd = mkstemp(template); /* create a temporary file for command output */
+ s.session = session;
+ s.fd = mkstemp(template); /* create a temporary file for command output */
unlink(template);
- if (session->fd <= -1) {
+ if (s.fd <= -1) {
ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n");
goto auth_callback_out;
}
- session->f = fdopen(session->fd, "w+");
- if (!session->f) {
+ s.f = fdopen(s.fd, "w+");
+ if (!s.f) {
ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n");
- close(session->fd);
+ close(s.fd);
goto auth_callback_out;
}
@@ -4461,10 +4465,6 @@
m.hdrcount = x + 1;
}
- s.session = session;
- s.fd = mkstemp(template); /* create a temporary file for command output */
- unlink(template);
-
if (process_message(&s, &m)) {
if (u_displayconnects) {
ast_verb(2, "HTTP Manager '%s' logged off from %s\n", session->username, ast_inet_ntoa(session->sin.sin_addr));
@@ -4474,8 +4474,8 @@
session->needdestroy = 1;
}
- if (session->f) {
- result_size = ftell(session->f); /* Calculate aprox. size of result */
+ if (s.f) {
+ result_size = ftell(s.f); /* Calculate aprox. size of result */
}
http_header = ast_str_create(80);
@@ -5011,7 +5011,8 @@
AST_RWLIST_UNLOCK(&users);
if (!reload) {
- sessions = ao2_container_alloc(100, NULL, mansession_cmp_fn);
+ /* If you have a NULL hash fn, you only need a single bucket */
+ sessions = ao2_container_alloc(1, NULL, mansession_cmp_fn);
}
if (webmanager_enabled && manager_enabled) {
More information about the asterisk-commits
mailing list