Example #1
0
void Ur5MessageDecoder::pushState(QByteArray data,Ur5State &state)
{
    if(data.size() == 251)
    {
        setJointData(removeHeader(data),state);
    }
    if(data.size() == 53)
    {
        setCartData(removeHeader(data),state);
    }
}
Example #2
0
    void getDataFromJSON(std::string in_str){
        //std::stringstream stream();
        try{
            // boost::property_tree::ptree pt;
            // boost::property_tree::read_json(stream, pt);
            
            // temperature = pt.get<double>("main.temp") - 273.15;
            // windSpeed = pt.get<double>("wind.speed");
            // humidity = pt.get<double>("main.humidity");
            
            // for(auto child : pt.get_child("weather")){
            //     sky = child.second.get<std::string>("description"); 
            // }
            
            uskorenie::weatherBoostPoweredJSONparser parser(removeHeader(in_str));
            
            auto data = parser.parse();
            
            temperature = data.temperature;
            windSpeed = data.windSpeed;
            humidity = data.humidity;
            sky = data.sky;
            
        } catch (std::exception &e){
            std::cerr << e.what() << '\n';
            //stream.str() << '\n';
        }

    }
Example #3
0
result_t HttpResponse::get_cookies(obj_ptr<List_base>& retVal)
{
    if (!m_cookies) {
        obj_ptr<List> cookies = new List();

        int32_t len, i;
        obj_ptr<List_base> headers;

        allHeader("Set-Cookie", headers);
        removeHeader("Set-Cookie");

        headers->get_length(len);

        for (i = 0; i < len; i++) {
            Variant v;
            exlib::string str;
            obj_ptr<HttpCookie> cookie;

            headers->_indexed_getter(i, v);
            str = v.string();

            cookie = new HttpCookie();
            if (cookie->parse(str) >= 0)
                cookies->append(cookie);
        }

        m_cookies = cookies;
    }

    retVal = m_cookies;
    return 0;
}
void removeOptionTag(string& hdrs, const string& hdr_name, const string& tag) {
  string options = getHeader(hdrs, hdr_name);

  // does hdr hdr_name exist?
  if (options.empty())
    return;

  // todo: optimize by doing inplace
  std::vector<string> options_v = explode(options, ",");
  string o_hdr;
  bool found = false;
  for (std::vector<string>::iterator it=options_v.begin();
       it != options_v.end(); it++) {
    if (trim(*it, " ")==tag) {
      found = true;
      continue;
    }
    if (it != options_v.begin())
      o_hdr = ", ";
    o_hdr+=*it;
  }
  if (!found)
    return;

  removeHeader(hdrs, hdr_name);
  if (o_hdr.empty())
    return;
  hdrs += hdr_name + COLSP + o_hdr + CRLF;
}
Example #5
0
  void Messageheader::setHeader(const char* key, const char* value, bool replace)
  {
    if (!*key)
      throw std::runtime_error("empty key not allowed in messageheader");

    if (replace)
      removeHeader(key);

    char* p = getEnd();

    size_t lk = std::strlen(key);     // length of key
    size_t lk2 = key[lk-1] == ':' ? lk + 1 : lk;  // length of key including trailing ':'
    size_t lv = std::strlen(value);   // length of value

    if (p - rawdata + lk2 + lv + 3 > MAXHEADERSIZE)
      throw std::runtime_error("message header too big");

    std::strcpy(p, key);   // copy key
    p += lk2;
    *(p - 2) = ':';        // make sure, key is prepended by ':'
    *(p - 1) = '\0';
    std::strcpy(p, value); // copy value
    p[lv + 1] = '\0';      // put new message end marker in place

    endOffset = (p + lv + 1) - rawdata;
  }
