belle_sip_headers_impl.c 3.63 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/



#include "belle-sip/headers.h"
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"


/************************
 * header_address
 ***********************/
struct _belle_sip_header_address {
	int ref;
	const char* displayname;
	belle_sip_uri_t* uri;
};
belle_sip_header_address_t* belle_sip_header_address_new() {
	return (belle_sip_header_address_t*)belle_sip_new0(belle_sip_header_address_t);
}

void belle_sip_header_address_delete(belle_sip_header_address_t* contact) {
	if (contact->displayname) free((void*)(contact->displayname));
	if (contact->uri) belle_sip_uri_delete(contact->uri);
}

GET_SET_STRING(belle_sip_header_address,displayname);

jehan's avatar
jehan committed
49 50 51 52 53 54
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value) {
		if (address->displayname != NULL) belle_sip_free((void*)(address->displayname));
		size_t value_size = strlen(value);
		address->displayname=belle_sip_malloc0(value_size-2+1);
		strncpy((char*)(address->displayname),value+1,value_size-2);
}
jehan's avatar
jehan committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
belle_sip_uri_t* belle_sip_header_address_get_uri(belle_sip_header_address_t* address) {
	return address->uri;
}

void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri) {
	address->uri=uri;
}

BELLE_SIP_REF(header_address)


/************************
 * header_contact
 ***********************/
struct _belle_sip_header_contact {
	belle_sip_header_address_t address;
	int ref;
	int expires;
	float qvalue;
	unsigned int wildcard;
 };

belle_sip_header_contact_t* belle_sip_header_contact_new() {
	return (belle_sip_header_contact_t*)belle_sip_new0(belle_sip_header_contact_t);
}

void belle_sip_header_contact_delete(belle_sip_header_contact_t* contact) {
jehan's avatar
jehan committed
82
	belle_sip_header_address_delete((belle_sip_header_address_t*)contact);
jehan's avatar
jehan committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
}

BELLE_SIP_PARSE(header_contact);

GET_SET_INT_PRIVATE(belle_sip_header_contact,expires,int,_);
GET_SET_INT_PRIVATE(belle_sip_header_contact,qvalue,float,_);
GET_SET_BOOL(belle_sip_header_contact,wildcard,is);

int belle_sip_header_contact_set_expires(belle_sip_header_contact_t* contact, int expires) {
	if (expires < 0 ) {
		return -1;
	}
	_belle_sip_header_contact_set_expires(contact,expires);
	return 0;
 }
int belle_sip_header_contact_set_qvalue(belle_sip_header_contact_t* contact, float qValue) {
jehan's avatar
jehan committed
99
	 if (qValue != -1 && qValue < 0 && qValue >1) {
jehan's avatar
jehan committed
100 101 102 103 104 105
		 return -1;
	 }
	 _belle_sip_header_contact_set_qvalue(contact,qValue);
	 return 0;
}

jehan's avatar
jehan committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
/**
* From header object inherent from header_address
*
*/
struct _belle_sip_header_from  {
	belle_sip_header_address_t address;
	int ref;
	const char* tag;
};

BELLE_SIP_NEW(header_from)
BELLE_SIP_REF(header_from)
BELLE_SIP_PARSE(header_from)
GET_SET_STRING(belle_sip_header_from,tag);

void belle_sip_header_from_delete(belle_sip_header_from_t* from) {
	belle_sip_header_address_delete((belle_sip_header_address_t*)from);
}
jehan's avatar
jehan committed
124 125 126 127