Exemple #1
0
int main()
{
int rc, fd;
char buffie[512] ;

fd = smtp_open(NULL, WANTED_SMTP_PORT, NULL);

if (fd < 0) goto kut;

set_envelope(fd, "nngs@localhost", "nngs@localhost");

rc = set_data(fd);
if (rc < 0) goto kut;
add_header(fd, "Subject", "Kuttje (met twee thee)");
add_header(fd, "Reply-To", "nngs@localhost");
add_header(fd, NULL, 0);

add_data(fd, "En een droge sherry, alstublieft!\n", 0);

while(fgets(buffie, sizeof buffie, stdin)) {
	rc = add_data(fd, buffie, 0);
	/* sleep(1); */
	if (rc < 0) break;
	}

add_data(fd, NULL, 0);

sleep(10);
close(fd);
kut:
exit(0);
}
Exemple #2
0
/* Call a given function on each file name in a given directory. */
void map_dir(int (*cb)(const char*, const char*), const char *cb_data, const char *dir)
{
	DIR *dfd = opendir(dir);
	struct dirent *dp;
	struct post *p = NULL;

	 while ((dp = readdir(dfd))) {
	 	if (dp->d_type == DT_REG) {
			char *in = mkpath(dir, dp->d_name);
			char *out = create_path(dp->d_name, cb_data);
			convert_move_file(in, cb_data);
			hack_root_tags(out);
			add_header(out, "header.html");

			
			(void)get_title_summery(&p, out);
			free(in);
			free(out);
			
		}
	 }

	char *list_out = create_path("list", cb_data);
	create_list_page(p, list_out);
	add_header(list_out, "header.html");
	free(list_out);

	//for (struct post *lst = p; lst->next ; lst = lst->next) {
		//printf("title = %s\nsummery = %s\n", lst->title, lst->summery);
	//}
}
Exemple #3
0
/* inlen and outlen will be written with the uncompressed and compressed sizes respectively */
int do_compress_stream_stream (http_headers *hdr, FILE *from, FILE *to, ZP_DATASIZE_TYPE *inlen, ZP_DATASIZE_TYPE *outlen){
	int status;
	int de_chunk = 0;

	/* if http body is chunked, de-chunk it while compressing */
	if (hdr->where_chunked > 0) {
		remove_header(hdr, hdr->where_chunked);
		de_chunk = 1;
	}
	
	/* previous content-length is invalid, discard it */
	hdr->where_content_length = -1;
	remove_header_str(hdr, "Content-Length");

	add_header(hdr, "Content-Encoding: gzip");
	add_header(hdr, "Connection: close");
	add_header(hdr, "Proxy-Connection: close");

	debug_log_puts ("Gzip stream-to-stream. Out Headers:");
	send_headers_to(to, hdr);
	fflush(to);
	
	status = gzip_stream_stream(from, to, Z_BEST_COMPRESSION, inlen, outlen, de_chunk);
	fflush(to);

	debug_log_difftime ("Compression+streaming");

	return (status);
}
Exemple #4
0
int do_compress_memory_stream (http_headers *hdr, const char *from, FILE *to, const ZP_DATASIZE_TYPE inlen, ZP_DATASIZE_TYPE *outlen){
	int status;
	int de_chunk = 0;

	/* if http body is chunked, de-chunk it while compressing */
	if (hdr->where_chunked > 0) {
		remove_header(hdr, hdr->where_chunked);
		de_chunk = 1;
	}
	
	add_header(hdr, "Content-Encoding: gzip");
	add_header(hdr, "Connection: close");
	add_header(hdr, "Proxy-Connection: close");
	
	debug_log_puts ("Gzip memory-to-stream. Out Headers:");
	remove_header(hdr, hdr->where_content_length);
        hdr->where_content_length=-1;
	send_headers_to(to, hdr);
	fflush(to);
	
	status = gzip_memory_stream(from, to, Z_BEST_COMPRESSION, inlen, outlen);
	fflush(to);

	debug_log_difftime ("Compression+streaming");

	return (status);
}
Exemple #5
0
/* similar to do_compress_stream_stream() but decompress instead */
int do_decompress_stream_stream (http_headers *hdr, FILE *from, FILE *to, ZP_DATASIZE_TYPE *inlen, ZP_DATASIZE_TYPE *outlen, int max_ratio, ZP_DATASIZE_TYPE min_eval){
	int status;
	int de_chunk = 0;

	/* if http body is chunked, de-chunk it while decompressing */
	if (hdr->where_chunked > 0) {
		remove_header(hdr, hdr->where_chunked);
		de_chunk = 1;
	}
	
	/* no longer gzipped, modify headers accordingly */
	hdr->content_encoding_flags = PROP_ENCODED_NONE;
	hdr->content_encoding = NULL;
	hdr->where_content_encoding = -1;
	remove_header_str(hdr, "Content-Encoding");

	/* previous content-length is invalid, discard it */
	hdr->where_content_length = -1;
	remove_header_str(hdr, "Content-Length");

	add_header(hdr, "Connection: close");
	add_header(hdr, "Proxy-Connection: close");
	
	debug_log_puts ("Gunzip stream-to-stream. Out Headers:");
	send_headers_to(to, hdr);
	fflush(to);
	
	status = gunzip_stream_stream(from, to, inlen, outlen, de_chunk, max_ratio, min_eval);
	fflush(to);

	debug_log_difftime ("Decompression+streaming");

	return (status);
}
Exemple #6
0
static int smtp_mail(FILE *fp, char *to, char *subj)
{
int rc, fd;
char buffie[1024] ;

fd = smtp_open(conffile.smtp_mta, conffile.smtp_portnum, conffile.smtp_helo);
if (fd < 0) { return child_perror("Smtp_open"); }

rc = set_envelope(fd, conffile.smtp_from, to);
if (rc < 0) { return child_perror("Smtp_envelope"); }

rc = set_data(fd);
if (rc < 0) { return child_perror("Smtp_data"); }
if (subj) add_header(fd, "Subject", subj);
if (conffile.smtp_reply_to) add_header(fd, "Reply-To", conffile.smtp_reply_to);
add_header(fd, "X-NNGS-SMTP", "Yes, Baby!" );
add_header(fd, NULL, 0);

while(fgets(buffie, sizeof buffie, fp)) {
	rc = add_data(fd, buffie, 0);
	if (rc < 0) { return child_perror("Smtp_loop"); }
	}

add_data(fd, NULL, 0);

close(fd);
return 0;
}
Exemple #7
0
void Sip_Request::add_default_headers(const Sip_Uri& from_uri, const Sip_Uri& to_uri,
                                      int seq_no, const std::string& call_id)
{
    add_header(new Sip_Header(new Sip_Header_Value_From(from_uri)));
    add_header(new Sip_Header(new Sip_Header_Value_To(to_uri)));
    add_header(new Sip_Header(new Sip_Header_Value_Call_ID(call_id)));
    add_header(new Sip_Header(new Sip_Header_Value_CSeq(_method, seq_no)));
    add_header(new Sip_Header(new Sip_Header_Value_Max_Forwards(70)));
}
/* Allocate _length number of bytes of free memory and returns the 
   address of the allocated portion. Returns 0 when out of memory. */ 
