Пример #1
0
string ClientInfo::clean(string str)
{
	replace_all(str, "=", "");
	replace_all(str, "+", "-");
	replace_all(str, "/", "_");
	
	return str;
}
Пример #2
0
string XmlNode::unquote(const string& a) {
    return
        replace_all(
            replace_all(
                replace_all(a,
                            "&lt;", "<"),
                "&gt;", ">"),
            "&amp;", "&");
}
Пример #3
0
string parser::fix_corrupted_data(const string &in)
{
    string out = in;
    replace_all(out, "mimetype:", "\"mimetype\":");
    replace_all(out, "compressed:", "\"compressed\":");
    replace_all(out, "encoding:", "\"encoding\":");
    replace_all(out, "data:", "\"data\":");
    return out;
}
Пример #4
0
// ensures all the delims are constant
std::string convertPathToDelims(const char* file)
{
  if (!file)
    return std::string();

  std::string delim;
  delim += _DirDelim;
  return replace_all(replace_all(file,"/",delim),"\\",delim);
}
void lcl_fred_replace_stuff(SCP_string &text)
{
	if (!Fred_running)
		return;

	replace_all(text, "\"", "$quote");
	replace_all(text, ";", "$semicolon");
	replace_all(text, "/", "$slash");
	replace_all(text, "\\", "$backslash");
}
Пример #6
0
std::string GumboInterface::substitute_xml_entities_into_attributes(char quote, const std::string &text)
{
    std::string result = substitute_xml_entities_into_text(text);
    if (quote == '"') {
        replace_all(result,"\"","&quot;");
    } else if (quote == '\'') {
        replace_all(result,"'","&apos;");
    }
    return result;
}
Пример #7
0
static inline void migrate_init()
{
	char buffer[MAX_PACKET_SIZE];
	struct timeval t1, t2, dt;

	gettimeofday_safe(&t1);
	eprintf("migrate to IP: #%s#\n", migrate_ip);
	init_sockaddr(&migrate_addr, migrate_ip, MANAGER_PORT);

	strcpy(buffer, "establish");
	send_msg(manager_socket, &migrate_addr, buffer, strlen(buffer));
	printf("sent establish\n");

	send_msg(manager_socket, &migrate_addr, out_invite.buffer, out_invite.size);
	printf("sent INIT\n");

	send_msg(manager_socket, &migrate_addr, out_ack.buffer, out_ack.size);
	printf("sent ACK\n");

	send_msg(manager_socket, &migrate_addr, out_op_ok.buffer, out_op_ok.size);
	printf("sent OPTIONS OK\n");

	recv_msg(manager_socket, &migrate_addr, buffer);
	printf("\nreceived:\n%s\n", buffer);
	gettimeofday_safe(&t2);

	time_diff(&t1, &t2, &dt);
	printf("time 1: %lu.%06lu\n", dt.tv_sec, dt.tv_usec);

	init_sockaddr(&migrate_addr, remote_ip, MANAGER_PORT);
	strcpy(buffer, "redirect: ");
	strcat(buffer, migrate_ip);
	gettimeofday_safe(&t1);
	send_msg(manager_socket, &migrate_addr, buffer, strlen(buffer));
	gettimeofday_safe(&t2);

	time_diff(&t1, &t2, &dt);
	printf("time 2: %lu.%06lu\n", dt.tv_sec, dt.tv_usec);

	gettimeofday_safe(&t1);
	get_data(out_ack.buffer, &ack_data);
	memset(buffer, 0, MAX_PACKET_SIZE);
	strcpy(buffer, bye);
	replace_all(buffer, "local_ip", local_ip);
	replace_all(buffer, "remote_ip", remote_ip);
	replace_all(buffer, "from_tag", ack_data.to_tag);
	replace_all(buffer, "to_tag", ack_data.from_tag);
	replace_all(buffer, "call_id", ack_data.call_id);
	send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer, strlen(buffer));
	gettimeofday_safe(&t2);

	time_diff(&t1, &t2, &dt);
	printf("time 3: %lu.%06lu\n", dt.tv_sec, dt.tv_usec);
}
Пример #8
0
void TextIOHandler::show_message(MessageType type, String const& message) {
	flush();
	stream = stderr;
	if (type == MESSAGE_WARNING) {
		*this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n         ")) << ENDL;
	} else {
		*this << RED << _("ERROR: ") << NORMAL << replace_all(message,_("\n"),_("\n       ")) << ENDL;
	}
	flush();
	stream = stdout;
	if (raw_mode) raw_mode_status = max(raw_mode_status, type == MESSAGE_WARNING ? 1 : 2);
}
Пример #9
0
    ACE_TString PrepareString(const ACE_TString& str)
    {
        ACE_TString newstr;
        if(str.length()>MAX_STRING_LENGTH)
            newstr = str.substr(0, MAX_STRING_LENGTH);
        else
            newstr = str;

        replace_all(newstr, ACE_TEXT("\\"), ACE_TEXT("\\\\"));
        replace_all(newstr, ACE_TEXT("\""), ACE_TEXT("\\\""));
        replace_all(newstr, ACE_TEXT("\r"), ACE_TEXT("\\r"));
        replace_all(newstr, ACE_TEXT("\n"), ACE_TEXT("\\n"));

        return newstr;
    }
