예제 #1
1
void ViewerCmdLine::parse()
{
  const CmdLineOption options[] = {
    HELP,
    HELP_SHORT,
    OPTIONS_FILE,
    LISTEN,
    HOST,
    PORT,
    PASSWORD,
    SHOW_CONTROLS,
    VIEW_ONLY,
    USE_CLIPBOARD,
    SCALE,
    FULL_SCREEN,
    WARN_FULL_SCREEN,
    ENCODING,
    COPY_RECT,
    MOUSE_CURSOR,
    MOUSE_LOCAL,
    MOUSE_SWAP,
    JPEG_IMAGE_QUALITY,
    COMPRESSION_LEVEL
  };

  if (!processCmdLine(&options[0], sizeof(options) / sizeof(CmdLineOption))) {
    throw CommandLineFormatException();
  }

  if (isHelpPresent()) {
    throw CommandLineFormatHelp();
  }


  if (m_wpcl.getArgumentsCount() > 2) {
    throw CommandLineFormatException();
  }

  if (m_wpcl.getArgumentsCount() > 1) {
    if (isPresent(ViewerCmdLine::HOST)) {
      throw CommandLineFormatException();
    }
  }

  if (isPresent(ViewerCmdLine::OPTIONS_FILE)) {
    parseOptionsFile();
  } else {
    if (isPresent(ViewerCmdLine::LISTEN)) {
      *m_isListening = true;
    } else {
      if (!parseHost()) {
        throw CommandLineFormatException();
      }
    }
  }
  parsePassword();
  parseEncoding();
  parseMouseShape();
  parseMouseCursor();
  parseScale();
  parseFullScreen();
  parseCompressionLevel();
  parseWarnFullScr();
  parseMouseSwap();
  parseUseClipboard();
  parseShowControl();
  parseCopyRect();
  parseViewOnly();
  parseJpegImageQuality();
}
예제 #2
0
파일: Url.cpp 프로젝트: asionius/fibjs
void Url::parseHost(const char*& url)
{
    const char* p0 = url;

    while (true) {
        parseHost(url, m_hostname, m_port);
        m_ipv6 = qstrchr(m_hostname.c_str(), ':') != NULL;

        if (*url != ',')
            break;

        url++;
    }

    if (url > p0) {
        if (m_hostname.length() > 0) {
            if (m_ipv6) {
                m_host.append("[");
                m_host.append(m_hostname);
                m_host.append("]");
            } else
                m_host.append(m_hostname);
        }

        if (m_port.length() > 0) {
            m_host.append(":");
            m_host.append(m_port);
        }
    }
}
   void TcpSymbianSerial::handleConnect(const char* method, uint32 src)
   {
      char* tmp = strdup_new(method);
      char* host = NULL;
      uint16 port = 0;
#ifdef SYMBIAN_DELAY_DISCONNECT
      if(m_queue->isTimerSet(m_connectionTimer)){
         DBG("stopping timer %u", m_connectionTimer);
         m_queue->stopTimer(m_connectionTimer);
      }
#endif
      if(!parseHost(tmp, &host, &port)){
         WARN("parsing of %s failed.", method);
         sendConnectionNotify(DISCONNECTING, METHOD_ERROR, src);
         // this look suspicious
         //rootPublic()->connectionNotify(CLEAR, UNSPECIFIED, src);
      } else {
         DBG("Host parsed as %s:%u", host, port);
         if(m_tcpAdmin){
            if(! m_tcpAdmin->IsConnected()){
               DBG("Not already connected.");
               m_tcpAdmin->ConnectionControl(CONNECT, method);
            } else {
               DBG("Probably fake-disconnected.");
               //just a faked disconnect before. 
               sendConnectionNotify(CONNECTING, REQUESTED, src);
               sendConnectionNotify(CONNECTED, REQUESTED, src);
            }
         } else {
            DBG("No TcpAdmin, DISCONNECT INTERNAL_ERROR");
            sendConnectionNotify(DISCONNECTING, INTERNAL_ERROR, src);
         }
      }
      delete[] tmp;
   }
