void at_auth_subscribe(ati ti, jpacket jp) { /* Here we actually subscribe to the user */ xmlnode x; jid jnew; x = xmlnode_new_tag("presence"); jnew = jid_new(xmlnode_pool(x), ti->i->id); jid_set(jnew, "registered", JID_RESOURCE); log_debug(ZONE, "[AIM] Subscribing to %s presence\n", jid_full(jp->from)); xmlnode_put_attrib(x, "to", jid_full(jp->from)); xmlnode_put_attrib(x, "from", jid_full(jnew)); xmlnode_put_attrib(x, "type", "subscribe"); at_deliver(ti,x); return; }
/* Browse for members of a room */ void con_room_browsewalk(gpointer key, gpointer data, gpointer arg) { jid userjid; cnu user = (cnu)data; xmlnode q = (xmlnode)arg; xmlnode xml; if(user == NULL || q == NULL) { log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE); return; } xml = xmlnode_insert_tag(q, "item"); userjid = jid_new(xmlnode_pool(xml), jid_full(user->room->id)); jid_set(userjid, user->localid->resource, JID_RESOURCE); xmlnode_put_attrib(xml, "category", "user"); xmlnode_put_attrib(xml, "type", "client"); xmlnode_put_attrib(xml, "name", user->localid->resource); xmlnode_put_attrib(xml, "jid", jid_full(userjid)); }
/* * js_session_new -- creates a new session, registers the resource for it * * Sets up all the data associated with the new session, then send it a * start spacket, which basically notifies all modules about the new session * * returns * a pointer to the new session */ session js_session_new(jsmi si, dpacket dp) { pool p; session s, cur; udata u; int i; char routeres[10]; /* screen out illegal calls */ if (dp == NULL || dp->id->user == NULL || dp->id->resource == NULL || xmlnode_get_attrib(dp->x, "from") == NULL) return NULL; if ((u = js_user(si, dp->id, 0)) == NULL) return NULL; if (u->scount >= MAX_USER_SESSIONS) { THREAD_DEC(u->ref); return NULL; } log_debug("session_create %s", jid_full(dp->id)); /* create session */ p = pool_heap(1024); s = pmalloco(p, sizeof(struct session_struct)); s->p = p; s->si = si; /* save authorative remote session id */ s->sid = jid_new(p, xmlnode_get_attrib(dp->x, "from")); /* session identity */ s->id = jid_new(p, jid_full(dp->id)); /* id bez resource */ s->uid = jid_user(s->id); s->route = jid_new(p, jid_full(dp->id)); snprintf(routeres, 9, "%X", s); jid_set(s->route, routeres, JID_RESOURCE); s->res = pstrdup(p, dp->id->resource); s->u = u; jid_full(s->sid); jid_full(s->uid); jid_full(s->id); jid_full(s->route); { register char *text; text = xmlnode_get_attrib(dp->x, "ip"); if (text) { s->ip = pstrdup(s->p, xmlnode_get_attrib(dp->x, "ip")); xmlnode_hide_attrib(dp->x, "ip"); } else s->ip = "none"; } /* default settings */ s->exit_flag = 0; s->roster = 0; s->priority = -129; s->presence = jutil_presnew(JPACKET__UNAVAILABLE, NULL, NULL); xmlnode_put_attrib(s->presence, "from", jid_full(s->id)); s->c_in = s->c_out = 0; for (i = 0; i < es_LAST; i++) s->events[i] = NULL; SEM_LOCK(u->sem); if (u->sessions != NULL) { s->q = get_mtq_queue(si, u->sessions->q); for (cur = u->sessions; cur != NULL; cur = cur->next) if (j_strcmp(dp->id->resource, cur->res) == 0) js_session_end_nosem(cur, "Replaced by new connection"); } else { s->q = get_mtq_queue(si, NULL); } /* make sure we're linked with the user */ s->next = s->u->sessions; s->u->sessions = s; s->u->scount++; SEM_UNLOCK(u->sem); /* session start */ { packet_thread_p pt; pt = malloc(sizeof(packet_thread_t)); pt->s = s; pt->type = 0; fast_mtq_send(s->q->mtq, pt); } THREAD_DEC(u->ref); return s; }
/* Handles logging for each room, simply returning if logfile is not defined */ void con_room_log(cnr room, char *nick, char *message) { time_t t; xmlnode xml; jid user; char *output; char timestr[80]; size_t timelen = 79; FILE *logfile; pool p; if(message == NULL || room == NULL) { log_warn(NAME, "[%s] ERR: Aborting - NULL reference found - ", FZONE); return; } logfile = room->logfile; if(logfile == NULL) { log_debug(NAME, "[%s] Logging not enabled for this room", FZONE); return; } p = pool_heap(1024); /* nicked from mod_time */ t = time(NULL); if(room->logformat == LOG_XHTML) strftime(timestr, timelen, "<a name=\"t%H:%M:%S\" href=\"#t%H:%M:%S\">[%H:%M:%S]</a>", localtime(&t)); else strftime(timestr, timelen, "[%H:%M:%S]", localtime(&t)); if(room->logformat == LOG_XML) { xml = jutil_msgnew("groupchat", jid_full(room->id) , NULL, strescape(p, message)); user = jid_new(xmlnode_pool(xml), jid_full(room->id)); jid_set(user, strescape(p, nick), JID_RESOURCE); xmlnode_put_attrib(xml, "from", jid_full(user)); jutil_delay(xml, NULL); fprintf(logfile, "%s\n", xmlnode2str(xml)); xmlnode_free(xml); } else if(room->logformat == LOG_XHTML) { if(nick) { if(j_strncmp(message, "/me ", 4) == 0) { output = extractAction(_con_room_xhtml_strescape(p, message), p); fprintf(logfile, "<span class=\"time\">%s</span> * <span class=\"nick\">%s</span>%s<br />\n", timestr, strescape(p, nick), output); } else { fprintf(logfile, "<span class=\"time\">%s</span> <<span class=\"nick\">%s</span>> %s<br />\n", timestr, strescape(p, nick), _con_room_xhtml_strescape(p, message)); } } else { fprintf(logfile, "<span class=\"time\">%s</span> --- %s<br />\n", timestr, message); } } else { if(nick) { if(j_strncmp(message, "/me ", 4) == 0) { output = extractAction(message, p); fprintf(logfile, "%s * %s%s\n", timestr, nick, output); } else { fprintf(logfile, "%s <%s> %s\n", timestr, nick, message); } } else { fprintf(logfile, "%s --- %s\n", timestr, message); } } fflush(logfile); pool_free(p); return; }