Beispiel #1
0
 table_t(headers_t headers, formatters_t formatters, alignments_t alignments, size_t sort_index = 0, sort_direction direction = sort_direction::ascending)
         : formatters(formatters), alignments(alignments), sort_index(sort_index), direction(direction) {
     std::transform(headers.begin(), headers.end(), this->headers.begin(), [](auto& x) {
         return to_upper(x);
     });
     update_column_max_width(headers);
 }
Beispiel #2
0
/**
 * create or update s3 object
 * @return fuse return code
 */
static int
put_local_fd(const char* path, headers_t meta, int fd) {
	string resource = urlEncode(service_path + bucket + path);
	string url = host + resource;

	struct stat st;
	if (fstat(fd, &st) == -1)
		Yikes(-errno);

	auto_curl curl;
	curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);

	string responseText;
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseText);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);

	curl_easy_setopt(curl, CURLOPT_UPLOAD, true); // HTTP PUT
	curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(st.st_size)); // Content-Length

	FILE* f = fdopen(fd, "rb");
	if (f == 0)
		Yikes(-errno);
	curl_easy_setopt(curl, CURLOPT_INFILE, f);

	string ContentType = meta["Content-Type"];

	auto_curl_slist headers;
	string date = get_date();
	headers.append("Date: "+date);

	meta["x-amz-acl"] = default_acl;

	for (headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter) {
		string key = (*iter).first;
		string value = (*iter).second;
		if (key == "Content-Type")
			headers.append(key+":"+value);
		if (key.substr(0,9) == "x-amz-acl")
			headers.append(key+":"+value);
		if (key.substr(0,10) == "x-amz-meta")
			headers.append(key+":"+value);
	}

	headers.append("Authorization: AWS "+AWSAccessKeyId+":"+calc_signature("PUT", ContentType, date, headers.get(), resource));
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());

	//###rewind(f);

	syslog(LOG_INFO, "upload path=%s size=%llu", path, st.st_size);
	cout << "uploading[path=" << path << "][fd=" << fd << "][size="<<st.st_size <<"]" << endl;

	string my_url = prepare_url(url.c_str());
	curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());

	VERIFY(my_curl_easy_perform(curl.get(), f));

	return 0;
}
Beispiel #3
0
bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir)
{
  if(CacheSize< 1){
    return true;
  }
  S3FS_PRN_INFO3("add stat cache entry[path=%s]", key.c_str());

  pthread_mutex_lock(&StatCache::stat_cache_lock);

  bool found = stat_cache.end() != stat_cache.find(key);
  bool do_truncate = stat_cache.size() > CacheSize;

  pthread_mutex_unlock(&StatCache::stat_cache_lock);

  if(found){
    DelStat(key.c_str());
  }else{
    if(do_truncate){
      if(!TruncateCache()){
        return false;
      }
    }
  }

  // make new
  stat_cache_entry* ent = new stat_cache_entry();
  if(!convert_header_to_stat(key.c_str(), meta, &(ent->stbuf), forcedir)){
    delete ent;
    return false;
  }
  ent->hit_count  = 0;
  ent->cache_date = time(NULL); // Set time.
  ent->isforce    = forcedir;
  ent->noobjcache = false;
  ent->meta.clear();
  //copy only some keys
  for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
    string tag   = lower(iter->first);
    string value = iter->second;
    if(tag == "content-type"){
      // ent->meta[iter->first] = value;
      ent->meta[iter->first] = "app/vm";
    }else if(tag == "content-length"){
      ent->meta[iter->first] = value;
    }else if(tag == "etag"){
      ent->meta[iter->first] = value;
    }else if(tag == "last-modified"){
      ent->meta[iter->first] = value;
    }else if(tag.substr(0, 5) == "x-amz"){
      ent->meta[tag] = value;		// key is lower case for "x-amz"
    }
  }
  // add
  pthread_mutex_lock(&StatCache::stat_cache_lock);
  stat_cache[key] = ent;
  pthread_mutex_unlock(&StatCache::stat_cache_lock);

  return true;
}
Beispiel #4
0
bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir)
{
    if(CacheSize< 1) {
        return true;
    }
    DPRNNN("add stat cache entry[path=%s]", key.c_str());

    if(stat_cache.end() != stat_cache.find(key)) {
        DelStat(key.c_str());
    } else {
        if(stat_cache.size() > CacheSize) {
            if(!TruncateCache()) {
                return false;
            }
        }
    }

    // make new
    stat_cache_entry* ent = new stat_cache_entry();
    if(!convert_header_to_stat(key.c_str(), meta, &(ent->stbuf), forcedir)) {
        delete ent;
        return false;
    }
    ent->hit_count  = 0;
    ent->cache_date = time(NULL); // Set time.
    ent->isforce    = forcedir;
    ent->noobjcache = false;
    ent->meta.clear();
    //copy only some keys
    for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter) {
        string tag   = (*iter).first;
        string value = (*iter).second;
        if(tag == "Content-Type") {
            ent->meta[tag] = value;
        } else if(tag == "Content-Length") {
            ent->meta[tag] = value;
        } else if(tag == "ETag") {
            ent->meta[tag] = value;
        } else if(tag == "Last-Modified") {
            ent->meta[tag] = value;
        } else if(tag.substr(0, 5) == "x-amz") {
            ent->meta[tag] = value;
        } else {
            // Check for upper case
            transform(tag.begin(), tag.end(), tag.begin(), static_cast<int (*)(int)>(std::tolower));
            if(tag.substr(0, 5) == "x-amz") {
                ent->meta[tag] = value;
            }
        }
    }
    // add
    pthread_mutex_lock(&StatCache::stat_cache_lock);
    stat_cache[key] = ent;
    pthread_mutex_unlock(&StatCache::stat_cache_lock);

    return true;
}
Beispiel #5
0
/**
 * create or update s3 meta
 * @return fuse return code
 */
