static void expire_cookies(List *cookies) { Cookie *value = NULL; time_t now = 0; long pos = 0; if (cookies == NULL) { error(0, "expire_cookies: Null argument(s) - no Cookie list"); return; } /* Walk through the cookie cache */ time(&now); if (gwlist_len(cookies) > 0) { debug("wap.wsp.http", 0, "expire_cookies: Cookies in cache"); for (pos = 0; pos < gwlist_len(cookies); pos++) { value = gwlist_get(cookies, pos); gw_assert(value != NULL); if (value->max_age != -1) { /* Interesting value */ if (value->max_age + value->birth < now) { debug("wap.wsp.http", 0, "expire_cookies: Expired cookie (%s)", octstr_get_cstr(value->name)); cookie_destroy(value); gwlist_delete(cookies, pos, 1); } } } } else debug("wap.wsp.http", 0, "expire_cookies: No cookies in cache"); return; }
static int have_cookie(List *cookies, Cookie *cookie) { Cookie *value = NULL; long pos = 0; if (cookies == NULL || cookie == NULL) { error(0, "have_cookie: Null argument(s) - no Cookie list, Cookie or both"); return 0; } /* Walk through the cookie cache, comparing cookie */ while (pos < gwlist_len(cookies)) { value = gwlist_get(cookies, pos); /* octstr_compare() now only returns 0 on an exact match or if both args are 0 */ debug ("wap.wsp.http", 0, "have_cookie: Comparing name (%s:%s), path (%s:%s), domain (%s:%s)", octstr_get_cstr(cookie->name), octstr_get_cstr(value->name), octstr_get_cstr(cookie->path), octstr_get_cstr(value->path), octstr_get_cstr(cookie->domain), octstr_get_cstr(value->domain)); /* Match on no value or value and value equality for name, path and domain */ if ( (value->name == NULL || ((value->name != NULL && cookie->name != NULL) && octstr_compare(value->name, cookie->name) == 0)) && (value->path == NULL || ((value->path != NULL && cookie->path != NULL) && octstr_compare(value->path, cookie->path) == 0)) && (value->domain == NULL || ((value->domain != NULL && cookie->domain != NULL) && octstr_compare(value->domain, cookie->domain) == 0)) ) { /* We have a match according to 4.3.3 - discard the old one */ cookie_destroy(value); gwlist_delete(cookies, pos, 1); /* Discard the new cookie also if max-age is 0 - set if expiry date is up */ if (cookie->max_age == 0) { debug("wap.wsp.http", 0, "have_cookie: Discarding expired cookie (%s)", octstr_get_cstr(cookie->name)); return 1; } debug("wap.wsp.http", 0, "have_cookie: Updating cached cookie (%s)", octstr_get_cstr (cookie->name)); break; } else { pos++; } } return 0; }
/* Remove part i in list of body parts. */ void mime_entity_remove_part(MIMEEntity *e, int i) { MIMEEntity *m; gw_assert(e != NULL); gw_assert(i >= 0); gw_assert(i < gwlist_len(e->multiparts)); m = gwlist_get(e->multiparts, i); gwlist_delete(e->multiparts, i, 1); if (m == e->start) e->start = NULL; mime_entity_destroy(m); }
/* Replace part i in list of body parts. Old one will be deleted */ void mime_entity_replace_part(MIMEEntity *e, int i, MIMEEntity *newpart) { MIMEEntity *m; gw_assert(e != NULL); gw_assert(i >= 0); gw_assert(i < gwlist_len(e->multiparts)); m = gwlist_get(e->multiparts, i); gwlist_delete(e->multiparts, i, 1); gwlist_insert(e->multiparts, i, mime_entity_duplicate(newpart)); if (m == e->start) e->start = NULL; mime_entity_destroy(m); }
static void main_for_producer_and_consumer(void) { List *list; int i; Item *item; struct producer_info tab[NUM_PRODUCERS]; long p, n, index; int errors; list = gwlist_create(); init_received(); for (i = 0; i < NUM_PRODUCERS; ++i) { tab[i].list = list; tab[i].start_index = i * NUM_ITEMS_PER_PRODUCER; gwlist_add_producer(list); tab[i].id = gwthread_create(producer, tab + i); } for (i = 0; i < NUM_CONSUMERS; ++i) gwthread_create(consumer, list); gwthread_join_every(producer); gwthread_join_every(consumer); while (gwlist_len(list) > 0) { item = gwlist_get(list, 0); gwlist_delete(list, 0, 1); warning(0, "main: %ld %ld %ld", (long) item->producer, item->num, item->index); } errors = 0; for (p = 0; p < NUM_PRODUCERS; ++p) { for (n = 0; n < NUM_ITEMS_PER_PRODUCER; ++n) { index = p * NUM_ITEMS_PER_PRODUCER + n; if (!received[index]) { error(0, "Not received: producer=%ld " "item=%ld index=%ld", tab[p].id, n, index); errors = 1; } } } if (errors) panic(0, "Not all messages were received."); }
static List *make_mm_flags(List *oflags, List *flag_cmds) { List *l = oflags ? oflags : gwlist_create(); int i, n; for (i = 0, n = gwlist_len(l); i < n; i++) { /* cleanup list. */ Octstr *x = gwlist_get(l,i); int ch = octstr_get_char(x, 0); if (ch == '+' || ch == '-' || ch == '/') octstr_delete(x,0,1); } for (i = 0, n = (flag_cmds ? gwlist_len(flag_cmds) : 0); i<n; i++) { Octstr *x = gwlist_get(flag_cmds,i); int ch = octstr_get_char(x, 0); char *s = octstr_get_cstr(x); int j, m, cmd; if (ch == '+' || ch == '-' || ch == '/') { s++; cmd = ch; } else cmd = '+'; /* Find it in original. If existent, remove it. */ for (j = 0, m = gwlist_len(l); j < m; j++) if (octstr_str_compare(gwlist_get(l,j),s) == 0) { Octstr *y = gwlist_get(l,j); gwlist_delete(l,j,1); octstr_destroy(y); j--; m--; } if (cmd == '+' || cmd == '/') gwlist_append(l, octstr_create(s)); } return l; }
/* Remove any replies that have no corresponding request and that * are equal to the default. */ static void strip_default_capabilities(List *caps, List *req) { long i; Capability *cap; int count; /* Hmm, this is an O(N*N) operation, which may be bad. */ i = 0; while (i < gwlist_len(caps)) { cap = gwlist_get(caps, i); count = wsp_cap_count(req, cap->id, cap->name); if (count == 0 && is_default_cap(cap)) { gwlist_delete(caps, i, 1); wsp_cap_destroy(cap); } else { i++; } } }
unsigned int dbpool_check(DBPool *p) { long i, len, n = 0, reinit = 0; gw_assert(p != NULL && p->pool != NULL && p->db_ops != NULL); /* * First check if db_ops->check function pointer is here. * NOTE: db_ops->check is optional, so if it is not there, then * we have nothing todo and we simple return list length. */ if (p->db_ops->check == NULL) return gwlist_len(p->pool); gwlist_lock(p->pool); len = gwlist_len(p->pool); for (i = 0; i < len; i++) { DBPoolConn *pconn; pconn = gwlist_get(p->pool, i); if (p->db_ops->check(pconn->conn) != 0) { /* something was wrong, reinitialize the connection */ gwlist_delete(p->pool, i, 1); dbpool_conn_destroy(pconn); p->curr_size--; reinit++; len--; i--; } else { n++; } } gwlist_unlock(p->pool); /* reinitialize brocken connections */ if (reinit > 0) n += dbpool_increase(p, reinit); return n; }
static void sanitize_capabilities(List *caps, WSPMachine *m) { long i; Capability *cap; unsigned long ui; for (i = 0; i < gwlist_len(caps); i++) { cap = gwlist_get(caps, i); /* We only know numbered capabilities. Let the application * layer negotiate whatever it wants for unknown ones. */ if (cap->name != NULL) continue; switch (cap->id) { case WSP_CAPS_CLIENT_SDU_SIZE: /* Check if it's a valid uintvar. The value is the * max SDU size we will send, and there's no * internal limit to that, so accept any value. */ if (cap->data != NULL && octstr_extract_uintvar(cap->data, &ui, 0) < 0) goto bad_cap; else m->client_SDU_size = ui; break; case WSP_CAPS_SERVER_SDU_SIZE: /* Check if it's a valid uintvar */ if (cap->data != NULL && (octstr_extract_uintvar(cap->data, &ui, 0) < 0)) goto bad_cap; /* XXX Our MRU is not quite unlimited, since we * use signed longs in the library functions -- * should we make sure we limit the reply value * to LONG_MAX? (That's already a 2GB packet) */ break; case WSP_CAPS_PROTOCOL_OPTIONS: /* Currently we don't support any Push, nor * session resume, nor acknowledgement headers, * so make sure those bits are not set. */ if (cap->data != NULL && octstr_len(cap->data) > 0 && (octstr_get_char(cap->data, 0) & 0xf0) != 0) { warning(0, "WSP: Application layer tried to " "negotiate protocol options."); octstr_set_bits(cap->data, 0, 4, 0); } break; case WSP_CAPS_EXTENDED_METHODS: /* XXX Check format here */ break; case WSP_CAPS_HEADER_CODE_PAGES: /* We don't support any yet, so don't let this * be negotiated. */ if (cap->data) goto bad_cap; break; } continue; bad_cap: error(0, "WSP: Found illegal value in capabilities reply."); wsp_cap_dump(cap); gwlist_delete(caps, i, 1); i--; wsp_cap_destroy(cap); continue; } }