int AmReplyHandler::handleRequest(AmCtrlInterface* ctrl)
{
    AmSipReply reply;

    string tmp_str;
    SAFECTRLCALL1(getParam,tmp_str);
    
    DBG("response from Ser: %s\n",tmp_str.c_str());
    if( parse_return_code(tmp_str.c_str(),// res_code_str,
			  reply.code,reply.reason) == -1 ){
	ERROR("while parsing return code from Ser.\n");
	//cleanup(ctrl);
	return -1;
    }

    /* Parse complete response:
     *
     *   [next_request_uri->cmd.from_uri]CRLF
     *   [next_hop->cmd.next_hop]CRLF
     *   [route->cmd.route]CRLF
     *   ([headers->n_cmd.hdrs]CRLF)*
     *   CRLF
     *   ([body->body]CRLF)*
     */
	
    SAFECTRLCALL1(getParam,reply.next_request_uri);
    SAFECTRLCALL1(getParam,reply.next_hop);
    SAFECTRLCALL1(getParam,reply.route);

    SAFECTRLCALL1(getLines,reply.hdrs);
    SAFECTRLCALL1(getLines,reply.body);

    if(reply.hdrs.empty()){
	ERROR("reply is missing headers: <%i %s>\n",
	      reply.code,reply.reason.c_str());
	return -1;
    }
    
    reply.local_tag = getHeader(reply.hdrs,"From");
    reply.local_tag = extract_tag(reply.local_tag);

    reply.remote_tag = getHeader(reply.hdrs,"To");
    reply.remote_tag = extract_tag(reply.remote_tag);

    string cseq_str;
    cseq_str   = getHeader(reply.hdrs,"CSeq");
    if(str2i(cseq_str,reply.cseq)){
	ERROR("could not parse CSeq header\n");
	return -1;
    }

    AmSessionContainer::instance()->postEvent(
	    reply.local_tag,
	    new AmSipReplyEvent(reply));

//     if(reply.code >= 200)
// 	cleanup(ctrl);

    return 0;
}
Пример #2
0
cache_set* cache_get_line_index(Cache *cache, int addr, size_t *set_i, size_t *line_i) {
	size_t set_index;
	int tag;
	if (cache->assoc == DIRECT) {
		set_index = extract_set_index(cache, addr);
		tag = extract_tag(cache, addr);
	}
	else if (cache->assoc == FULL_ASSOC) {
		set_index = 0;
		tag = extract_tag(cache, addr);
	}
	else { // n-assoc
		set_index = extract_set_index(cache, addr);
		tag = extract_tag(cache, addr);
	}
	
	cache_set *cur_set = cache->sets[set_index];
	size_t line_index = get_line_index(cur_set, tag);

	*set_i = set_index;
	*line_i = line_index;

	return cur_set;
}
Пример #3
0
 ///////////////////////////////////////////////////////////////////////
 /// tag access
 tag_type get_tag() const volatile
 {
     return extract_tag(state_);
 }
bool UnixSocketAdapter::receive(AmSipReply &reply)
{
  string tmp_str;
  string cseq_str;

#ifdef OpenSER
  unsigned int mi_res_code;
  string mi_res_msg;
#endif

  if (cacheMsg() < 0)
    goto failure;

#ifdef OpenSER
  SAFECTRLCALL1(getParam,tmp_str);
    
  DBG("MI response from OpenSER: %s\n",tmp_str.c_str());
  if( parse_return_code(tmp_str.c_str(),// res_code_str,
      mi_res_code, mi_res_msg) == -1 ){
    ERROR("while parsing MI return code from OpenSER.\n");
    goto failure;
  }

  if (mi_res_code != 200) {
      ERROR("MI response from OpenSER\n");
      goto failure;
  }

  SAFECTRLCALL1(getParam,tmp_str);
  DBG("SIP response from OpenSER: %s\n",tmp_str.c_str());
  if( parse_return_code(tmp_str.c_str(),// res_code_str,
      reply.code, reply.reason) == -1 ){
    ERROR("while parsing return code from Ser.\n");
    goto failure;
  }
#else
  SAFECTRLCALL1(getParam,tmp_str);

  DBG("response from Ser: %s\n",tmp_str.c_str());
  if( parse_return_code(tmp_str.c_str(),// res_code_str,
      reply.code,reply.reason) == -1 ){
    ERROR("while parsing return code from Ser.\n");
    goto failure;
  }
#endif

  /* Parse complete response:
   *
   *   [next_request_uri->cmd.from_uri]CRLF
   *   [next_hop->cmd.next_hop]CRLF
   *   [route->cmd.route]CRLF
   *   ([headers->n_cmd.hdrs]CRLF)*
   *   CRLF
   *   ([body->body]CRLF)*
   */
	
  SAFECTRLCALL1(getParam,reply.next_request_uri);
  SAFECTRLCALL1(getParam,reply.next_hop);
  SAFECTRLCALL1(getParam,reply.route);

  SAFECTRLCALL1(getLines,reply.hdrs);
  SAFECTRLCALL1(getLines,reply.body);

  if(reply.hdrs.empty()){
    ERROR("reply is missing headers: <%i %s>\n",
	  reply.code,reply.reason.c_str());
    goto failure;
  }

  reply.local_tag = getHeader(reply.hdrs,"From");
  reply.local_tag = extract_tag(reply.local_tag);

  reply.remote_tag = getHeader(reply.hdrs,"To");
  reply.remote_tag = extract_tag(reply.remote_tag);

  cseq_str   = getHeader(reply.hdrs,"CSeq");
  if(str2i(cseq_str,reply.cseq)){
    ERROR("could not parse CSeq header\n");
    goto failure;
  }

  reply.content_type = getHeader(reply.hdrs,"Content-Type");

  return true;
failure:
  //cleanup(ctrl);
  return false;
}
Пример #5
0
 /* @{ */
 tag_t get_tag() const volatile
 {
     return extract_tag(ptr);
 }