Beispiel #1
0
 shared_ptr<string> Endpoint::refreshBuffer() {
   shared_ptr<string> r;
   if ( buffer_ ) {
     r = buffer_->refresh(handle_,
           std::bind(&Endpoint::notify_subscribers, this, std::placeholders::_1));
   } else {
     // Read data directly from the underlying IOHandle.
     boost::lock_guard<boost::mutex> guard(mtx_);
     if (handle_->hasRead()) {
       r = handle_->doRead();
       notify_subscribers(r);
     }
   }
   return r;
 }
Beispiel #2
0
    void InternalEndpoint::doWrite(const RemoteMessage& v) {
      if ( msgcodec_ ) {
        shared_ptr<string> bufv = make_shared<string>(std::move(msgcodec_->encode(v)));
        if ( buffer_ ) {
          bool success = buffer_->push_back(bufv);
          if ( !success ) {
            // Flush buffer, and then try to append again.
            flushBuffer();

            // Try to append again, and if this still fails, throw a buffering exception.
            success = buffer_->push_back(bufv);
          }

          if ( ! success )
            { throw BufferException("Failed to buffer value during endpoint write."); }
        } else {
          boost::lock_guard<boost::mutex> guard(mtx_);
          handle_->doWrite(bufv);
          notify_subscribers(bufv);
        }
      }
    }
Beispiel #3
0
 Collection<R_elem<RemoteMessage>> InternalEndpoint::doReadBlock(int blockSize) {
   Collection<R_elem<RemoteMessage>> r;
   shared_ptr<string> v;
   if ( msgcodec_ ) {
     if ( buffer_ ) {
       int i = blockSize;
       do {
         v = buffer_->refresh(handle_,
               std::bind(&Endpoint::notify_subscribers, this, std::placeholders::_1));
         if ( v ) {
           shared_ptr<RemoteMessage> outv = msgcodec_->decode(*v);
           if ( outv ) {
             R_elem<RemoteMessage> elem(*outv);
             r.insert(std::move(elem));
           }
         }
       } while ( --i > 0 && handle_->hasRead() );
     } else {
       // Read data directly from the underlying IOHandle.
       boost::lock_guard<boost::mutex> guard(mtx_);
       int i = blockSize;
       do {
         v = handle_->doRead();
         notify_subscribers(v); // Produce a notification for every tuple in a block read.
         if ( v ) {
           shared_ptr<RemoteMessage> outv = msgcodec_->decode(*v);
           if ( outv ) {
             R_elem<RemoteMessage> elem(*outv);
             r.insert(std::move(elem));
           }
         }
       } while ( --i > 0 && handle_->hasRead() );
     }
   }
   return r;
 }
AAAMessage* cxdx_process_rtr(AAAMessage *rtr) {
    LM_DBG("Processing RTR");
    
    AAAMessage *rta_msg;
    AAA_AVP* avp;
    str public_id;
    impurecord_t* r;
    int res = 0;
    udomain_t* udomain;
	impu_contact_t *impucontact;
    
    rta_msg = cdpb.AAACreateResponse(rtr);//session ID?
    if (!rta_msg) return 0;

    avp = cxdx_get_next_public_identity(rtr,0,AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__);	
    if(avp==0){
	    LM_WARN("RTR received with only IMPI (username AVP) - currently S-CSCF does not support this kind of RTR\n");
	    return 0;
	    //TODO add support for receiving RTR with IMPI
	    //get all impus related to this impu
	    //get all contacts related to each impu
	    //set the contact expire for each contact to now
    }else{
	    public_id=avp->data;
	    LM_DBG("RTR received with IMPU [%.*s] in public identity AVP - this is supported\n", public_id.len, public_id.s);

	    //TODO this should be a configurable module param
	    if (ul.register_udomain(domain, &udomain) < 0) {
		LM_ERR("Unable to register usrloc domain....aborting\n");
		return 0;
	    }
	    
	    ul.lock_udomain(udomain, &public_id);
            res = ul.get_impurecord(udomain, &public_id, &r);
            if (res != 0) {
                LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s);
                ul.unlock_udomain(udomain, &public_id);
                //no point in continuing
                return 0;
            }
	    
		impucontact = r->linked_contacts.head;
		while (impucontact) {
			LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s);
			ul.lock_contact_slot_i(impucontact->contact->sl);
			impucontact->contact->state = CONTACT_DELETE_PENDING;
			if (r->shead) {
				//send NOTIFY to all subscribers of this IMPU.
				notify_subscribers(r, 0, 0);
			}
			impucontact->contact->state = CONTACT_DELETED;
			ul.unlock_contact_slot_i(impucontact->contact->sl);
			
			impucontact = impucontact->next;
		}
	    
	    ul.unlock_udomain(udomain, &public_id);
	    
	    while(cdpb.AAAGetNextAVP(avp) && (avp=cxdx_get_next_public_identity(rtr,cdpb.AAAGetNextAVP(avp),AVP_IMS_Public_Identity,IMS_vendor_id_3GPP,__FUNCTION__))!=0){
		    public_id=avp->data;
		    LM_DBG("RTR also has public id [%.*s]\n", public_id.len, public_id.s);
		    ul.lock_udomain(udomain, &public_id);
		    res = ul.get_impurecord(udomain, &public_id, &r);
		    if (res != 0) {
			LM_WARN("Strange, '%.*s' Not found in usrloc\n", public_id.len, public_id.s);
			ul.unlock_udomain(udomain, &public_id);
			//no point in continuing
			return 0;
		    }

		    impucontact = r->linked_contacts.head;
			while (impucontact) {
				LM_DBG("Deleting contact with AOR [%.*s]\n", impucontact->contact->aor.len, impucontact->contact->aor.s);
				ul.lock_contact_slot_i(impucontact->contact->sl);
				impucontact->contact->state = CONTACT_DELETE_PENDING;
				if (r->shead) {
					//send NOTIFY to all subscribers of this IMPU.
					notify_subscribers(r, 0, 0);
				}
				impucontact->contact->state = CONTACT_DELETED;
				ul.unlock_contact_slot_i(impucontact->contact->sl);
				impucontact = impucontact->next;
		    }

		    ul.unlock_udomain(udomain, &public_id);
		}		
    }
    cxdx_add_vendor_specific_appid(rta_msg,IMS_vendor_id_3GPP,IMS_Cx,0 /*IMS_Cx*/);
    
    cxdx_add_auth_session_state(rta_msg,1);		

    /* send an RTA back to the HSS */
    cxdx_add_result_code(rta_msg,DIAMETER_SUCCESS);
    
    return rta_msg;
    
    
}