25 #include <stringprep.h>
45 #define AMP_TRIGGERED 1
46 #define AMP_INVALID_RULE 2
47 #define AMP_INVALID_CONDITION 3
48 #define AMP_INVALID_ACTION 4
49 #define AMP_INVALID_VALUE 5
50 #define AMP_NOT_ACCEPTABLE 6
64 while (rule_c != NULL) {
68 rule_tmp = rule_c->
next;
75 if (!pkt || !rule)
return NULL;
144 rule_c->action = strdup(
"drop");
147 rule_c->action = strdup(
"alert");
150 rule_c->action = strdup(
"error");
153 rule_c->action = strdup(
"notify");
155 if (!rule_c->action) {
164 rule_c->condition = strdup(
"deliver");
168 rule_c->value = strdup(
"direct");
169 if (user->
top != NULL)
175 rule_c->value = strdup(
"none");
177 && user->
top == NULL)
183 rule_c->value = strdup(
"none");
185 && user->
top == NULL)
189 if (!rule_c->value) {
197 else if (
nad_find_attr(pkt->
nad, elem, -1,
"condition",
"match-resource") >= 0
199 rule_c->condition = strdup(
"match-resource");
203 rule_c->value = strdup(
"exact");
210 rule_c->value = strdup(
"any");
211 if (user->
top == NULL)
217 rule_c->value = strdup(
"other");
222 if (!rule_c->value) {
232 rule_c->condition = strdup(
"expire-at");
242 else if (stamp < time(NULL))
247 if (!rule_c->condition) {
263 rule_c->next = calloc(1,
sizeof(
struct amp_rule_st));
264 rule_c = rule_c->next;
271 while (rule_c != NULL) {
272 if (rule_c->result > 0) {
275 if (!strcmp(rule_c->action,
"drop") && !errormode)
279 else if (!strcmp(rule_c->action,
"alert") && !errormode) {
286 else if (!strcmp(rule_c->action,
"error") && !errormode) {
293 else if (!strcmp(rule_c->action,
"notify") && !errormode) {
300 rule_c = rule_c->next;
336 nad_append_attr(res->nad, -1,
"name",
"Advanced Message Processing support");
382 if (mod->
init)
return 0;
388 if (option != NULL) {
393 if (option != NULL) {
398 if (option != NULL) {
403 if (option != NULL) {
408 if (option != NULL) {
413 if (option != NULL) {
418 if (option != NULL) {
419 log_debug(
ZONE,
"condition Match-Resource disabled in config.");
423 if (option != NULL) {
428 if (option != NULL) {
mod_ret_t(* pkt_sm)(mod_instance_t mi, pkt_t pkt)
pkt-sm handler
pkt_type_t type
packet type
jid_t jid
session jid (user@host/res)
#define AMP_INVALID_CONDITION
int nad_append_attr(nad_t nad, int ns, const char *name, const char *val)
attach new attr to the last elem
data structures and prototypes for the session manager
int offlinestorageDisabled
const char * jid_user(jid_t jid)
expand and return the user
static mod_ret_t _amp_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
const char * jid_full(jid_t jid)
expand and return the full
single instance of a module in a chain
int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth)
locate the next elem at a given depth with an optional matching name
config_t config
config context
int init
number of times the module intialiser has been called
static void _amp_free(module_t mod)
struct amp_rule_st * amp_rule_t
void amp_rule_free(amp_rule_t rule)
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
struct _mod_amp_config_st * mod_amp_config_t
#define uri_AMP_ACTION_DROP
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
static mod_ret_t _amp_pkt_user(mod_instance_t mi, user_t user, pkt_t pkt)
#define AMP_INVALID_ACTION
int disableConditionMatchResource
int disableConditionExpireAt
struct amp_rule_st * next
int disableConditionDeliver
sess_t top
top priority session
#define uri_AMP_ACTION_NOTIFY
module_t mod
module that this is an instance of
jid_t from
packet addressing (not used for routing)
void * private
module private data
packet summary data wrapper
nad_t nad
nad of the entire packet
session manager global context
mod_ret_t(* in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt)
in-sess handler
void amp_error_pkt(pkt_t pkt, amp_rule_t rule)
#define uri_AMP_CONDITION_MATCHRESOURCE
void pkt_id(pkt_t src, pkt_t dest)
convenience - copy the packet id from src to dest
#define uri_AMP_ACTION_ERROR
void pkt_router(pkt_t pkt)
pkt_t amp_build_response_pkt(pkt_t pkt, amp_rule_t rule)
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
void feature_register(sm_t sm, const char *feature)
register a feature
sess_t sess_match(user_t user, const char *resource)
match a session by resource
static mod_ret_t _amp_pkt_sm(mod_instance_t mi, pkt_t pkt)
packet was unhandled, should be passed to the next module
packet was handled (and freed)
There is one instance of this struct per user who is logged in to this c2s instance.
int jid_compare_user(jid_t a, jid_t b)
compare the user portion of two jids
time_t datetime_in(char *date)
void(* free)(module_t mod)
called when module is freed
mod_ret_t(* pkt_user)(mod_instance_t mi, user_t user, pkt_t pkt)
pkt-user handler
#define AMP_INVALID_VALUE
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val)
get a matching attr on this elem, both name and optional val
pkt_t pkt_create(sm_t sm, const char *elem, const char *type, const char *to, const char *from)
mod_ret_t
module return values
#define uri_AMP_CONDITION_DELIVER
#define uri_AMP_CONDITION_EXPIREAT
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope