git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4968 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-04-18 16:10:46 +00:00
parent 376d177b3c
commit fbf2a1cb79
7 changed files with 72 additions and 46 deletions

View File

@ -24,12 +24,13 @@ void *iks_stack_alloc (ikstack *s, size_t size);
char *iks_stack_strdup (ikstack *s, const char *src, size_t len);
char *iks_stack_strcat (ikstack *s, char *old, size_t old_len, const char *src, size_t src_len);
void iks_stack_stat (ikstack *s, size_t *allocated, size_t *used);
void iks_stack_delete (ikstack *s);
void iks_stack_delete (ikstack **sp);
/***** utilities *****/
void *iks_malloc (size_t size);
void iks_free (void *ptr);
void iks_real_free (void *ptr);
void iks_set_mem_funcs (void *(*malloc_func)(size_t size), void (*free_func)(void *ptr));
char *iks_strdup (const char *src);
@ -42,6 +43,8 @@ size_t iks_strlen (const char *src);
char *iks_escape (ikstack *s, char *src, size_t len);
char *iks_unescape (ikstack *s, char *src, size_t len);
#define iks_free(p) if (p) {iks_real_free(p) ; p = NULL;}
/***** dom tree *****/
enum ikstype {

View File

@ -96,7 +96,7 @@ iks_filter_remove_rule (iksfilter *f, iksrule *rule)
if (rule->next) rule->next->prev = rule->prev;
if (f->rules == rule) f->rules = rule->next;
if (f->last_rule == rule) f->last_rule = rule->prev;
iks_stack_delete (rule->s);
iks_stack_delete (&rule->s);
}
void
@ -174,7 +174,7 @@ iks_filter_delete (iksfilter *f)
rule = f->rules;
while (rule) {
tmp = rule->next;
iks_stack_delete (rule->s);
iks_stack_delete (&rule->s);
rule = tmp;
}
iks_free (f);

View File

@ -60,7 +60,7 @@ iks_new (const char *name)
if (!s) return NULL;
x = iks_new_within (name, s);
if (!x) {
iks_stack_delete (s);
iks_stack_delete (&s);
return NULL;
}
return x;
@ -202,7 +202,7 @@ iks_hide (iks *x)
void
iks_delete (iks *x)
{
if (x) iks_stack_delete (x->s);
if (x) iks_stack_delete (&x->s);
}
/***** Node Traversing *****/

View File

@ -182,10 +182,20 @@ iks_stack_stat (ikstack *s, size_t *allocated, size_t *used)
}
void
iks_stack_delete (ikstack *s)
iks_stack_delete (ikstack **sp)
{
ikschunk *c, *tmp;
ikstack *s;
if (!sp) {
return;
}
s = *sp;
if (!s) {
return;
}
c = s->meta->next;
while (c) {
tmp = c->next;
@ -199,4 +209,5 @@ iks_stack_delete (ikstack *s)
c = tmp;
}
iks_free (s);
*sp = NULL;
}

View File

@ -629,5 +629,5 @@ iks_parser_delete (iksparser *prs)
if (prs->deleteHook) prs->deleteHook (prs->user_data);
if (prs->stack) iks_free (prs->stack);
if (prs->atts) iks_free (prs->atts);
if (prs->s) iks_stack_delete (prs->s); else iks_free (prs);
if (prs->s) iks_stack_delete (&prs->s); else iks_free (prs);
}

View File

@ -22,7 +22,7 @@ iks_malloc (size_t size)
}
void
iks_free (void *ptr)
iks_real_free (void *ptr)
{
if (my_free_func)
my_free_func (ptr);

View File

@ -595,8 +595,8 @@ static int on_disco_default(void *user_data, ikspak *pak)
iks_insert_attrib(tag, "var", FEATURES[x].name);
}
}
iks_send(handle->parser, iq);
apr_queue_push(handle->queue, iq);
iq = NULL;
send = 1;
}
fail:
@ -919,8 +919,8 @@ static int on_commands(void *user_data, ikspak *pak)
iks_insert_attrib(x, "xmlns:gr", "google:roster");
iks_insert_attrib(x, "gr:ext", "2");
iks_insert_attrib(x, "gr:include", "all");
iks_send(handle->parser, iq);
iks_delete(iq);
apr_queue_push(handle->queue, iq);
iq = NULL;
break;
}
#endif
@ -1123,14 +1123,14 @@ static int on_stream(ldl_handle_t *handle, int type, iks *node)
iks *t;
if (handle->features & IKS_STREAM_BIND) {
t = iks_make_resource_bind(handle->acc);
iks_send(handle->parser, t);
iks_delete(t);
apr_queue_push(handle->queue, t);
t = NULL;
}
if (handle->features & IKS_STREAM_SESSION) {
t = iks_make_session();
iks_insert_attrib(t, "id", "auth");
iks_send(handle->parser, t);
iks_delete(t);
apr_queue_push(handle->queue, t);
t = NULL;
}
} else {
if (handle->features & IKS_STREAM_SASL_MD5) {
@ -1150,8 +1150,8 @@ static int on_stream(ldl_handle_t *handle, int type, iks *node)
slen = (uint32_t)(strlen(handle->acc->user) + strlen(handle->password) + 2);
b64encode((unsigned char *)s, slen, (unsigned char *) base64, sizeof(base64));
iks_insert_cdata(x, base64, 0);
iks_send(handle->parser, x);
iks_delete(x);
apr_queue_push(handle->queue, x);
x = NULL;
} else {
globals.logger(DL_LOG_DEBUG, "Memory ERROR!\n");
break;
@ -1303,45 +1303,57 @@ static void j_setup_filter(ldl_handle_t *handle)
static void ldl_flush_queue(ldl_handle_t *handle, int done)
{
iks *msg;
void *pop;
void *pop = NULL;
unsigned int len = 0, x = 0;
while(apr_queue_trypop(handle->queue, &pop) == APR_SUCCESS) {
msg = (iks *) pop;
iks_send(handle->parser, msg);
iks_delete(msg);
if (pop) {
msg = (iks *) pop;
iks_send(handle->parser, msg);
iks_delete(msg);
pop = NULL;
} else {
break;
}
}
len = apr_queue_size(handle->retry_queue);
if (globals.debug && len) {
globals.logger(DL_LOG_DEBUG, "Processing %u packets in retry queue\n", len);
}
apr_thread_mutex_lock(handle->lock);
while(x < len && apr_queue_trypop(handle->retry_queue, &pop) == APR_SUCCESS) {
struct packet_node *packet_node = (struct packet_node *) pop;
apr_time_t now = apr_time_now();
x++;
if (packet_node->next <= now) {
if (packet_node->retries > 0) {
packet_node->retries--;
if (globals.debug) {
globals.logger(DL_LOG_DEBUG, "Sending packet %s (%d left)\n", packet_node->id, packet_node->retries);
}
iks_send(handle->parser, packet_node->xml);
packet_node->next = now + 5000000;
}
}
if (packet_node->retries == 0 || done) {
if (globals.debug) {
globals.logger(DL_LOG_DEBUG, "Discarding packet %s\n", packet_node->id);
}
apr_hash_set(handle->retry_hash, packet_node->id, APR_HASH_KEY_STRING, NULL);
iks_delete(packet_node->xml);
free(packet_node);
pop = NULL;
while(x < len && apr_queue_trypop(handle->retry_queue, &pop) == APR_SUCCESS) {
if (!pop) {
break;
} else {
apr_queue_push(handle->retry_queue, packet_node);
struct packet_node *packet_node = (struct packet_node *) pop;
apr_time_t now = apr_time_now();
x++;
if (packet_node->next <= now) {
if (packet_node->retries > 0) {
packet_node->retries--;
if (globals.debug) {
globals.logger(DL_LOG_DEBUG, "Sending packet %s (%d left)\n", packet_node->id, packet_node->retries);
}
iks_send(handle->parser, packet_node->xml);
packet_node->next = now + 5000000;
}
}
if (packet_node->retries == 0 || done) {
if (globals.debug) {
globals.logger(DL_LOG_DEBUG, "Discarding packet %s\n", packet_node->id);
}
apr_hash_set(handle->retry_hash, packet_node->id, APR_HASH_KEY_STRING, NULL);
iks_delete(packet_node->xml);
free(packet_node);
} else {
apr_queue_push(handle->retry_queue, packet_node);
}
pop = NULL;
}
}
apr_thread_mutex_unlock(handle->lock);