예제 #4
0
void Uri::Private::parseAuthority()
{
    m_parserAux.clear();
    const size_t parserOldPos = m_parserPos;
    parseUserinfo();
    if (!expectChar('@')) {
        m_parserPos = parserOldPos;
    }
    parseHost();
    if (expectChar(':')) {
        parsePort();
    }
}
예제 #5
0
파일: Url.cpp 프로젝트: asionius/fibjs
result_t Url::parse(exlib::string url, bool parseQueryString, bool slashesDenoteHost)
{
    bool bHost;
    clear();
    m_slashes = false;

    trimUrl(url, url);
    const char* c_str = url.c_str();
    bool hasHash = qstrchr(c_str, '#') != NULL;

    if (!slashesDenoteHost && !hasHash && isUrlSlash(*c_str)) {
        parsePath(c_str);
        parseQuery(c_str);
        parseHash(c_str);

        if (parseQueryString) {
            m_queryParsed = new HttpCollection();
            m_queryParsed->parse(m_query);
        }

        return 0;
    }

    parseProtocol(c_str);

    bHost = checkHost(c_str);

    if (slashesDenoteHost || m_protocol.length() > 0 || bHost)
        m_slashes = ((isUrlSlash(*c_str) && isUrlSlash(c_str[1])) && (m_protocol.length() <= 0 || m_protocol.compare("javascript:")));

    if (m_protocol.compare("javascript:") && m_slashes) {
        c_str += 2;
        parseAuth(c_str);
        parseHost(c_str);
    }

    parsePath(c_str);
    parseQuery(c_str);
    parseHash(c_str);

    if (parseQueryString) {
        m_queryParsed = new HttpCollection();
        m_queryParsed->parse(m_query);
    }

    return 0;
}
예제 #6
0
파일: Uri.cpp 프로젝트: mfichman/http
static ParseResult<Authority> parseAuthority(char const* str) {
    ParseResult<Authority> result{};
    if (str[0] == '\0' || str[0] != '/' || str[1] != '/') {
        result.ch = str;
        return result;
    } 
    
    auto user = parseUser(str+2); // For "//"
    auto host = parseHost(user.ch);
    auto port = parsePort(host.ch);

    result.value.userIs(user.value);
    result.value.hostIs(host.value);
    result.value.portIs(port.value);
    result.ch = port.ch;

    return result; 
}
예제 #7
0
파일: url.hpp 프로젝트: Habbie/pdnsnonfork
      bool parse(const std::string& url) {
          // setup
          protocol = ""; host = ""; port = 0; 
          username = ""; password = ""; path = ""; 
          parameters = ""; anchor =""; pathless = true;

          if (url.size() > YAHTTP_MAX_URL_LENGTH) return false;
          size_t pos = 0;
          if (*(url.begin()) != '/') { // full url?
             if (parseSchema(url, pos) == false) return false;
             if (pathless) {
                parameters = url.substr(pos);
                return true;
             }
             if (parseUserPass(url, pos) == false) return false;
             if (parseHost(url, pos) == false) return false;
          }
          if (parsePath(url, pos) == false) return false;
          if (parseParameters(url, pos) == false) return false;
          return parseAnchor(url, pos);
      };
예제 #8
0
QList<Host> Discover::parseProcessOutput(const QByteArray &processData)
{
    m_reader.clear();
    m_reader.addData(processData);

    QList<Host> hosts;

    while (!m_reader.atEnd() && !m_reader.hasError()) {

        QXmlStreamReader::TokenType token = m_reader.readNext();
        if(token == QXmlStreamReader::StartDocument)
            continue;

        if(token == QXmlStreamReader::StartElement && m_reader.name() == "host") {
            Host host = parseHost();
            if (host.isValid()) {
                hosts.append(host);
            }
        }
    }
    return hosts;
}
예제 #9
0
// source            = scheme ":"
//                   / ( [ scheme "://" ] host [ port ] )
//                   / "'self'"
//
bool CSPSourceList::parseSource(const UChar* begin, const UChar* end,
                                String& scheme, String& host, int& port,
                                bool& hostHasWildcard, bool& portHasWildcard)
{
    if (begin == end)
        return false;

    if (equalIgnoringCase("'self'", begin, end - begin)) {
        addSourceSelf();
        return false;
    }

    if (equalIgnoringCase("'unsafe-inline'", begin, end - begin)) {
        addSourceUnsafeInline();
        return false;
    }

    if (equalIgnoringCase("'unsafe-eval'", begin, end - begin)) {
        addSourceUnsafeEval();
        return false;
    }

    const UChar* position = begin;

    const UChar* beginHost = begin;
    skipUtil(position, end, ':');

    if (position == end) {
        // This must be a host-only source.
        if (!parseHost(beginHost, position, host, hostHasWildcard))
            return false;
        return true;
    }

    if (end - position == 1) {
        ASSERT(*position == ':');
        // This must be a scheme-only source.
        if (!parseScheme(begin, position, scheme))
            return false;
        return true;
    }

    ASSERT(end - position >= 2);
    if (position[1] == '/') {
        if (!parseScheme(begin, position, scheme)
            || !skipExactly(position, end, ':')
            || !skipExactly(position, end, '/')
            || !skipExactly(position, end, '/'))
            return false;
        beginHost = position;
        skipUtil(position, end, ':');
    }

    if (position == beginHost)
        return false;

    if (!parseHost(beginHost, position, host, hostHasWildcard))
        return false;

    if (position == end) {
        port = 0;
        return true;
    }

    if (!skipExactly(position, end, ':'))
        ASSERT_NOT_REACHED();

    if (!parsePort(position, end, port, portHasWildcard))
        return false;

    return true;
}
예제 #10
0
// source            = scheme ":"
//                   / ( [ scheme "://" ] host [ port ] [ path ] )
//                   / "'self'"
bool CSPSourceList::parseSource(const UChar* begin, const UChar* end, String& scheme, String& host, int& port, String& path, CSPSource::WildcardDisposition& hostWildcard, CSPSource::WildcardDisposition& portWildcard)
{
    if (begin == end)
        return false;

    if (equalIgnoringCase("'none'", begin, end - begin))
        return false;

    if (end - begin == 1 && *begin == '*') {
        addSourceStar();
        return true;
    }

    if (equalIgnoringCase("'self'", begin, end - begin)) {
        addSourceSelf();
        return true;
    }

    if (equalIgnoringCase("'unsafe-inline'", begin, end - begin)) {
        addSourceUnsafeInline();
        return true;
    }

    if (equalIgnoringCase("'unsafe-eval'", begin, end - begin)) {
        addSourceUnsafeEval();
        return true;
    }

    String nonce;
    if (!parseNonce(begin, end, nonce))
        return false;

    if (!nonce.isNull()) {
        addSourceNonce(nonce);
        return true;
    }

    DigestValue hash;
    ContentSecurityPolicyHashAlgorithm algorithm = ContentSecurityPolicyHashAlgorithmNone;
    if (!parseHash(begin, end, hash, algorithm))
        return false;

    if (hash.size() > 0) {
        addSourceHash(algorithm, hash);
        return true;
    }

    const UChar* position = begin;
    const UChar* beginHost = begin;
    const UChar* beginPath = end;
    const UChar* beginPort = 0;

    skipWhile<UChar, isNotColonOrSlash>(position, end);

    if (position == end) {
        // host
        //     ^
        return parseHost(beginHost, position, host, hostWildcard);
    }

    if (position < end && *position == '/') {
        // host/path || host/ || /
        //     ^            ^    ^
        return parseHost(beginHost, position, host, hostWildcard) && parsePath(position, end, path);
    }

    if (position < end && *position == ':') {
        if (end - position == 1) {
            // scheme:
            //       ^
            return parseScheme(begin, position, scheme);
        }

        if (position[1] == '/') {
            // scheme://host || scheme://
            //       ^                ^
            if (!parseScheme(begin, position, scheme)
                || !skipExactly<UChar>(position, end, ':')
                || !skipExactly<UChar>(position, end, '/')
                || !skipExactly<UChar>(position, end, '/'))
                return false;
            if (position == end)
                return false;
            beginHost = position;
            skipWhile<UChar, isNotColonOrSlash>(position, end);
        }

        if (position < end && *position == ':') {
            // host:port || scheme://host:port
            //     ^                     ^
            beginPort = position;
            skipUntil<UChar>(position, end, '/');
        }
    }

    if (position < end && *position == '/') {
        // scheme://host/path || scheme://host:port/path
        //              ^                          ^
        if (position == beginHost)
            return false;
        beginPath = position;
    }

    if (!parseHost(beginHost, beginPort ? beginPort : beginPath, host, hostWildcard))
        return false;

    if (beginPort) {
        if (!parsePort(beginPort, beginPath, port, portWildcard))
            return false;
    } else {
        port = 0;
    }

    if (beginPath != end) {
        if (!parsePath(beginPath, end, path))
            return false;
    }

    return true;
}
// source            = scheme ":"
//                   / ( [ scheme "://" ] host [ port ] [ path ] )
//                   / "'self'"
//
bool ContentSecurityPolicySourceList::parseSource(const UChar* begin, const UChar* end, String& scheme, String& host, int& port, String& path, bool& hostHasWildcard, bool& portHasWildcard)
{
    if (begin == end)
        return false;

    if (equalLettersIgnoringASCIICase(begin, end - begin, "'none'"))
        return false;

    if (end - begin == 1 && *begin == '*') {
        m_allowStar = true;
        return true;
    }

    if (equalLettersIgnoringASCIICase(begin, end - begin, "'self'")) {
        m_allowSelf = true;
        return true;
    }

    if (equalLettersIgnoringASCIICase(begin, end - begin, "'unsafe-inline'")) {
        m_allowInline = true;
        return true;
    }

    if (equalLettersIgnoringASCIICase(begin, end - begin, "'unsafe-eval'")) {
        m_allowEval = true;
        return true;
    }

    const UChar* position = begin;
    const UChar* beginHost = begin;
    const UChar* beginPath = end;
    const UChar* beginPort = nullptr;

    skipWhile<UChar, isNotColonOrSlash>(position, end);

    if (position == end) {
        // host
        //     ^
        return parseHost(beginHost, position, host, hostHasWildcard);
    }

    if (position < end && *position == '/') {
        // host/path || host/ || /
        //     ^            ^    ^
        return parseHost(beginHost, position, host, hostHasWildcard) && parsePath(position, end, path);
    }

    if (position < end && *position == ':') {
        if (end - position == 1) {
            // scheme:
            //       ^
            return parseScheme(begin, position, scheme);
        }

        if (position[1] == '/') {
            // scheme://host || scheme://
            //       ^                ^
            if (!parseScheme(begin, position, scheme)
                || !skipExactly<UChar>(position, end, ':')
                || !skipExactly<UChar>(position, end, '/')
                || !skipExactly<UChar>(position, end, '/'))
                return false;
            if (position == end)
                return false;
            beginHost = position;
            skipWhile<UChar, isNotColonOrSlash>(position, end);
        }

        if (position < end && *position == ':') {
            // host:port || scheme://host:port
            //     ^                     ^
            beginPort = position;
            skipUntil<UChar>(position, end, '/');
        }
    }

    if (position < end && *position == '/') {
        // scheme://host/path || scheme://host:port/path
        //              ^                          ^
        if (position == beginHost)
            return false;

        beginPath = position;
    }

    if (!parseHost(beginHost, beginPort ? beginPort : beginPath, host, hostHasWildcard))
        return false;

    if (!beginPort)
        port = 0;
    else {
        if (!parsePort(beginPort, beginPath, port, portHasWildcard))
            return false;
    }

    if (beginPath != end) {
        if (!parsePath(beginPath, end, path))
            return false;
    }

    return true;
}
예제 #12
0
static struct host
parseHost
(json_value *hostObj, int *ret)
{
  json_value *jName = json_find(hostObj, "name", json_string);
  json_value *jMac  = json_find(hostObj, "mac",  json_string);

  if ((NULL == jName) || (NULL == jMac))
    return (*ret = 1), (struct host) {0};

  struct host result = {
    .name       = utilStringDup(jName->u.string.ptr),
    .macAddress = utilStringDup(jMac->u.string.ptr)
  };

  return result;
}

static struct host *
parseHosts
(json_value *root, size_t *numHosts)
{
  json_value *jHosts = json_find(root, "hosts", json_array);
  if (NULL == jHosts)
    return NULL;

  const size_t numJHosts     = jHosts->u.array.length;
  struct host *result = calloc(numJHosts, sizeof(*result));

  for (size_t i=0; i<numJHosts; i++)
  {
    json_value *jHostObj = jHosts->u.array.values[i];

    int ret   = 0;
    result[i] = parseHost(jHostObj, &ret);
    
    if (ret)
    {
      free(result);
      return NULL;
    }
  }

  *numHosts = numJHosts;
  return result;
}

static struct resource
parseResource
(json_value *jResource, int *ret)
{
  json_value *jName = json_find(jResource, "name", json_string);
  json_value *jHost = json_find(jResource, "host", json_string);
  json_value *jVars = json_find(jResource, "vars", json_array);
  
  if ((NULL == jName) || (NULL == jHost) || (NULL == jVars))
    return (*ret = 1), (struct resource) {0};

  const size_t numVars = jVars->u.array.length;
  char **keyMap = calloc(numVars, sizeof(char *));
  char **valMap = calloc(numVars, sizeof(char *));

  for (size_t i=0; i<numVars; i++)
  {
    json_value *jVar = jVars->u.array.values[i];
    if (jVar->type != json_array)
      return (*ret = 1), (struct resource) {0};

    if (jVar->u.array.length != 2)
      return (*ret = 1), (struct resource) {0};

    json_value *jKey = jVar->u.array.values[0];
    json_value *jVal = jVar->u.array.values[1];

    if (jKey->type != json_string)
      return (*ret = 1), (struct resource) {0};

    if (jVal->type != json_string)
      return (*ret = 1), (struct resource) {0};

    keyMap[i] = utilStringDup(jKey->u.string.ptr);
    valMap[i] = utilStringDup(jVal->u.string.ptr);
  }

  struct resource result = {
    .name     = utilStringDup(jName->u.string.ptr),
    .host     = utilStringDup(jHost->u.string.ptr),
    .numVars  = numVars,
    .keyMap   = keyMap,
    .valMap   = valMap,
  };

  return result;
}

