diff -cr asterisk-1.8.15.0-orig/channels/chan_sip.c asterisk-1.8.15.0/channels/chan_sip.c
*** asterisk-1.8.15.0-orig/channels/chan_sip.c	Mon Jul  9 16:38:18 2012
--- asterisk-1.8.15.0/channels/chan_sip.c	Thu Sep 20 18:04:44 2012
***************
*** 16361,16366 ****
--- 16361,16482 ----
  }
  
  
+ /**
+  * Envoi d'un message de type messagerien instantanee
+  */
+ static int send_message_by_name(const char *from, char *peername,const char *content_type, char *text)
+  {
+  	struct sip_pvt *p;
+  	struct sip_peer *r;
+  	struct sip_request req;
+  	char *sender_peername,*sender_name, *tmp, *tmp1;
+  	char clen[256];
+  
+  	p = sip_alloc(NULL, NULL, 0, SIP_MESSAGE,NULL);
+  	if (!p) {
+  		ast_log(LOG_WARNING, "Unable to build sip pvt data for message\n");
+  		return RESULT_FAILURE;
+  	}
+  
+  	//ast_log(LOG_WARNING,"Envoi de %s  \n",peername);
+  
+  	if (create_addr(p, peername,NULL,0,NULL)) {
+  		sip_destroy(p);
+  		ast_verbose("Could not create address for message delivery to '%s' \n", peername);
+  		return RESULT_FAILURE;
+  	}
+  
+  	// Affichage pour debug du from complet
+  	ast_log(LOG_DEBUG,"send_message_by_name : from complet : %s \n",ast_strdupa(from));
+  
+  	// Recherche du nom dans le message de l'envoyeur
+  	// ie le CallerName car il n'est pas defini dans l'asterisk, on reprend celui du softphone de l'emetteur
+  	sender_name=ast_strdupa(from);
+  	tmp=strstr(sender_name,"\"");
+  	if (tmp) {
+  		tmp+=1; // on decale de 1 pour virer le double quote du debut
+  		sender_name=tmp;
+  		if ((tmp=strstr(sender_name,"\""))) {
+  			*tmp='\0';
+  			tmp++;
+  			ast_log(LOG_DEBUG,"send_message_by_name : nom de l'expediteur : %s \n",sender_name);
+                          // dans le sip_pvt (preparation du message sip), on recopie le nom du from trouve
+  			ast_string_field_set(p, fromname,sender_name);
+  		}
+  	}
+  
+  	// Recherche du numero et du domaine de l'envoyeur
+  	sender_peername=ast_strdupa(from);	
+  	tmp=strstr(sender_peername,"sip:");
+  	if (tmp) {
+  		tmp+=4;
+  		sender_peername=tmp;
+  		if ((tmp=strstr(sender_peername,"@")))
+  		{
+  			*tmp='\0';
+  			tmp++;
+  			if ((tmp1=strstr(tmp,">"))) {
+  				*tmp1='\0';
+  				ast_log(LOG_DEBUG,"send_message_by_name : domaine trouve : %s \n",tmp);
+  				ast_string_field_set(p, fromdomain, tmp);
+  			}
+  		}
+  		r=find_peer(sender_peername,NULL,1,FINDALLDEVICES, FALSE, 0);
+  		if (r) {
+  			if (!ast_strlen_zero(r->cid_name)) {
+  				ast_log(LOG_DEBUG,"send_message_by_name : Changement du nom par %s\n",r->cid_name);
+  				ast_string_field_set(p, fromname,r->cid_name);
+  			}
+  			if (!ast_strlen_zero(r->username)) {
+  				ast_log(LOG_DEBUG,"send_message_by_name : Changement du num par %s\n",r->username);
+  				ast_string_field_set(p, fromuser,r->username);
+  			}
+  			if (!ast_strlen_zero(r->fromdomain)) {
+  				ast_log(LOG_DEBUG,"send_message_by_name : Changement du domaine par %s\n",r->fromdomain);
+  				ast_string_field_set(p, fromdomain,r->fromdomain);
+  			}
+  		} else {
+  			ast_log(LOG_DEBUG,"send_message_by_name : peer de destination NON trouve ! \n");
+  		}
+  	}
+  
+  	initreqprep(&req, p, SIP_MESSAGE,NULL);
+  	/* Recalculate our side, and recalculate Call ID */
+  	//if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p))
+  	//	memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
+  	build_via(p);
+  	build_callid_pvt(p);
+  
+  
+  	// These are added by initreqprep
+  	// add_header(&req, "From", callerid);
+  	// add_header(&req, "To", peername);
+  
+  	// we could use addtext, but we want to support different content-types, such
+  	// as application/im-iscomposing+xml
+  	// add_text(&req, text);
+  
+  	snprintf(clen, sizeof(clen), "%d", strlen(text));
+  	add_header(&req, "Content-Type", content_type);
+  	//add_header(&req, "Content-Length", clen);
+  	add_content(&req, text);
+  
+  	ast_log(LOG_DEBUG,"send_message_by_name : envoi du message\n ");	
+  
+  	send_request(p, &req, XMIT_RELIABLE, p->ocseq);
+  	sip_scheddestroy(p, 15000);
+  	return RESULT_SUCCESS;
+  }
+  
+  static int send_message_by_name_or_queue(const char *from, char *peername,const char *content_type, char *text) {
+  
+          if (send_message_by_name(from,peername,content_type,text)) {
+                  return RESULT_FAILURE;
+          }
+          return RESULT_SUCCESS;
+  
+  }
+ 
  /*! \brief  Receive SIP MESSAGE method messages
  \note	We only handle messages within current calls currently
  	Reference: RFC 3428 */