extern Addr my_malloc(unsigned int _length) {
	// Round up to the size we need
	int needed_size = basic_logarithm(_length);
	
	// Check if there is already a free block of the needed size
	if (freelist[needed_size][0] != NULL) {
		// There is already a block free
		Header* available = freelist[needed_size][0];
		remove_header(available);
		available->is_allocated = true;
		return (void*) get_free_space(available);
	}
	else {
		// There isn't a block free
		// We need to break up a bigger block
		
		// Find the smallest available
		int power = needed_size + 1;
		
		while (power < 32 && freelist[power][0] == NULL) {
			power++;
		}
		if (power == 32) {
			// No block big enough free
			//printf("None big enough\n");
			return NULL;
		}
		assert(freelist[power][0] != NULL);
		Header* header, *split;
		while (freelist[needed_size][0] == NULL) {
			header = freelist[power][0];
			remove_header(header);
			split = split_block(header);
			if (header == split) {
				// Block can't split further
				header->is_allocated = true;
				return get_free_space(header);
			}
			else if (split == NULL) {
				// Split failed
				return NULL;
			}
			else {
				header->size -= 1;
				split->size = header->size - 1;
				add_header(header);
				add_header(split);
			}
			power--;
		}
		// We have a block ready
		Header* ready = freelist[needed_size][0];
		remove_header(ready);
		ready->is_allocated = true;
		return get_free_space(ready);
	}
}
Exemple #9
0
int cloudfs_connect(char *username, char *password, char *authurl, int use_snet)
{
  static struct {
    char username[MAX_HEADER_SIZE], password[MAX_HEADER_SIZE],
         authurl[MAX_URL_SIZE], use_snet;
  } reconnect_args;

  long response = -1;
  static int initialized = 0;

  if (!initialized)
  {
    LIBXML_TEST_VERSION
    init_locks();
    curl_global_init(CURL_GLOBAL_ALL);
    strncpy(reconnect_args.username, username, sizeof(reconnect_args.username));
    strncpy(reconnect_args.password, password, sizeof(reconnect_args.password));
    strncpy(reconnect_args.authurl, authurl, sizeof(reconnect_args.authurl));
    reconnect_args.use_snet = use_snet;
    initialized = 1;
  }
  else
  {
    username = reconnect_args.username;
    password = reconnect_args.password;
    authurl = reconnect_args.authurl;
    use_snet = reconnect_args.use_snet;
  }

  
  pthread_mutex_lock(&pool_mut);
  debugf("Authenticating...");
  storage_token[0] = storage_url[0] = '\0';
  curl_slist *headers = NULL;
  add_header(&headers, "X-Auth-User", username);
  add_header(&headers, "X-Auth-Key", password);
  CURL *curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_VERBOSE, debug);
  curl_easy_setopt(curl, CURLOPT_URL, authurl);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, &header_dispatch);
  curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
  curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
  curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
  curl_easy_perform(curl);
  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
  curl_slist_free_all(headers);
  curl_easy_cleanup(curl);
  if (use_snet && storage_url[0])
    rewrite_url_snet(storage_url);
  pthread_mutex_unlock(&pool_mut);
  return (response >= 200 && response < 300 && storage_token[0] && storage_url[0]);
}
Exemple #10
0
int cloudfs_copy_object(const char *src, const char *dst)
{
  char *dst_encoded = curl_escape(dst, 0);
  curl_slist *headers = NULL;
  add_header(&headers, "X-Copy-From", src);
  add_header(&headers, "Content-Length", "0");
  int response = send_request("PUT", dst_encoded, NULL, NULL, headers);
  curl_free(dst_encoded);
  curl_slist_free_all(headers);
  return (response >= 200 && response < 300);
}
Exemple #11
0
/* we are a mini-web server. We need to read the request from stdin */
static int setup_standalone(struct cgi_state *cgi)
{
	char line[1024];
	char *url=NULL;
	char *p;

	while (fgets(line, sizeof(line)-1, stdin)) {
		trim_tail(line, CRLF);
		if (line[0] == 0) break;
		if (strncasecmp(line,"GET ", 4)==0) {
			cgi->got_request = 1;
			url = strdup(&line[4]);
		} else if (strncasecmp(line,"POST ", 5)==0) {
			cgi->got_request = 1;
			cgi->request_post = 1;
			url = strdup(&line[5]);
		} else if (strncasecmp(line,"PUT ", 4)==0) {
			cgi->got_request = 1;
			cgi->http_error(cgi, "400 Bad Request", "",
					"This server does not accept PUT requests");
			return -1;
		} else if (strncasecmp(line,"Content-Length: ", 16)==0) {
			add_header(cgi, line);
			cgi->content_length = atoi(&line[16]);
		} else if (strncasecmp(line,"Content-Type: ", 14)==0) {
			add_header(cgi, line);
			cgi->content_type = strdup(&line[14]);
		} else {
			add_header(cgi, line);
		}
		/* ignore all other requests! */
	}

	if (!url) {
		cgi->http_error(cgi, "400 Bad Request", "",
				"You must specify a GET or POST request");
		exit(1);
	}

	/* trim the URL */
	if ((p = strchr(url,' ')) || (p=strchr(url,'\t'))) {
		*p = 0;
	}

	/* anything following a ? in the URL is part of the query string */
	if ((p=strchr(url,'?'))) {
		cgi->query_string = p+1;
		*p = 0;
	}

	cgi->url = url;
	cgi->pathinfo = url;
	return 0;
}
	void curl(const std::string& uri, const std::string& method = "GET", const std::string& content="", bool auth=false)
	{
		
		set_url(uri);
		if (auth)
		{
			cout << __LINE__ << ":" << uri << endl;
			add_header("Accept: application/json");
			add_header("Accept-Language: en_US");
			/*
			string userpass = m_client_id + ":" + m_client_secret;
			curl_easy_setopt(m_curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
			curl_easy_setopt(m_curl, CURLOPT_USERPWD, userpass.c_str());
			
			curl_easy_setopt(m_curl, CURLOPT_SSH_KNOWNHOSTS, "/root/.ssh/known_hosts");
		*/
			curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, auth_request_callback);

			//curl_easy_setopt(m_curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)29);
			//curl_easy_setopt(m_curl, CURLOPT_MAXREDIRS, 50L);

			//////////////////////////////////////////////////////////////////////////
			curl_easy_setopt(m_curl, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
			curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 1L);
			curl_easy_setopt(m_curl, CURLOPT_USERPWD, "AQHK3B-gB3sdb1ierWaMMap-6dKJtC-NGIRPeCa6GsZHVioiso-peMOyDgdCpThLv2rz39BTzqk6ajWy:EOiC6EF3aXo9X4whY5l51QPlQ9vzDsbcM2ihIyUqqNDUQ2NrMpvpjUZqeJ6AJ7bmzXXXyV4BOYsmq-Lo");
			curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
			curl_easy_setopt(m_curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)29);
			curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "curl/7.29.0");
			
			curl_easy_setopt(m_curl, CURLOPT_MAXREDIRS, 50L);
			curl_easy_setopt(m_curl, CURLOPT_SSH_KNOWNHOSTS, "/root/.ssh/known_hosts");
			curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, "POST");
			curl_easy_setopt(m_curl, CURLOPT_TCP_KEEPALIVE, 1L);

		}
		else 
		{
			cout << __LINE__ << ":" << uri << endl;
			add_header("Content-Type:application/json");
			add_header("Authorization:"+m_token_type+" "+ m_access_token);
		}
