Commit 3cfd37d1 authored by jehan's avatar jehan
Browse files

fix memory leaks

parent 9c20abcc
......@@ -42,6 +42,78 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="test" path="tester" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290" moduleId="org.eclipse.cdt.core.settings" name="debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="debug config" id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290" name="debug" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.1209613831" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.973927327" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder arguments="CFLAGS=&quot;-g&quot;" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.190701400" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.419159753" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.c.linker.input.1079464415" superClass="cdt.managedbuild.tool.macosx.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base.482704190" name="MacOS X C++ Linker" superClass="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.macosx.base.1494835356" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1387320866" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.macosx.base.84823320" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1713349409" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2089521215" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="test" path="tester" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="belle-sip.null.1195886304" name="belle-sip"/>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/belle-sip"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
......@@ -54,16 +126,6 @@
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="makefileGenerator">
<runAction arguments="-E -P -v -dD" command="" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
......@@ -94,36 +156,6 @@
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/${specs_file}&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'g++ -E -P -v -dD &quot;${plugin_state_location}/specs.cpp&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/specs.c&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.1730055672;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999.2120750423;cdt.managedbuild.tool.gnu.c.compiler.input.1221270428">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
......@@ -136,16 +168,6 @@
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="makefileGenerator">
<runAction arguments="-E -P -v -dD" command="" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
......@@ -176,56 +198,59 @@
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526;cdt.managedbuild.tool.gnu.c.compiler.input.2089521215">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/${specs_file}&quot;'" command="sh" useDefault="true"/>
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'g++ -E -P -v -dD &quot;${plugin_state_location}/specs.cpp&quot;'" command="sh" useDefault="true"/>
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/specs.c&quot;'" command="sh" useDefault="true"/>
<runAction arguments="-E -P -v -dD ${plugin_state_location}/specs.cpp" command="g++" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
<runAction arguments="-s -C src discovery" command="make" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="makefileGenerator">
<runAction arguments="-E -P -v -dD" command="" useDefault="true"/>
<scannerInfoProvider id="specsFile">
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
......@@ -259,53 +284,6 @@
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/${specs_file}&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'g++ -E -P -v -dD &quot;${plugin_state_location}/specs.cpp&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="-c 'gcc -E -P -v -dD &quot;${plugin_state_location}/specs.c&quot;'" command="sh" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="test" path="tester" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="belle-sip.null.1195886304" name="belle-sip"/>
</storageModule>
</cproject>
......@@ -293,9 +293,11 @@ typedef struct _belle_sip_header_content_length belle_sip_header_content_length_
belle_sip_header_content_length_t* belle_sip_header_content_length_new();
belle_sip_header_content_length_t* belle_sip_header_content_length_parse (const char* content_length) ;
belle_sip_header_content_length_t* belle_sip_header_content_length_create (int content_length) ;
unsigned int belle_sip_header_content_length_get_content_length(const belle_sip_header_content_length_t* content_length);
void belle_sip_header_content_length_set_content_length(belle_sip_header_content_length_t* content_length,unsigned int length);
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
#define BELLE_SIP_CONTENT_LENGTH "Content-Length"
/******************************
* authorization header inherit from parameters
......
......@@ -105,6 +105,7 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
uri=belle_sip_uri_to_string(belle_sip_header_authorization_get_uri(authorization));
md5_append(&state,(const md5_byte_t *)uri,strlen(uri));
md5_finish(&state,out);
belle_sip_free(uri);
for (di = 0; di < 16; ++di)
sprintf(ha2 + di * 2, "%02x", out[di]);
/*response=MD5(HA1:nonce:HA2)*/
......
......@@ -194,6 +194,7 @@ belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* med
return media->media_formats;
}
void belle_sdp_media_set_media_formats( belle_sdp_media_t* media, belle_sip_list_t* formats) {
/*belle_sip_list_free(media->media_formats); to allow easy list management might be better to add an append format method*/
media->media_formats = formats;
}
void belle_sdp_media_destroy(belle_sdp_media_t* media) {
......
......@@ -81,9 +81,9 @@ static void belle_sip_header_address_init(belle_sip_header_address_t* object){
belle_sip_parameters_init((belle_sip_parameters_t*)object); /*super*/
}
static void belle_sip_header_address_destroy(belle_sip_header_address_t* contact) {
if (contact->displayname) belle_sip_free((void*)(contact->displayname));
if (contact->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(contact->uri));
static void belle_sip_header_address_destroy(belle_sip_header_address_t* address) {
if (address->displayname) belle_sip_free((void*)(address->displayname));
if (address->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(address->uri));
}
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
......@@ -570,9 +570,15 @@ int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* c
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
BELLE_SIP_NEW_HEADER(header_content_length,header,BELLE_SIP_CONTENT_LENGTH)
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
belle_sip_header_content_length_t* belle_sip_header_content_length_create (int content_length) {
belle_sip_header_content_length_t* obj;
obj = belle_sip_header_content_length_new();
belle_sip_header_content_length_set_content_length(obj,content_length);
return obj;
}
/**************************
* Expires header object inherent from header
****************************
......@@ -737,6 +743,8 @@ static void belle_sip_header_authorization_destroy(belle_sip_header_authorizatio
}
if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce);
AUTH_BASE_DESTROY(authorization)
DESTROY_STRING(authorization,response);
DESTROY_STRING(authorization,qop);
}
static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
......@@ -843,8 +851,9 @@ struct _belle_sip_header_www_authenticate {
static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authenticate_t* www_authenticate) {
AUTH_BASE_DESTROY(www_authenticate)
if (www_authenticate->domain) belle_sip_free((void*)www_authenticate->domain);
if (www_authenticate->qop) belle_sip_list_free(www_authenticate->qop);\
if (www_authenticate->qop) belle_sip_list_free_with_data(www_authenticate->qop,belle_sip_free);
}
void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
www_authenticate->stale=-1;
......
......@@ -43,7 +43,7 @@ void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t fun
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_source_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL,NULL,TRUE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL,NULL,FALSE);
belle_sip_source_t * belle_sip_fd_source_new(belle_sip_source_func_t func, void *data, int fd, unsigned int events, unsigned int timeout_value_ms){
belle_sip_source_t *s=belle_sip_object_new(belle_sip_source_t);
......@@ -69,7 +69,7 @@ struct belle_sip_main_loop{
};
void belle_sip_main_loop_remove_source(belle_sip_main_loop_t *ml, belle_sip_source_t *source){
if (!source->node.next || !source->node.prev) return; /*nothing to do*/
if (!source->node.next && !source->node.prev) return; /*nothing to do*/
ml->sources=belle_sip_list_remove_link(ml->sources,&source->node);
ml->nsources--;
......@@ -83,6 +83,7 @@ static void belle_sip_main_loop_destroy(belle_sip_main_loop_t *ml){
belle_sip_main_loop_remove_source(ml,ml->control);
close(ml->control_fds[0]);
close(ml->control_fds[1]);
belle_sip_object_unref(ml->control);
}
static int main_loop_done(void *data, unsigned int events){
......@@ -120,8 +121,8 @@ void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_
unsigned long belle_sip_main_loop_add_timeout(belle_sip_main_loop_t *ml, belle_sip_source_func_t func, void *data, unsigned int timeout_value_ms){
belle_sip_source_t * s=belle_sip_timeout_source_new(func,data,timeout_value_ms);
s->on_remove=(belle_sip_source_remove_callback_t)belle_sip_object_unref;
belle_sip_main_loop_add_source(ml,s);
belle_sip_object_unref(s);
return s->id;
}
......
......@@ -149,7 +149,7 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_object_vptr_t *vptr;
newobj=belle_sip_malloc0(obj->size);
newobj->ref=1;
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
vptr=obj->vptr;
......
......@@ -24,8 +24,8 @@ void belle_sip_parameters_init(belle_sip_parameters_t *obj){
}
static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
if (params->param_list) belle_sip_list_free (params->param_list);
if (params->paramnames_list) belle_sip_list_free (params->paramnames_list);
if (params->param_list) belle_sip_list_free_with_data (params->param_list, (void (*)(void*))belle_sip_param_pair_destroy);
if (params->paramnames_list) belle_sip_list_free(params->paramnames_list);
}
static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const belle_sip_parameters_t *orig){
......
......@@ -70,22 +70,135 @@ static void fix_incoming_via(belle_sip_request_t *msg, const struct addrinfo* or
belle_sip_header_via_set_rport(via,atoi(rport));
}
}
static int get_message_start_pos(char *buff, size_t bufflen) {
/*FIXME still to optimize an better tested, specially REQUEST PATH and error path*/
int i;
int res=0;
int status_code;
char method[16];
char saved_char1;
int saved_char1_index;
for(i=0; i<bufflen-12;i++) { /*9=strlen( SIP/2.0\r\n)*/
saved_char1_index=bufflen-1;
saved_char1=buff[saved_char1_index]; /*make sure buff is null terminated*/
buff[saved_char1_index]='\0';
if ((res=sscanf(buff+i,"SIP/2.0 %d ",&status_code)) == 1) {
buff[saved_char1_index]=saved_char1;
return i;
}
if (res==1) return i;
else {
res=sscanf(buff+i,"%16s %*s SIP/2.0 ",(char*)&method);
}
}
return -1;
}
static void belle_sip_channel_input_stream_reset(belle_sip_channel_input_stream_t* input_stream,int message_size) {
int message_residu=0;
if (message_size>0 && input_stream->write_ptr-input_stream->read_ptr>message_size) {
/*still message available, copy a beginning of stream ?*/
message_residu = input_stream->write_ptr-input_stream->read_ptr - message_size;
memcpy(input_stream->buff
,input_stream->read_ptr+message_size,
message_residu);
}
input_stream->read_ptr=input_stream->write_ptr=input_stream->buff;
input_stream->write_ptr+=message_residu;
input_stream->state=WAITING_MESSAGE_START;
input_stream->msg=NULL;
}
static size_t belle_sip_channel_input_stream_get_buff_lenght(belle_sip_channel_input_stream_t* input_stream) {
return MAX_CHANNEL_BUFF_SIZE - (input_stream->write_ptr-input_stream->read_ptr);
}
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
int err;
err=belle_sip_channel_recv(obj,&obj->input_stream.buff,MAX_CHANNEL_BUFF_SIZE-1);
if (err>0){
obj->input_stream.buff[err]='\0';
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,&obj->input_stream.buff);
obj->input_stream.msg=belle_sip_message_parse(obj->input_stream.buff);
int num;
int offset;
int i;
size_t message_size;
belle_sip_header_content_length_t* content_length_header;
int content_length;
num=belle_sip_channel_recv(obj,obj->input_stream.write_ptr,belle_sip_channel_input_stream_get_buff_lenght(&obj->input_stream)-1);
if (num>0){
/*first null terminate the buff*/
obj->input_stream.write_ptr[num]='\0';
obj->input_stream.write_ptr+=num;
if (obj->input_stream.state == WAITING_MESSAGE_START) {
/*search for request*/
if ((offset=get_message_start_pos(obj->input_stream.read_ptr,num)) >=0 ) {
/*message found !*/
if (offset>0) {
belle_sip_warning("trashing [%i] bytes in frot of sip message on channel [%p]",offset,obj);
obj->input_stream.read_ptr+=offset;
}
obj->input_stream.state=MESSAGE_AQUISITION;
} else {
belle_sip_warning("Unexpected [%s] received on channel [%p], trashing",obj->input_stream.write_ptr,obj);
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
}
if (obj->input_stream.state==MESSAGE_AQUISITION) {
/*search for \r\n\r\n*/
for (i=0;i<obj->input_stream.write_ptr-obj->input_stream.read_ptr;i++) {
if (strncmp("\r\n\r\n",&obj->input_stream.read_ptr[i],4)==0) {
/*end of message found*/
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,obj->input_stream.read_ptr);
obj->input_stream.msg=belle_sip_message_parse_raw(obj->input_stream.read_ptr
,obj->input_stream.write_ptr-obj->input_stream.read_ptr
,&message_size);
if (obj->input_stream.msg){
if (belle_sip_message_is_request(obj->input_stream.msg)) fix_incoming_via(BELLE_SIP_REQUEST(obj->input_stream.msg),obj->peer);
/*check for body*/
if ((content_length_header = (belle_sip_header_content_length_t*)belle_sip_message_get_header(obj->input_stream.msg,BELLE_SIP_CONTENT_LENGTH)) != NULL
&& belle_sip_header_content_length_get_content_length(content_length_header)>0) {
obj->input_stream.read_ptr+=message_size;
obj->input_stream.state=BODY_AQUISITION;
} else {
/*no body*/
goto message_ready;
}
}else{
belle_sip_error("Could not parse this message.");
belle_sip_error("Could not parse [%s], resetting channel [%p]",obj->input_stream.read_ptr,obj);
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
}
}
}
if (obj->input_stream.state==BODY_AQUISITION) {
content_length=belle_sip_header_content_length_get_content_length((belle_sip_header_content_length_t*)belle_sip_message_get_header(obj->input_stream.msg,BELLE_SIP_CONTENT_LENGTH));
if (content_length >= obj->input_stream.write_ptr-obj->input_stream.read_ptr) {
/*great body completed*/
belle_sip_message_set_body(obj->input_stream.msg,obj->input_stream.read_ptr,content_length);
goto message_ready;
}
}
return;
message_ready:
obj->incoming_messages=belle_sip_list_append(obj->incoming_messages,obj->input_stream.msg);
belle_sip_channel_input_stream_reset(&obj->input_stream,message_size);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_event,obj,revents);
if (obj->input_stream.write_ptr-obj->input_stream.read_ptr>0) {
/*process residu*/
belle_sip_channel_process_data(obj,revents);
}
return;
} else {
belle_sip_error("Receive error on channel [%p]",obj);
}
return;
}
void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack, int fd, belle_sip_source_func_t process_data,const char *bindip,int localport,const char *peername, int peer_port){
obj->peer_name=belle_sip_strdup(peername);
obj->peer_port=peer_port;
......@@ -98,6 +211,7 @@ void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack,
if (process_data) {
belle_sip_fd_source_init((belle_sip_source_t*)obj,(belle_sip_source_func_t)process_data,obj,fd,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR,-1);
}
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
void belle_sip_channel_add_listener(belle_sip_channel_t *obj, belle_sip_channel_listener_t *l){
......@@ -155,8 +269,15 @@ const struct addrinfo * belle_sip_channel_get_peer(belle_sip_channel_t *obj){
}
belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
belle_sip_message_t* result = obj->input_stream.msg;
obj->input_stream.msg=NULL;
belle_sip_message_t* result=NULL;
belle_sip_list_t* front;
if ((front=obj->incoming_messages)==NULL) {
belle_sip_error("Cannot pickup incoming message, empty list");
} else {
result = (belle_sip_message_t*)obj->incoming_messages->data;
obj->incoming_messages=belle_sip_list_remove_link(obj->incoming_messages,obj->incoming_messages);
belle_sip_free(front);
}
return result;
}
......@@ -193,6 +314,7 @@ void channel_process_queue(belle_sip_channel_t *obj){
break;
case BELLE_SIP_CHANNEL_READY:
send_message(obj, obj->msg);
/* no break */
case BELLE_SIP_CHANNEL_ERROR:
belle_sip_object_unref(obj->msg);
obj->msg=NULL;
......
......@@ -51,7 +51,7 @@ void (*on_sending)(belle_sip_channel_listener_t *l, belle_sip_channel_t *obj, be
BELLE_SIP_DECLARE_INTERFACE_END
#define BELLE_SIP_CHANNEL_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_channel_listener_t)
#define MAX_CHANNEL_BUFF_SIZE 64000
#define MAX_CHANNEL_BUFF_SIZE 64000 + 1500 + 1
typedef enum input_stream_state {
WAITING_MESSAGE_START=0
......@@ -62,6 +62,8 @@ typedef enum input_stream_state {
typedef struct belle_sip_channel_input_stream{
input_stream_state_t state;
char buff[MAX_CHANNEL_BUFF_SIZE];
char* read_ptr;
char* write_ptr;
belle_sip_message_t *msg;
}belle_sip_channel_input_stream_t;
......@@ -79,6 +81,7 @@ struct belle_sip_channel{
unsigned long resolver_id;