Example #6
0
void HTTPPacket::setKeepAlive(bool keepAlive) {
    ANET_LOG(SPAM, "isKeepAlive:%d", isKeepAlive());
    if (isKeepAlive() == keepAlive) {
        return ;
    }

    if (HTTP_1_0 == getVersion()) {
        if(keepAlive) {
            addHeader("Connection", CONNECTION_KEEP_ALIVE);
        } else {
            removeHeader("Connection");
        }
    } else {
        if(keepAlive) {
            removeHeader("Connection");
        } else {
            addHeader("Connection", CONNECTION_CLOSE);
        }
    }
}
Example #7
0
bool HTTPPacket::addHeader(const char *key, const char *value) {
    if (NULL == key) return false;
    if (NULL == value) return false;
//    _headers.erase(key);
    removeHeader(key);
    char *newKey = strdup(key);
    assert(newKey);
    char *newValue = strdup(value);
    assert(newValue);
    (void)_headers.insert(make_pair(newKey, newValue));
    return true;
}
Example #8
0
void AmB2BSession::onSipRequest(const AmSipRequest& req)
{
  bool fwd = sip_relay_only &&
    (req.method != SIP_METH_CANCEL);

  if( ((req.method == SIP_METH_SUBSCRIBE) ||
       (req.method == SIP_METH_NOTIFY) ||
       (req.method == SIP_METH_REFER))
      && !subs->onRequestIn(req) ) {
    return;
  }

  if(!fwd)
    AmSession::onSipRequest(req);
  else {
    updateRefreshMethod(req.hdrs);

    if(req.method == SIP_METH_BYE)
      onBye(req);
  }

  B2BSipRequestEvent* r_ev = new B2BSipRequestEvent(req,fwd);

  if (fwd) {
    DBG("relaying B2B SIP request (fwd) %s %s\n", r_ev->req.method.c_str(), r_ev->req.r_uri.c_str());

    if(r_ev->req.method == SIP_METH_NOTIFY) {

      string event = getHeader(r_ev->req.hdrs,SIP_HDR_EVENT,true);
      string id = get_header_param(event,"id");
      event = strip_header_params(event);

      if(event == "refer" && !id.empty()) {

	int id_int=0;
	if(str2int(id,id_int)) {

	  unsigned int mapped_id=0;
	  if(getMappedReferID(id_int,mapped_id)) {

	    removeHeader(r_ev->req.hdrs,SIP_HDR_EVENT);
	    r_ev->req.hdrs += SIP_HDR_COLSP(SIP_HDR_EVENT) "refer;id=" 
	      + int2str(mapped_id) + CRLF;
	  }
	}
      }
    }

    int res = relayEvent(r_ev);
    if (res == 0) {
      // successfuly relayed, store the request
      if(req.method != SIP_METH_ACK)
        recvd_req.insert(std::make_pair(req.cseq,req));
    }
    else {
      // relay failed, generate error reply
      DBG("relay failed, replying error\n");
      AmSipReply n_reply;
      errCode2RelayedReply(n_reply, res, 500);
      dlg->reply(req, n_reply.code, n_reply.reason);
    }

    return;
  }

  DBG("relaying B2B SIP request %s %s\n", r_ev->req.method.c_str(), r_ev->req.r_uri.c_str());
  relayEvent(r_ev);
}
void HttpEntity::clearContent() {
	content.clear();
	removeHeader(http::ContentLength);
}
Example #10
0
void DSMCall::B2BremoveHeader(const string& hdr) {
    removeHeader(invite_req.hdrs, hdr);
}
Example #11
0
int main(int argc, char *argv[])
{
	char						*firmwareFileName;
	FILE						*fpFirmwareFile;
	int							inquiryType;
	int							firstRecordType;
	int							result;
	int							fileSize;
	int							isSpkg = 0;
	struct stat					statBuf;
	IcsImageHeader_Record_t		recordBuffer;
	uint8_t						cssBuf[CSS_HEADER_SIZE + 10];

	struct option longopts[] = 
	{
		{ "showVersion", no_argument, &inquiryType, SHOWVERSION },
		{ "showType",    no_argument, &inquiryType, SHOWTYPE    },
		{ "help",        no_argument, &inquiryType, HELP        },
		{ 0,             0,           0           , 0           }
	};

	/* parse options for inquiry type */
	if ((result = getopt_long(argc, argv, "", longopts, NULL)))	// assignment, not ==
		Usage();

	if (inquiryType == HELP)
		Usage_full();

	if (argc != 3)
		Usage();

	/* set up endian-ness */

	initializeState();

	/* stat file to get size and allocate buffers */

	firmwareFileName = argv[2];

	if (stat(firmwareFileName, &statBuf) < 0) {
		fprintf(stderr, "Error taking stat of file {%s}: %s\n",
			firmwareFileName, strerror(errno));
		exit(1);
	}

	fileSize = (int)statBuf.st_size;
	bufSize = fileSize + 1024; /* pad by 1K to be safe */
	if ((cmpBuffer = malloc(bufSize)) == NULL) {
		fprintf(stderr, "Error allocating memory for firmware buffer\n");
		goto fail;
	}
	if ((appBuffer = malloc(bufSize * 3)) == NULL) {
		fprintf(stderr, "Error allocating memory for inflated firmware buffer\n");
		goto fail;
	}

	memset(cmpBuffer, 0, bufSize);
	memset(appBuffer, 0, bufSize * 3);

	/* open file */
 
	if ((fpFirmwareFile = fopen(firmwareFileName, "rb")) == NULL)
	{
		fprintf(stderr, "Error opening file {%s} for input: %s\n",
			firmwareFileName, strerror(errno));
		goto fail;
	}

	if (0 == fread(&cssBuf, CSS_HEADER_SIZE, 1, fpFirmwareFile))
	{
		fprintf(stderr, "Error reading file {%s}: %s\n",
			firmwareFileName, strerror(errno));
		goto fail;
	}

	isSpkg = checkCssHeader(cssBuf);

	/* get first record, check if ICS image file */

	fseek(fpFirmwareFile, isSpkg ? CSS_HEADER_SIZE : 0, SEEK_SET);

	if (0 == fread(&firstRecordType, 4, 1, fpFirmwareFile))
	{
		fprintf(stderr, "Error reading file {%s}: %s\n",
			firmwareFileName, strerror(errno));
		goto fail;
	}

	fseek(fpFirmwareFile, isSpkg ? CSS_HEADER_SIZE : 0, SEEK_SET);

	if (ICS_IMAGE_HEADER_RECORD_TYPE_INFO != toHostEndian32(firstRecordType))
	{
		fprintf(stderr, "This is not a valid firmware image file\n");
		goto fail;
	}

	/* read in header, display what is asked for */

	if (ERR_OK != getRecord(fpFirmwareFile, &recordBuffer))
		goto fail;

	switch (inquiryType)
	{
		case SHOWVERSION:
			displayVersion(recordBuffer.payload.info.version);
			break;
		case SHOWTYPE:
			/*
			 * For the type, we really want to look for the embedded strings first.
			 * Call removeHeader, which will remove the ICS header from the package
			 * file and place it in the compressed buffer. Then call
			 * displayEmbeddedProdAndBsp which inflates and then searches. If the search
			 * fails, it is a pre-3.1.0.1 release, so feed the codes from the ICS header
			 * to displayType.
			 */
			result = removeHeader(argv[2], cmpBuffer);
			if (!displayEmbeddedProdAndBsp()) /* if this fails, try old way */
				displayType(toHostEndian32(recordBuffer.payload.info.productCode),
			    	        toHostEndian32(recordBuffer.payload.info.bspCode));
			break;
		default:
			fprintf(stderr, "Unknown inquiry type\n");
			goto fail;
	}

	fclose(fpFirmwareFile);
fail:
	if (cmpBuffer != NULL)
		free(cmpBuffer);
	if (appBuffer != NULL)
		free(appBuffer);
	exit(0);
}
Example #12
0
void fixReplaces(string& req_hdrs, bool is_invite) {

  string replaces;
  string refer_to;
  AmUriParser refer_target;
  vector<string> hdrs;                      // headers from Refer-To URI
  vector<string>::iterator replaces_hdr_it; // Replaces header from Refer-To URI

  DBG("Replaces handler: fixing %s request\n", is_invite?"INVITE":"REFER");

  if (is_invite) {
    replaces = getHeader(req_hdrs, SIP_HDR_REPLACES, true);
    if (replaces.empty()) {
      DBG("Replaces handler: no Replaces in INVITE, ignoring\n");
      return;
    }
  } else {
    refer_to = getHeader(req_hdrs, SIP_HDR_REFER_TO, SIP_HDR_REFER_TO_COMPACT, true);
    if (refer_to.empty()) {
      DBG("Replaces handler: empty Refer-To header, ignoring\n");
      return;
    }

    size_t pos=0; size_t end=0;
    if (!refer_target.parse_contact(refer_to, pos, end)) {
      DBG("Replaces handler: unable to parse Refer-To name-addr, ignoring\n");
      return;
    }

    if (refer_target.uri_headers.empty()) {
      DBG("Replaces handler: no headers in Refer-To target, ignoring\n");
      return;
    }

    hdrs = explode(refer_target.uri_headers, ";");
    for (replaces_hdr_it=hdrs.begin(); replaces_hdr_it != hdrs.end(); replaces_hdr_it++) {

      string s = URL_decode(*replaces_hdr_it);
      const char* Replaces_str = "Replaces";
      if ((s.length() >= 8) &&
	  !strncmp(Replaces_str, s.c_str(), 8)) {
	size_t pos = 8;
	while (s.length()>pos && (s[pos] == ' ' || s[pos] == '\t')) pos++;
	if (s[pos] != '=')
	  continue;
	pos++;
	while (s.length()>pos && (s[pos] == ' ' || s[pos] == '\t')) pos++;
	replaces = s.substr(pos);
	break;
      }
    }
    
    if (replaces_hdr_it == hdrs.end()) {
      DBG("Replaces handler: no Replaces headers in Refer-To target, ignoring\n");
      return;
    }
  }

  DBG("Replaces found: '%s'\n", replaces.c_str());
  size_t ftag_begin; size_t ftag_len;
  size_t ttag_begin; size_t ttag_len;
  size_t cid_len=0;
 
  // todo: parse full replaces header and reconstruct including unknown params
  if (!findTag(replaces, "from-tag=", ftag_begin, ftag_len)) {
    WARN("Replaces missing 'from-tag', ignoring\n");
    return;
  }

  if (!findTag(replaces, "to-tag=", ttag_begin, ttag_len)) {
    WARN("Replaces missing 'to-tag', ignoring\n");
    return;
  }
  while (cid_len < replaces.size() && replaces[cid_len] != ';')
    cid_len++;

  string ftag = replaces.substr(ftag_begin, ftag_len);
  string ttag = replaces.substr(ttag_begin, ttag_len);
  string callid = replaces.substr(0, cid_len);
  bool early_only = replaces.find("early-only") != string::npos;

  DBG("Replaces handler: found callid='%s', ftag='%s', ttag='%s'\n",
      callid.c_str(), ftag.c_str(), ttag.c_str());

  SBCCallRegistryEntry other_dlg;
  if (SBCCallRegistry::lookupCall(ttag, other_dlg)) {
    replaces = other_dlg.callid+
      ";from-tag="+other_dlg.ltag+";to-tag="+other_dlg.rtag;
    if (early_only)
      replaces += ";early_only";
    DBG("Replaces handler: mapped Replaces to: '%s'\n", replaces.c_str());

    if (is_invite) {
      removeHeader(req_hdrs, SIP_HDR_REPLACES);
      req_hdrs+=SIP_HDR_COLSP(SIP_HDR_REPLACES)+replaces+CRLF;
    } else {
      string replaces_enc = SIP_HDR_REPLACES "="+URL_encode(replaces);
      string new_hdrs;
      for (vector<string>::iterator it = hdrs.begin(); it != hdrs.end(); it++) {
	if (it != hdrs.begin())
	  new_hdrs+=";";

	if (it != replaces_hdr_it) {
	  // different hdr, just add it
	  new_hdrs+=*it;
	} else {
	  //reconstructed replaces hdr
	  new_hdrs+=replaces_enc;
	}
      }
      refer_target.uri_headers=new_hdrs;
      removeHeader(req_hdrs, SIP_HDR_REFER_TO);
      removeHeader(req_hdrs, SIP_HDR_REFER_TO_COMPACT);
      req_hdrs+=SIP_HDR_COLSP(SIP_HDR_REFER_TO)+refer_target.nameaddr_str()+CRLF;
    }

  } else {
    DBG("Replaces handler: call with tag '%s' not found\n", ttag.c_str());
  }

 
}