#ifdef DEBUG
		curl_easy_setopt(m_curl, CURLOPT_HEADER, 1);
#endif
		/*curl_easy_setopt(m_curl, CURLOPT_TCP_KEEPALIVE, 1L);
		curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, content.c_str());
		curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_headerlist);
		curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, method.c_str());*/
		
		on_request();
		
		curl_slist_free_all(m_headerlist);
		m_headerlist = NULL;
	}
Exemple #13
0
GList *
add_optional_headers(GList *headers)
{
  headers = add_header(headers, storage_header(stormfs.storage_class));
  headers = add_header(headers, acl_header(stormfs.acl));
  if(stormfs.encryption)
    headers = add_header(headers, encryption_header());
  if(stormfs.expires != NULL)
    headers = add_header(headers, expires_header(stormfs.expires));

  return headers;
}
Exemple #14
0
int add_vendor_avp (struct buffer *buf)
{
    add_header(buf, 0x6 + strlen (VENDOR_NAME), 0x8);
    strcpy ((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), VENDOR_NAME);
    buf->len += 0x6 + strlen (VENDOR_NAME);
    return 0;
}
Exemple #15
0
static int git_format_config(const char *var, const char *value, void *cb)
{
	if (!strcmp(var, "format.headers")) {
		if (!value)
			die("format.headers without value");
		add_header(value);
		return 0;
	}
	if (!strcmp(var, "format.suffix"))
		return git_config_string(&fmt_patch_suffix, var, value);
	if (!strcmp(var, "format.cc")) {
		if (!value)
			return config_error_nonbool(var);
		ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
		extra_cc[extra_cc_nr++] = xstrdup(value);
		return 0;
	}
	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
		return 0;
	}
	if (!strcmp(var, "format.numbered")) {
		if (value && !strcasecmp(value, "auto")) {
			auto_number = 1;
			return 0;
		}
		numbered = git_config_bool(var, value);
		auto_number = auto_number && numbered;
		return 0;
	}

	return git_log_config(var, value, cb);
}
Exemple #16
0
Fichier : log.c Projet : davvid/git
static int git_format_config(const char *var, const char *value, void *cb)
{
	if (!strcmp(var, "format.headers")) {
		if (!value)
			die("format.headers without value");
		add_header(value);
		return 0;
	}
	if (!strcmp(var, "format.suffix"))
		return git_config_string(&fmt_patch_suffix, var, value);
	if (!strcmp(var, "format.to")) {
		if (!value)
			return config_error_nonbool(var);
		string_list_append(value, &extra_to);
		return 0;
	}
	if (!strcmp(var, "format.cc")) {
		if (!value)
			return config_error_nonbool(var);
		string_list_append(value, &extra_cc);
		return 0;
	}
	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
		return 0;
	}
	if (!strcmp(var, "format.numbered")) {
		if (value && !strcasecmp(value, "auto")) {
			auto_number = 1;
			return 0;
		}
		numbered = git_config_bool(var, value);
		auto_number = auto_number && numbered;
		return 0;
	}
	if (!strcmp(var, "format.attach")) {
		if (value && *value)
			default_attach = xstrdup(value);
		else
			default_attach = xstrdup(git_version_string);
		return 0;
	}
	if (!strcmp(var, "format.thread")) {
		if (value && !strcasecmp(value, "deep")) {
			thread = THREAD_DEEP;
			return 0;
		}
		if (value && !strcasecmp(value, "shallow")) {
			thread = THREAD_SHALLOW;
			return 0;
		}
		thread = git_config_bool(var, value) && THREAD_SHALLOW;
		return 0;
	}
	if (!strcmp(var, "format.signoff")) {
		do_signoff = git_config_bool(var, value);
		return 0;
	}

	return git_log_config(var, value, cb);
}
/* Frees the section of physical memory previously allocated 
   using ’my_malloc’. Returns 0 if everything ok. */
