/* Post raw to a user and propagate it to all of it's subuser */ void post_raw(RAW *raw, USERS *user, acetables *g_ape) { subuser *sub = user->subuser; while (sub != NULL) { post_raw_sub(copy_raw_z(raw), sub, g_ape); sub = sub->next; } }
/* Post raw to a user and propagate it to all of it's subuser with *sub exception */ void post_raw_restricted(RAW *raw, USERS *user, subuser *sub, acetables *g_ape) { subuser *tSub = user->subuser; if (sub == NULL) { return; } while (tSub != NULL) { if (sub != tSub) { post_raw_sub(copy_raw_z(raw), tSub, g_ape); } tSub = tSub->next; } }
void sendback_session(USERS *user, session *sess, acetables *g_ape) { subuser *current = user->subuser; while (current != NULL) { if (current->need_update) { json_item *jlist = json_new_object(), *jobj_item = json_new_object(); RAW *newraw; current->need_update = 0; json_set_property_strZ(jobj_item, sess->key, sess->val); json_set_property_objN(jlist, "sessions", 8, jobj_item); newraw = forge_raw("SESSIONS", jlist); newraw->priority = RAW_PRI_HI; post_raw_sub(copy_raw_z(newraw), current, g_ape); } current = current->next; } }
subuser *addsubuser(ape_socket *client, const char *channel, USERS *user, acetables *g_ape) { subuser *sub; if (getsubuser(user, channel) != NULL || strlen(channel) > MAX_HOST_LENGTH) { return NULL; } sub = xmalloc(sizeof(*sub)); sub->client = client; sub->state = ADIED; sub->user = user; memcpy(sub->channel, channel, strlen(channel)+1); sub->next = user->subuser; sub->nraw = 0; sub->wait_for_free = 0; sub->properties = NULL; sub->headers.sent = 0; sub->headers.content = NULL; sub->burn_after_writing = 0; sub->idle = time(NULL); sub->need_update = 0; sub->current_chl = 0; sub->raw_pools.nraw = 0; /* Pre-allocate a pool of raw to reduce the number of malloc calls */ /* Low priority raws */ sub->raw_pools.low.nraw = 0; sub->raw_pools.low.size = 32; sub->raw_pools.low.rawhead = init_raw_pool(sub->raw_pools.low.size); sub->raw_pools.low.rawfoot = sub->raw_pools.low.rawhead; /* High priority raws */ sub->raw_pools.high.nraw = 0; sub->raw_pools.high.size = 8; sub->raw_pools.high.rawhead = init_raw_pool(sub->raw_pools.high.size); sub->raw_pools.high.rawfoot = sub->raw_pools.high.rawhead; (user->nsub)++; user->subuser = sub; /* if the previous subuser have some messages in queue, copy them to the new subuser */ if (sub->next != NULL && sub->next->raw_pools.low.nraw) { struct _raw_pool *rTmp; for (rTmp = sub->next->raw_pools.low.rawhead; rTmp->raw != NULL; rTmp = rTmp->next) { if (rTmp->raw->refcount == 0) { rTmp->raw->refcount = 1; } post_raw_sub(copy_raw_z(rTmp->raw), sub, g_ape); } } FIRE_EVENT_NONSTOP(addsubuser, sub, g_ape); return sub; }