Example #1
0
inline QString qstr(const std::string& _in) { return QString::fromUtf8(_in.data(), _in.size()); }
Example #2
0
	long Socket::send(const std::string &buf) const
	{
		return send_all(this->socket_handle, buf.data(), buf.length() );
	}
Example #3
0
void HashFunctions::sha512(const std::string &data, unsigned char out_hash[64])
{
	sha512(data.data(), data.length(), out_hash);
}
Example #4
0
int SqliteStatement::bind (int position, const std::string& value)
{
    return sqlite3_bind_text (statement, position, value.data (), value.size (), SQLITE_TRANSIENT);
}
Example #5
0
unsigned NetClient::sendString(const std::string &s) throw(const SocketException &)
{
  return sendData(s.data(), s.length());
}
 /**
  * Add a member to the relation.
  *
  * @param type The type (node, way, or relation).
  * @param ref The ID of the member.
  * @param role The role of the member.
  * @param full_member Optional pointer to the member object. If it
  *                    is available a copy will be added to the
  *                    relation.
  * @throws std:length_error If role is longer than osmium::max_osm_string_length
  */
 void add_member(osmium::item_type type, object_id_type ref, const std::string& role, const osmium::OSMObject* full_member = nullptr) {
     add_member(type, ref, role.data(), role.size(), full_member);
 }