Пример #10
0
int
TokenServer::tokenToUser(ServerContext& ctxt, const string& token, string& user)
{
	if (ctxt.user() != string(":root") && ctxt.user() != string(":admin") && ctxt.user() != string(":web"))
	{
		return -ENOENT;
	}

	token_map_t::iterator it = active_tokens.find(token);
	if (it != active_tokens.end())
	{
		// cache for 60 seconds
		time_t when = get<0>(it->second);
		if (when < time(0) + 60)
		{
			user = get<1>(it->second);
			return 0;
		}
		active_tokens.erase(token);
	}
	string path = SEPSTR + token + "/:tokenuser";
	SingleFile file(ctxt, *this, path.c_str());
	user = file.get();
	replace_all(user, "\n", "");
	if (user.empty())
	{
		return -ENOENT;
	}
	active_tokens[token] = make_pair(time(0), user);
	return 0;
}
Пример #11
0
void lcl_replace_stuff(char *text, unsigned int max_len)
{
	Assert(text);	// Goober5000

	if (Fred_running)
		return;

	if (!Player)
		return;

	int i;
	char replace[LCL_NUM_REPLACEMENTS][2][NAME_LENGTH];

	// fill replacements array (this is if we want to add more in the future)
	strcpy(replace[0][0], "$callsign");
	strcpy(replace[0][1], Player->callsign);
	strcpy(replace[1][0], "$rank");
	strcpy(replace[1][1], Ranks[Player->stats.rank].name);
	strcpy(replace[2][0], "$quote");
	strcpy(replace[2][1], "\"");
	strcpy(replace[3][0], "$semicolon");
	strcpy(replace[3][1], ";");

	// do all replacements
	for (i = 0; i < LCL_NUM_REPLACEMENTS; i++)
	{
		// replace all instances of that string
		replace_all(text, replace[i][0], replace[i][1], max_len);
	}
}
Пример #12
0
map<int,var_val___>::iterator var___::huashen__(const string& s1,char use,size_t n){
	string s=s1;
	replace_all(s,"\\","/");
	/*int i;
	for(i=huashen_.size();--i>=0;){
		if(huashen_[i].rfind__(s,n))
			break;
	}
	return i<0 ? huashen_.end() : huashen_.find(i);*/
	/*map<int,var_val___>::reverse_iterator mi;
	for(mi=huashen_.rbegin();mi!=huashen_.rend();mi--){
		if(mi->second.rfind__(s,n)){
			if(use=='x')
				--mi;
			return mi.base();
		}
	}
	return huashen_.end();*/
	map<int,var_val___>::iterator mi1=huashen_.end();
	for(map<int,var_val___>::iterator mi=huashen_.begin();mi!=huashen_.end();mi++){
		if(mi->second.rfind__(s,n))
			mi1=mi;
	}
	return mi1;
}
Пример #13
0
int
TokenServer::checkToken(const char *path, file_stat_t& fs)
{
	const char *bname = base_name(path);
	if (Config::instance()->enable_token_server() && strncmp(bname, ".token-",  7) == 0)
	{
		string b64;
		sha2_loop(Config::instance()->token_group(), 5, b64);
		replace_all(b64, "=", "");
		b64 = "/.token-" + b64std2inet(b64);
		if (b64 == bname)
		{
			fs.fs_ino = 1;
			fs.fs_size = 0;
			fs.fs_blocks = 1024;
			fs.fs_atime = fs.fs_mtime = fs.fs_ctime = time(0);
			fs.fs_mode = S_IFREG | 0000;
			fs.fs_nlink = 0;
			fs.fs_uid = 65534;
			fs.fs_gid = 65534;
			fs.fs_blksize = 4096;
			return 0;
		}
	}
	return -ENOENT;
}
Пример #14
0
int CMyString::Replace(const wchar_t * lpszOld, const wchar_t * lpszNew)
{
	CMyString			strOld(lpszOld);
	CMyString			strNew(lpszNew);

	return replace_all(*this, strOld, strNew);
}
Пример #15
0
string Bubble::drawTextLine(int x0, int y0, string text, int maxwidth, float rel_height, bool centered) const {
    string prefix = "", oldprefix = "";
    int height, width = 0;
    while (width < maxwidth && oldprefix != text) {
	oldprefix = prefix;
	// Find the next word boundary
	size_t len = prefix.length();
	size_t word_idx = text.find(" ", len+1);

	if (word_idx != string::npos) {
	    prefix = text.substr(0, word_idx);
	} else {
	    prefix = text;
	}
	imlib_get_text_size(prefix.c_str(), &width, &height);
    }

    imlib_get_text_size(oldprefix.c_str(), &width, &height);
    int xpos = x0 + 2;
    if (centered) xpos += (maxwidth-width)/2;
    int ypos = y0 - height/2 - static_cast<int>(round(1.1*rel_height*(height/2.0)));
    imlib_text_draw(xpos, ypos, replace_all(oldprefix, "~", " ").c_str());
    //imlib_image_draw_line(x0, y0, x0+maxwidth, y0, 0);
    if (oldprefix == text) return "";
    else                   return text.substr(oldprefix.length()+1);
}
Пример #16
0
std::string GumboInterface::substitute_xml_entities_into_text(const std::string &text)
{
    std::string result = text;
    // replacing & must come first 
    replace_all(result, "&", "&amp;");
    replace_all(result, "<", "&lt;");
    replace_all(result, ">", "&gt;");
    // convert non-breaking spaces to entities to prevent their loss for later editing
    // See the strange//buggy behaviour of Qt QTextDocument toPlainText() routine 
    if (m_hasnbsp) {
        replace_all(result, "\xc2\xa0", "&nbsp;");
    } else {
        replace_all(result, "\xc2\xa0", "&#160;");
    }
    return result;
}
Пример #17
0
    ACE_TString RebuildString(const ACE_TString& str)
    {
        ACE_TString resultstr = str, tmpstr;
        ACE_TCHAR search[3][3] = { ACE_TEXT("\\n"), ACE_TEXT("\\r"), ACE_TEXT("\\\"") };
        ACE_TCHAR replace[3][2] = { ACE_TEXT("\n"), ACE_TEXT("\r"), ACE_TEXT("\"") };

        for(size_t j = 0; j < 3; j++)
        {
            size_t pos1 = 0, oldpos = 0;
            tmpstr = resultstr;
            resultstr.clear();
            while( (pos1 = tmpstr.find(search[j], pos1)) != ACE_TString::npos)
            {
                int i = (int)pos1;
                int slashes = 0;
                while(i >= 0 && tmpstr[i--] == '\\')slashes++;
                if(slashes % 2 != 0) //odd number of \ means the character should be escaped
                {
                    resultstr += tmpstr.substr(oldpos, pos1 - oldpos) + replace[j];
                    oldpos = pos1 + 2;
                }
                pos1 += 2;
            }

            resultstr += tmpstr.substr(oldpos, tmpstr.length() - oldpos);
        }

        replace_all(resultstr, ACE_TEXT("\\\\"), ACE_TEXT("\\"));
        return resultstr;
    }