extern int my_free(Addr _a) {
	Header* header = (Header*) ((long) _a - sizeof(Header));
	header->is_allocated = false;
	add_header(header);
	coalesce_headers();
	return 0;
}
Exemple #18
0
ssize_t h2o_set_header_by_str(h2o_mem_pool_t *pool, h2o_headers_t *headers, const char *name, size_t name_len, int maybe_token,
                              const char *value, size_t value_len, int overwrite_if_exists)
{
    ssize_t cursor;

    if (maybe_token) {
        const h2o_token_t *token = h2o_lookup_token(name, name_len);
        if (token != NULL) {
            return h2o_set_header(pool, headers, token, value, value_len, overwrite_if_exists);
        }
    }

    cursor = h2o_find_header_by_str(headers, name, name_len, -1);
    if (cursor != -1) {
        if (overwrite_if_exists) {
            h2o_iovec_t *slot = &headers->entries[cursor].value;
            slot->base = (char *)value;
            slot->len = value_len;
        }
        return cursor;
    } else {
        h2o_iovec_t *name_buf = h2o_mem_alloc_pool(pool, *name_buf, 1);
        name_buf->base = (char *)name;
        name_buf->len = name_len;
        return add_header(pool, headers, name_buf, NULL, value, value_len, (h2o_header_flags_t){0});
    }
}
Exemple #19
0
void h2o_add_header_by_str(h2o_mempool_t *pool, h2o_headers_t *headers, const char *name, size_t name_len, int maybe_token, const char *value, size_t value_len)
{
    h2o_buf_t *name_buf;

    if (maybe_token) {
        const h2o_token_t *token = h2o_lookup_token(name, name_len);
        if (token != NULL) {
            add_header(pool, headers, (h2o_buf_t*)token, value, value_len);
            return;
        }
    }
    name_buf = h2o_mempool_alloc(pool, sizeof(h2o_buf_t));
    name_buf->base = (char*)name;
    name_buf->len = name_len;
    add_header(pool, headers, name_buf, value, value_len);
}
int main ( int argc, char** argv )
{
    add_header("jd-anthratice");
    add_backgrounds("#282D33","#2F343F","#888");   // darker

    add_color("#282D33"	,"dark_anthracite=#282D33");
    add_color("#353a3f"	,"anthracite=#353a3f");		// #2F343F
    add_color("#edd400"	,"yellow=#edd400");
    add_color("#fd971f"	,"orange=#fd971f");
    add_color("#85816f"	,"dark_beige=#85816f");
    add_color("#979381"	,"beige=#979381");
    add_color("#8eb33b"	,"green=#8eb33b");		// "#7af234"
    add_color("#086aa7"	,"dark_blue=#086aa7");
    add_color("#729fcf"	,"blue=#729fcf");		// #729fcf
    add_color("#2597a6"	,"cyan=#2597a6");		// #00b8b8
    add_color("#77dfd8"	,"light_cyan=#77dfd8");		// #66d9ef
    //~ add_color("#c75646"	,"dark_red=#c75646");		// unused
    add_color("#cf0912"	,"red=#cf0912");
    add_color("#EAEAEA"	,"almost_white=#EAEAEA");
    add_color("#d0d0d0"	,"grey=#d0d0d0");
    add_color("#888"	,"mid_grey=#888");
    add_color("#666666"	,"dark_grey=#666666");		// #3B4149

    add_footer();
}
Exemple #21
0
/* jz: Dialed Number 21 */
int add_number_avp (struct buffer *buf, char *no)
{
    add_header(buf, (0x6 + strlen (no)), 0x15);
    strncpy ((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), no, strlen (no));
    buf->len += 0x6 + strlen (no);
    return 0;
}
Exemple #22
0
 bool
 Compiler::process_file(const Path& path, const Flags& flags) {
    FlagsManager new_flags(*this, flags);
    cxx::Backend backend(*this);
    Path output_path = get_cxx_output_path(flags, path) + "cpp";
    std::ofstream output(output_path.c_str());
    add_header(output);
    const SourceFileAst* src = reader()->read_file(path, flags);
    FormatterContext ctx;
    for (auto ast : src->asts) {
       const Expression* expr = elaborate(ast).code();
       if (auto imp = is<Import>(expr))
          process_import(backend, output, *imp);
       else if (expr != nullptr) {
          if (auto tl = backend.translate_top_level(expr))
             push_top_level(ctx, tl);
       }
    }
    for (auto x: get_specializations()) {
       auto decl = specs_to_decl(backend, x);
       if (auto fundef = dynamic_cast<const cxx::FunDef*>(decl))
          ctx.fun_defs.push_back(fundef);
       else
          push_decl(ctx, decl);
    }
    format_cxx(ctx, output);
    if (not compile_cxx_file(output_path))
       internal_error("intermediate C++ translation failed to compile");
    return true;
 }
