本文整理汇总了C++中buf_new函数的典型用法代码示例。如果您正苦于以下问题:C++ buf_new函数的具体用法?C++ buf_new怎么用?C++ buf_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buf_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ed_init
int ed_init(Context_t* ctx)
{
CmdHook_t *hooks;
int i;
/* logging*/
log_add(LL_ERROR, "error.log");
log_add(LL_DEBUG, "debug.log");
/* screen */
ctx->scr = ncs_new();
ncs_init(ctx->scr);
/* buffer */
ctx->c_buffer = buf_new("scratch.txt");
ctx->cmd_buffer = buf_new("cmdbuf.txt");
/* main context */
ed_set_mode(ctx, ED_HOTKEY_MODE);
ed_load_cmd_cfg(ctx, "cmds.txt");
hooks = cmdlib_get_lib();
i = 0;
while (hooks[i].type != CMD_COUNT)
{
ed_bind_cmd_hook(ctx, hooks[i].type, hooks[i].cmd_hook_cb);
i++;
}
return 0;
}
开发者ID:anzzik,项目名称:editor,代码行数:33,代码来源:editor.c
示例2: pgp_rkeylist
int pgp_rkeylist(REMAILER remailer[], int keyid[], int n)
/* Step through all remailers and get keyid */
{
BUFFER *userid;
BUFFER *id;
int i, err;
userid = buf_new();
id = buf_new();
for (i = 1; i < n; i++) {
buf_clear(userid);
buf_setf(userid, "<%s>", remailer[i].addr);
keyid[i]=0;
if (remailer[i].flags.pgp) {
buf_clear(id);
err = pgpdb_getkey(PK_VERIFY, PGP_ANY, NULL, NULL, NULL, NULL, userid, NULL, id, NULL, NULL);
if (id->length == 8) {
/* printf("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
id->data[0], id->data[1], id->data[2], id->data[3], id->data[4], id->data[5], id->data[6], id->data[7], id->data[8], remailer[i].addr); */
keyid[i] = (((((id->data[4] << 8) + id->data[5]) << 8) + id->data[6]) << 8) + id->data[7];
}
}
}
buf_free(userid);
return (0);
}
开发者ID:merkinmuffley,项目名称:mixmaster4096,代码行数:29,代码来源:pgpdb.c
示例3: gs_init
int gs_init() {
int i=0;
mGs = (struct gs_t *)MALLOC(sizeof(*mGs));
memset(mGs, 0, sizeof(*mGs));
mGs->mEp = epoll_create(1024);
if (0 >= mGs->mEp) {
fprintf(stderr, "create epoll fail\n");
exit(0);
}
mGs->mSon = 65535;
mGs->mSos = (struct so_t **)MALLOC(mGs->mSon * sizeof(struct so_t *));
for (i=0; i<mGs->mSon; ++i) {
struct so_t *so = (struct so_t *)MALLOC(sizeof(*so));
memset(so, 0, sizeof(*so));
so->mId = i;
so->mLock = lock_new();
so->mRLock = lock_new();
so->mWLock = lock_new();
so->mELock = lock_new();
so->mRBuf = buf_new();
so->mWBuf = buf_new();
mGs->mSos[i] = so;
}
mGs->mQLock = lock_new();
return 0;
}
开发者ID:eligo,项目名称:mul,代码行数:26,代码来源:gs.c
示例4: v2_merge
int v2_merge(BUFFER *mid)
{
char fname[PATHMAX], line[LINELEN];
BUFFER *temp, *msg;
FILE *l, *f;
int i, numpackets;
struct stat sb;
long d;
int n;
int err = -1;
temp = buf_new();
msg = buf_new();
pool_packetfile(fname, mid, 0);
l = fopen(fname, "a+");
if (l != NULL)
lock(l);
pool_packetfile(fname, mid, 1);
f = fopen(fname, "rb");
if (f == NULL)
goto end;
fscanf(f, "%32s %ld %d %d\n", line, &d, &i, &numpackets);
fclose(f);
/* do we have all packets? */
for (i = 1; i <= numpackets; i++) {
pool_packetfile(fname, mid, i);
if (stat(fname, &sb) != 0)
goto end;
}
errlog(LOG, "Reassembling multipart message.\n");
for (i = 1; i <= numpackets; i++) {
pool_packetfile(fname, mid, i);
f = fopen(fname, "rb");
if (f == NULL)
goto end;
fscanf(f, "%32s %ld %d %d\n", line, &d, &n, &n);
buf_clear(temp);
buf_read(temp, f);
v2body_setlen(temp);
buf_append(msg, temp->data + 4, temp->length - 4);
fclose(f);
unlink(fname);
}
err = v2body(msg);
end:
if (l != NULL)
fclose(l);
pool_packetfile(fname, mid, 0);
unlink(fname);
buf_free(temp);
buf_free(msg);
return (err);
}
开发者ID:crooks,项目名称:mixmaster,代码行数:56,代码来源:rem2.c
示例5: buf_read
buf_t* buf_read(FILE *f)
{
const int sigsize = 8;
wint_t wc;
uint8_t y;
int ret;
buf_t *b;
wchar_t wcswap[sigsize];
uint8_t yswap[2];
int i;
/* read sig bytes or first sigsize chars */
for(i = 0; i < sigsize; i++) {
wc = getwc(f);
EXIT_FERROR(f);
if(wc == WEOF) {
b = buf_new(false);
EXIT_NULL(b);
buf_push_nwchar(b, wcswap, i);
return b;
}
wcswap[i] = (wchar_t)wc;
}
/* check for sig to determine if 8xp */
if( !wcsncmp(wcswap, L"**TI83F*", sigsize) ) {
b = buf_new(true);
} else {
b = buf_new(false);
}
/* not 8xp, so just read the rest */
if( !b->is_8xp) {
buf_push_nwchar(b, wcswap, sigsize);
while( (wc = getwc(f)) != WEOF) {
buf_push_wchar(b, (wchar_t)wc);
}
return b;
}
/* discard remainder of header */
for(i = sigsize; i < HEADER_SIZE; i++) {
ret = fread(&y, sizeof(uint8_t), 1, f);
EXIT_FERROR(f);
/* EOF this early means malformed 8xp */
if(ret <= 0) {
printf("\e[1mtok8x:\e[0m"
"\e[1;31merror:\e[0m %s\n",
"malformed .8xp input"
);
exit(EIO);
}
}
开发者ID:shmibs,项目名称:tok8x,代码行数:54,代码来源:buf.c
示例6: mix_dearmor
int mix_dearmor(BUFFER *in, BUFFER *out)
{
BUFFER *line, *md;
int tempbuf = 0;
int err = 0;
line = buf_new();
md = buf_new();
if (in == out) {
tempbuf = 1;
out = buf_new();
}
do {
err = buf_getline(in, line);
if (err == -1)
goto end;
}
while (!bufeq(line, begin_remailer));
do {
/* skip lines before message digest */
if (buf_getline(in, md) == -1)
break;
} while (strlen(md->data) != 24);
decode(in, out);
err = buf_getline(in, line);
if (err != 0 || !bufeq(line, end_remailer))
err = -1;
else {
digest_md5(out, line);
encode(line, 0);
if (!buf_eq(md, line))
err = -1;
if (out->length != 20480)
err = -1;
}
end:
if (err == -1)
errlog(NOTICE, "Malformatted message.\n");
if (tempbuf) {
buf_move(in, out);
buf_free(out);
}
buf_free(line);
buf_free(md);
return (err);
}
开发者ID:crooks,项目名称:mixmaster,代码行数:52,代码来源:rem2.c
示例7: pgp_latestkeys
int pgp_latestkeys(BUFFER* outtxt, int algo)
/* returns our latest key from pgpkey.txt in the buffer outtxt
* with pgp key header, ascii armored
*
* Can probably be extended to do this for all keys if we pass
* the keyring file and the userid
*
* IN: algo: PGP_ANY, PGP_ES_RSA, PGP_E_ELG, PGP_S_DSA
* OUT: outtxt
*/
{
int err = -1;
long expires_found = 0, expires;
BUFFER *key, *userid, *tmptxt;
KEYRING *keys;
key = buf_new();
userid = buf_new();
buf_sets(userid, REMAILERNAME);
tmptxt = buf_new();
keys = pgpdb_open(PGPKEY, NULL, 0, PGP_TYPE_PUBLIC);
if (keys != NULL) {
while (pgpdb_getnext(keys, key, NULL, userid) != -1) {
buf_clear(tmptxt);
if (pgp_makekeyheader(PGP_PUBKEY, key, tmptxt, NULL, algo) == 0) {
buf_rewind(key);
pgp_getkey(PK_VERIFY, algo, NULL, NULL, &expires, key, NULL, NULL, NULL, NULL);
if (expires == 0 || (expires_found <= expires)) {
err = 0;
buf_clear(outtxt);
buf_appends(outtxt, "Type Bits/KeyID Date User ID\n");
buf_cat(outtxt, tmptxt);
buf_nl(outtxt);
pgp_armor(key, PGP_ARMOR_KEY);
buf_cat(outtxt, key);
buf_nl(outtxt);
expires_found = expires;
}
}
}
pgpdb_close(keys);
}
buf_free(key);
buf_free(userid);
buf_free(tmptxt);
return (err);
}
开发者ID:merkinmuffley,项目名称:mixmaster4096,代码行数:50,代码来源:pgpdb.c
示例8: pgp_readkeyring
static int pgp_readkeyring(BUFFER *keys, char *filename)
{
FILE *keyfile;
BUFFER *armored, *line, *tmp;
int err = -1;
if ((keyfile = mix_openfile(filename, "rb")) == NULL)
return (err);
armored = buf_new();
buf_read(armored, keyfile);
fclose(keyfile);
if (pgp_ispacket(armored)) {
err = 0;
buf_move(keys, armored);
} else {
line = buf_new();
tmp = buf_new();
while (1) {
do
if (buf_getline(armored, line) == -1) {
goto end_greedy_dearmor;
}
while (!bufleft(line, begin_pgp)) ;
buf_clear(tmp);
buf_cat(tmp, line);
buf_appends(tmp, "\n");
do {
if (buf_getline(armored, line) == -1) {
goto end_greedy_dearmor;
}
buf_cat(tmp, line);
buf_appends(tmp, "\n");
} while (!bufleft(line, end_pgp)) ;
if (pgp_dearmor(tmp, tmp) == 0) {
err = ARMORED;
buf_cat(keys, tmp);
}
}
end_greedy_dearmor:
buf_free(line);
buf_free(tmp);
}
buf_free(armored);
return (err);
}
开发者ID:merkinmuffley,项目名称:mixmaster4096,代码行数:49,代码来源:pgpdb.c
示例9: readhostkey
/* returns success or failure */
static int readhostkey(const char * filename, sign_key * hostkey, int type) {
int ret = DROPBEAR_FAILURE;
int i;
buffer *buf;
buf = buf_new(2000);
if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
goto out;
}
buf_setpos(buf, 0);
if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
goto out;
}
ret = DROPBEAR_SUCCESS;
out:
if (ret == DROPBEAR_FAILURE) {
for (i = 0; sshhostkey[i].name != NULL; i++) {
if (sshhostkey[i].val == type) {
sshhostkey[i].usable = 0;
break;
}
}
fprintf(stderr, "Failed reading '%s', disabling %s\n", filename,
type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
}
buf_burn(buf);
buf_free(buf);
return ret;
}
开发者ID:zipangotes,项目名称:DSL-G624T_GPL_code,代码行数:34,代码来源:runopts.c
示例10: test_proto_control0
static void
test_proto_control0(void *arg)
{
(void)arg;
buf_t *buf = buf_new();
/* The only remaining function for the v0 control protocol is the function
that detects whether the user has stumbled across an old controller
that's using it. The format was:
u16 length;
u16 command;
u8 body[length];
*/
/* Empty buffer -- nothing to do. */
tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));
/* 3 chars in buf -- can't tell */
buf_add(buf, "AUT", 3);
tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));
/* command in buf -- easy to tell */
buf_add(buf, "HENTICATE ", 10);
tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));
/* Control0 command header in buf: make sure we detect it. */
buf_clear(buf);
buf_add(buf, "\x09\x05" "\x00\x05" "blah", 8);
tt_int_op(1, OP_EQ, peek_buf_has_control0_command(buf));
done:
buf_free(buf);
}
开发者ID:jfrazelle,项目名称:tor,代码行数:31,代码来源:test_proto_misc.c
示例11: http_reply
static int http_reply (RESTSESSION * r, int status, struct buf * response)
{
struct buf *b;
int ret;
char respcode[100];
char content_len[256];
b = buf_new ();
sprintf (respcode, "HTTP/1.1 %03d\r\n", status);
buf_append_data (b, respcode, strlen (respcode));
buf_append_data (b, content_type, strlen (content_type));
buf_append_data (b, connection_close, strlen (connection_close));
sprintf (content_len, "Content-Length: %d\r\n", response->len);
buf_append_data (b, content_len, strlen (content_len));
buf_append_data (b, "\r\n", 2);
buf_append_data (b, response->ptr, response->len);
ret = 0;
if (send (r->socket, b->ptr, b->len, 0) != b->len)
ret = -1;
buf_free (b);
buf_free (response);
http_cleanup (r);
return ret;
}
开发者ID:Voxar,项目名称:spot,代码行数:27,代码来源:gw-http.c
示例12: auth_generate_auth_hmac
static void auth_generate_auth_hmac(struct login_ctx *l) {
struct buf* buf = buf_new();
buf_append_data(buf, l->client_parameters->ptr,
l->client_parameters->len);
buf_append_data(buf, l->server_parameters->ptr,
l->server_parameters->len);
buf_append_u8(buf, 0); /* random data length */
buf_append_u8(buf, 0); /* unknown */
buf_append_u16(buf, 8); /* puzzle solution length */
buf_append_u32(buf, 0); /* unknown */
/* <-- random data would go here */
buf_append_data(buf, l->puzzle_solution, 8);
#ifdef DEBUG_LOGIN
hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr,
buf->len);
hexdump8x32 ("auth_generate_auth_hmac, HMAC key", l->key_hmac,
sizeof (l->key_hmac));
#endif
sha1_hmac(l->key_hmac, sizeof(l->key_hmac),
buf->ptr, buf->len, l->auth_hmac);
#ifdef DEBUG_LOGIN
hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", l->auth_hmac,
sizeof(l->auth_hmac));
#endif
buf_free(buf);
}
开发者ID:Kitof,项目名称:openspotify,代码行数:31,代码来源:login.c
示例13: gw_browse
int gw_browse (SPOTIFYSESSION * s, unsigned char kind, char *id_as_hex, int num_ids)
{
DECOMPRESSCTX *dctx;
unsigned char id[16*num_ids];
hex_ascii_to_bytes (id_as_hex, id, 16*num_ids);
dctx = (DECOMPRESSCTX *) malloc (sizeof (DECOMPRESSCTX));
dctx->z.zalloc = Z_NULL;
dctx->z.zfree = Z_NULL;
dctx->z.opaque = Z_NULL;
dctx->z.avail_in = 0;
dctx->z.next_in = Z_NULL;
if (inflateInit2 (&dctx->z, -MAX_WBITS) != Z_OK) {
free (dctx);
return -1;
}
dctx->decompression_done = 0;
dctx->b = buf_new();
s->output = dctx;
s->output_len = 0;
return cmd_browse (s->session, kind, id, num_ids, gw_browse_result_callback,
(void *) s);
}
开发者ID:Voxar,项目名称:spot,代码行数:28,代码来源:gw-browse.c
示例14: auth_generate_auth_hmac
void auth_generate_auth_hmac (SESSION * session, unsigned char *auth_hmac,
unsigned int mac_len)
{
(void)mac_len;
struct buf* buf = buf_new();
buf_append_data(buf, session->init_client_packet->ptr,
session->init_client_packet->len);
buf_append_data(buf, session->init_server_packet->ptr,
session->init_server_packet->len);
buf_append_u8(buf, 0); /* random data length */
buf_append_u8(buf, 0); /* unknown */
buf_append_u16(buf, 8); /* puzzle solution length */
buf_append_u32(buf, 0); /* unknown */
/* <-- random data would go here */
buf_append_data(buf, session->puzzle_solution, 8);
#ifdef DEBUG_LOGIN
hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr,
buf->len);
hexdump8x32 ("auth_generate_auth_hmac, HMAC key", session->key_hmac,
sizeof (session->key_hmac));
#endif
sha1_hmac ( session->key_hmac, sizeof (session->key_hmac),
buf->ptr, buf->len, auth_hmac);
#ifdef DEBUG_LOGIN
hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", auth_hmac,
mac_len);
#endif
buf_free(buf);
}
开发者ID:alt-,项目名称:bada-spotify,代码行数:34,代码来源:auth.c
示例15: readhostkey
/* returns success or failure, and the keytype in *type. If we want
* to restrict the type, type can contain a type to return */
int readhostkey(const char * filename, sign_key * hostkey, int *type) {
int ret = DROPBEAR_FAILURE;
buffer *buf;
buf = buf_new(MAX_PRIVKEY_SIZE);
if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
goto out;
}
buf_setpos(buf, 0);
addrandom(buf_getptr(buf, buf->len), buf->len);
if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
goto out;
}
ret = DROPBEAR_SUCCESS;
out:
buf_burn(buf);
buf_free(buf);
return ret;
}
开发者ID:BBBSnowball,项目名称:mehari,代码行数:27,代码来源:common-runopts.c
示例16: send_client_auth
int send_client_auth (SESSION * session)
{
int ret;
struct buf* buf = buf_new();
buf_append_data(buf, session->auth_hmac, 20);
buf_append_u8(buf, 0); /* random data length */
buf_append_u8(buf, 0); /* unknown */
buf_append_u16(buf, 8); /* puzzle solution length */
buf_append_u32(buf, 0);
/* <-- random data would go here */
buf_append_data (buf, session->puzzle_solution, 8);
#ifdef DEBUG_LOGIN
hexdump8x32 ("send_client_auth, second client packet", buf->ptr,
buf->len);
#endif
ret = send(session->ap_sock, buf->ptr, buf->len, 0);
if (ret <= 0) {
DSFYDEBUG("send_client_auth(): connection lost\n");
buf_free(buf);
return -1;
}
else if (ret != buf->len) {
DSFYDEBUG("send_client_auth(): only wrote %d of %d bytes\n",
ret, buf->len);
buf_free(buf);
return -1;
}
buf_free(buf);
return 0;
}
开发者ID:alt-,项目名称:bada-spotify,代码行数:35,代码来源:auth.c
示例17: http_reply_need_auth
static int http_reply_need_auth (RESTSESSION * r)
{
struct buf *b;
int ret;
char buf[256];
b = buf_new();
strcpy (buf, "HTTP/1.1 401\r\n");
buf_append_data (b, buf, strlen (buf));
strcpy (buf, "WWW-Authenticate: Basic realm=\"Spotify\"\r\n");
buf_append_data (b, buf, strlen (buf));
buf_append_data (b, content_type, strlen (content_type));
buf_append_data (b, connection_close, strlen (connection_close));
strcpy (buf, "Content-Length: 0\r\n");
buf_append_data (b, buf, strlen (buf));
buf_append_data (b, "\r\n", 2);
ret = 0;
if (send (r->socket, b->ptr, b->len, 0) != b->len)
ret = -1;
buf_free (b);
http_cleanup (r);
return ret;
}
开发者ID:Voxar,项目名称:spot,代码行数:26,代码来源:gw-http.c
示例18: send_header
/*
* Send header information which includes current working direcotry,
* command line arguments, and CLASSPATH environment variable
* to the server.
*/
void send_header(int fd, int argc, char** argv, char* authtoken)
{
char path_buffer[MAXPATHLEN];
buf read_buf = buf_new(BUFFER_SIZE, NULL);
int i;
// send current working directory.
buf_printf(&read_buf, "%s: ", HEADER_KEY_CURRENT_WORKING_DIR);
char* cwd = getcwd(path_buffer, MAXPATHLEN);
if (cwd == NULL) {
perror("ERROR: getcwd");
exit(1);
}
buf_add(&read_buf, cwd);
buf_add(&read_buf, "\n");
buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_AUTHTOKEN, authtoken);
// send command line arguments.
char *encoded_ptr, *encoded_work;
for (i = 1; i < argc; i++) {
if (argv[i] != NULL) {
// base64 encoded data is less "(original size) * 1.5 + 5" as much as raw data
// "+5" is a extra space for '=' padding and NULL as the end of string
encoded_ptr = malloc(sizeof(char) * strlen(argv[i]) * 1.5 + 5);
if (encoded_ptr == NULL) {
perror("ERROR: failed to malloc");
exit(1);
}
encoded_work = encoded_ptr; // copy for free
base64_encode(encoded_work, (unsigned char*) argv[i]);
buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_ARG, encoded_work);
free(encoded_ptr);
}
}
// send envvars.
if (client_option.env_include_mask != NULL) {
make_env_headers(&read_buf,
environ,
client_option.env_include_mask,
client_option.env_exclude_mask);
}
char* cp = getenv("CLASSPATH");
if (cp != NULL) {
buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_CP, cp);
}
buf_printf(&read_buf, "\n");
read_buf.size--; /* remove trailing '\0' */
#ifdef WINDOWS
send(fd, read_buf.buffer, read_buf.size, 0);
#else
write(fd, read_buf.buffer, read_buf.size);
#endif
buf_delete(&read_buf);
}
开发者ID:adaksuman,项目名称:groovyserv,代码行数:65,代码来源:session.c
示例19: buf_new_with_capacity
/** Create and return a new buf with default chunk capacity <b>size</b>.
*/
buf_t *
buf_new_with_capacity(size_t size)
{
buf_t *b = buf_new();
b->default_chunk_size = buf_preferred_chunk_size(size);
return b;
}
开发者ID:Samdney,项目名称:tor,代码行数:9,代码来源:buffers.c
示例20: test_buffers_tls_read_mocked
static void
test_buffers_tls_read_mocked(void *arg)
{
uint8_t *mem;
buf_t *buf;
(void)arg;
mem = tor_malloc(64*1024);
crypto_rand((char*)mem, 64*1024);
tls_read_ptr = mem;
n_remaining = 64*1024;
MOCK(tor_tls_read, mock_tls_read);
buf = buf_new();
next_reply_val[0] = 1024;
tt_int_op(128, ==, read_to_buf_tls(NULL, 128, buf));
next_reply_val[0] = 5000;
next_reply_val[1] = 5000;
tt_int_op(6000, ==, read_to_buf_tls(NULL, 6000, buf));
done:
UNMOCK(tor_tls_read);
tor_free(mem);
buf_free(buf);
}
开发者ID:HansoHan,项目名称:tor-1,代码行数:28,代码来源:test_buffers.c
注:本文中的buf_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论