Пример #1
0
void shellHistoryAdd( const char * line ) {
    if ( line[0] == '\0' )
        return;

    // dont record duplicate lines
    static string lastLine;
    if ( lastLine == line )
        return;
    lastLine = line;

    // We don't want any .auth() or .createUser() shell helpers added, but we want to
    // be able to add things like `.author`, so be smart about how this is
    // detected by using regular expresions. This is so we can avoid storing passwords
    // in the history file in plaintext.
    static pcrecpp::RE hiddenHelpers(
            "\\.\\s*(auth|createUser|updateUser|changeUserPassword)\\s*\\(");
    // Also don't want the raw user management commands to show in the shell when run directly
    // via runCommand.
    static pcrecpp::RE hiddenCommands(
                "(run|admin)Command\\s*\\(\\s*{\\s*(createUser|updateUser)\\s*:");
    if (!hiddenHelpers.PartialMatch(line) && !hiddenCommands.PartialMatch(line))
    {
        linenoiseHistoryAdd( line );
    }
}
Пример #2
0
bool Main::Config::ExecuteConfigCommands(Ui::Command & handler)
{
    static char const * const vimpcrcFile = "/.vimpcrc";
    static char const * const home        = "HOME";
    static bool configCommandsExecuted    = false;

    pcrecpp::RE const commentCheck("^\\s*\".*");

    if (configCommandsExecuted == false)
    {
        configCommandsExecuted = true;

        std::string configFile(getenv(home));
        configFile.append(vimpcrcFile);

        std::string   input;
        std::ifstream inputStream(configFile.c_str());

        if (inputStream)
        {
            while (!inputStream.eof())
            {
                std::getline(inputStream, input);

                if ((input != "") && (commentCheck.FullMatch(input.c_str()) == false))
                {
                    handler.ExecuteCommand(input);
                }
            }
        }
    }

    return true;
}
Пример #3
0
// static protected
MemcacheCommand MemcacheCommand::makeRequestCommand(u_char* data,
                                                    int length,
                                                    string sourceAddress,
                                                    string destinationAddress)
{
  // set <key> <flags> <exptime> <bytes> [noreply]\r\n
  static string commandName = "set";
  static pcrecpp::RE re(commandName + string(" (\\S+) \\d+ \\d+ (\\d+)"),
                        pcrecpp::RE_Options(PCRE_MULTILINE));
  string key;
  int size = -1;
  string input = "";

  for (int i = 0; i < length; i++) {
    int cid = (int)data[i];
    if (isprint(cid) || cid == 10 || cid == 13) {
      input += static_cast<char>(data[i]);
    }
  }
  if (input.length() < 11) { // set k 0 0 1
    return MemcacheCommand();
  }

  re.PartialMatch(input, &key, &size);
  if (size >= 0) {
    return MemcacheCommand(MC_REQUEST, sourceAddress, destinationAddress, commandName, key, size);
  }
  return MemcacheCommand();
}
Пример #4
0
// Returns true if parsing succeeded, false otherwise. Parsing can fail if the uri
// reference isn't properly formed.
bool cdom::parseUriRef(const string& uriRef,
                       string& scheme,
                       string& authority,
                       string& path,
                       string& query,
                       string& fragment) {

#ifdef USE_URIPARSER
    UriParserStateA state;
    UriUriA uri;
    state.uri = &uri;
    if ( uriParseUriA(&state, uriRef.c_str()) == 0 ) {
        scheme = fromRange(uri.scheme);
        authority = fromRange(uri.hostText);
        path = fromList(uri.pathHead, "/");
        if (uri.absolutePath != URI_TRUE and uri.hostText.first == NULL)
            path = path.erase(0, 1);
        query = fromRange(uri.query);
        fragment = fromRange(uri.fragment);
        uriFreeUriMembersA(&uri);
        return true;
    }
#else
    // This regular expression for parsing URI references comes from the URI spec:
    //   http://tools.ietf.org/html/rfc3986#appendix-B
    static pcrecpp::RE re("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
    string s1, s3, s6, s8;
    if (re.FullMatch(uriRef, &s1, &scheme, &s3, &authority, &path, &s6, &query, &s8, &fragment))
        return true;
#endif

    return false;
}
Пример #5
0
int32_t SongWindow::DetermineColour(uint32_t line) const
{
   uint32_t printLine = line + FirstLine();
   Mpc::Song * song   = (printLine < BufferSize()) ? Buffer().Get(printLine) : NULL;

   int32_t colour = Colour::Song;

   if (song != NULL)
   {
      if ((song->URI() == client_.GetCurrentSongURI()))
      {
         colour = Colour::CurrentSong;
      }
      else if (client_.SongIsInQueue(*song))
      {
         colour = Colour::FullAdd;
      }
      else if ((search_.LastSearchString() != "") && (settings_.Get(Setting::HighlightSearch) == true) &&
               (search_.HighlightSearch() == true))
      {
         pcrecpp::RE const expression(".*" + search_.LastSearchString() + ".*", search_.LastSearchOptions());

         if (expression.FullMatch(song->FormatString(settings_.Get(Setting::SongFormat))))
         {
            colour = Colour::SongMatch;
         }
      }
   }

   return colour;
}
Пример #6
0
static void _check_re_error(const pcrecpp::RE& re)
{
  if (re.error().length() >0)
    {
      std::stringstream b;
      b << "bad regexp `" << re.pattern() << "': " << re.error();
      throw std::runtime_error(b.str());
    }
}
Пример #7
0
// Returns true if parsing succeeded, false otherwise. Parsing can fail if the uri
// reference isn't properly formed.
bool cdom::parseUriRef(const string& uriRef,
                       string& scheme,
                       string& authority,
                       string& path,
                       string& query,
                       string& fragment) {
	// This regular expression for parsing URI references comes from the URI spec:
	//   http://tools.ietf.org/html/rfc3986#appendix-B
	static pcrecpp::RE re("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
	string s1, s3, s6, s8;
	if (re.FullMatch(uriRef, &s1, &scheme, &s3, &authority, &path, &s6, &query, &s8, &fragment))
		return true;

	return false;
}
Пример #8
0
static
int
read_dnssec_keygen_file_as_map(std::istream& i,
			       std::map<std::string,std::string>& m)
{
    static pcrecpp::RE re_DNSKeyFile("(\\S+):\\s*(.*)");

    std::string s;
    while (getline(i, s)) {
	std::string key;
	std::string value;
	if (re_DNSKeyFile.FullMatch(s, &key, &value)) {
	    m[key] = value;
	}
    }
    return m.size();
}
Пример #9
0
void shellHistoryAdd( const char * line ) {
    if ( line[0] == '\0' )
        return;

    // dont record duplicate lines
    static string lastLine;
    if ( lastLine == line )
        return;
    lastLine = line;

    // We don't want any .auth() or .addUser() commands added, but we want to
    // be able to add things like `.author`, so be smart about how this is
    // detected by using regular expresions.
    static pcrecpp::RE hiddenCommands("\\.(auth|addUser)\\s*\\(");
    if (!hiddenCommands.PartialMatch(line))
    {
        linenoiseHistoryAdd( line );
    }
}
Пример #10
0
bool MemcacheCommand::parseResponse(u_char *data, int length)
{
  static pcrecpp::RE re("VALUE (\\S+) \\d+ (\\d+)",
                        pcrecpp::RE_Options(PCRE_MULTILINE));
  bool found_response = false;
  string key;
  int size = -1;
  string input = "";
  for (int i = 0; i < length; i++) {
    int cid = (int)data[i];
    if (isprint(cid) || cid == 10 || cid == 13) {
      input += (char)data[i];
    }
  }
  re.PartialMatch(input, &key, &size);
  if (size >= 0) {
    objectSize = size;
    objectKey = key;
    found_response = true;
  }
  return found_response;
}
Пример #11
0
// static protected
MemcacheCommand MemcacheCommand::makeResponseCommand(u_char *data,
                                                     int length,
                                                     string sourceAddress,
                                                     string destinationAddress)
{
  // VALUE <key> <flags> <bytes> [<cas unique>]\r\n
  static string commandName = "get";
  static pcrecpp::RE re("(VALUE (\\S+) \\d+ (\\d+))",
                        pcrecpp::RE_Options(PCRE_MULTILINE));
  static int minimum_length = 11; // 'VALUE a 0 1'

  string whole;
  string key;
  int size = -1;

  MemcacheCommand mc(MC_RESPONSE, sourceAddress, destinationAddress, commandName);
  int offset = 0;
  while (length - offset >= minimum_length) {
    //Logger::getLogger("command")->debug(CONTEXT, "%.*s", length, data + offset);
    if (!re.PartialMatch(data + offset, &whole, &key, &size)) {
      break;
    }
    //Logger::getLogger("command")->debug(whole);
    //Logger::getLogger("command")->debug(key);
    if (size >= 0) {
      mc.pushObject(key, size);
      offset += whole.length() + 2 + size + 2; // 2 for '\r\n', 2 for '\r\n'
    } else {
      break;
    }
  }

  if (mc.getObjectNumber() > 0) {
    return mc;
  } else {
    return MemcacheCommand();
  }
}
Пример #12
0
bool event_t::check_attributes(string &error_message, const attribute_t &a, bool empty_only)
{
  static pcrecpp::RE known_keyword =
    "APPLICATION|TITLE|TEST|COMMAND|USER|CROUP|"
    "DBUS_SERVICE|DBUS_PATH|DBUS_INTERFACE|DBUS_METHOD|DBUS_SIGNAL|"
    "PLUGIN|BACKUP" ;
  static pcrecpp::RE upper_case = "[A-Z_]+" ;
  static pcrecpp::RE app_name = "[A-Za-z_][A-Za-z_0-9]*" ;

  bool app_name_found = false ;

  for(map<string,string>::const_iterator it=a.txt.begin(); it!=a.txt.end(); ++it)
  {
    if(it->first.empty())
      return error_message += ": empty attribute key", false ;
    if(it->second.empty())
      return error_message += ": empty value of attribute '"+it->first+"'", false ;
    if(empty_only)
      continue ;
    if(upper_case.FullMatch(it->first))
    {
      if(!known_keyword.FullMatch(it->first))
        return error_message = "unknown upper case event attribute key '"+it->first+"'", false ;
      if(it->first=="APPLICATION")
      {
        app_name_found = true ;
        if(!app_name.FullMatch(it->second))
          return error_message = "invalid application name '"+it->second+"'", false ;
      }
    }
  }

  if(empty_only || app_name_found)
    return true ;
  else
    return error_message = "no application name given", false ;
}