예제 #1
0
/**
 * Returns the expires value from the message.
 * First it searches into the Expires header and if not found it also looks 
 * into the expires parameter in the contact header
 * @param msg - the SIP message
 * @param is_shm - msg from shared memory
 * @returns the value of the expire or the default 3600 if none found
 */
int cscf_get_max_expires(struct sip_msg *msg, int is_shm)
{
	unsigned int exp;
	int max_expires = -1;
	struct hdr_field *h;
	contact_t *c;
	/*first search in Expires header */
	max_expires = cscf_get_expires_hdr(msg, is_shm);

	cscf_parse_contacts(msg);
	for(h=msg->contact;h;h=h->next){
		if (h->type==HDR_CONTACT_T && h->parsed) {
			for(c=((contact_body_t *) h->parsed)->contacts;c;c=c->next){
				if(c->expires){
					if (!str2int(&(c->expires->body), (unsigned int*)&exp) && (int)exp>max_expires) max_expires = exp;
				}
			}
		}	
	}

	if(is_shm){
		for(h=msg->contact;h;h=h->next){
			if (h->type==HDR_CONTACT_T && h->parsed) {
				free_contact((contact_body_t**)&(h->parsed));
				h->parsed = 0;
			}
		}
	}

	return max_expires;
}
예제 #2
0
static gboolean
destroy (NstPlugin *plugin)
{
	GHashTableIter iter;
	GPtrArray *contacts_group;
	ContactData *dat;

	g_hash_table_iter_init (&iter, contact_hash);
	while (g_hash_table_iter_next (&iter, NULL, (gpointer)&contacts_group)) {
		gint accounts;
		accounts = contacts_group->len;

		gint i;
		for (i = 0; i < accounts; ++i) {
			dat = g_ptr_array_index (contacts_group, i);
			free_contact (dat);
		}
		g_ptr_array_free (contacts_group, TRUE);
	}
	g_hash_table_destroy (contact_hash);
	return TRUE;
}
예제 #3
0
/* returns : -1 - error
 *            0 - ok, but no contact added
 *            n - ok and n contacts added
 */
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
													long max, str *reason)
{
	static struct sip_msg  dup_rpl;
	static contact_t *scontacts[MAX_CONTACTS_PER_REPLY];
	struct hdr_field *hdr;
	struct hdr_field *contact_hdr;
	contact_t        *contacts;
	int n,i;
	int added;
	int dup;
	int ret;

	/* dup can be:
	 *    0 - sh reply but nothing duplicated 
	 *    1 - sh reply but only contact body parsed
	 *    2 - sh reply and contact header and body parsed
	 *    3 - private reply
	 */
	dup = 0; /* sh_rpl not duplicated */
	ret = 0; /* success and no contact added */

	if (sh_rpl==0 || sh_rpl==FAKED_REPLY)
		return 0;

	if (sh_rpl->contact==0) {
		/* contact header is not parsed */
		if ( sh_rpl->msg_flags&FL_SHM_CLONE ) {
			/* duplicate the reply into private memory to be able 
			 * to parse it and after words to free the parsed mems */
			memcpy( &dup_rpl, sh_rpl, sizeof(struct sip_msg) );
			dup = 2;
			/* ok -> force the parsing of contact header */
			if ( parse_headers( &dup_rpl, HDR_CONTACT_T, 0)<0 ) {
				LOG(L_ERR,"ERROR:uac_redirect:shmcontact2dset: dup_rpl "
					"parse failed\n");
				ret = -1;
				goto restore;
			}
			if (dup_rpl.contact==0) {
				DBG("DEBUG:uac_redirect:shmcontact2dset: contact hdr not "
					"found in dup_rpl\n");
				goto restore;
			}
			contact_hdr = dup_rpl.contact;
		} else {
			dup = 3;
			/* force the parsing of contact header */
			if ( parse_headers( sh_rpl, HDR_CONTACT_T, 0)<0 ) {
				LOG(L_ERR,"ERROR:uac_redirect:shmcontact2dset: sh_rpl "
					"parse failed\n");
				ret = -1;
				goto restore;
			}
			if (sh_rpl->contact==0) {
				DBG("DEBUG:uac_redirect:shmcontact2dset: contact hdr not "
					"found in sh_rpl\n");
				goto restore;
			}
			contact_hdr = sh_rpl->contact;
		}
	} else {
		contact_hdr = sh_rpl->contact;
	}

	/* parse the body of contact header */
	if (contact_hdr->parsed==0) {
		if ( parse_contact(contact_hdr)<0 ) {
			LOG(L_ERR,"ERROR:uac_redirect:shmcontact2dset: contact hdr "
				"parse failed\n");
			ret = -1;
			goto restore;
		}
		if (dup==0)
			dup = 1;
	}


	/* we have the contact header and its body parsed -> sort the contacts
	 * based on the q value */
	contacts = ((contact_body_t*)contact_hdr->parsed)->contacts;
	if (contacts==0) {
		DBG("DEBUG:uac_redirect:shmcontact2dset: contact hdr "
			"has no contacts\n");
		goto restore;
	}
	n = sort_contacts( contacts, scontacts);

	/* to many branches ? */
	if (max!=-1 && n>max)
		n = max;

	added = 0;

	/* add the sortet contacts as branches in dset and log this! */
	for ( i=0 ; i<n ; i++ ) {
		DBG("DEBUG:uac_redirect:shmcontact2dset: adding contact <%.*s>\n",
			scontacts[i]->uri.len, scontacts[i]->uri.s);
		if (append_branch( 0, &scontacts[i]->uri, 0, Q_UNSPECIFIED, 0, 0)<0 ) {
			LOG(L_ERR,"ERROR:uac_redirect:shmcontact2dset: failed to add "
				"contact to dset\n");
		} else {
			added++;
			if (rd_acc_fct!=0 && reason) {
				/* log the redirect */
				req->new_uri =  scontacts[i]->uri;
				rd_acc_fct( req, (char*)reason, acc_db_table);
			}
		}
	}

	ret = (added==0)?-1:added;
restore:
	if (dup==1) {
		free_contact( (contact_body_t**)(&contact_hdr->parsed) );
	} else if (dup==2) {
		/* are any new headers found? */
		if (dup_rpl.last_header!=sh_rpl->last_header) {
			/* identify in the new headere list (from dup_rpl) 
			 * the sh_rpl->last_header and start remove everything after */
			hdr = sh_rpl->last_header;
			free_hdr_field_lst(hdr->next);
			hdr->next=0;
		}
	}
	return ret;

}
예제 #4
0
/* returns : -1 - error
 *            0 - ok, but no contact added
 *            n - ok and n contacts added
 */
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
											long max, pv_elem_t *reason)
{
	static struct sip_msg  dup_rpl;
	static str scontacts[MAX_CONTACTS_PER_REPLY];
	static qvalue_t  sqvalues[MAX_CONTACTS_PER_REPLY];
	struct hdr_field *hdr;
	struct hdr_field *contact_hdr;
	contact_t        *contacts;
	str backup_uri;
	int n,i;
	int added;
	int dup;
	int ret;

	dup = 0; /* sh_rpl not duplicated */
	ret = 0; /* success and no contact added */
	contact_hdr = NULL;
	hdr = NULL;

	if (sh_rpl==0 || sh_rpl==FAKED_REPLY)
		return 0;

	if ( sh_rpl->msg_flags&FL_SHM_CLONE ) {
		/* duplicate the reply into private memory to be able
		 * to parse it and after words to free the parsed mems */
		memcpy( &dup_rpl, sh_rpl, sizeof(struct sip_msg) );
		LM_DBG("duplicating shm reply\n");
		dup = 1;
		/* ok -> force the parsing of contact header */
		if ( parse_headers( &dup_rpl, HDR_EOH_F, 0)<0 ) {
			LM_ERR("dup_rpl parse failed\n");
			ret = -1;
			goto restore;
		}
		if (dup_rpl.contact==0) {
			LM_DBG("contact hdr not found in dup_rpl\n");
			goto restore;
		}
		contact_hdr = dup_rpl.contact;
	} else {
		/* parse directly the current copy */
		/* force the parsing of contact header */
		if ( parse_headers( sh_rpl, HDR_EOH_F, 0)<0 ) {
			LM_ERR("sh_rpl parse failed\n");
			ret = -1;
			goto restore;
		}
		if (sh_rpl->contact==0) {
			LM_DBG("contact hdr not found in sh_rpl\n");
			goto restore;
		}
		contact_hdr = sh_rpl->contact;
	}

	/* iterate through all contact headers and extract the URIs */
	for( n=0,hdr=contact_hdr ; hdr ; hdr=hdr->sibling ) {

		/* parse the body of contact header */
		if (hdr->parsed==0) {
			if ( parse_contact(hdr)<0 ) {
				LM_ERR("contact hdr parse failed\n");
				ret = -1;
				goto restore;
			}
		}

		/* we have the contact header and its body parsed -> sort the contacts
		 * based on the q value */
		contacts = ((contact_body_t*)hdr->parsed)->contacts;
		if (contacts==0) {
			LM_DBG("contact hdr has no contacts\n");
		} else {
			sort_contacts( contacts, scontacts, sqvalues, &n);
		}

		/* clean currently added contact */
		if (dup)
			free_contact( (contact_body_t**)(void*)(&hdr->parsed) );
	}

	if (n==0) {
		LM_DBG("no contacts left after filtering\n");
		goto restore;
	}

	/* to many branches ? */
	if (max!=-1 && n>max)
		n = max;

	LM_DBG("%d contacts remaining after filtering and sorting\n",n);

	added = 0;

	/* add the sorted contacts as branches in dset and log this! */
	for ( i=0 ; i<n ; i++ ) {
		LM_DBG("adding contact <%.*s>\n",
			scontacts[i].len, scontacts[i].s);
		if (i==0) {
			/* set RURI*/
			if ( set_ruri( req, &scontacts[i])==-1 ) {
				LM_ERR("failed to set new RURI\n");
				goto restore;
			}
			set_ruri_q(req, sqvalues[i]);
		} else {
			if (append_branch(0,&scontacts[i],0,0,sqvalues[i],0,0)<0) {
				LM_ERR("failed to add contact to dset\n");
				continue;
			}
		}
		added++;
		if (rd_acc_fct!=0 && reason) {
			/* log the redirect */
			backup_uri = req->new_uri;
			req->new_uri =  scontacts[i];
			//FIXME
			rd_acc_fct( req, (char*)reason, acc_db_table,
					NULL, NULL, NULL, NULL);
			req->new_uri = backup_uri;
		}
	}

	ret = (added==0)?-1:added;
restore:
	if (dup==1) {
		/* free current parsed contact header */
		if (hdr && hdr->parsed)
			free_contact( (contact_body_t**)(void*)(&hdr->parsed) );
		/* are any new headers found? */
		if (dup_rpl.last_header!=sh_rpl->last_header) {
			/* identify in the new headere list (from dup_rpl)
			 * the sh_rpl->last_header and start remove everything after */
			hdr = sh_rpl->last_header;
			free_hdr_field_lst(hdr->next);
			hdr->next=0;
		}
	}
	return ret;
}
예제 #5
0
/* returns : -1 - error
 *            0 - ok, but no contact added
 *            n - ok and n contacts added
 */
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
								long max, struct acc_param *reason, unsigned int bflags)
{
	static struct sip_msg  dup_rpl;
	static contact_t *scontacts[MAX_CONTACTS_PER_REPLY];
	static qvalue_t  sqvalues[MAX_CONTACTS_PER_REPLY];
	struct hdr_field *hdr;
	struct hdr_field *contact_hdr;
	contact_t        *contacts;
	int n,i;
	int added;
	int dup;
	int ret;

	/* dup can be:
	 *    0 - sh reply but nothing duplicated 
	 *    1 - sh reply but only contact body parsed
	 *    2 - sh reply and contact header and body parsed
	 *    3 - private reply
	 */
	dup = 0; /* sh_rpl not duplicated */
	ret = 0; /* success and no contact added */
	contact_hdr = 0;

	if (sh_rpl==0 || sh_rpl==FAKED_REPLY)
		return 0;

	if (sh_rpl->contact==0) {
		/* contact header is not parsed */
		if ( sh_rpl->msg_flags&FL_SHM_CLONE ) {
			/* duplicate the reply into private memory to be able 
			 * to parse it and afterwards to free the parsed mems */
			memcpy( &dup_rpl, sh_rpl, sizeof(struct sip_msg) );
			dup = 2;
			/* ok -> force the parsing of contact header */
			if ( parse_headers( &dup_rpl, HDR_EOH_F, 0)<0 ) {
				LM_ERR("dup_rpl parse failed\n");
				ret = -1;
				goto restore;
			}
			if (dup_rpl.contact==0) {
				LM_DBG("contact hdr not found in dup_rpl\n");
				goto restore;
			}
			contact_hdr = dup_rpl.contact;
		} else {
			dup = 3;
			/* force the parsing of contact header */
			if ( parse_headers( sh_rpl, HDR_EOH_F, 0)<0 ) {
				LM_ERR("sh_rpl parse failed\n");
				ret = -1;
				goto restore;
			}
			if (sh_rpl->contact==0) {
				LM_DBG("contact hdr not found in sh_rpl\n");
				goto restore;
			}
			contact_hdr = sh_rpl->contact;
		}
	} else {
		contact_hdr = sh_rpl->contact;
	}

	/* parse the body of contact headers */
	hdr = contact_hdr;
	while(hdr) {
		if (hdr->type == HDR_CONTACT_T) {
			if (hdr->parsed==0) {
				if(parse_contact(hdr) < 0) {
					LM_ERR("failed to parse Contact body\n");
					ret = -1;
					goto restore;
				}
				if (dup==0)
					dup = 1;
				}
		}
		hdr = hdr->next;
	}

	/* we have the contact header and its body parsed -> sort the contacts
	 * based on the q value */
	contacts = ((contact_body_t*)contact_hdr->parsed)->contacts;
	if (contacts==0) {
		LM_DBG("contact hdr has no contacts\n");
		goto restore;
	}
	n = sort_contacts(contact_hdr, scontacts, sqvalues);
	if (n==0) {
		LM_DBG("no contacts left after filtering\n");
		goto restore;
	}

	i=0;

	/* more branches than requested in the parameter
	 * - add only the last ones from sorted array,
	 *   because the order is by increasing q */
	if (max!=-1 && n>max)
		i = n - max;

	added = 0;

	/* add the sortet contacts as branches in dset and log this! */
	for (  ; i<n ; i++ ) {
		LM_DBG("adding contact <%.*s>\n", scontacts[i]->uri.len,
				scontacts[i]->uri.s);
		if(sruid_next(&_redirect_sruid)==0) {
			if(append_branch( 0, &scontacts[i]->uri, 0, 0, sqvalues[i],
						bflags, 0, &_redirect_sruid.uid, 0,
						&_redirect_sruid.uid, &_redirect_sruid.uid)<0) {
				LM_ERR("failed to add contact to dset\n");
			} else {
				added++;
				if (rd_acc_fct!=0 && reason) {
					/* log the redirect */
					req->new_uri =  scontacts[i]->uri;
					//FIXME
					rd_acc_fct( req, (char*)reason, acc_db_table);
				}
			}
		} else {
			LM_ERR("failed to generate ruid for a new branch\n");
		}
	}

	ret = (added==0)?-1:added;
restore:
	if (dup==1) {
		free_contact( (contact_body_t**)(void*)(&contact_hdr->parsed) );
	} else if (dup==2) {
		/* are any new headers found? */
		if (dup_rpl.last_header!=sh_rpl->last_header) {
			/* identify in the new headere list (from dup_rpl) 
			 * the sh_rpl->last_header and start remove everything after */
			hdr = sh_rpl->last_header;
			free_hdr_field_lst(hdr->next);
			hdr->next=0;
		}
	}
	return ret;

}
예제 #6
0
파일: hf.c 프로젝트: Jared-Prime/kamailio
/** Frees a hdr_field structure.
 * WARNING: it frees only parsed (and not name.s, body.s)
 */
