/* * js_session_get -- find the session for a resource * * Given a user and a resource, find the corresponding session * if the user is logged in. Otherwise return NULL. * * parameters * user -- the user's udata record * res -- the resource to search for * * returns * a pointer to the session if the user is logged in * NULL if the user isn't logged in on this resource */ session js_session_get(udata user, char *res) { session cur; /* session pointer */ /* screen out illeagal calls */ if (user == NULL || res == NULL) return NULL; /* find the session and return it */ SEM_LOCK(user->sem); for (cur = user->sessions; cur != NULL; cur = cur->next) if ((j_strcmp(res, cur->res) == 0) && (!cur->exit_flag)) { SEM_UNLOCK(user->sem); return cur; } /* find any matching resource that is a subset and return it */ for (cur = user->sessions; cur != NULL; cur = cur->next) if ((j_strncmp(res, cur->res, j_strlen(cur->res)) == 0) && (!cur->exit_flag)) { SEM_UNLOCK(user->sem); return cur; } SEM_UNLOCK(user->sem); /* if we got this far, there is no session */ return NULL; }
/* 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; }