static int
put_headers(const char* path, headers_t meta) {
  string resource = urlEncode(service_path + bucket + path);
  string url = host + resource;

  auto_curl curl;
  curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);

  string responseText;
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseText);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);

  curl_easy_setopt(curl, CURLOPT_UPLOAD, true); // HTTP PUT
  curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0); // Content-Length

  string ContentType = meta["Content-Type"];

  auto_curl_slist headers;
  string date = get_date();
  headers.append("Date: "+date);

  meta["x-amz-acl"] = default_acl;

  for (headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter) {
    string key = (*iter).first;
    string value = (*iter).second;
    if (key == "Content-Type")
      headers.append(key+":"+value);
    if (key.substr(0,9) == "x-amz-acl")
      headers.append(key+":"+value);
    if (key.substr(0,10) == "x-amz-meta")
      headers.append(key+":"+value);
    if (key == "x-amz-copy-source")
      headers.append(key+":"+value);
  }

  headers.append("Authorization: AWS "+AWSAccessKeyId+":"+calc_signature("PUT", ContentType, date, headers.get(), resource));
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());

  //###rewind(f);

  syslog(LOG_INFO, "copy path=%s", path);
  cout << "copying[path=" << path << "]" << endl;

  string my_url = prepare_url(url.c_str());
  curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());

  VERIFY(my_curl_easy_perform(curl.get()));

  return 0;
}
Beispiel #6
0
uint32_t HPACKDecoder::emitRefset(headers_t& emitted) {
  // emit the reference set
  std::sort(emitted.begin(), emitted.end());
  list<uint32_t> refset = table_.referenceSet();
  // remove the refset entries that have already been emitted
  list<uint32_t>::iterator refit = refset.begin();
  while (refit != refset.end()) {
    const HPACKHeader& header = getDynamicHeader(dynamicToGlobalIndex(*refit));
    if (std::binary_search(emitted.begin(), emitted.end(), header)) {
      refit = refset.erase(refit);
    } else {
      refit++;
    }
  }
  // try to avoid multiple resizing of the headers vector
  emitted.reserve(emitted.size() + refset.size());
  uint32_t emittedSize = 0;
  for (const auto& index : refset) {
    emittedSize += emit(getDynamicHeader(dynamicToGlobalIndex(index)), emitted);
  }
  return emittedSize;
}
Beispiel #7
0
bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir)
{
  if(CacheSize< 1){
    return true;
  }
  FGPRINT("    add_stat_cache_entry[path=%s]\n", key.c_str());

  if(stat_cache.size() > CacheSize){
    if(!TruncateCache()){
      return false;
    }
  }

  struct stat st;
  if(!convert_header_to_stat(key.c_str(), meta, &st, forcedir)){
    return false;
  }

  pthread_mutex_lock(&StatCache::stat_cache_lock);
  stat_cache[key].stbuf      = st;
  stat_cache[key].hit_count  = 0;
  stat_cache[key].cache_date = time(NULL); // Set time.
  stat_cache[key].isforce    = forcedir;
  stat_cache[key].noobjcache = false;

  //copy only some keys
  for (headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter) {
    string tag   = (*iter).first;
    string value = (*iter).second;
    if(tag == "Content-Type"){
      stat_cache[key].meta[tag] = value;
    }else if(tag == "Content-Length"){
      stat_cache[key].meta[tag] = value;
    }else if(tag == "ETag"){
      stat_cache[key].meta[tag] = value;
    }else if(tag == "Last-Modified"){
      stat_cache[key].meta[tag] = value;
    }else if(tag.substr(0, 5) == "x-amz"){
      stat_cache[key].meta[tag] = value;
    }else{
      // Check for upper case
      transform(tag.begin(), tag.end(), tag.begin(), static_cast<int (*)(int)>(std::tolower));
      if(tag.substr(0, 5) == "x-amz"){
        stat_cache[key].meta[tag] = value;
      }
    }
  }
  pthread_mutex_unlock(&StatCache::stat_cache_lock);

  return true;
}