*** channels/chan_sip.c-org	Wed Mar 18 15:34:02 2009
--- channels/chan_sip.c	Thu Mar 19 01:09:13 2009
***************
*** 1023,1041 ****
  	struct sip_history_head *history;	/*!< History of this SIP dialog */
  	size_t history_entries;			/*!< Number of entires in the history */
  	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
  	AST_LIST_HEAD_NOLOCK(request_queue, sip_request) request_queue; /*!< Requests that arrived but could not be processed immediately */
  	int request_queue_sched_id;		/*!< Scheduler ID of any scheduled action to process queued requests */
  	struct sip_pvt *next;			/*!< Next dialog in chain */
  	struct sip_invite_param *options;	/*!< Options for INVITE */
  	int autoframing;
  	int hangupcause;			/*!< Storage of hangupcause copied from our owner before we disconnect from the AST channel (only used at hangup) */
! } *iflist = NULL;
  
  /*! Max entires in the history list for a sip_pvt */
  #define MAX_HISTORY_ENTRIES 50
  
  #define FLAG_RESPONSE (1 << 0)
  #define FLAG_FATAL (1 << 1)
  
  /*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission */
  struct sip_pkt {
--- 1023,1042 ----
  	struct sip_history_head *history;	/*!< History of this SIP dialog */
  	size_t history_entries;			/*!< Number of entires in the history */
  	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
  	AST_LIST_HEAD_NOLOCK(request_queue, sip_request) request_queue; /*!< Requests that arrived but could not be processed immediately */
  	int request_queue_sched_id;		/*!< Scheduler ID of any scheduled action to process queued requests */
  	struct sip_pvt *next;			/*!< Next dialog in chain */
  	struct sip_invite_param *options;	/*!< Options for INVITE */
  	int autoframing;
  	int hangupcause;			/*!< Storage of hangupcause copied from our owner before we disconnect from the AST channel (only used at hangup) */
! 	char addHeaderAutoAnswer;		/*!< If add Call-Info: answer-after=0 */ 
! } *iflist = NULL;	
  
  /*! Max entires in the history list for a sip_pvt */
  #define MAX_HISTORY_ENTRIES 50
  
  #define FLAG_RESPONSE (1 << 0)
  #define FLAG_FATAL (1 << 1)
  
  /*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission */
  struct sip_pkt {
***************
*** 3049,3066 ****
--- 3050,3069 ----
  			/* This is the referer */
  			referer = ast_var_value(current);
  		} else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) {
  			/* We're replacing a call. */
  			p->options->replaces = ast_var_value(current);
  		} else if (!strcasecmp(ast_var_name(current), "T38CALL")) {
  			p->t38.state = T38_LOCAL_DIRECT;
  			if (option_debug)
  				ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name);
+ 		} else if (!strcasecmp(ast_var_name(current), "AUTO_ANSWER_A")) {
+ 			p->addHeaderAutoAnswer = atoi(ast_var_value(current));
  		}
  
  	}
  	
  	res = 0;
  	ast_set_flag(&p->flags[0], SIP_OUTGOING);
  
  	if (p->options->transfer) {
  		char buf[SIPBUFSIZE/2];
***************
*** 7316,7333 ****
--- 7319,7351 ----
  		}
  	}
  	/* This new INVITE is part of an attended transfer. Make sure that the
  	other end knows and replace the current call with this new call */
  	if (p->options && p->options->replaces && !ast_strlen_zero(p->options->replaces)) {
  		add_header(&req, "Replaces", p->options->replaces);
  		add_header(&req, "Require", "replaces");
  	}
  
+ 	if ( p->addHeaderAutoAnswer )	/* if Originate sets a variable: AUTO_ANSWER_A=1 */
+ 	{
+ 		char callInfo[200];
+ 		switch ( p->addHeaderAutoAnswer )
+ 		{
+ 		case 1:
+ 			snprintf(callInfo, sizeof(callInfo), "<sip:%s>\\;answer-after=0", ast_inet_ntoa(p->ourip));
+ 			add_header(&req, "Call-Info", callInfo);
+ 			break;
+ 		case 2:
+ 			add_header(&req, "Call-Info", "answer-after=0");
+ 			break;
+ 		}
+ 	}
+ 
  	add_header(&req, "Allow", ALLOWED_METHODS);
  	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
  	if (p->options && p->options->addsipheaders && p->owner) {
  		struct ast_channel *chan = p->owner; /* The owner channel */
  		struct varshead *headp;
  	
  		ast_channel_lock(chan);
  
  		headp = &chan->varshead;

