示例#1
0
/* inserts an item to table, and removes the least item if the table is full */
int addcert2table(ttable *ptable, tcert_item *pcert)
{
	tcert_item *pshmcert;
	unsigned int uhash;

	if (!(pshmcert=(tcert_item *)shm_malloc(sizeof(*pshmcert)))) {
		LOG(L_ERR, "AUTH_IDENTITY:addcert2table: No enough shared memory\n");
		return -1;
	}
	memset(pshmcert, 0, sizeof(*pshmcert));
	if (str_duplicate(&pshmcert->surl, &pcert->surl))
		return -2;

	if (str_duplicate(&pshmcert->scertpem, &pcert->scertpem))
		return -3;

	pshmcert->ivalidbefore=pcert->ivalidbefore;
	pshmcert->uaccessed=1;

	uhash=get_hash1_raw(pcert->surl.s, pcert->surl.len) & (CERTIFICATE_TABLE_ENTRIES-1);

	if (insert_into_table(ptable, (void*)pshmcert, uhash))
		return -4;

	return 0;
}
/* begin the code for Autocomplete ------------------------------------------------------------------------------------------------------------
 This function adds a word into the table if it is not there already. It has no return value.
 */
void AutoComplete_AddWord(const char *word)
{
    Table *lastContainingPtr = getLastContaining(word);//get a pointer that points to the table that contains the last occurrence of the word
    if (lastContainingPtr == NULL || wordLocation(lastContainingPtr, word) == NULL){//check to make sure that the word is not already in the table
        TotalWords ++;//since the word has never been in the table before, increment the total number of words
        insert_into_table(word);//call the insert function
    }
#if DEBUG//run this code if DEBUG is set to true
    else {
        printf("The word (%s) was already inserted, and will not be added twice.\n", word);
    }
#endif
    
}
示例#3
0
/* inserts a callid item to table, and removes the least item if the table is full */
int proc_cid(ttable *ptable,
			 str *scid,
			 str *sftag,
			 unsigned int ucseq,
			 time_t ivalidbefore)
{
	tcid_item *pshmcid, *pcid_item;
	tdlg_item *pshmdlg, *pdlg_item, *pdlg_item_prev;
	unsigned int uhash;

	/* we suppose that this SIP request is not replayed so it doesn't exist in
	   the table so we prepare to insert */
	if (!(pshmdlg=(tdlg_item *)shm_malloc(sizeof(*pshmdlg)))) {
		LOG(L_ERR, "AUTH_IDENTITY:addcid2table: No enough shared memory\n");
		return -1;
	}
	memset(pshmdlg, 0, sizeof(*pshmdlg));
	if (str_duplicate(&pshmdlg->sftag, sftag))
		return -2;
	pshmdlg->ucseq=ucseq;


	/* we're looking for this call-id item if exists */
	uhash=get_hash1_raw(scid->s, scid->len) & (CALLID_TABLE_ENTRIES-1);

	lock_element(&ptable->entries[uhash]);

	pcid_item = search_item_in_table_unsafe(ptable,
											(const void *)scid, /* Call-id is the key */
											uhash);
	/* we've found one call-id so we're looking for the required SIP request */
	if (pcid_item) {
		for (pdlg_item=pcid_item->pdlgs, pdlg_item_prev=NULL;
		     pdlg_item;
			 pdlg_item=pdlg_item->pnext) {
			if (pdlg_item->sftag.len==sftag->len
				&& !memcmp(pdlg_item->sftag.s, sftag->s, sftag->len)) {
				/* we found this call with this from tag */
				if (pdlg_item->ucseq>=ucseq) {
					/* we've found this or older request in the table!
					   this call is replayed! */
					release_element(&ptable->entries[uhash]);

					shm_free(pshmdlg->sftag.s);
					shm_free(pshmdlg);
					return AUTH_FOUND;
				} else {
					/* this is another later request whithin this dialog so we
					   update the saved cseq */
					pdlg_item->ucseq=ucseq;
					release_element(&ptable->entries[uhash]);

					shm_free(pshmdlg->sftag.s);
					shm_free(pshmdlg);
					return 0;
				}
			}
			/* we save the previous dialog item in order to append a new item more easily */
			pdlg_item_prev ?
				(pdlg_item_prev=pdlg_item_prev->pnext) :
				(pdlg_item_prev=pdlg_item);
		}
		/* we append this to item dialogs*/
		pdlg_item_prev->pnext=pshmdlg;
		/* this is the latest request; we hold all request concerned this
		   call-id until the latest request is valid */
		pcid_item->ivalidbefore=ivalidbefore;
	}

	release_element(&ptable->entries[uhash]);

	if (!pcid_item) {
		/* this is the first request with this call-id */
		if (!(pshmcid=(tcid_item *)shm_malloc(sizeof(*pshmcid)))) {
			LOG(L_ERR, "AUTH_IDENTITY:addcid2table: No enough shared memory\n");
			return -4;
		}
		memset(pshmcid, 0, sizeof(*pshmcid));
		if (str_duplicate(&pshmcid->scid, scid)) {
			return -5;
		}
		pshmcid->ivalidbefore=ivalidbefore;
		pshmcid->pdlgs=pshmdlg;
		if (insert_into_table(ptable, (void*)pshmcid, uhash))
			return -6;
	}

	return 0;
}