void* thread_fn(void* arg) { lli slee, start, end; lli loops_ps = loops_per_sec; double lratio = 1.0 - ratio; double wratio = lratio / (1. - lratio); lli loops, i; int syncl = sync_barrier; int local_finish; long long int interval = *((long long int*)arg); while(1) { r_lock(); /* begin reading */ if (syncl) { pthread_barrier_wait(&barrier); // this can't fail according to docs } local_finish = finished; r_unlock(); if (local_finish) { break; } start = GET_TIME(); mysleep(interval); end = GET_TIME(); slee = end - start; loops = (lli)(loops_ps * slee * wratio / 1000000.0); for (i=0; i < loops; i++) { LOOP(); } } return 0; }
/** * Searches for a r_public record and returns it. * \note Aquires the lock on the hash slot on success, so release it when you are done. * @param aor - the address of record to look for * @returns - the r_public found, 0 if not found */ r_public* get_r_public(str aor) { r_public *p=0; unsigned int hash; hash = get_aor_hash(aor,r_hash_size); r_lock(hash); p = registrar[hash].head; while(p){ if (p->aor.len == aor.len && strncasecmp(p->aor.s,aor.s,aor.len)==0) return p; p = p->next; } r_unlock(hash); /* * Here i plan to put the function that tries to match the aor with the wPSI * There might be an issue * if i return this locked, then i have to wait for the lock in the next one... * mmmh... might be an issue * */ if (scscf_support_wildcardPSI) return(get_matching_wildcard_psi(aor)); else return 0; }
/** * Expires all the contacts of public identities that are related to the given private id * @param private_id - private identity to expire contacts for */ void r_private_expire(str private_id) { int expire,i; r_public *p; r_contact *c; r_act_time(); expire = time_now; for(i=0;i<r_hash_size;i++){ r_lock(i); for(p = registrar[i].head;p;p=p->next){ if (p->s){ lock_get(p->s->lock); if (p->s->private_identity.len == private_id.len && strncasecmp(p->s->private_identity.s,private_id.s,private_id.len)==0){ for(c=p->head;c;c=c->next) c->expires = expire; } lock_release(p->s->lock); } } r_unlock(i); } print_r(L_ALERT); }
std::string SeessionID::ReadFunction(std::string sid) { ReadLock r_lock(myLock); int id = ptrsmap[sid].i; std::string msg; bool num = false; if(mmap.size()>0) { for (msgMap::const_iterator i = mmap.begin(), e = mmap.end(); i != e; ++i) { if (i->i <= id) continue; msg += i->msg; msg += ","; num = true; ptrsmap[sid].i = i->i; } } if (num) { msg = msg.substr(0, msg.length() - 1); } msg = "[" + msg; msg = msg + "]"; return msg; }
r_public* get_matching_wildcard_psi(str aor) { r_public *p=0; t_regexp_unit *t; regex_t exp; char *c,*temp; int len; int errcode; p = registrar[r_hash_size].head; r_lock(r_hash_size); while (p) { for(t=p->regexp->head;t;t=t->next) { LOG(L_DBG,"get_matching_wildcard_psi match %.*s with %s\n",aor.len,aor.s,t->s); c=shm_malloc((aor.len)+1); memcpy(c,aor.s,aor.len); c[aor.len]='\0'; errcode=regcomp(&(exp),t->s,REG_ICASE|REG_EXTENDED|REG_NOSUB); if(errcode!=0) { // there was an error LOG(L_DBG,"there was at least ONE error in regcomp %i\n",errcode); //shm_free(temp); temp=NULL; len=regerror(errcode,&(exp),NULL,0); temp=shm_malloc(len); regerror(errcode,&(exp),temp,len); LOG(L_DBG,"and that was %s",temp); shm_free(temp); temp=NULL; //shm_free(newwpsi); r_unlock(r_hash_size); return NULL; } if (regexec(&(exp),c,0,NULL,0)==0) { //LOG(L_DBG,"A match has been produced!!!!!\n"); shm_free(c); return p; } else { //LOG(L_ERR,"there was no match\n"); } shm_free(c); } p=p->next; } LOG(L_ERR,"get_r_public (Trying wildcard PSI) found no match\n"); r_unlock(r_hash_size); return 0; }
vector< MsgCustomerPos > DataProvider::getMsgCustomerPoses() { boost::shared_lock<boost::shared_mutex> r_lock(mutexVecMsgCustomerPos); vector< MsgCustomerPos > tempVecMsg; for(unsigned int i=0; i<vecMsgCustomerPos.size(); ++i) tempVecMsg.push_back(*vecMsgCustomerPos.at(i)); return tempVecMsg; }
/** * Debug print the contents of the entire registrar. * @param log_level - logging level */ void print_r(int log_level) { r_public *p; r_contact *c; r_subscriber *s; int i; if (debug<log_level) return; /* to avoid useless calls when nothing will be printed */ r_act_time(); LOG(log_level,ANSI_GREEN"INF:"M_NAME":---------- Registrar Contents begin --------\n"); for(i=0;i<r_hash_size;i++){ r_lock(i); p = registrar[i].head; while(p){ LOG(log_level,ANSI_GREEN"INF:"M_NAME":[%4d] P: <"ANSI_BLUE"%.*s"ANSI_GREEN"> R["ANSI_MAGENTA"%2d"ANSI_GREEN"] Early-IMS: <"ANSI_YELLOW"%.*s"ANSI_GREEN"> \n",i, p->aor.len,p->aor.s,p->reg_state,p->early_ims_ip.len,p->early_ims_ip.s); if (p->ccf1.len) LOG(log_level,ANSI_GREEN"INF:"M_NAME": CCF1: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> CCF2: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> \n", p->ccf1.len,p->ccf1.s,p->ccf2.len,p->ccf2.s); if (p->ecf1.len) LOG(log_level,ANSI_GREEN"INF:"M_NAME": ECF1: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> ECF2: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> \n", p->ecf1.len,p->ecf1.s,p->ecf2.len,p->ecf2.s); c = p->head; while(c){ LOG(log_level,ANSI_GREEN"INF:"M_NAME": C: <"ANSI_RED"%.*s"ANSI_GREEN"> Exp:["ANSI_MAGENTA"%4ld"ANSI_GREEN"]\n", c->uri.len,c->uri.s,c->expires-time_now); LOG(log_level,ANSI_GREEN"INF:"M_NAME": UP: {"ANSI_BLUE" iptv[%s], text[%s], data[%s], audio[%s], video[%s], control[%s], isfocus[%s], automata[%s], application[%s]\n mobility[%s]"ANSI_GREEN" }\n", ((c->user_pref->iptv == TRUE)?"yes":"no"), ((c->user_pref->text == TRUE)?"yes":"no"), ((c->user_pref->data == TRUE)?"yes":"no"), ((c->user_pref->audio == TRUE)?"yes":"no"), ((c->user_pref->video == TRUE)?"yes":"no"), ((c->user_pref->control == TRUE)?"yes":"no"), ((c->user_pref->isfocus == TRUE)?"yes":"no"), ((c->user_pref->automata == TRUE)?"yes":"no"), ((c->user_pref->application== TRUE)?"yes":"no"), ((c->user_pref->mobility.val_list[0] == MOBILE)?"mobile":"fixed") ) ; LOG(log_level,ANSI_GREEN"INF:"M_NAME": Path:"ANSI_YELLOW"%.*s"ANSI_GREEN"\n",c->path.len,c->path.s); LOG(log_level,ANSI_GREEN"INF:"M_NAME": UA: <%.*s>\n", c->ua.len,c->ua.s); c = c->next; } s = p->shead; while(s){ LOG(log_level,ANSI_GREEN"INF:"M_NAME": S: Event["ANSI_BLUE"%d"ANSI_GREEN "] Exp:["ANSI_MAGENTA"%4ld"ANSI_GREEN"] <"ANSI_CYAN"%.*s"ANSI_GREEN"> \n", s->event,s->expires-time_now,s->subscriber.len,s->subscriber.s); s = s->next; } p = p->next; } r_unlock(i); } LOG(log_level,"INF:"M_NAME":---------- Registrar Contents end ----------\n"); }
r_public* get_r_public_wpsi(str pi) { r_public *p=0; r_lock(r_hash_size); p = registrar[r_hash_size].head; while(p){ if (p->aor.len == pi.len && strncasecmp(p->aor.s,pi.s,pi.len)==0) return p; p = p->next; } r_unlock(r_hash_size); return 0; }
/** * Searches for a r_public record and returns it. * \note Aquires the lock on the hash slot on success, so release it when you are done. * @param aor - the address of record to look for * @returns - the r_public found, 0 if not found */ r_public* get_r_public(str aor) { r_public *p=0; unsigned int hash; hash = get_aor_hash(aor,r_hash_size); r_lock(hash); p = registrar[hash].head; while(p){ if (p->aor.len == aor.len && strncasecmp(p->aor.s,aor.s,aor.len)==0) return p; p = p->next; } r_unlock(hash); return 0; }
bool LeaseClerk::change(int64_t id, LeaseStatus status) { RWLock::Lock r_lock(mutex_, READ_LOCKER); LeaseEntryPtr lease = find(id); if (lease == 0) { TBSYS_LOG(ERROR, "lease not found by block id: %u", id); return false; } tbutil::Monitor<tbutil::Mutex>::Lock lock(*lease); lease->change(status); lease->notifyAll(); GFactory::get_timer()->cancel(lease); return true; }
/** * Creates and Adds a new r_public record. * \note Aquires the lock on the hash_slot on success, so release it when you are done. * \note When calling be sure that get_r_public(aor) returns 0, to avoid unreachable duplicates * @param aor - the address of record * @param reg_state - current registration state * @param s - the subscription attached * @returns the newly added r_public or NULL on error */ r_public* add_r_public(str aor,enum Reg_States reg_state,ims_subscription *s) { r_public *p; unsigned int hash; p = new_r_public(aor,reg_state,s); hash = p->hash; if (!p) return 0; p->next=0; r_lock(hash); p->prev=registrar[hash].tail; if (p->prev) p->prev->next = p; registrar[hash].tail = p; if (!registrar[hash].head) registrar[hash].head=p; return p; }
/** * Destroy the registrar */ void r_storage_destroy() { int i; r_public *p,*np; for(i=0;i<r_hash_size;i++){ r_lock(i); p = registrar[i].head; while(p){ np = p->next; free_r_public(p); p = np; } r_unlock(i); lock_dealloc(registrar[i].lock); } shm_free(registrar); }
/** * Destroy the registrar */ void r_storage_destroy() { int i; r_contact *c,*nc; for(i=0;i<r_hash_size;i++){ r_lock(i); c = registrar[i].head; while(c){ nc = c->next; free_r_contact(c); c = nc; } r_unlock(i); lock_dealloc(registrar[i].lock); } shm_free(registrar); }
/** * Creates and Adds a new r_contact * \note Aquires the lock on the hash_slot on success, so release it when you are done. * \note When calling be sure that get_r_contact(...) returns 0, to avoid unreachable duplicates * @param host - the host part of the contact, in string * @param port - the port number of the contact * @param transport - the transport of the contact * @param uri - URI of the contact * @param reg_state - Registration state * @param expires - expires in * @param service_route - array of service routes * @param service_route_cnt - the size of the array above * @param pinhole - NAT pin hole * @param sos_flag - type of registration: Emergency or Normal * @returns the newly added r_contact, 0 on error */ r_contact* add_r_contact(str host,int port,int transport,str uri, enum Reg_States reg_state,int expires,str *service_route,int service_route_cnt, r_nat_dest *pinhole, r_reg_type sos_flag) { r_contact *c; if (!registrar) return 0; c = new_r_contact(host,port,transport,uri,reg_state, expires, service_route, service_route_cnt, sos_flag); if (!c) return 0; c->next=0; r_lock(c->hash); c->prev=registrar[c->hash].tail; if (c->prev) c->prev->next = c; registrar[c->hash].tail = c; if (!registrar[c->hash].head) registrar[c->hash].head=c; c->pinhole = pinhole; c->sos_flag = sos_flag; return c; }
/** x = number being decoded in base N max_lock = index of highest lock acquired so far mask = bit mask; ith bit set if lock i has been acquired. */ void Body( size_t x, int max_lock=-1, unsigned int mask=0 ) const { int i = (int) (x % RecurN); bool first = (mask&1U<<i)==0; if( first ) { // first time to acquire lock if( i<max_lock ) // out of order acquisition might lead to deadlock, so stop return; max_lock = i; } if( (i&1)!=0 ) { // acquire lock on location RecurArray[i] using explict acquire tbb::recursive_mutex::scoped_lock r_lock; r_lock.acquire( RecurMutex[i] ); int a = RecurArray[i]; ASSERT( (a==0)==first, "should be either a==0 if it is the first time to acquire the lock or a!=0 otherwise" ); ++RecurArray[i]; if( x ) Body( x/RecurN, max_lock, mask|1U<<i ); --RecurArray[i]; ASSERT( a==RecurArray[i], "a is not equal to RecurArray[i]" ); // release lock on location RecurArray[i] using explicit release; otherwise, use implicit one if( (i&2)!=0 ) r_lock.release(); } else { // acquire lock on location RecurArray[i] using implicit acquire tbb::recursive_mutex::scoped_lock r_lock( RecurMutex[i] ); int a = RecurArray[i]; ASSERT( (a==0)==first, "should be either a==0 if it is the first time to acquire the lock or a!=0 otherwise" ); ++RecurArray[i]; if( x ) Body( x/RecurN, max_lock, mask|1U<<i ); --RecurArray[i]; ASSERT( a==RecurArray[i], "a is not equal to RecurArray[i]" ); // release lock on location RecurArray[i] using explicit release; otherwise, use implicit one if( (i&2)!=0 ) r_lock.release(); } }
/** * Searches for a r_contact contact and returns it. * \note Will lock the hash_slot if found! So release it when you are done! * @param host - the IP in string format * @param port - the port number * @param transport - the transport type * @param sos_mask - type of registration * @returns - the r_contact found, 0 if not found */ r_contact* get_r_contact(str host,int port,int transport, r_reg_type sos_mask) { r_contact *c=0; unsigned int hash; if (!registrar) return 0; hash = get_contact_hash(host,port,transport,r_hash_size); r_lock(hash); c = registrar[hash].head; while(c){ if (c->port == port && (c->sos_flag & sos_mask) && // c->transport == transport && /* because xten doesn't care about protocols */ c->host.len == host.len && strncasecmp(c->host.s,host.s,host.len)==0) return c; c = c->next; } r_unlock(hash); return 0; }
/** * Debug print the contents of the entire registrar. * @param log_level - logging level */ void print_r(int log_level) { r_public *p; r_contact *c; r_subscriber *s; int i; if (debug<log_level) return; /* to avoid useless calls when nothing will be printed */ r_act_time(); LOG(log_level,ANSI_GREEN"INF:"M_NAME":---------- Registrar Contents begin --------\n"); for(i=0;i<r_hash_size;i++){ r_lock(i); p = registrar[i].head; while(p){ LOG(log_level,ANSI_GREEN"INF:"M_NAME":[%4d] P: <"ANSI_BLUE"%.*s"ANSI_GREEN"> R["ANSI_MAGENTA"%2d"ANSI_GREEN"] Early-IMS: <"ANSI_YELLOW"%.*s"ANSI_GREEN"> \n",i, p->aor.len,p->aor.s,p->reg_state,p->early_ims_ip.len,p->early_ims_ip.s); if (p->ccf1.len) LOG(log_level,ANSI_GREEN"INF:"M_NAME": CCF1: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> CCF2: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> \n", p->ccf1.len,p->ccf1.s,p->ccf2.len,p->ccf2.s); if (p->ecf1.len) LOG(log_level,ANSI_GREEN"INF:"M_NAME": ECF1: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> ECF2: <"ANSI_MAGENTA"%.*s"ANSI_GREEN"> \n", p->ecf1.len,p->ecf1.s,p->ecf2.len,p->ecf2.s); c = p->head; while(c){ LOG(log_level,ANSI_GREEN"INF:"M_NAME": C: <"ANSI_RED"%.*s"ANSI_GREEN"> Exp:["ANSI_MAGENTA"%4ld"ANSI_GREEN"]\n", c->uri.len,c->uri.s,c->expires-time_now); LOG(log_level,ANSI_GREEN"INF:"M_NAME": Path:"ANSI_YELLOW"%.*s"ANSI_GREEN"\n",c->path.len,c->path.s); LOG(log_level,ANSI_GREEN"INF:"M_NAME": UA: <%.*s>\n", c->ua.len,c->ua.s); c = c->next; } s = p->shead; while(s){ LOG(log_level,ANSI_GREEN"INF:"M_NAME": S: Event["ANSI_BLUE"%d"ANSI_GREEN "] Exp:["ANSI_MAGENTA"%4ld"ANSI_GREEN"] <"ANSI_CYAN"%.*s"ANSI_GREEN"> \n", s->event,s->expires-time_now,s->subscriber.len,s->subscriber.s); s = s->next; } p = p->next; } r_unlock(i); } LOG(log_level,"INF:"M_NAME":---------- Registrar Contents end ----------\n"); }
r_contact * get_next_em_r_contact(str pub_id, contact_t * crt_contact){ r_contact * c = NULL; r_public * crt_pub_id; unsigned int hash; if (!registrar) return 0; for(hash=0; hash<r_hash_size;hash++){ r_lock(hash); for(c = registrar[hash].head;c!=NULL; c=c->next){ if(!(c->sos_flag & EMERG_REG)) continue; if(crt_contact->uri.len == c->uri.len && strncasecmp(crt_contact->uri.s, c->uri.s, crt_contact->uri.len) ==0){ LOG(L_DBG,"DBG:"M_NAME":update_contacts: found contact %.*s, but on the same host\n", crt_contact->uri.len, crt_contact->uri.s); continue; } crt_pub_id = c->head; if(!crt_pub_id) continue; if(crt_pub_id->aor.len == pub_id.len && strncasecmp(crt_pub_id->aor.s,pub_id.s,pub_id.len)==0) { LOG(L_DBG,"DBG:"M_NAME":get_next_em_r_contact: found contact %.*s:%i\n", c->host.len, c->host.s, c->port); return c; } } r_unlock(hash); } return 0; }
bool LeaseClerk::commit(int64_t id, uint32_t lease_id, LeaseStatus status) { LeaseEntryPtr lease = 0; { RWLock::Lock r_lock(mutex_, READ_LOCKER); lease = find(id); if (lease == 0) { TBSYS_LOG(WARN, "lease not found by id: %"PRI64_PREFIX"d", id); return false; } } TBSYS_LOG(DEBUG,"commit : %"PRI64_PREFIX"d, status: %d", id, status); Monitor<Mutex>::Lock lock(*lease); if (lease->id() != lease_id) { lease->notifyAll(); TBSYS_LOG(ERROR, "id: %"PRI64_PREFIX"d lease id not match %u:%u", id, lease->id(), lease_id); return false; } if (!lease->is_valid_lease()) { TBSYS_LOG(WARN, "id: %"PRI64_PREFIX"d has lease, but it: %u was invalid", id, lease_id); lease->change(LEASE_STATUS_EXPIRED); lease->notifyAll(); return false; } lease->change(status); lease->notifyAll(); TBSYS_LOG(DEBUG, "cancel ---------%"PRI64_PREFIX"d", lease->id()); GFactory::get_timer()->cancel(lease); return true; }
/** * Creates a snapshots of the registrar and then calls the dumping function. * @returns 1 on success or 0 on failure */ int make_snapshot_registrar() { bin_data x={0,0,0}; r_contact *c; int i,k; time_t unique = time(0); FILE *f; switch (pcscf_persistency_mode) { case NO_PERSISTENCY: return 0; case WITH_FILES: f = bin_dump_to_file_create(pcscf_persistency_location,"pregistrar",unique); if (!f) return 0; for(i=0;i<r_hash_size;i++){ if (!bin_alloc(&x,1024)) goto error; r_lock(i); c = registrar[i].head; if (c){ while(c){ if (!bin_encode_r_contact(&x,c)) goto error; c = c->next; } r_unlock(i); k = bind_dump_to_file_append(f,&x); if (k!=x.len) { LOG(L_ERR,"ERR:"M_NAME":make_snapshot_registrar: error while dumping to file - only wrote %d bytes of %d \n",k,x.len); r_unlock(i); bin_free(&x); return 0; } } else r_unlock(i); bin_free(&x); } return bind_dump_to_file_close(f,pcscf_persistency_location,"pregistrar",unique); break; case WITH_DATABASE_BULK: if (!bin_alloc(&x,1024)) goto error; for(i=0;i<r_hash_size;i++){ r_lock(i); c = registrar[i].head; while(c){ if (!bin_encode_r_contact(&x,c)) goto error; c = c->next; } r_unlock(i); } return bin_dump_to_db(&x, P_REGISTRAR); case WITH_DATABASE_CACHE: return bin_dump_to_db(NULL, P_REGISTRAR); //ignore x, x is empty default: LOG(L_ERR,"ERR:"M_NAME":make_snapshot_registrar: Snapshot done but no such mode %d\n",pcscf_persistency_mode); return 0; } error: if (x.s) bin_free(&x); return 0; }
std::string SeessionID::GetIPAddr(const std::string & sid) { ReadLock r_lock(myLock); return ptrsmap[sid].ipaddr; }
MsgRobotPos DataProvider::getLatestMsgRobotPos() { boost::shared_lock<boost::shared_mutex> r_lock(mutexMsgRobotPos); return *this->msgRobotPos; }
void DataProvider::setRunning(bool running_) { boost::shared_lock<boost::shared_mutex> r_lock(mutexMsgRobotPause); this->running = running_; }
bool DataProvider::isRunning() { boost::shared_lock<boost::shared_mutex> r_lock(mutexMsgRobotPause); return this->running; }
Direction::DIRECTION DataProvider::getLatestBaseDir() { boost::shared_lock<boost::shared_mutex> r_lock(mutexMsgEnvironment); return this->dirBase; }
MsgEnvironment DataProvider::getLatestMsgEnvironment() { boost::shared_lock<boost::shared_mutex> r_lock(mutexMsgEnvironment); return *this->msgEnvironment; }
Ptr_strVector SeessionID::GetVect(const std::string & sid) { ReadLock r_lock(myLock); return ptrsmap[sid].ptr_s; }
bool SeessionID::GetKillFlag(const std::string & sid) { ReadLock r_lock(myLock); return ptrsmap[sid].killflag; }
/** * Loads the registrar data from the last snapshot. * @returns 1 on success or 0 on failure */ int load_snapshot_registrar() { bin_data x; r_contact *c; int k,max; FILE *f; switch (pcscf_persistency_mode){ case NO_PERSISTENCY: k=0; case WITH_FILES: f = bin_load_from_file_open(pcscf_persistency_location,"pregistrar"); if (!f) return 0; bin_alloc(&x,128*1024); k=bin_load_from_file_read(f,&x); max = x.max; x.max=0; LOG(L_INFO,"INFO:"M_NAME":load_snapshot_registrar: max %d len %d\n",x.max,x.len); while(x.max<x.len){ c = bin_decode_r_contact(&x); if (!c) return 0; LOG(L_INFO,"INFO:"M_NAME":load_snapshot_registrar: Loaded r_contact for <%.*s>\n",c->uri.len,c->uri.s); r_lock(c->hash); c->prev = registrar[c->hash].tail; c->next = 0; if (registrar[c->hash].tail) registrar[c->hash].tail->next = c; registrar[c->hash].tail = c; if (!registrar[c->hash].head) registrar[c->hash].head = c; r_unlock(c->hash); memmove(x.s,x.s+x.max,x.len-x.max); x.len -= x.max; x.max = max; k=bin_load_from_file_read(f,&x); max = x.max; x.max = 0; } bin_free(&x); bin_load_from_file_close(f); k = 1; break; case WITH_DATABASE_BULK: k=bin_load_from_db(&x, P_REGISTRAR); x.max=0; LOG(L_INFO,"INFO:"M_NAME":load_snapshot_registrar: max %d len %d\n",x.max,x.len); while(x.max<x.len){ c = bin_decode_r_contact(&x); if (!c) return 0; LOG(L_INFO,"INFO:"M_NAME":load_snapshot_registrar: Loaded r_contact for <%.*s>\n",c->uri.len,c->uri.s); r_lock(c->hash); c->prev = registrar[c->hash].tail; c->next = 0; if (registrar[c->hash].tail) registrar[c->hash].tail->next = c; registrar[c->hash].tail = c; if (!registrar[c->hash].head) registrar[c->hash].head = c; r_unlock(c->hash); } bin_free(&x); break; case WITH_DATABASE_CACHE: k=bin_load_from_db(NULL, P_REGISTRAR); //ignore x, x is empty break; default: LOG(L_ERR,"ERR:"M_NAME":load_snapshot_registrar: Can't resume because no such mode %d\n",pcscf_persistency_mode); k=0; } if (!k) goto error; return 1; error: return 0; }
/** * Debug print the contents of the entire registrar. */ void print_r(int log_level) { r_public *p; r_contact *c; int i,j; #ifdef SER_MOD_INTERFACE if (!is_printable(log_level)) #else if (debug<log_level) #endif return; /* to avoid useless calls when nothing will be printed */ r_act_time(); LOG(log_level,"INF:"M_NAME":---------- Registrar Contents begin --------\n"); if (!registrar) return; for(i=0;i<r_hash_size;i++){ r_lock(i); c = registrar[i].head; while(c){ LOG(log_level,ANSI_GREEN"INF:"M_NAME":[%4d] C: <"ANSI_RED"%d://%.*s:%d"ANSI_GREEN"> Exp:["ANSI_MAGENTA"%4ld"ANSI_GREEN"] R:["ANSI_MAGENTA"%2d"ANSI_GREEN"] SOS:["ANSI_MAGENTA"%c"ANSI_GREEN"] <%.*s>\n",i, c->transport,c->host.len,c->host.s,c->port, c->expires-time_now,c->reg_state, (c->sos_flag & EMERG_REG)?'X':' ', c->uri.len,c->uri.s); for(j=0;j<c->service_route_cnt;j++) LOG(log_level,ANSI_GREEN"INF:"M_NAME": SR: <"ANSI_YELLOW"%.*s"ANSI_GREEN">\n",c->service_route[j].len,c->service_route[j].s); if(c->pinhole) { if (c->pinhole->nat_addr.len>=4) LOG(log_level,ANSI_GREEN"INF:"M_NAME": NAT:<"ANSI_CYAN"%d://%d.%d.%d.%d:%d"ANSI_GREEN">\n", c->pinhole->proto, c->pinhole->nat_addr.u.addr[0], c->pinhole->nat_addr.u.addr[1], c->pinhole->nat_addr.u.addr[2], c->pinhole->nat_addr.u.addr[3], (unsigned short)c->pinhole->nat_port); } if (c->security){ switch(c->security->type){ case SEC_NONE: break; case SEC_TLS: if (c->security->data.tls) LOG(log_level,ANSI_GREEN"INF:"M_NAME": TLS: %.*s tls://%.*s:%d\n", c->security->sec_header.len,c->security->sec_header.s, c->host.len,c->host.s,c->security->data.tls->port_tls); break; case SEC_IPSEC: if (c->security->data.ipsec) LOG(log_level,ANSI_GREEN"INF:"M_NAME": IPSec: UAS: %d:%d->%d UAC: %d:%d<-%d E[%.*s] I[%.*s]\n", c->security->data.ipsec->spi_uc,c->security->data.ipsec->port_uc,c->security->data.ipsec->spi_ps, c->security->data.ipsec->spi_us,c->security->data.ipsec->port_us,c->security->data.ipsec->spi_pc, c->security->data.ipsec->ealg.len,c->security->data.ipsec->ealg.s,c->security->data.ipsec->alg.len,c->security->data.ipsec->alg.s); } } if (c->security_temp){ switch(c->security_temp->type){ case SEC_NONE: break; case SEC_TLS: if (c->security_temp->data.tls) LOG(log_level,ANSI_GREEN"INF:"M_NAME": TLS: %.*s tls://%.*s:%d\n", c->security_temp->sec_header.len,c->security_temp->sec_header.s, c->host.len,c->host.s,c->security_temp->data.tls->port_tls); break; case SEC_IPSEC: if (c->security_temp->data.ipsec) LOG(log_level,ANSI_GREEN"INF:"M_NAME": Temp.IPSec: UAS: %d:%d->%d UAC: %d:%d<-%d E[%.*s] I[%.*s]\n", c->security_temp->data.ipsec->spi_uc,c->security_temp->data.ipsec->port_uc,c->security_temp->data.ipsec->spi_ps, c->security_temp->data.ipsec->spi_us,c->security_temp->data.ipsec->port_us,c->security_temp->data.ipsec->spi_pc, c->security_temp->data.ipsec->ealg.len,c->security_temp->data.ipsec->ealg.s,c->security_temp->data.ipsec->alg.len,c->security_temp->data.ipsec->alg.s); } } p = c->head; while(p){ LOG(log_level,ANSI_GREEN"INF:"M_NAME": P: D[%c] <"ANSI_BLUE"%.*s"ANSI_GREEN"> \n", (p->is_default?'X':' '),p->aor.len,p->aor.s); p = p->next; } c = c->next; } r_unlock(i); } LOG(log_level,"INF:"M_NAME":---------- Registrar Contents end ----------\n"); }