void clean_hdr_field(struct hdr_field* const hf)
{
	void** h_parsed;

	if (hf->parsed){
		h_parsed=&hf->parsed; /* strict aliasing warnings workarround */
		switch(hf->type){
		/* headers with pkg alloc for parsed structure (alphabetic order) */
		case HDR_ACCEPT_T:
			pkg_free(hf->parsed);
			break;

		case HDR_ALLOW_T:
			free_allow_header(hf);
			break;

		case HDR_AUTHORIZATION_T:
			free_credentials((auth_body_t**)h_parsed);
			break;

		case HDR_CONTACT_T:
			free_contact((contact_body_t**)h_parsed);
			break;

		case HDR_CONTENTDISPOSITION_T:
			free_disposition( ((struct disposition**)h_parsed));
			break;

		case HDR_CSEQ_T:
			free_cseq(hf->parsed);
			break;

		case HDR_DATE_T:
			free_date(hf->parsed);
			break;

		case HDR_DIVERSION_T:
			free_to(hf->parsed);
			break;

		case HDR_EVENT_T:
			free_event((event_t**)h_parsed);
			break;

		case HDR_EXPIRES_T:
			free_expires((exp_body_t**)h_parsed);
			break;

		case HDR_FROM_T:
			free_to(hf->parsed);
			break;

		case HDR_IDENTITY_INFO_T:
			free_identityinfo(hf->parsed);
			break;

		case HDR_IDENTITY_T:
			free_identity(hf->parsed);
			break;

		case HDR_PAI_T:
			free_pai_ppi_body(hf->parsed);
			break;

		case HDR_PPI_T:
			free_pai_ppi_body(hf->parsed);
			break;

		case HDR_PROXYAUTH_T:
			free_credentials((auth_body_t**)h_parsed);
			break;

		case HDR_RECORDROUTE_T:
			free_rr((rr_t**)h_parsed);
			break;

		case HDR_REFER_TO_T:
			free_to(hf->parsed);
			break;

		case HDR_ROUTE_T:
			free_rr((rr_t**)h_parsed);
			break;

		case HDR_RPID_T:
			free_to(hf->parsed);
			break;

		case HDR_SESSIONEXPIRES_T:
			hdr_free_parsed(h_parsed);
			break;

		case HDR_SIPIFMATCH_T:
			free_sipifmatch((str **)h_parsed);
			break;

		case HDR_SUBSCRIPTION_STATE_T:
			free_subscription_state((subscription_state_t**)h_parsed);
			break;

		case HDR_SUPPORTED_T:
			hdr_free_parsed(h_parsed);
			break;

		case HDR_TO_T:
			free_to(hf->parsed);
			break;

		case HDR_VIA_T:
			free_via_list(hf->parsed);
			break;

		/* headers with no alloc for parsed structure */
		case HDR_CALLID_T:
		case HDR_MAXFORWARDS_T:
		case HDR_CONTENTTYPE_T:
		case HDR_CONTENTLENGTH_T:
		case HDR_RETRY_AFTER_T:
		case HDR_REQUIRE_T:
		case HDR_PROXYREQUIRE_T:
		case HDR_UNSUPPORTED_T:
		case HDR_ACCEPTLANGUAGE_T:
		case HDR_ORGANIZATION_T:
		case HDR_PRIORITY_T:
		case HDR_SUBJECT_T:
		case HDR_USERAGENT_T:
		case HDR_SERVER_T:
		case HDR_MIN_SE_T:
		case HDR_ACCEPTCONTACT_T:
		case HDR_ALLOWEVENTS_T:
		case HDR_CONTENTENCODING_T:
		case HDR_REFERREDBY_T:
		case HDR_REJECTCONTACT_T:
		case HDR_REQUESTDISPOSITION_T:
		case HDR_WWW_AUTHENTICATE_T:
		case HDR_PROXY_AUTHENTICATE_T:
		case HDR_PATH_T:
		case HDR_PRIVACY_T:
		case HDR_REASON_T:
			break;

		default:
			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
			    hf->type);
			break;
		}
	}
}
예제 #7
0
파일: hf.c 프로젝트: KISSMonX/opensips
/*
 * Frees a hdr_field structure,
 * WARNING: it frees only parsed (and not name.s, body.s)
 */
