static int ac_packetfilter_simple(ac_sip_t *asip, void *data) { osip_message_t* sip = asip->req->evt->sip; int code = osip_message_get_status_code(sip); LOG_DEBUG("Performing simple ac on %s->%s, remote: %d\n", asip->from, asip->to, asip->req->remote_msg); /* filter only inbound */ if (asip->req->remote_msg && !asip->req->internally_generated) { /* todo: we should check that the sip from == the aor associated with the connection (on remote calls) */ /* except that that would mess up the gateway things. */ //ASSERT_ZERO(sipp_get_sip_aors_simple(sip, &local_aor, &remote_aor, 1), end); /* if ((!MSG_IS_RESPONSE(asip->evt->sip) && (strcmp(asip->from, asip->remote) || strcmp(asip->to, asip->local))) || (MSG_IS_RESPONSE(asip->evt->sip) && (strcmp(asip->to, asip->remote) || strcmp(asip->from, asip->local)))) asip->verdict = AC_VERDICT_REJECT; else */ if (MSG_IS_RESPONSE(sip)) { /* reject 482 merges, as server loops aren't of any interest to us */ if (code == 482) { LOG_WARN("Skipping %d response\n", code); asip->verdict = AC_VERDICT_REJECT; } } else if (MSG_IS_ACK(sip) || MSG_IS_BYE(sip) || MSG_IS_CANCEL(sip) || MSG_IS_UPDATE(sip)) { /* this we should let through pretty much undisturbed */ } else if (MSG_IS_SUBSCRIBE(sip) || MSG_IS_PUBLISH(sip)) { /* if this is remotely got, just reject */ asip->verdict = AC_VERDICT_REJECT; } else if (MSG_IS_INVITE(sip) || MSG_IS_MESSAGE(sip)) { /* hm, nothing.. */ // } else if (MSG_IS_NOTIFY(sip)) { } else { /* todo: what about OPTIONS? */ LOG_WARN("Got unsupported request\n"); asip->verdict = AC_VERDICT_UNSUPP; } } else { /* allow *all* outgoing! */ asip->verdict = AC_VERDICT_ALLOW; } return 1; }
static int eXosip_retry_with_auth (eXosip_event_t * je) { if (!je || !je->request || !je->response) return -1; if (je->rid>0) { return _eXosip_retry_register_with_auth (je); } else if (je->cid>0) { return _eXosip_retry_invite_with_auth (je); } #ifndef MINISIZE else if (je->sid>0) { return _eXosip_retry_subscribe_with_auth (je); } else if (je->nid>0) { return _eXosip_retry_notify_with_auth (je); } else if (MSG_IS_PUBLISH (je->request)) return _eXosip_retry_publish_with_auth (je); #endif else { osip_transaction_t *tr=NULL; eXosip_transaction_find(je->tid, &tr); if (tr!=NULL) { return _eXosip_retry_with_auth (NULL, &tr, NULL); } } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: Can't retry event %d with auth\n", je->type)); return -1; }
static int _eXosip_retry_with_auth (eXosip_dialog_t * jd, osip_transaction_t ** ptr, int *retry) { osip_transaction_t *out_tr = NULL; osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; jinfo_t *ji = NULL; int cseq; osip_via_t *via; int i; if (!ptr) return -1; if (jd != NULL) { if (jd->d_out_trs == NULL) return -1; } out_tr = *ptr; if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return -1; if (retry && (*retry >= 3)) return -1; osip_message_clone (out_tr->orig_request, &msg); if (msg == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return -1; } via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return -1; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } i = eXosip_update_top_via(msg); if (i!=0) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: unsupported protocol\n")); return -1; } if (eXosip_add_authentication_information (msg, out_tr->last_response) < 0) { osip_message_free (msg); return -1; } osip_message_force_update (msg); if (MSG_IS_INVITE (msg)) i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); else i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return -1; } /* replace with the new tr */ if (MSG_IS_PUBLISH(msg)) { /* old transaction is put in the garbage list */ osip_list_add (eXosip.j_transactions, out_tr, 0); /* new transaction is put in the publish context */ *ptr = tr; } else osip_list_add (eXosip.j_transactions, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); ji = osip_transaction_get_your_instance (out_tr); osip_transaction_set_your_instance (out_tr, NULL); osip_transaction_set_your_instance (tr, ji); osip_transaction_add_event (tr, sipevent); if (retry) (*retry)++; eXosip_update (); /* fixed? */ __eXosip_wakeup (); return 0; }