Exemple #23
0
ssize_t h2o_add_header_by_str(h2o_mem_pool_t *pool, h2o_headers_t *headers, const char *name, size_t name_len, int maybe_token,
                              const char *orig_name, const char *value, size_t value_len)
{
    h2o_iovec_t *name_buf;

    if (maybe_token) {
        const h2o_token_t *token = h2o_lookup_token(name, name_len);
        if (token != NULL) {
            return add_header(pool, headers, (h2o_iovec_t *)token, orig_name, value, value_len, (h2o_header_flags_t){0});
        }
    }
    name_buf = h2o_mem_alloc_pool(pool, *name_buf, 1);
    name_buf->base = (char *)name;
    name_buf->len = name_len;
    return add_header(pool, headers, name_buf, orig_name, value, value_len, (h2o_header_flags_t){0});
}
Exemple #24
0
void h2o_set_header_by_str(h2o_mempool_t *pool, h2o_headers_t *headers, const char *name, size_t name_len, int maybe_token, const char *value, size_t value_len, int overwrite_if_exists)
{
    ssize_t cursor;

    if (maybe_token) {
        const h2o_token_t *token = h2o_lookup_token(name, name_len);
        if (token != NULL) {
            h2o_set_header(pool, headers, token ,value, value_len, overwrite_if_exists);
            return;
        }
    }

    cursor = h2o_find_header_by_str(headers, name, name_len, -1);
    if (cursor != -1) {
        if (overwrite_if_exists) {
            h2o_buf_t *slot = &headers->entries[cursor].value;
            slot->base = (char*)value;
            slot->len = value_len;
        }
    } else {
        h2o_buf_t *name_buf = h2o_mempool_alloc(pool, sizeof(h2o_buf_t));
        name_buf->base = (char*)name;
        name_buf->len = name_len;
        add_header(pool, headers, name_buf, value, value_len);
    }
}
Exemple #25
0
int add_randvect_avp (struct buffer *buf, unsigned char *c, int len)
{
    add_header(buf, (0x6 + len), 0x24);
    memcpy((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), c, len);
    buf->len += 0x6 + len;
    return 0;
}
Exemple #26
0
/* Create the iwb xml content file. */
static void
create_xml_content (gchar *content_filename,
                    gchar *img_dir_path,
                    gchar *background_image)
{
  int savepoint_number = -1;
  GDir *img_dir;  

  fp = fopen (content_filename, "w");

  add_header ();
  add_background (img_dir_path, background_image);

  if (!background_image)
    {
      savepoint_number = 0;
    }

  img_dir = g_dir_open (img_dir_path, 0, NULL);

  while (g_dir_read_name (img_dir))
    {
      savepoint_number++;
    }

  g_dir_close (img_dir);

  add_savepoints (savepoint_number);
  add_background_reference ();
  add_savepoint_references (savepoint_number);
  close_iwb ();
  fclose (fp);
}
 void 
 VariantHeaderMerger<fields_forward_LUT_ordering, fields_reverse_LUT_ordering, samples_forward_LUT_ordering, samples_reverse_LUT_ordering>::
 add_headers(const vector<VariantHeader>& headers)
 {
   for(const auto& header : headers)
     add_header(header);
 }