Example #7
0
bool DMetadata::setItemRating(int rating, const DMetadataSettingsContainer& settings) const
{
    // NOTE : with digiKam 0.9.x, we have used IPTC Urgency to store Rating.
    // Now this way is obsolete, and we use standard XMP rating tag instead.

    if (rating < RatingMin || rating > RatingMax)
    {
        qCDebug(DIGIKAM_METAENGINE_LOG) << "Rating value to write is out of range!";
        return false;
    }

    //qCDebug(DIGIKAM_METAENGINE_LOG) << getFilePath() << " ==> Rating:" << rating;

    QList<NamespaceEntry> toWrite = settings.getReadMapping(QString::fromUtf8(DM_RATING_CONTAINER));

    if (!settings.unifyReadWrite())
        toWrite = settings.getWriteMapping(QString::fromUtf8(DM_RATING_CONTAINER));

    for (NamespaceEntry entry : toWrite)
    {
        if (entry.isDisabled)
            continue;

        const std::string myStr = entry.namespaceName.toStdString();
        const char* nameSpace   = myStr.data();

        switch(entry.subspace)
        {
            case NamespaceEntry::XMP:
                if (!setXmpTagString(nameSpace, QString::number(entry.convertRatio.at(rating))))
                {
                    qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace;
                    return false;
                }
                break;
            case NamespaceEntry::EXIF:
                if (QLatin1String(nameSpace) == QLatin1String("Exif.Image.0x4749"))
                {
                    // Wrapper around rating percents managed by Windows Vista.
                    int ratePercents = 0;

                    switch (rating)
                    {
                        case 0:
                            ratePercents = 0;
                            break;
                        case 1:
                            ratePercents = 1;
                            break;
                        case 2:
                            ratePercents = 25;
                            break;
                        case 3:
                            ratePercents = 50;
                            break;
                        case 4:
                            ratePercents = 75;
                            break;
                        case 5:
                            ratePercents = 99;
                            break;
                    }

                    if (!setExifTagLong(nameSpace, ratePercents))
                    {
                        qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace;
                        return false;
                    }
                }
                else
                {
                    if (!setExifTagLong(nameSpace, rating))
                    {
                        qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace;
                        return false;
                    }
                }
                break;
            case NamespaceEntry::IPTC: // IPTC rating deprecated
            default:
                break;
        }
    }

    return true;
}
Example #8
0
static int FileWriteStr(const std::string &str, FILE *fp)
{
    return fwrite(str.data(), 1, str.size(), fp);
}
Example #9
0
bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCurlFile& http, const std::string& cacheContext)
{
  CURL url(scrURL.m_url);
  http.SetReferer(scrURL.m_spoof);
  std::string strCachePath;

  if (scrURL.m_isgz)
    http.SetAcceptEncoding("gzip");

  if (!scrURL.m_cache.empty())
  {
    strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,
                              "scrapers", cacheContext, scrURL.m_cache);
    if (XFILE::CFile::Exists(strCachePath))
    {
      XFILE::CFile file;
      XFILE::auto_buffer buffer;
      if (file.LoadFile(strCachePath, buffer) > 0)
      {
        strHTML.assign(buffer.get(), buffer.length());
        return true;
      }
    }
  }

  std::string strHTML1(strHTML);

  if (scrURL.m_post)
  {
    std::string strOptions = url.GetOptions();
    strOptions = strOptions.substr(1);
    url.SetOptions("");

    if (!http.Post(url.Get(), strOptions, strHTML1))
      return false;
  }
  else
    if (!http.Get(url.Get(), strHTML1))
      return false;

  strHTML = strHTML1;

  std::string mimeType(http.GetMimeType());
  CMime::EFileType ftype = CMime::GetFileTypeFromMime(mimeType);
  if (ftype == CMime::FileTypeUnknown)
    ftype = CMime::GetFileTypeFromContent(strHTML);

  if (ftype == CMime::FileTypeZip || ftype == CMime::FileTypeGZip)
  {
    XFILE::CZipFile file;
    std::string strBuffer;
    int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz); // FIXME: use FileTypeGZip instead of scrURL.m_isgz?
    if (iSize > 0)
    {
      strHTML = strBuffer;
      CLog::Log(LOGDEBUG, "%s: Archive \"%s\" was unpacked in memory", __FUNCTION__, scrURL.m_url.c_str());
    }
    else
      CLog::Log(LOGWARNING, "%s: \"%s\" looks like archive, but cannot be unpacked", __FUNCTION__, scrURL.m_url.c_str());
  }

  std::string reportedCharset(http.GetServerReportedCharset());
  if (ftype == CMime::FileTypeHtml)
  {
    std::string realHtmlCharset, converted;
    if (!CCharsetDetection::ConvertHtmlToUtf8(strHTML, converted, reportedCharset, realHtmlCharset))
      CLog::Log(LOGWARNING, "%s: Can't find precise charset for HTML \"%s\", using \"%s\" as fallback", __FUNCTION__, scrURL.m_url.c_str(), realHtmlCharset.c_str());
    else
      CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for HTML \"%s\"", __FUNCTION__, realHtmlCharset.c_str(), scrURL.m_url.c_str());

    strHTML = converted;
  }
  else if (ftype == CMime::FileTypeXml)
  {
    CXBMCTinyXML xmlDoc;
    xmlDoc.Parse(strHTML, reportedCharset);
    
    std::string realXmlCharset(xmlDoc.GetUsedCharset());
    if (!realXmlCharset.empty())
    {
      CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for XML \"%s\"", __FUNCTION__, realXmlCharset.c_str(), scrURL.m_url.c_str());
      std::string converted;
      g_charsetConverter.ToUtf8(realXmlCharset, strHTML, converted);
      strHTML = converted;
    }
  }
  else if (ftype == CMime::FileTypePlainText || StringUtils::CompareNoCase(mimeType.substr(0, 5), "text/") == 0)
  {
    std::string realTextCharset, converted;
    CCharsetDetection::ConvertPlainTextToUtf8(strHTML, converted, reportedCharset, realTextCharset);
    strHTML = converted;
    if (reportedCharset != realTextCharset)
      CLog::Log(LOGWARNING, "%s: Using \"%s\" charset for plain text \"%s\" instead of server reported \"%s\" charset", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str(), reportedCharset.c_str());
    else
      CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for plain text \"%s\"", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str());
  }
  else if (!reportedCharset.empty())
  {
    CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for \"%s\"", __FUNCTION__, reportedCharset.c_str(), scrURL.m_url.c_str());
    if (reportedCharset != "UTF-8")
    {
      std::string converted;
      g_charsetConverter.ToUtf8(reportedCharset, strHTML, converted);
      strHTML = converted;
    }
  }
  else
    CLog::Log(LOGDEBUG, "%s: Using content of \"%s\" as binary or text with \"UTF-8\" charset", __FUNCTION__, scrURL.m_url.c_str());

  if (!scrURL.m_cache.empty())
  {
    std::string strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,
                              "scrapers", cacheContext, scrURL.m_cache);
    XFILE::CFile file;
    if (!file.OpenForWrite(strCachePath, true) || file.Write(strHTML.data(), strHTML.size()) != static_cast<ssize_t>(strHTML.size()))
      return false;
  }
  return true;
}
Example #10
0
void CGI::RealOutput(const std::string &what)
{
    RealOutput(what.data(), what.length());
}
Example #11
0
 void operator & (const std::string &s)
 {
   size_t size = s.size();
   *this & (size);
   stream.write(s.data(), size);
 }