void clean_hdr_field(struct hdr_field* hf)
{
	if (hf->parsed){
		switch(hf->type){
		case HDR_VIA_T:
			free_via_list(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_TO_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_FROM_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_CSEQ_T:
			free_cseq(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_CALLID_T:
			break;

		case HDR_CONTACT_T:
			free_contact((contact_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_MAXFORWARDS_T:
			break;

		case HDR_ROUTE_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_RECORDROUTE_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_PATH_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_CONTENTTYPE_T:
			free_contenttype((content_t**)(void*)(&hf->parsed));
			break;

		case HDR_CONTENTLENGTH_T:
			break;

		case HDR_AUTHORIZATION_T:
			free_credentials((auth_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_EXPIRES_T:
			free_expires((exp_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_PROXYAUTH_T:
			free_credentials((auth_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_SUPPORTED_T:
			free_supported((struct supported_body**)(void*)(&(hf->parsed)));
			break;

		case HDR_PROXYREQUIRE_T:
			break;

		case HDR_UNSUPPORTED_T:
			break;

		case HDR_ALLOW_T:
			free_allow((struct allow_body**)(void*)(&(hf->parsed)));
			break;

		case HDR_EVENT_T:
			free_event((event_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_ACCEPT_T:
			pkg_free(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_ACCEPTLANGUAGE_T:
			break;
			
		case HDR_ORGANIZATION_T:
			break;
			
		case HDR_PRIORITY_T:
			break;

		case HDR_SUBJECT_T:
			break;

		case HDR_USERAGENT_T:
			break;

		case HDR_ACCEPTDISPOSITION_T:
			break;

		case HDR_CONTENTDISPOSITION_T:
			free_disposition( ((struct disposition**)(void*)(&hf->parsed)) );
			break;

		case HDR_DIVERSION_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_RPID_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_REFER_TO_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_SESSION_EXPIRES_T:
			free_session_expires((struct session_expires*)hf->parsed );
			hf->parsed = NULL;
			break;

		case HDR_MIN_SE_T:
			break;

		case HDR_MIN_EXPIRES_T:
			break;

		case HDR_PPI_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_PAI_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_PRIVACY_T:
			break;

		case HDR_RETRY_AFTER_T:
			break;

		case HDR_CALL_INFO_T:
			free_call_info(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_WWW_AUTHENTICATE_T:
		case HDR_PROXY_AUTHENTICATE_T:
			free_authenticate((struct authenticate_body *)hf->parsed);
			hf->parsed = NULL;
			break;

		default:
			LM_CRIT("unknown header type %d\n", hf->type);
			break;
		}
	}
}
예제 #8
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx, delete_all = 0, updated = 0;
	dldev_t dev;
	contact_t db;
	contact_data_t rec;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	while((i = getopt(argc, argv, "hd:a")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'a':
			delete_all = 1;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	memset(&rec, 0, sizeof(contact_data_t));
	BEGIN_OPT()
		OPT("msg", rec.msg)
		OPT("type", rec.type)
		OPT("area", rec.area)
		OPT("number", rec.number)
	END_OPT()

	if(delete_all){
		fprintf(stderr,
			"WARNING: DELETE ALL CONTACTS IN THE WATCH (Y/N)? ");
		if(tolower(getchar()) != 'y')
			exit(0);
	}else
	if(istty && (!rec.msg || !rec.type || !rec.area || !rec.number))
		usage();

	/* TODO: long phone number extending to the next or previous record */

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, "CONTACT")) < 0){
		ERROR("CONTACT application not found");
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}

	read_contact(&db, data);
	free(data);

	if(delete_all){
		while(!del_contact(&db, 0))
			updated = 1;
	}else{
		if(!istty && !del_contact_file(&db, stdin))
			updated = 1;

		if(rec.msg && rec.type && rec.area && rec.number &&
			(i = find_contact(&db, &rec)) >= 0 &&
			!del_contact(&db, i))
			updated = 1;
	}

	if(updated){
		create_contact(&db, &data, &len);
		if(load_add(&dev, idx, data)){
			ERROR("load_add");
			goto end;
		}
		free(data);
	}

	print_contact(&db, stdout);
	free_contact(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
예제 #9
0
/* 
 * Frees a hdr_field structure,
 * WARNING: it frees only parsed (and not name.s, body.s)
 */
void clean_hdr_field(struct hdr_field* hf)
{
	if (hf->parsed){
		switch(hf->type){
		case HDR_VIA:
			free_via_list(hf->parsed);
			break;

		case HDR_TO:
			free_to(hf->parsed);
			break;

		case HDR_FROM:
			free_to(hf->parsed);
			break;

		case HDR_CSEQ:
			free_cseq(hf->parsed);
			break;

		case HDR_CALLID:
			break;

		case HDR_CONTACT:
			free_contact((contact_body_t**)(&(hf->parsed)));
			break;

		case HDR_MAXFORWARDS:
			break;

		case HDR_ROUTE:
			free_rr((rr_t**)(&hf->parsed));
			break;

		case HDR_RECORDROUTE:
			free_rr((rr_t**)(&hf->parsed));
			break;

		case HDR_CONTENTTYPE:
			break;

		case HDR_CONTENTLENGTH:
			break;

		case HDR_AUTHORIZATION:
			free_credentials((auth_body_t**)(&(hf->parsed)));
			break;

		case HDR_EXPIRES:
			free_expires((exp_body_t**)(&(hf->parsed)));
			break;

		case HDR_PROXYAUTH:
			free_credentials((auth_body_t**)(&(hf->parsed)));
			break;

		case HDR_SUPPORTED:
			break;

		case HDR_PROXYREQUIRE:
			break;

		case HDR_UNSUPPORTED:
			break;

		case HDR_ALLOW:
			break;

		case HDR_EVENT:
			free_event((event_t**)(&(hf->parsed)));
			break;

		case HDR_ACCEPT:
			pkg_free(hf->parsed);
			break;

		case HDR_ACCEPTLANGUAGE:
			break;
			
		case HDR_ORGANIZATION:
			break;
			
		case HDR_PRIORITY:
			break;

		case HDR_SUBJECT:
			break;

		case HDR_USERAGENT:
			break;

		case HDR_ACCEPTDISPOSITION:
			break;

		case HDR_CONTENTDISPOSITION:
			free_disposition( ((struct disposition**)(&hf->parsed)) );
			break;

		default:
			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
			    hf->type);
			break;
		}
	}
}