static void _colon (char* ptr,Task_Data * IData)
{
	IData->state = 1;
	word(IData);
	add_header (IData->forth_buffer,IData);
	compile((int*)(int)docol,IData);
}
Exemple #29
0
	/** Constructs a zipper ostream decorator
	 *
	 * \param ostream_ ostream where the compressed output is written
	 * \param is_gzip_ true if gzip header and footer have to be added
	 * \param level_ level of compression 0, bad and fast, 9, good and slower,
	 * \param strategy_ compression strategy
	 * \param window_size_ see zlib doc
	 * \param memory_level_ see zlib doc
	 * \param buffer_size_ the buffer size used to zip data

	 When is_gzip_ is true, a gzip header and footer is automatically added.
	 */
	basic_zip_ostream( 
		ostream_reference ostream_, 
        int open_mode = std::ios::out, 
		bool is_gzip_ = false,
		size_t level_ = Z_DEFAULT_COMPRESSION,
		EStrategy strategy_ = DefaultStrategy,
		size_t window_size_ = 15,
		size_t memory_level_ = 8,
		size_t buffer_size_ = default_buffer_size
		)
	: 
		zip_ostreambase_type(
            ostream_,
            level_,
            strategy_,
            window_size_,
            memory_level_,
            buffer_size_
            ), 
		m_is_gzip(is_gzip_),
		ostream_type(rdbuf())
	{
		if (m_is_gzip)
			add_header();
	};
Exemple #30
0
 void response::set_header(const std::string &name, const std::string &value) {
     auto i=headers.find(name);
     if (i!=headers.end()) {
         headers.erase(name);
     }
     add_header(name, value);
 }