Example #12
0
void CGI::OutputBody(const std::string &body)
{
    OutputBody(body.data(), body.length());
}
Example #13
0
 void WriteString(ignite::impl::binary::BinaryWriterImpl& writer, const std::string & str)
 {
     writer.WriteString(str.data(), static_cast<int32_t>(str.size()));
 }
Example #14
0
Integer::Integer(std::string str) {
	i = atoi(str.data());
}
Example #15
0
INT64 StringUtility::StringToInt64( std::string str )
{
	INT64 i;
	i = _atoi64(str.data());
	return i;
}
Example #16
0
void StreamBuffer::load(const std::string &str){
	clear();
	put(str.data(), str.size());
}
Example #17
0
types::Function::ReturnValue sci_duplicate(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() != 2)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }

    if (_iRetCount > 1)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }
    types::Double* pIn1 = in[0]->getAs<types::Double>();
    if (pIn1->isComplex())
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 1);
        return types::Function::Error;
    }

    if (in[1]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }
    types::Double* pIn2 = in[1]->getAs<types::Double>();
    if (pIn2->isComplex())
    {
        Scierror(999, _("%s: Wrong type for input argument #%d : A real matrix expected.\n"), funname.data(), 2);
        return types::Function::Error;
    }

    int m1, n1, n, m2, n2, m3, n3;

    m1 = pIn1->getRows();
    n1 = pIn1->getCols();
    n = m1 * n1;

    if (n == 0)
    {
        out.push_back(types::Double::Empty());
        return types::Function::OK;
    }

    m2 = pIn2->getRows();
    n2 = pIn2->getCols();

    if (n != m2 * n2)
    {
        Scierror(999, _("%s: 1st and 2nd argument must have equal size\n"), funname.data());
        return types::Function::Error;
    }

    comp_size(pIn2->getReal(), n3, n);

    m3 = 1;
    double* d3;
    types::Double* pOut = new types::Double(n3, m3, &d3);
    duplicata(n, pIn1->getReal(), pIn2->getReal(), d3, n3);
    out.push_back(pOut);

    return types::Function::OK;
}
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_key(getCombinerKey(_combine.mux))
{
	std::string strCombiner;
	m_nInputs = compileCombiner(_color, _alpha, strCombiner);

	if (usesTexture()) {
		strFragmentShader.assign(fragment_shader_header_common_variables);
		if (gDP.otherMode.cycleType == G_CYC_2CYCLE)
			strFragmentShader.append(fragment_shader_header_common_variables_blend_mux_2cycle);
		strFragmentShader.append(fragment_shader_header_common_functions);
	} else {
		strFragmentShader.assign(fragment_shader_header_common_variables_notex);
		if (gDP.otherMode.cycleType == G_CYC_2CYCLE)
			strFragmentShader.append(fragment_shader_header_common_variables_blend_mux_2cycle);
		strFragmentShader.append(fragment_shader_header_common_functions_notex);
	}
	strFragmentShader.append(fragment_shader_header_main);
	const bool bUseLod = usesLOD();
	if (bUseLod) {
		strFragmentShader.append("  lowp vec4 readtex0, readtex1; \n");
		strFragmentShader.append("  lowp float lod_frac = mipmap(readtex0, readtex1);	\n");
	} else {
		if (usesTile(0)) {
			strFragmentShader.append("  nCurrentTile = 0; \n");
			strFragmentShader.append("  lowp vec4 readtex0 = readTex(uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0] != 0); \n");
		}
		if (usesTile(1)) {
			strFragmentShader.append("  nCurrentTile = 1; \n");
			strFragmentShader.append("  lowp vec4 readtex1 = readTex(uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1] != 0); \n");
		}
	}
	const bool bUseHWLight = config.generalEmulation.enableHWLighting != 0 && GBI.isHWLSupported() && usesShadeColor();
	if (bUseHWLight)
		strFragmentShader.append("  calc_light(vNumLights, vShadeColor.rgb, input_color); \n");
	else
		strFragmentShader.append("  input_color = vShadeColor.rgb;\n");
	strFragmentShader.append("  vec_color = vec4(input_color, vShadeColor.a); \n");
	strFragmentShader.append(strCombiner);
	strFragmentShader.append("  gl_FragColor = fragColor; \n");
	strFragmentShader.append(fragment_shader_end);

	if (config.generalEmulation.enableNoise == 0)
		strFragmentShader.append(fragment_shader_dummy_noise);

	if (bUseHWLight)
		strFragmentShader.append(fragment_shader_calc_light);
	if (bUseLod)
		strFragmentShader.append(fragment_shader_fake_mipmap);
	else if (usesTexture()) {
		if (config.texture.bilinearMode == BILINEAR_3POINT)
			strFragmentShader.append(fragment_shader_readtex_3point);
		else
			strFragmentShader.append(fragment_shader_readtex);
	}
	if (config.generalEmulation.enableNoise != 0)
		strFragmentShader.append(fragment_shader_noise);

	GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	const GLchar * strShaderData = strFragmentShader.data();
	glShaderSource(fragmentShader, 1, &strShaderData, NULL);
	glCompileShader(fragmentShader);
	if (!checkShaderCompileStatus(fragmentShader))
		LOG(LOG_ERROR, "Error in fragment shader:\n%s\n", strFragmentShader.data());

	m_program = glCreateProgram();
	_locate_attributes();
	if (usesTexture())
		glAttachShader(m_program, g_vertex_shader_object);
	else
		glAttachShader(m_program, g_vertex_shader_object_notex);
	glAttachShader(m_program, fragmentShader);
	glLinkProgram(m_program);
	assert(checkProgramLinkStatus(m_program));
	glDeleteShader(fragmentShader);
	_locateUniforms();
}
Example #19
0
int DMetadata::getItemRating(const DMetadataSettingsContainer& settings) const
{
    if (getFilePath().isEmpty())
    {
        return -1;
    }

    long rating        = -1;
    bool xmpSupported  = hasXmp();
    bool iptcSupported = hasIptc();
    bool exivSupported = hasExif();

    for (NamespaceEntry entry : settings.getReadMapping(QString::fromUtf8(DM_RATING_CONTAINER)))
    {
        if (entry.isDisabled)
            continue;

        const std::string myStr = entry.namespaceName.toStdString();
        const char* nameSpace   = myStr.data();
        QString value;

        switch(entry.subspace)
        {
            case NamespaceEntry::XMP:
                if (xmpSupported)
                    value = getXmpTagString(nameSpace, false);
                break;
            case NamespaceEntry::IPTC:
                if (iptcSupported)
                    value = QString::fromUtf8(getIptcTagData(nameSpace));
                break;
            case NamespaceEntry::EXIF:
                if (exivSupported)
                    getExifTagLong(nameSpace, rating);
                break;
            default:
                break;
        }

        if (!value.isEmpty())
        {
            bool ok = false;
            rating  = value.toLong(&ok);

            if (!ok)
            {
                return -1;
            }
        }

        int index = entry.convertRatio.indexOf(rating);

        // Exact value was not found,but rating is in range,
        // so we try to approximate it
        if ((index == -1)                         &&
            (rating > entry.convertRatio.first()) &&
            (rating < entry.convertRatio.last()))
        {
            for (int i = 0 ; i < entry.convertRatio.size() ; ++i)
            {
                if (rating > entry.convertRatio.at(i))
                {
                    index = i;
                }
            }
        }

        if (index != -1)
        {
            return index;
        }
    }

    return -1;
}
Example #20
0
	static inline std::string hex(const std::string &data) { return hex(data.data(),(unsigned int)data.length()); }
Example #21
0
Std_String HashMD5Impl::GetStringHash(std::string strValue)
{
	int nLen = strValue.size();
	const unsigned char* pBuf = (const unsigned char*)strValue.data();
	return ComputeHash(pBuf, nLen);
}
Example #22
0
/**
 * Callback used for doc request
 */
static void doc_request_cb(struct evhttp_request *req, void *arg)
{
	std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();

	if (evhttp_request_get_command(req) != EVHTTP_REQ_GET)
	{
		std::cerr << "Invalid query request! Needs to be GET" << std::endl;
		evhttp_send_error(req, HTTP_BADREQUEST, 0);
	}
	else
	{
		struct evbuffer *evb = NULL;
		const char *uri = evhttp_request_get_uri(req);
		struct evhttp_uri *decoded = NULL;
		// const char *path = NULL;
		const char *query = NULL;

		printf("Got a GET request for %s\n",  uri);

		// Decode the URI
		decoded = evhttp_uri_parse(uri);

		if (!decoded)
		{
			printf("It's not a good URI. Sending BADREQUEST\n");
			evhttp_send_error(req, HTTP_BADREQUEST, 0);
			return;
		}

		// path = evhttp_uri_get_path(decoded);
		// std::cout << path << std::endl;

		query = evhttp_uri_get_query(decoded);
		// std::cout << query << std::endl;

		// This holds the content we're sending
		evb = evbuffer_new();

		struct evkeyvalq params;	// create storage for your key->value pairs
		struct evkeyval *param;		// iterator

		int result = evhttp_parse_query_str(query, &params);

		if (result == 0)
		{
			bool found = false;

			for (param = params.tqh_first; param; param = param->next.tqe_next)
			{
				std::string key(param->key);
				std::string value(param->value);

				// printf("%s %s\n", key.c_str(), value.c_str());

				if (key.compare(zsearch::server::DOC_ID_KEY) == 0)
				{
					unsigned int docId = 0;

					try
					{
						docId = ZUtil::getUInt(value);

						std::cout << "retrieving document " << value << std::endl;

						std::shared_ptr<IDocument> document = make_shared<DocumentImpl>();

						if (engine->getDoc(docId, document))
						{
							std::stringstream ss;
							document->write(ss);
							const std::string docStr = ss.str();
							// cout << docStr << endl;

							evbuffer_add(evb, docStr.data(), docStr.size());
							found = true;
						}
					}

					// TODO: consider splitting out the errors so we know if the problem is getting the docId or in the engine

					catch (const std::string& e)
					{
						// no need to do anything here
						// evbuffer_add_printf(evb, "Invalid docId\n");
						// evbuffer_add_printf(evb, e.c_str());
					}

					break; // break out of looping through parameters
				}
			}

			if (found)
			{
				evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "text/xml");
				evhttp_send_reply(req, 200, "OK", evb);
			}
			else
			{
				/*
				evbuffer_add_printf(evb, "Document not found or invalid docId");
				evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "text/html");
				*/

				evhttp_send_error(req, 404, "Document not found.");
			}

		}
		else
		{
			evhttp_send_error(req, HTTP_BADREQUEST, 0);
		}

		evhttp_clear_headers(&params);


		if (decoded)
		{
			evhttp_uri_free(decoded);
		}

		if (evb)
		{
			evbuffer_free(evb);
		}
	}

	std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
	std::chrono::nanoseconds timeTaken = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0);
	std::cout << ZUtil::printTimeTaken(timeTaken) << std::endl;
}
Example #23
0
int SqliteStatement::bindStatic (int position, const std::string& value)
{
    return sqlite3_bind_text (statement, position, value.data (), value.size (), SQLITE_STATIC);
}
Example #24
0
void MD5Hash::UpdateData(const std::string &str)
{
	UpdateData((const uint8*)str.data(), (int)str.length());
}
Example #25
0
void session::transform(const std::string &data, struct dnet_id &id)
{
	dnet_transform(m_node->m_node, (void *)data.data(), data.size(), &id);
}
Example #26
0
long StringUtility::StringToLong( std::string str )
{
	int n = 0;
	n = atol(str.data());
	return n;
}
Example #27
0
	long Socket::nonblock_send(const std::string &buf, const std::chrono::milliseconds &timeout) const
	{
		return nonblock_send_all(this->socket_handle, buf.data(), buf.length(), timeout);
	}
Example #28
0
int StringUtility::StringToInt( std::string str )
{
	int n = 0;
	n = atoi(str.data());
	return n;
}
Example #29
0
std::string HashFunctions::sha512_224(const std::string &data, bool uppercase)
{
	return sha512_224(data.data(), data.length(), uppercase);
}
Example #30
0
void transmit(const std::string& s){
  ROS_DEBUG("Sending '%s'", s.c_str());
	transmit((uint8_t*)s.data(), s.length());
}