***************
*** 16370,16382 ****
  	char *bufp;
  	struct ast_frame f;
  	const char *content_type = get_header(req, "Content-Type");
  
! 	if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */
! 		transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */
  		if (!p->owner)
  			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
  		return;
! 	}
  
  	if (get_msg_text(buf, sizeof(buf), req)) {
  		ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid);
--- 16486,16502 ----
  	char *bufp;
  	struct ast_frame f;
  	const char *content_type = get_header(req, "Content-Type");
+ 	char *message_to = "";
+ 	char *type;
+ 	char *tmp ;
+ 	char hint[AST_MAX_EXTENSION];
  
! 	/*if (strncmp(content_type, "text/plain", strlen("text/plain"))) {
! 		transmit_response(p, "415 Unsupported Media Type", req);
  		if (!p->owner)
  			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
  		return;
! 	}*/
  
  	if (get_msg_text(buf, sizeof(buf), req)) {
  		ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid);
***************
*** 16409,16416 ****
  	}
  
  	/* Message outside of a call, we do not support that */
! 	ast_log(LOG_WARNING, "Received message to %s from %s, dropped it...\n  Content-Type:%s\n  Message: %s\n", get_header(req, "To"), get_header(req, "From"), content_type, buf);
! 	transmit_response(p, "405 Method Not Allowed", req);
  	sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
  	return;
  }
--- 16529,16568 ----
  	}
  
  	/* Message outside of a call, we do not support that */
! 	/*ast_log(LOG_WARNING, "Received message to %s from %s, dropped it...\n  Content-Type:%s\n  Message: %s\n", get_header(req, "To"), get_header(req, "From"), content_type, buf);
! 	transmit_response(p, "405 Method Not Allowed", req);*/
! 
! 	tmp=get_header(req,"To");
! 	if (! (tmp=strstr(tmp,"sip:"))) {
! 		ast_log(LOG_WARNING,"Received message to %s from %s, dropped it because target is not sip and we don't support that...\n  Content-Type:%s\n  Message: %s\n", get_header(req,"To"), get_header(req,"From"), content_type, buf);
! 		transmit_response(p, "405 Method not allowed", req);
! 		return;
! 	}
! 	tmp+=4;
! 	message_to=ast_strdupa(tmp);
! 	if ((tmp=strstr(message_to,"@"))) {
! 		*tmp='\0';
! 	}
! 	ast_log(LOG_DEBUG,"receive_message : Message to : %s from %s \n",message_to,p->cid_name);
! 	// Recherche de l'existance du destinataire dans les hint qui doivent donc etre presents
! 	if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, "local", message_to)) {
! 		message_to=hint;
! 		type=strsep(&message_to,"/");
! 		if (strncmp(type,"SIP",3)) {
! 			ast_log(LOG_WARNING,"Received message to %s from %s, dropped it, because hint channel type is not SIP, but %s. We don't support this...\n  Content-Type:%s\n  Message: %s\n", get_header(req,"To"), get_header(req,"From"), type, content_type, buf);
! 			transmit_response(p, "405 Method not allowed", req);
! 			return;
! 		}
! 		if (send_message_by_name_or_queue(get_header(req,"From"), message_to,content_type, buf)) {
! 			transmit_response(p, "405 Method not allowed", req);
! 		} else {
! 			transmit_response(p, "202 Accepted", req);
! 		}
! 	} else {
! 		ast_log(LOG_WARNING,"Received message to %s from %s, dropped it because hint not found ...\n  Content-Type:%s\n  Message: %s\n", get_header(req,"To"), get_header(req,"From"), content_type, buf);
! 		transmit_response(p, "405 Method not allowed", req);	/* Good enough or? */
! 	}
! 
  	sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
  	return;
  }
***************
*** 20787,20795 ****
  		break;
  	case 403:	/* Forbidden */
  		ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname);
! 		AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 403"));
  		r->regstate = REG_STATE_NOAUTH;
! 		pvt_set_needdestroy(p, "received 403 response");
  		break;
  	case 404:	/* Not found */
  		ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username, p->registry->hostname);
--- 20939,20947 ----
  		break;
  	case 403:	/* Forbidden */
  		ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname);
! 		//AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 403"));
  		r->regstate = REG_STATE_NOAUTH;
! 		//pvt_set_needdestroy(p, "received 403 response");
  		break;
  	case 404:	/* Not found */
  		ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username, p->registry->hostname);
diff -cr asterisk-1.8.15.0-orig/main/dsp.c asterisk-1.8.15.0/main/dsp.c
*** asterisk-1.8.15.0-orig/main/dsp.c	Fri Jun 15 17:56:08 2012
--- asterisk-1.8.15.0/main/dsp.c	Thu Sep 20 15:29:07 2012
***************
*** 1350,1357 ****
  		break;
  	default:
  		/*Display warning only once. Otherwise you would get hundreds of warnings every second */
! 		if (dsp->display_inband_dtmf_warning)
  			ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec));
  		dsp->display_inband_dtmf_warning = 0;
  		return af;
  	}
--- 1350,1358 ----
  		break;
  	default:
  		/*Display warning only once. Otherwise you would get hundreds of warnings every second */
! 		/*if (dsp->display_inband_dtmf_warning)
  			ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec));
+ 		*/
  		dsp->display_inband_dtmf_warning = 0;
  		return af;
  	}
