/*! \brief * Check if the originating REGISTER message was formed correctly * The whole message must be parsed before calling the function * _s indicates whether the contact was star */ int check_contacts(struct sip_msg* _m, int* _s) { struct hdr_field* p; contact_t* c; *_s = 0; /* Message without contacts is OK */ if (_m->contact == 0) return 0; if (((contact_body_t*)_m->contact->parsed)->star == 1) { /* The first Contact HF is star */ /* Expires must be zero */ if (get_expires_hf(_m) > 0) { rerrno = R_STAR_EXP; return 1; } /* Message must contain no contacts */ if (((contact_body_t*)_m->contact->parsed)->contacts) { rerrno = R_STAR_CONT; return 1; } /* Message must contain no other Contact HFs */ p = _m->contact->next; while(p) { if (p->type == HDR_CONTACT_T) { rerrno = R_STAR_CONT; return 1; } p = p->next; } *_s = 1; } else { /* The first Contact HF is not star */ /* Message must contain no star Contact HF */ p = _m->contact->next; while(p) { if (p->type == HDR_CONTACT_T) { if (((contact_body_t*)p->parsed)->star == 1) { rerrno = R_STAR_CONT; return 1; } /* check also the lenght of all contacts */ for(c=((contact_body_t*)p->parsed)->contacts ; c ; c=c->next) { if (c->uri.len > CONTACT_MAX_SIZE || (c->received && c->received->len>RECEIVED_MAX_SIZE) ) { rerrno = R_CONTACT_LEN; return 1; } } } p = p->next; } } return 0; }
/* * Check if the originating REGISTER message was formed correctly * The whole message must be parsed before calling the function * _s indicates whether the contact was star */ int check_contacts(struct sip_msg* _m, int* _s) { struct hdr_field* p; *_s = 0; /* Message without contacts is OK */ if (_m->contact == 0) return 0; if (((contact_body_t*)_m->contact->parsed)->star == 1) { /* The first Contact HF is star */ /* Expires must be zero */ if (get_expires_hf(_m) > 0) { rerrno = R_STAR_EXP; return 1; } /* Message must contain no contacts */ if (((contact_body_t*)_m->contact->parsed)->contacts) { rerrno = R_STAR_CONT; return 1; } /* Message must contain no other Contact HFs */ p = _m->contact->next; while(p) { if (p->type == HDR_CONTACT_T) { rerrno = R_STAR_CONT; return 1; } p = p->next; } *_s = 1; } else { /* The first Contact HF is not star */ /* Message must contain no star Contact HF */ p = _m->contact->next; while(p) { if (p->type == HDR_CONTACT_T) { if (((contact_body_t*)p->parsed)->star == 1) { rerrno = R_STAR_CONT; return 1; } } p = p->next; } } return 0; }
/*! \brief * Calculate absolute expires value per contact as follows: * 1) If the contact has expires value, use the value. If it * is not zero, add actual time to it * 2) If the contact has no expires parameter, use expires * header field in the same way * 3) If the message contained no expires header field, use * the default value */ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e) { if (!_ep || !_ep->body.len) { *_e = get_expires_hf(_m); } else { if (str2int(&_ep->body, (unsigned int*)_e) < 0) { *_e = get_expire_val(); } /* Convert to absolute value */ if (*_e != 0) *_e += act_time; } if ((*_e != 0) && ((*_e - act_time) < cfg_get(registrar, registrar_cfg, min_expires))) { *_e = cfg_get(registrar, registrar_cfg, min_expires) + act_time; } if ((*_e != 0) && cfg_get(registrar, registrar_cfg, max_expires) && ((*_e - act_time) > cfg_get(registrar, registrar_cfg, max_expires))) { *_e = cfg_get(registrar, registrar_cfg, max_expires) + act_time; } }
/* * Calculate absolute expires value per contact as follows: * 1) If the contact has expires value, use the value. If it * is not zero, add actual time to it * 2) If the contact has no expires parameter, use expires * header field in the same way * 3) If the message contained no expires header field, use * the default value */ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e) { if (!_ep || !_ep->body.len) { *_e = get_expires_hf(_m); } else { if (str2int(&_ep->body, (unsigned int*)_e) < 0) { *_e = default_expires; } /* Convert to absolute value */ if (*_e != 0) *_e += act_time; } if ((*_e != 0) && ((*_e - act_time) < min_expires)) { *_e = min_expires + act_time; } if ((*_e != 0) && max_expires && ((*_e - act_time) > max_expires)) { *_e = max_expires + act_time; } }
/*! \brief * Calculate absolute expires value per contact as follows: * 1) If the contact has expires value, use the value. If it * is not zero, add actual time to it * 2) If the contact has no expires parameter, use expires * header field in the same way * 3) If the message contained no expires header field, use * the default value */ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novariation) { int range = 0; if (!_ep || !_ep->body.len) { *_e = get_expires_hf(_m); if ( *_e < 0 ) { *_e = cfg_get(registrar, registrar_cfg, default_expires); range = cfg_get(registrar, registrar_cfg, default_expires_range); } else { range = cfg_get(registrar, registrar_cfg, expires_range); } } else { if (str2int(&_ep->body, (unsigned int*)_e) < 0) { *_e = cfg_get(registrar, registrar_cfg, default_expires); range = cfg_get(registrar, registrar_cfg, default_expires_range); } else { range = cfg_get(registrar, registrar_cfg, expires_range); } } if ( *_e != 0 ) { if (!novariation) { *_e = randomize_expires( *_e, range ); } if (*_e < cfg_get(registrar, registrar_cfg, min_expires)) { *_e = cfg_get(registrar, registrar_cfg, min_expires); } if (cfg_get(registrar, registrar_cfg, max_expires) && (*_e > cfg_get(registrar, registrar_cfg, max_expires))) { *_e = cfg_get(registrar, registrar_cfg, max_expires); } /* Convert to absolute value */ *_e += act_time; } }
/*! \brief * Check if the originating REGISTER message was formed correctly * The whole message must be parsed before calling the function * _s indicates whether the contact was star */ int check_contacts(struct sip_msg* _m, int* _s) { struct hdr_field* p; contact_t* c; *_s = 0; /* Message without contacts is OK */ if (_m->contact == 0) return 0; if (((contact_body_t*)_m->contact->parsed)->star == 1) { /* The first Contact HF is star */ /* Expires must be zero */ if (get_expires_hf(_m) != 0) { LM_WARN("expires must be 0 for star contact\n"); rerrno = R_STAR_EXP; return 1; } /* Message must contain no contacts */ if (((contact_body_t*)_m->contact->parsed)->contacts) { LM_WARN("star contact cannot be mixed with other contacts\n"); rerrno = R_STAR_CONT; return 1; } /* Message must contain no other Contact HFs */ p = _m->contact->next; while(p) { if (p->type == HDR_CONTACT_T) { LM_WARN("star contact cannot be mixed with other contacts\n"); rerrno = R_STAR_CONT; return 1; } p = p->next; } *_s = 1; } else { /* The first Contact HF is not star */ p = _m->contact; while(p) { if (p->type == HDR_CONTACT_T) { /* Message must contain no star Contact HF */ if (((contact_body_t*)p->parsed)->star == 1) { LM_WARN("star contact cannot be mixed with other contacts\n"); rerrno = R_STAR_CONT; return 1; } /* check also the length of all contacts */ for(c=((contact_body_t*)p->parsed)->contacts ; c ; c=c->next) { if (c->uri.len > contact_max_size) { LM_WARN("contact uri is too long: [%.*s]\n", c->uri.len, c->uri.s); rerrno = R_CONTACT_LEN; return 1; } if (c->received && c->received->len>RECEIVED_MAX_SIZE) { LM_WARN("received attribute of contact is too long\n"); rerrno = R_CONTACT_LEN; return 1; } } } p = p->next; } } return 0; }