Пример #18
0
bool
BlackList::is_black_listed(uint32_t pid)
{
	char buffer[2048];
	sprintf(buffer, "/proc/%u/cmdline", pid);

	if (!file_exists(buffer))
	{
		return true;
	}

	string contents;
	FILE *in = fopen(buffer, "r");
	if (in == NULL)
	{
		return true;
	}
	*buffer = 0;
	if (NULL == fgets(buffer, sizeof (buffer), in))
	{
		fclose(in);
		return true;
	}
	fclose(in);
	contents = buffer;
	replace_all(contents, "\n", "");
	return is_black_listed(contents.c_str());
}
Пример #19
0
int CMyString::Replace(wchar_t chOld, wchar_t chNew)
{
	CMyString			strOld(chOld);
	CMyString			strNew(chNew);

	return replace_all(*this, strOld, strNew);
}
Пример #20
0
void UserInterface::exec_fityk_script(const string& filename)
{
    user_interrupt = false;

    boost::scoped_ptr<FileOpener> opener;
    if (endswith(filename, ".gz"))
        opener.reset(new GzipFileOpener);
    else
        opener.reset(new NormalFileOpener);
    if (!opener->open(filename.c_str())) {
        warn("Can't open file: " + filename);
        return;
    }

    int line_index = 0;
    char *line;
    string s;
    while ((line = opener->read_line()) != NULL) {
        ++line_index;
        if (line[0] == '\0')
            continue;
        if (ctx_->get_verbosity() >= 0)
            show_message (kQuoted, S(line_index) + "> " + line);
        s += line;
        if (*(s.end() - 1) == '\\') {
            s.resize(s.size()-1);
            continue;
        }
        if (s.find("_SCRIPT_DIR_/") != string::npos) {
            string dir = get_directory(filename);
            replace_all(s, "_EXECUTED_SCRIPT_DIR_/", dir); // old magic string
            replace_all(s, "_SCRIPT_DIR_/", dir); // new magic string
        }
        Status r = execute_line(s);
        if (r != kStatusOk &&
                ctx_->get_settings()->on_error[0] != 'n' /*nothing*/)
            break;
        if (user_interrupt) {
            mesg("Script stopped by signal INT.");
            break;
        }
        s.clear();
    }
    if (line == NULL && !s.empty())
        throw SyntaxError("unfinished line");
}
Пример #21
0
void var___::val__(const string& val,list<string>* rems){
	if(rems&&rems->size()>0){
		for(list<string>::iterator li=rems->begin();li!=rems->end();++li){
			replace_all(*li,"\\","/");
			huashen__(*li,val);
		}
	}else
		huashen__("",val);
}
Пример #22
0
const char *luaL_gsub (LuaThread *L, const char *s, const char *p, const char *r) {
  THREAD_CHECK(L);

  std::string result = replace_all(s, p, r);

  LuaString* s2 = L->l_G->strings_->Create(result.c_str());
  L->stack_.push(s2);
  return s2->c_str();
}
Пример #23
0
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
	int len = input.length();
	switch(key) {
/*	case ' ':
		input += "%20";
		break;
	case 'x':
		showXYZ = (showXYZ) ? false : true;
		break;
	case 'q':
		eyeZ += 0.005f;
		break;
	case 'w':
		eyeZ -= 0.005f;
		break;
*/
	case OF_KEY_LEFT:
		if (--current < 0) current = cities.size() - 1;
		break;
	case OF_KEY_RIGHT:
		if (++current >= cities.size()) current = 0;
		break;
	case OF_KEY_UP:
		eyeZ -= 0.001f;
		break;
	case OF_KEY_DOWN:
		eyeZ += 0.001f;
		break;
	case OF_KEY_PAGE_UP:
		//eyeY += 0.005f;
		break;
	case OF_KEY_PAGE_DOWN:
		//eyeY -= 0.005f;
		break;
	case OF_KEY_BACKSPACE:
		if (len) input.erase(len-1);
		break;
	case OF_KEY_RETURN:
		input = replace_all(input, " ", "%20");
		try {
			cities.push_back(City(input, *earth));
			input.erase(0);
			current = cities.size() - 1;
		} catch (runtime_error e) {
			cout << e.what() << endl;
			input.erase(0);
			showError = true;
		}
		break;
	default:
		showError = false;
		input += key;
		break;
	}
}
Пример #24
0
string GetExt(string path){
	int index=path.find_last_of('.');
	if(index==-1){
		return "";
	}
	else{
		string type=path.substr(index+1);
		return replace_all(type,"jpg","jpeg");
	}
}
Пример #25
0
int
TokenServer::fromTokenGroup(ServerContext& ctxt, const string& tokenGroup)
{
	string b64;
	sha2_loop(tokenGroup, 5, b64);
	replace_all(b64, "=", "");
	b64 = "/.token-" + b64std2inet(b64);
	ServerFile file(ctxt, *this, b64.c_str());
	return file.exists() ? 0 : -ENOENT;
}
Пример #26
0
void conv_mac_to_dos (void)
{
  gint CurrentPage, res;
  
  CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook));
  res = replace_all (CurrentPage, TRUE, FALSE, 0, "\r", "\r\n");
  if (!res)
    print_msg ("This file is already DOS formated...");
  else
    print_msg ("File converted from MAC to DOS Format...");
}
Пример #27
0
static SkString filename_to_derived_filename(const SkString& filename, const char *suffix) {
    SkString diffName (filename);
    const char* cstring = diffName.c_str();
    size_t dotOffset = strrchr(cstring, '.') - cstring;
    diffName.remove(dotOffset, diffName.size() - dotOffset);
    diffName.append(suffix);

    // In case we recursed into subdirectories, replace slashes with something else
    // so the diffs will all be written into a single flat directory.
    diffName = replace_all(diffName, PATH_DIV_STR, "_");
    return diffName;
}
void AudioSinksManager::InternalAudioSink::start_sink() {
    assert(manager->pa_mainloop.get_strand().running_in_this_thread());
    assert(state == State::NONE);
    manager->logger->trace("(AudioSink '{}') Starting sink", name);
    state = State::STARTED;
    std::string escaped_name = replace_all(
            replace_all(replace_all(pretty_name, "\\", "\\\\"), " ", "\\ "), "\"", "\\\"");
    std::stringstream arguments;
    arguments << "sink_name=" << identifier
              << " sink_properties=device.description=\"(Chromecast)\\ " << escaped_name << "\"";
    pa_operation* op = pa_context_load_module(manager->context, "module-null-sink",
                                              arguments.str().c_str(), module_load_callback, this);
    if (op) {
        pa_operation_unref(op);
    } else {
        manager->logger->error("(AudioSink '{}') Failed to start loading module: {}", name,
                               manager->get_pa_error());
        state = State::DEAD;
        manager->unregister_audio_sink(shared_from_this());
    }
}
Пример #29
0
CertInfo::CertInfo(ServerSession& s)
	: m_session(s)
{
	string out;
	m_user = s.user();
	if (m_user == "")
	{
		m_user = "******";
	}
	if (m_user == ":root")
	{
		m_user = "******";
	}
	make_hash64("md5", m_user, out);
	// user for country if enforced
	m_ip_addr = s.peerAddress();
	m_cn = ClientInfo::for_cert(s);
	m_cn += ";" + out + ";";
	replace_all(m_cn, "=", "");
	replace_all(m_cn, "+", "-");
	replace_all(m_cn, "/", "_");
	make_hash64("md5", m_cn, out);
	replace_all(out, "=", "");
	replace_all(out, "+", "-");
	replace_all(out, "/", "_");
	m_cn += out;
	// CN = CID
	// O = org name (inode)
}
Пример #30
-1
std::string GumboInterface::substitute_xml_entities_into_text(const std::string &text)
{
    std::string result = text;
    // replacing & must come first 
    replace_all(result, "&", "&amp;");
    replace_all(result, "<", "&lt;");
    replace_all(result, ">", "&gt;");
    return result;
}