コード例 #1
0
ファイル: bin_pcscf.c プロジェクト: winer632/openimscore-code
/**
 *	Decode a security from a binary data structure
 * @param x - binary data to decode from
 * @param sec - ** to write into
 * @returns 1 on success or 0 on failure
 */
int bin_decode_r_security(bin_data *x,r_security **sec)
{
	int len;
	str s;
	char c;
	int y;

	if (!bin_decode_char(x,	&c)) goto error;
	
	if (c==0) {
		*sec = 0;
		return 1;
	}
	
	len = sizeof(r_security);
	*sec = (r_security*) shm_malloc(len);
	if (!*sec) {
		LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_security: Error allocating %d bytes.\n",len);
		goto error;
	}
	memset(*sec,0,len);

	if (!bin_decode_str(x,&s)||!str_shm_dup(&((*sec)->sec_header),&s)) goto error;
	if (!bin_decode_int(x,&y)) goto error;
	(*sec)->type = y;
	switch ((*sec)->type){
		case SEC_NONE:
			break;		
		case SEC_TLS:
			if (!bin_decode_tls(x,&((*sec)->data.tls))) goto error;		
			break;
		case SEC_IPSEC:
			if (!bin_decode_ipsec(x,&((*sec)->data.ipsec))) goto error;
			break;
	}	
	if (!bin_decode_int(x,	&y)) goto error;
	(*sec)->q = ((float)y)/1000.0;
	
	return 1;
error:
	LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_security: Error while decoding (at %d (%04x)).\n",x->max,x->max);
	if (*sec) {
		if ((*sec)->sec_header.s) shm_free((*sec)->sec_header.s);
		switch ((*sec)->type){
			case SEC_NONE:
				break;		
			case SEC_TLS:
				if ((*sec)->data.tls) free_r_tls((*sec)->data.tls);
				break;
			case SEC_IPSEC:
				if ((*sec)->data.ipsec) free_r_ipsec((*sec)->data.ipsec); 
				break;
		}	
		shm_free(*sec);
		*sec = 0;
	}
	return 0;
}
コード例 #2
0
void free_r_security(r_security *s)
{
	if (!s) return;
	switch (s->type){
		case SEC_NONE:
			break;
		case SEC_TLS:
			if (s->data.tls) free_r_tls(s->data.tls);
			break;
		case SEC_IPSEC:
			if (s->data.ipsec) free_r_ipsec(s->data.ipsec);
			break;		
	}
	if (s->sec_header.s) shm_free(s->sec_header.s);
	shm_free(s);
}