📄 sm.h
字号:
/* * jabberd - Jabber Open Source Server * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, * Ryan Eatmon, Robert Norris * * This program is free software; you can redistribute it and/or drvify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA *//** @file sm/sm.h * @brief data structures and prototypes for the session manager * @author Jeremie Miller * @author Robert Norris * $Date: 2004/12/07 15:38:24 $ * $Revision: 1.53.2.6 $ */#ifdef HAVE_CONFIG_H# include <config.h>#endif#include "sx/sx.h"#include "sx/sasl.h"#include "sx/ssl.h"#include "mio/mio.h"#include "util/util.h"#ifdef HAVE_SIGNAL_H# include <signal.h>#endif#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif/* forward declarations */typedef struct sm_st *sm_t;typedef struct user_st *user_t;typedef struct sess_st *sess_t;typedef struct aci_st *aci_t;typedef struct storage_st *storage_t;typedef struct mm_st *mm_t;/* namespace uri strings */#define uri_AUTH "jabber:iq:auth"#define uri_REGISTER "jabber:iq:register"#define uri_ROSTER "jabber:iq:roster"#define uri_AGENTS "jabber:iq:agents"#define uri_DELAY "jabber:x:delay"#define uri_VERSION "jabber:iq:version"#define uri_TIME "jabber:iq:time"#define uri_VCARD "vcard-temp"#define uri_PRIVATE "jabber:iq:private"#define uri_BROWSE "jabber:iq:browse"#define uri_EVENT "jabber:x:event"#define uri_GATEWAY "jabber:iq:gateway"#define uri_LAST "jabber:iq:last"#define uri_EXPIRE "jabber:x:expire"#define uri_PRIVACY "jabber:iq:privacy"#define uri_SEARCH "jabber:iq:search"#define uri_DISCO "http://jabber.org/protocol/disco"#define uri_DISCO_ITEMS "http://jabber.org/protocol/disco#items"#define uri_DISCO_INFO "http://jabber.org/protocol/disco#info"#define uri_VACATION "http://jabber.org/protocol/vacation"/* indexed known namespace values */#define ns_AUTH (1)#define ns_REGISTER (2)#define ns_ROSTER (3)#define ns_AGENTS (4)#define ns_DELAY (5)#define ns_VERSION (6)#define ns_TIME (7)#define ns_VCARD (8)#define ns_PRIVATE (9)#define ns_BROWSE (10)#define ns_EVENT (11)#define ns_GATEWAY (12)#define ns_LAST (13)#define ns_EXPIRE (14)#define ns_PRIVACY (15)#define ns_SEARCH (16)#define ns_DISCO (17)#define ns_DISCO_ITEMS (18)#define ns_DISCO_INFO (19)#define ns_VACATION (20)/** packet types */typedef enum { pkt_NONE = 0x00, /**< no packet */ pkt_MESSAGE = 0x10, /**< message */ pkt_PRESENCE = 0x20, /**< presence */ pkt_PRESENCE_UN = 0x21, /**< presence (unavailable) */ pkt_PRESENCE_INVIS = 0x22, /**< presence (invisible) */ pkt_PRESENCE_PROBE = 0x24, /**< presence (probe) */ pkt_S10N = 0x40, /**< subscribe request */ pkt_S10N_ED = 0x41, /**< subscribed response */ pkt_S10N_UN = 0x42, /**< unsubscribe request */ pkt_S10N_UNED = 0x44, /**< unsubscribed response */ pkt_IQ = 0x80, /**< info/query (get) */ pkt_IQ_SET = 0x81, /**< info/query (set) */ pkt_IQ_RESULT = 0x82, /**< info/query (result) */ pkt_SESS = 0x100, /**< session start request */ pkt_SESS_END = 0x101, /**< session end request */ pkt_SESS_CREATE = 0x102, /**< session create request */ pkt_SESS_DELETE = 0x104, /**< session delete request */ pkt_SESS_FAILED = 0x08, /**< session request failed (mask) */ pkt_SESS_MASK = 0x10f, /**< session request (mask) */ pkt_ERROR = 0x200 /**< packet error */} pkt_type_t;/** route types */typedef enum { route_NONE = 0x00, /**< no route */ route_UNICAST = 0x10, /**< unicast */ route_BROADCAST = 0x11, /**< broadcast */ route_ADV = 0x20, /**< advertisement (available) */ route_ADV_UN = 0x21, /**< advertisement (unavailable) */ route_ERROR = 0x40 /**< route error */} route_type_t;/** packet summary data wrapper */typedef struct pkt_st { sm_t sm; /**< sm context */ sess_t source; /**< session this packet came from */ jid_t rto, rfrom; /**< addressing of enclosing route */ route_type_t rtype; /**< type of enclosing route */ pkt_type_t type; /**< packet type */ jid_t to, from; /**< packet addressing (not used for routing) */ int ns; /**< iq sub-namespace */ int pri; /**< presence priority */ nad_t nad; /**< nad of the entire packet */} *pkt_t;/** roster items */typedef struct item_st { jid_t jid; /**< id of this item */ char *name; /**< display name */ char **groups; /**< groups this item is in */ int ngroups; /**< number of groups in groups array */ int to, from; /**< subscription to this item (they get presence FROM us, they send presence TO us) */ int ask; /**< pending subscription (0 == none, 1 == subscribe, 2 == unsubscribe) */} *item_t;/** session manager global context */struct sm_st { char *id; /**< component id (hostname) */ char *router_ip; /**< ip to connect to the router at */ int router_port; /**< port to connect to the router at */ char *router_user; /**< username to authenticate to the router as */ char *router_pass; /**< password to authenticate to the router with */ char *router_pemfile; /**< name of file containing a SSL certificate & key for channel to the router */ mio_t mio; /**< mio context */ sx_env_t sx_env; /**< SX environment */ sx_plugin_t sx_sasl; /**< SX SASL plugin */ sx_plugin_t sx_ssl; /**< SX SSL plugin */ sx_t router; /**< SX of router connection */ int fd; /**< file descriptor of router connection */ xht users; /**< pointers to currently loaded users (key is user@@domain) */ xht sessions; /**< pointers to all connected sessions (key is random sm id) */ xht xmlns; /**< index of common namespaces (for iq sub-namespace in pkt_t) */ xht features; /**< feature index (key is feature string */ config_t config; /**< config context */ log_t log; /**< log context */ log_type_t log_type; /**< log type */ char *log_facility; /**< syslog facility (local0 - local7) */ char *log_ident; /**< log identifier */ int retry_init; /**< number of times to try connecting to the router at startup */ int retry_lost; /**< number of times to try reconnecting to the router if the connection drops */ int retry_sleep; /**< sleep interval between retries */ int retry_left; /**< number of tries left before failure */ prep_cache_t pc; /**< cache of stringprep'd ids */ storage_t st; /**< storage subsystem */ mm_t mm; /**< module subsystem */ xht acls; /**< access control lists (key is list name, value is jid_t list) */ char signature[2048]; /**< server signature */ int siglen; /**< length of signature */ int started; /**< true if we've connected to the router at least once */ int online; /**< true if we're currently bound in the router */};/** data for a single user */struct user_st { pool p; /**< memory pool this user is allocated off */ sm_t sm; /**< sm context */ jid_t jid; /**< user jid (user@@host) */ xht roster; /**< roster for this user (key is full jid of item, value is item_t) */ sess_t sessions; /**< list of action sessions */ sess_t top; /**< top priority session */ time_t active; /**< time that user first logged in (ever) */ void **module_data; /**< per-user module data */};/** data for a single session */struct sess_st { pool p; /**< memory pool this session is allocated off */ user_t user; /**< user this session belongs to */ jid_t jid; /**< session jid (user@@host/res) */ char c2s[1024]; /**< id of c2s that is handling their connection */ char sm_id[41]; /**< local id (for session control) */ char c2s_id[10]; /**< remote id (for session control) */ pkt_t pres; /**< copy of the last presence packet we received */ int available; /**< true if this session is available */ int invisible; /**< true if this session is invisible */ int pri; /**< current priority of this session */ jid_t A; /**< list of jids that this session has sent directed presence to */ jid_t E; /**< list of jids that bounced presence updates we sent them */ void **module_data; /**< per-session module data */ sess_t next; /**< next session (in a list of sessions) */};extern sig_atomic_t sm_lost_router;/* functions */xht aci_load(sm_t sm);int aci_check(xht acls, char *type, jid_t jid);int sm_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);int sm_mio_callback(mio_t m, mio_action_t a, int fd, void *data, void *arg);void sm_timestamp(time_t t, char timestamp[18]);void sm_c2s_action(sess_t dest, char *action, char *target);void sm_signature(sm_t sm, char *str);void dispatch(sm_t sm, pkt_t pkt);pkt_t pkt_error(pkt_t pkt, int err);pkt_t pkt_tofrom(pkt_t pkt);pkt_t pkt_dup(pkt_t pkt, const char *to, const char *from);pkt_t pkt_new(sm_t sm, nad_t nad);void pkt_free(pkt_t pkt);pkt_t pkt_create(sm_t sm, const char *elem, const char *type, const char *to, const char *from);void pkt_id(pkt_t src, pkt_t dest);void pkt_delay(pkt_t pkt, time_t t, const char *from);void pkt_router(pkt_t pkt);void pkt_sess(pkt_t pkt, sess_t sess);int pres_trust(user_t user, jid_t jid);void pres_roster(sess_t sess, item_t item);void pres_update(sess_t sess, pkt_t pres);void pres_error(sess_t sess, jid_t jid);void pres_deliver(sess_t sess, pkt_t pres);void pres_in(user_t user, pkt_t pres);void pres_probe(user_t user);void sess_route(sess_t sess, pkt_t pkt);sess_t sess_start(sm_t sm, jid_t jid);void sess_end(sess_t sess);sess_t sess_match(user_t user, char *resource);user_t user_load(sm_t sm, jid_t jid);void user_free(user_t user);int user_create(sm_t sm, jid_t jid);void user_delete(sm_t sm, jid_t jid);void feature_register(sm_t sm, char *feature);void feature_unregister(sm_t sm, char *feature);/* driver module manager *//** module return values */typedef enum { mod_HANDLED, /**< packet was handled (and freed) */ mod_PASS /**< packet was unhandled, should be passed to the next module */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -