Exemple #1
0
int http_url_parse_s(http_url_t *http_url, char *url) 
{
    bzero(http_url, sizeof(http_url_t));
    char *str, *cstr = url;
    char *estr = url + strlen(url);
    str  = strstr(url, "://");
    /* protocol */
    if(str != NULL) {
	if(_check_protocol(cstr, str - cstr)) {
            memcpy(http_url->protocol, cstr, str - cstr);
    	    cstr = str + 3;
	} else {
	    return URL_PROTO_UNRECOGNIZED;
	}
    }
    str = strchr(cstr, ':');
    if(str != NULL) {
	if( _check_host(cstr, str - cstr)) { /* contain port */
	    memcpy(http_url->host, cstr, str - cstr);
	    cstr = str + 1;
	    str = strchr(cstr, '/'); /* copy port */
	    str = str != NULL ? str : estr;
	    if(_check_port(cstr, str - cstr)) {
	        memcpy(http_url->port, cstr, str - cstr);
	    } else {
	        return URL_PORT_UNRECOGNIZED;
	    }
	    cstr = str;
	} else {
	    return URL_HOST_UNRECOGNIZED;
	}
    } else { /* no port */
	str = strchr(cstr, '/'); /* copy port */
	str = str != NULL ? str : estr;
	if(_check_host(cstr, str - cstr)) {
	    memcpy(http_url->host, cstr, str - cstr); /* copy host */
	    cstr = str;
	} else {
	    return URL_HOST_UNRECOGNIZED;
	}
    }
    /* copy path */
    str = strchr(cstr, '?');
    if(str != NULL) { /* contain search */
	if(_check_path(cstr, str - cstr)) {
            memcpy(http_url->path, cstr, str - cstr);
            cstr = str + 1;
	    strcpy(http_url->search, cstr);
	} else {
	    return URL_PATH_UNRECOGNIZED;
	}
    } else { /* not contain search */
	if(_check_path(cstr, strlen(cstr))) {
	    strcpy(http_url->path, cstr);
	} else {
	    return URL_PATH_UNRECOGNIZED;
	}
    }
    return URL_RECOGNIZED;
}
Exemple #2
0
  PathMan::LookUp PathMan::add_file(const char * path, uint8_t mode)
  {
    LookUp lu = {FAILURE, State(), 0, 0};
    uint32_t len;
    const char * basename;

    if (trie.root)
      lu.err = _check_path(path, len);

    basename = NULL;
    if (len > 1) {
      for (uint16_t k = 0; k < len; k++) {
        if (path[k] == '/') {
          if (len > 1 && k < len - 1) {
            basename = path + k + 1;
            lu.err = SUCCESS;
          }
        }
      }
    } else {
      lu.err = MALFORMED_PATH;
    }

    if (lu.err == SUCCESS) {
      size_t dlen = basename - path;
      char dirname[dlen + 1];
      memcpy(dirname, path, dlen); dirname[dlen] = 0;

      lu = lookup(dirname);
      if (lu.err == SUCCESS) {
        lu = add_file(lu.dir, basename, 0);
      }
    }
    return lu;
  }
Exemple #3
0
  PathMan::LookUp PathMan::add_dir(const char * path, uint8_t mode)
  {
    LookUp lu = {SUCCESS, State(), 0, 0};
    uint32_t     len;
    const char * basename = 0;

    lu.err = CORRUPTION;

    if (trie.root) {
      lu.err = _check_path(path, len);
      if (lu.err == SUCCESS) {
        lu.err = MALFORMED_PATH;
        if (len > 1) {
          for (uint16_t k = 0; k < len; k++) {
            if (path[k] == '/') {
              if (len > 1 && k < len - 1)
              basename = path + k + 1;
            }
          }
          lu.err = SUCCESS;
        }
      }
    }

    if (lu.err == SUCCESS) {
      {
        PTrie::Tuple tuple;
        DirTuple parent;
        uint16_t elen = len - (basename - path);
        uint16_t alen = path[len - 1] != '/' ? elen + 2 : elen + 1;
        char word[alen];

        memcpy(word + 1, basename, elen);
        word[0] = '/';
        word[alen - 1] = '/';

        tuple = trie._find_i(basename - path, path);
        if (!tuple.index) {
          lu.err = PATH_NOT_FOUND;
          goto out;
        }

        if (!tuple.node->data.isdir) {
          lu.err = NOT_A_DIR;
          goto out;
        }

        parent = DirIter(dirs, 0).get_node(tuple.node->data.data);

        DirTuple dir = _mkdir();
        if (!dir.index)
          goto out;

        Node node = {1,0,0,dir.index};
        dir.node->isused = 1;

        PTrie::Epo epo = {SUCCESS, tuple, {0,0}, {0,0}, PTrie::FAIL, 0, 0};
        epo = trie._insert(epo, alen-1, word, node, false);

        if (epo.err == SUCCESS) {
          PTrie::Epo epo1 = {epo.err, epo.tuple, {0,0}, {0,0}, PTrie::FAIL, 0, 0};
          epo1 = trie._insert(epo1, 2, word+alen-2, node, false);
          if (epo1.err == SUCCESS) {
            if (parent.index) {
              dir.node->next = parent.node->child;
              parent.node->child = dir.index;
            }
            State s = State(epo1);
            dir.node->state = s;
            lu.state = s;
            lu.dir = dir.node;
          } else {
            _rmdir(dir.index);
            lu.err = epo1.err;
          }
        }
      }
    }

  out:
    return lu;
  }