struct resource *
parseResources
(json_value *root, size_t *numResources)
{
  json_value *jResources = json_find(root, "resources", json_array);
  if (NULL == jResources)
    return NULL;

  const size_t numJResources  = jResources->u.array.length;
  struct resource *result     = calloc(numJResources, sizeof(*result));
  
  for (size_t i=0; i<numJResources; i++)
  {
    json_value *jResource = jResources->u.array.values[i];

    int ret       = 0;
    result[i]     = parseResource(jResource, &ret);
    result[i].id  = i;

    #if defined(CLUSTERD_BUILD)
      result[i].mutex = calloc(1, sizeof(pthread_mutex_t));
      result[i].inUse = calloc(1, sizeof(bool));
      pthread_mutex_init(result[i].mutex, NULL);
    #endif
  }

  *numResources = numJResources;
  return result;
}

configuration *
parseConfiguration
(void)
{
  char *jsonConfig = readFile(_configPath);
  if (NULL == jsonConfig)
  {
    fprintf(stderr, "Error: Unable to read configuration file\n");
    fprintf(stderr, "Does %s exist?\n", _configPath);
    return NULL;
  }

  json_value *root = json_parse(jsonConfig, strlen(jsonConfig));
  free(jsonConfig);
  if (NULL == root)
  {
    fprintf(stderr, "Error: Configuration file %s is malformed\n", _configPath);
    fprintf(stderr, "Unable to parse json\n");
    return NULL;
  }

  configuration *result = calloc(1, sizeof(configuration));
  result->hosts = parseHosts(root, &result->numHosts);
  if (NULL == result->hosts)
  {
    fprintf(stderr, "Error: Configuration file %s is malformed\n", _configPath);
    fprintf(stderr, "Unable to parse hosts\n");
    return NULL;
  }

  result->resources = parseResources(root, &result->numResources);
  if (NULL == result->hosts)
  {
    fprintf(stderr, "Error: Configuration file %s is malformed\n", _configPath);
    fprintf(stderr, "Unable to parse resources\n");
    return NULL;
  }

  json_value *jMaster = json_find(root, "master", json_string);
  if (NULL == jMaster)
  {
    fprintf(stderr, "Error: No master hostname set\n");
    return NULL;
  }

  if (jMaster->type != json_string)
  {
    fprintf(stderr, "Error: Master feild is not a string\n");
    return NULL;
  }

  result->master = utilStringDup(jMaster->u.string.ptr);

  json_value_free(root);

  return result;
}