*** ./asterisk/channels/chan_skinny.c	Sun Dec 19 16:13:41 2004
--- ./asterisk.skinny+/channels/chan_skinny.c	Tue Jan  4 21:55:45 2005
***************
*** 256,261 ****
--- 256,263 ----
  	char text[40];
  } displaytext_message;
  
+ #define CLEAR_DISPLAY_MESSAGE 0x009A
+ 
  #define	REGISTER_REJ_MESSAGE 0x009D
  typedef struct register_rej_message {
  	char errMsg[33];
***************
*** 934,939 ****
--- 936,968 ----
  	transmit_response(s, req);
  }
  
+ static void transmit_displaymessage(struct skinnysession *s, char *text)
+ {
+ 	skinny_req *req;
+ 
+ 	if (text == 0){
+ 		req = req_alloc(4);
+ 		req->len = 4;
+ 		req->e = CLEAR_DISPLAY_MESSAGE;
+ 	}else{
+ 		req = req_alloc(sizeof(struct displaytext_message));
+ 
+ 		/*XXX Is using 39 here legal? */
+ 		strncpy(req->data.displaytext.text,text,39);
+ 		req->len = sizeof(displaytext_message)+4;
+ 		req->e = DISPLAYTEXT_MESSAGE;
+ 		if (skinnydebug) {
+ 			ast_verbose("Displaying message '%s'\n",req->data.displaytext.text);
+ 		}
+ 	}
+ 
+ 	if (!req) {
+ 		ast_log(LOG_ERROR, "Unable to allocate skinny_request, this is bad\n");
+ 		return;
+ 	}
+ 	transmit_response(s, req);
+ }
+ 
  /* I do not believe skinny can deal with video. 
     Anyone know differently? */
  static struct ast_rtp *skinny_get_vrtp_peer(struct ast_channel *chan)
***************
*** 1508,1513 ****
--- 1537,1566 ----
  
  	transmit_lamp_indication(session, l->instance, SKINNY_LAMP_BLINK);
  	transmit_ringer_mode(session, SKINNY_RING_INSIDE);
+ 	/*transmit_displaymessage(session, "Incoming Call! w00t!");*/
+ 	
+ 	//Can you tell I don't know C?
+ 	if (ast->cid.cid_num){
+ 		char ciddisplay[39];
+ 		strcat (ciddisplay,"(");
+ 		strncat (ciddisplay, ast->cid.cid_num,3);
+ 		strcat (ciddisplay,") ");
+ 
+ 		strncat (ciddisplay, &ast->cid.cid_num[3],3);
+ 		strcat (ciddisplay,"-");
+ 		strncat (ciddisplay, &ast->cid.cid_num[6],4);
+ 		strncat (ciddisplay,"      ",6);
+ 		strncat (ciddisplay, ast->cid.cid_name,17);
+ 		if (skinnydebug) {
+ 			ast_verbose("Trying to send: '%s'\n",ciddisplay);
+ 		}
+ 
+ 		transmit_displaymessage(session, ciddisplay);
+ 	}else{
+ 		transmit_displaymessage(session, "Unknown Name");
+ 	}
+ 
+ 	//transmit_displaymessage(session, ast->cid.cid_num);
  	transmit_tone(session, tone);
  	transmit_callstate(session, l->instance, SKINNY_RINGIN, sub->callid);
  
***************
*** 1551,1562 ****
--- 1604,1625 ----
  	if ((sub->parent->type = TYPE_LINE) && (sub->parent->hookstate == SKINNY_OFFHOOK)) {
  			sub->parent->hookstate = SKINNY_ONHOOK;
  			transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
+ 			transmit_lamp_indication(s, l->instance, SKINNY_LAMP_OFF);
+ 			if (skinnydebug) {
+ 				ast_verbose("Attempting to Clear display on Skinny %s@%s\n",sub->parent->name, sub->parent->parent->name);
+ 			}
+ 			transmit_displaymessage(s, 0); /* clear display */
  			transmit_speaker_mode(s, SKINNY_SPEAKEROFF); 
  		} else if ((sub->parent->type = TYPE_LINE) && (sub->parent->hookstate == SKINNY_ONHOOK)) {
  			transmit_callstate(s, l->instance, SKINNY_ONHOOK, sub->callid);
  			transmit_speaker_mode(s, SKINNY_SPEAKEROFF); 
  			transmit_ringer_mode(s, SKINNY_RING_OFF);
  			transmit_tone(s, SKINNY_SILENCE);
+ 			transmit_lamp_indication(s, l->instance, SKINNY_LAMP_OFF);
+ 			if (skinnydebug) {
+ 				ast_verbose("Attempting to Clear display on Skinny %s@%s\n",sub->parent->name, sub->parent->parent->name);
+ 			}
+ 			transmit_displaymessage(s, 0); /* clear display */
  		} 
      }
      ast_mutex_lock(&sub->lock);
***************
*** 1715,1728 ****
      	}
  	switch(ind) {
  	case AST_CONTROL_RINGING:
! 		if (ast->_state == AST_STATE_RINGING) {
! 			if (!sub->progress) {		
  				transmit_tone(s, SKINNY_ALERT);
  				transmit_callstate(s, l->instance, SKINNY_RINGOUT, sub->callid);
  				sub->ringing = 1;
  				break;
! 			}
! 		}
  		return -1;
  	case AST_CONTROL_BUSY:
  		if (ast->_state != AST_STATE_UP) {		
--- 1778,1793 ----
      	}
  	switch(ind) {
  	case AST_CONTROL_RINGING:
! 		/*XXX This seems to keep the ringback from working. God Knows why */
! 
! 		//if (ast->_state != AST_STATE_RINGING) {
! 		//	if (!sub->progress) {		
  				transmit_tone(s, SKINNY_ALERT);
  				transmit_callstate(s, l->instance, SKINNY_RINGOUT, sub->callid);
  				sub->ringing = 1;
  				break;
! 		//	}
! 		//}
  		return -1;
  	case AST_CONTROL_BUSY:
  		if (ast->_state != AST_STATE_UP) {		
***************
*** 2182,2187 ****
--- 2247,2259 ----
             }
         	}
  
+ 	if (skinnydebug) {
+ 		ast_verbose("Attempting to Clear display on Skinny %s@%s\n",sub->parent->name, sub->parent->parent->name);
+ 	}
+ 	
+ 	transmit_displaymessage(s, 0); /* clear display */
+ 
+ 
         	if ((sub->parent->hookstate == SKINNY_ONHOOK) && (!sub->next->rtp)) {
  	    if (has_voicemail(sub->parent)) {
  	    	transmit_lamp_indication(s, s->device->lines->instance, SKINNY_LAMP_FLASH); 
