type
stringclasses 5
values | content
stringlengths 9
163k
|
|---|---|
functions
|
bool json_list_get_bool(struct JsonValue *list, size_t index, bool *val_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
return json_value_as_bool(jv, val_p);
}
|
functions
|
bool json_list_get_int(struct JsonValue *list, size_t index, int64_t *val_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
return json_value_as_int(jv, val_p);
}
|
functions
|
bool json_list_get_float(struct JsonValue *list, size_t index, double *val_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
return json_value_as_float(jv, val_p);
}
|
functions
|
bool json_list_get_string(struct JsonValue *list, size_t index, const char **val_p, size_t *len_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
return json_value_as_string(jv, val_p, len_p);
}
|
functions
|
bool json_list_get_list(struct JsonValue *list, size_t index, struct JsonValue **val_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
if (!has_type(jv, JSON_LIST))
return false;
*val_p = jv;
return true;
}
|
functions
|
bool json_list_get_dict(struct JsonValue *list, size_t index, struct JsonValue **val_p)
{
struct JsonValue *jv;
if (!json_list_get_value(list, index, &jv))
return false;
if (!has_type(jv, JSON_DICT))
return false;
*val_p = jv;
return true;
}
|
functions
|
bool dict_iter_helper(void *arg, void *jv)
{
struct DictIterState *state = arg;
struct JsonValue *key = jv;
struct JsonValue *val = get_next(key);
return state->cb_func(state->cb_arg, key, val);
}
|
functions
|
bool json_dict_iter(struct JsonValue *dict, json_dict_iter_callback_f cb_func, void *cb_arg)
{
struct DictIterState state;
struct CBTree *tree;
tree = get_dict_tree(dict);
if (!tree)
return false;
state.cb_func = cb_func;
state.cb_arg = cb_arg;
return cbtree_walk(tree, dict_iter_helper, &state);
}
|
functions
|
bool json_list_iter(struct JsonValue *list, json_list_iter_callback_f cb_func, void *cb_arg)
{
struct JsonValue *elem;
struct ValueList *vlist;
vlist = get_list_vlist(list);
if (!vlist)
return false;
for (elem = vlist->first; elem; elem = get_next(elem)) {
if (!cb_func(cb_arg, elem))
return false;
}
|
functions
|
bool json_list_append(struct JsonValue *list, struct JsonValue *val)
{
if (!val)
return false;
if (!has_type(list, JSON_LIST))
return false;
if (!is_unattached(val))
return false;
set_parent(val, list);
set_next(val, NULL);
real_list_append(list, val);
return true;
}
|
functions
|
bool json_list_append_null(struct JsonValue *list)
{
struct JsonValue *v;
v = json_new_null(get_context(list));
return json_list_append(list, v);
}
|
functions
|
bool json_list_append_bool(struct JsonValue *list, bool val)
{
struct JsonValue *v;
v = json_new_bool(get_context(list), val);
return json_list_append(list, v);
}
|
functions
|
bool json_list_append_int(struct JsonValue *list, int64_t val)
{
struct JsonValue *v;
v = json_new_int(get_context(list), val);
return json_list_append(list, v);
}
|
functions
|
bool json_list_append_float(struct JsonValue *list, double val)
{
struct JsonValue *v;
v = json_new_float(get_context(list), val);
return json_list_append(list, v);
}
|
functions
|
bool json_list_append_string(struct JsonValue *list, const char *val)
{
struct JsonValue *v;
v = json_new_string(get_context(list), val);
return json_list_append(list, v);
}
|
functions
|
bool json_dict_put(struct JsonValue *dict, const char *key, struct JsonValue *val)
{
struct JsonValue *kjv;
struct JsonContainer *c;
if (!key || !val)
return false;
if (!has_type(dict, JSON_DICT))
return false;
if (!is_unattached(val))
return false;
c = get_container(dict);
kjv = json_new_string(c->c_ctx, key);
if (!kjv)
return false;
if (!real_dict_add_key(c->c_ctx, dict, kjv))
return false;
set_next(kjv, val);
set_next(val, NULL);
set_parent(val, dict);
return true;
}
|
functions
|
bool json_dict_put_null(struct JsonValue *dict, const char *key)
{
struct JsonValue *v;
v = json_new_null(get_context(dict));
return json_dict_put(dict, key, v);
}
|
functions
|
bool json_dict_put_bool(struct JsonValue *dict, const char *key, bool val)
{
struct JsonValue *v;
v = json_new_bool(get_context(dict), val);
return json_dict_put(dict, key, v);
}
|
functions
|
bool json_dict_put_int(struct JsonValue *dict, const char *key, int64_t val)
{
struct JsonValue *v;
v = json_new_int(get_context(dict), val);
return json_dict_put(dict, key, v);
}
|
functions
|
bool json_dict_put_float(struct JsonValue *dict, const char *key, double val)
{
struct JsonValue *v;
v = json_new_float(get_context(dict), val);
return json_dict_put(dict, key, v);
}
|
functions
|
bool json_dict_put_string(struct JsonValue *dict, const char *key, const char *val)
{
struct JsonValue *v;
v = json_new_string(get_context(dict), val);
return json_dict_put(dict, key, v);
}
|
functions
|
void json_free_context(struct JsonContext *ctx)
{
if (ctx) {
CxMem *pool = ctx->pool;
memset(ctx, 0, sizeof(*ctx));
cx_destroy(pool);
}
|
functions
|
void json_set_options(struct JsonContext *ctx, unsigned int options)
{
ctx->options = options;
}
|
includes
|
#include <stddef.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <stdarg.h>
|
includes
|
#include <string.h>
|
functions
|
void
getString(xmlrpc_env *const envP,
const char **const formatP,
va_listx *const argsP,
xmlrpc_value **const valPP) {
const char *str;
size_t len;
str = (const char *) va_arg(argsP->v, char*);
if (*(*formatP) == '#') {
++(*formatP);
len = (size_t) va_arg(argsP->v, size_t);
}
|
functions
|
void
getWideString(xmlrpc_env *const envP ATTR_UNUSED,
const char **const formatP ATTR_UNUSED,
va_listx *const argsP ATTR_UNUSED,
xmlrpc_value **const valPP ATTR_UNUSED) {
#if HAVE_UNICODE_WCHAR
wchar_t *wcs;
size_t len;
wcs = (wchar_t*) va_arg(argsP->v, wchar_t*);
if (**formatP == '#') {
(*formatP)++;
len = (size_t) va_arg(argsP->v, size_t);
}
|
functions
|
void
getBase64(xmlrpc_env *const envP,
va_listx *const argsP,
xmlrpc_value **const valPP) {
unsigned char *value;
size_t length;
value = (unsigned char *) va_arg(argsP->v, unsigned char*);
length = (size_t) va_arg(argsP->v, size_t);
*valPP = xmlrpc_base64_new(envP, length, value);
}
|
functions
|
void
getArray(xmlrpc_env *const envP,
const char **const formatP,
char const delimiter,
va_listx *const argsP,
xmlrpc_value **const arrayPP) {
xmlrpc_value *arrayP;
arrayP = xmlrpc_array_new(envP);
/* Add items to the array until we hit our delimiter. */
while (**formatP != delimiter && !envP->fault_occurred) {
xmlrpc_value *itemP;
if (**formatP == '\0')
xmlrpc_env_set_fault(
envP, XMLRPC_INTERNAL_ERROR,
"format string ended before closing ')'.");
else {
getValue(envP, formatP, argsP, &itemP);
if (!envP->fault_occurred) {
xmlrpc_array_append_item(envP, arrayP, itemP);
xmlrpc_DECREF(itemP);
}
|
functions
|
void
getStructMember(xmlrpc_env *const envP,
const char **const formatP,
va_listx *const argsP,
xmlrpc_value **const keyPP,
xmlrpc_value **const valuePP) {
/* Get the key */
getValue(envP, formatP, argsP, keyPP);
if (!envP->fault_occurred) {
if (**formatP != ':')
xmlrpc_env_set_fault(
envP, XMLRPC_INTERNAL_ERROR,
"format string does not have ':' after a "
"structure member key.");
else {
/* Skip over colon that separates key from value */
(*formatP)++;
/* Get the value */
getValue(envP, formatP, argsP, valuePP);
}
|
functions
|
void
getStruct(xmlrpc_env *const envP,
const char **const formatP,
char const delimiter,
va_listx *const argsP,
xmlrpc_value **const structPP) {
xmlrpc_value *structP;
structP = xmlrpc_struct_new(envP);
if (!envP->fault_occurred) {
while (**formatP != delimiter && !envP->fault_occurred) {
xmlrpc_value *keyP;
xmlrpc_value *valueP;
getStructMember(envP, formatP, argsP, &keyP, &valueP);
if (!envP->fault_occurred) {
if (**formatP == ',')
(*formatP)++; /* Skip over the comma */
else if (**formatP == delimiter) {
/* End of the line */
}
|
functions
|
void
mkArrayFromVal(xmlrpc_env *const envP,
xmlrpc_value *const value,
xmlrpc_value **const valPP) {
if (xmlrpc_value_type(value) != XMLRPC_TYPE_ARRAY)
xmlrpc_env_set_fault(envP, XMLRPC_INTERNAL_ERROR,
"Array format ('A'), non-array xmlrpc_value");
else
xmlrpc_INCREF(value);
*valPP = value;
}
|
functions
|
void
mkStructFromVal(xmlrpc_env *const envP,
xmlrpc_value *const value,
xmlrpc_value **const valPP) {
if (xmlrpc_value_type(value) != XMLRPC_TYPE_STRUCT)
xmlrpc_env_set_fault(envP, XMLRPC_INTERNAL_ERROR,
"Struct format ('S'), non-struct xmlrpc_value");
else
xmlrpc_INCREF(value);
*valPP = value;
}
|
functions
|
void
getValue(xmlrpc_env *const envP,
const char **const formatP,
va_listx *const argsP,
xmlrpc_value **const valPP) {
/*----------------------------------------------------------------------------
Get the next value from the list. *formatP points to the specifier
for the next value in the format string (i.e. to the type code
character) and we move *formatP past the whole specifier for the
next value. We read the required arguments from 'argsP'. We return
the value as *valPP with a reference to it.
For example, if *formatP points to the "i" in the string "sis",
we read one argument from 'argsP' and return as *valP an integer whose
value is the argument we read. We advance *formatP to point to the
last 's' and advance 'argsP' to point to the argument that belongs to
that 's'.
-----------------------------------------------------------------------------*/
char const formatChar = *(*formatP)++;
switch (formatChar) {
case 'i':
*valPP =
xmlrpc_int_new(envP, (xmlrpc_int32) va_arg(argsP->v,
xmlrpc_int32));
break;
case 'b':
*valPP =
xmlrpc_bool_new(envP, (xmlrpc_bool) va_arg(argsP->v,
xmlrpc_bool));
break;
case 'd':
*valPP =
xmlrpc_double_new(envP, (double) va_arg(argsP->v, double));
break;
case 's':
getString(envP, formatP, argsP, valPP);
break;
case 'w':
getWideString(envP, formatP, argsP, valPP);
break;
case 't':
*valPP = xmlrpc_datetime_new_sec(envP, va_arg(argsP->v, time_t));
break;
case '8':
*valPP = xmlrpc_datetime_new_str(envP, va_arg(argsP->v, char*));
break;
case '6':
getBase64(envP, argsP, valPP);
break;
case 'n':
*valPP =
xmlrpc_nil_new(envP);
break;
case 'I':
*valPP =
xmlrpc_i8_new(envP, (xmlrpc_int64) va_arg(argsP->v,
xmlrpc_int64));
break;
case 'p':
*valPP =
xmlrpc_cptr_new(envP, (void *) va_arg(argsP->v, void*));
break;
case 'A':
mkArrayFromVal(envP,
(xmlrpc_value *) va_arg(argsP->v, xmlrpc_value*),
valPP);
break;
case 'S':
mkStructFromVal(envP,
(xmlrpc_value *) va_arg(argsP->v, xmlrpc_value*),
valPP);
break;
case 'V':
*valPP = (xmlrpc_value *) va_arg(argsP->v, xmlrpc_value*);
xmlrpc_INCREF(*valPP);
break;
case '(':
getArray(envP, formatP, ')', argsP, valPP);
if (!envP->fault_occurred) {
XMLRPC_ASSERT(**formatP == ')');
(*formatP)++; /* Skip over closing parenthesis */
}
|
functions
|
void
xmlrpc_build_value_va(xmlrpc_env *const envP,
const char *const format,
va_list const args,
xmlrpc_value **const valPP,
const char **const tailP) {
XMLRPC_ASSERT_ENV_OK(envP);
XMLRPC_ASSERT(format != NULL);
if (strlen(format) == 0)
xmlrpc_faultf(envP, "Format string is empty.");
else {
va_listx currentArgs;
const char *formatCursor;
init_va_listx(¤tArgs, args);
formatCursor = &format[0];
getValue(envP, &formatCursor, ¤tArgs, valPP);
if (!envP->fault_occurred)
XMLRPC_ASSERT_VALUE_OK(*valPP);
*tailP = formatCursor;
}
|
includes
|
#include <stdarg.h>
|
includes
|
#include <stddef.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <string.h>
|
includes
|
#include <fcntl.h>
|
includes
|
#include <unistd.h>
|
includes
|
#include <errno.h>
|
includes
|
#include <sys/endian.h>
|
includes
|
#include <sysexits.h>
|
includes
|
#include <mpg123.h>
|
structs
|
struct mp3 {
mpg123_handle *h;
int fd;
int first;
int rate;
int channels;
int endian;
int octets;
int sign;
};
|
functions
|
int
mp3_copy(struct mp3 *m, void *buf, size_t size, struct audio *out) {
size_t r;
if (m == NULL || buf == NULL || size == 0 || out == NULL)
return EX_USAGE;
if (m->first) { /* setup audio output */
m->first = 0;
a_setrate(out, m->rate);
a_setchan(out, m->channels);
a_setend(out, m->endian);
a_setbits(out, m->octets << 3);
a_setsign(out, m->sign);
}
|
functions
|
void
mp3_close(struct mp3 *m) {
if (m == NULL)
return;
if (m->fd >= 0)
close(m->fd);
if (m->h != NULL) {
mpg123_close(m->h);
mpg123_delete(m->h);
}
|
includes
|
#include <string.h>
|
defines
|
#define ROUNDS 10
|
defines
|
#define STRICT_ALIGNMENT
|
defines
|
#define RC (&(Cx.q[256*N]))
|
functions
|
void whirlpool_block(WHIRLPOOL_CTX *ctx, const void *inp, size_t n)
{
int r;
const u8 *p = inp;
union {
u64 q[8];
u8 c[64];
}
|
includes
|
#include <stdarg.h>
|
includes
|
#include <stdio.h>
|
functions
|
int printf(const char* restrict format, ...) {
va_list ap;
va_start(ap, format);
int result = vfprintf(stdout, format, ap);
va_end(ap);
return result;
}
|
includes
|
#include <string.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <ctype.h>
|
includes
|
#include <sys/stat.h>
|
functions
|
M_CODE
lm_parser_css(worker_t *w, iobuf_t *buf, uehandle_t *ue_h,
url_t *url, attr_list_t *al)
{
return lm_extract_css_urls(ue_h, buf->ptr, buf->sz);
}
|
functions
|
M_CODE
lm_handler_writefile(worker_t *w, iohandle_t *h,
url_t *url)
{
int r;
char *name;
char *ext;
char *s;
int x;
int ext_offs;
int a_sz;
int sz;
struct stat st;
/**
* create a filename to download to
**/
if (url->ext_o) {
for (x = url->ext_o; *(url->str+x) && *(url->str+x) != '?'; x++)
;
if (!(ext = malloc(x-url->ext_o+1)))
return M_OUT_OF_MEM;
memcpy(ext, url->str+url->ext_o, x-url->ext_o);
ext[x-url->ext_o] = '\0';
ext_offs = url->ext_o-(url->file_o+1);
}
|
functions
|
M_CODE
lm_extract_css_urls(uehandle_t *ue_h, char *p, size_t sz)
{
char *e = p+sz;
char *t, *s;
while ((p = memmem(p, e-p, "url", 3))) {
p += 3;
while (isspace(*p)) p++;
if (*p == '(') {
do p++; while (isspace(*p));
t = (*p == '"' ? "\")"
: (*p == '\'' ? "')" : ")"));
if (*t != ')')
p++;
}
|
functions
|
M_CODE
lm_parser_text(worker_t *w, iobuf_t *buf,
uehandle_t *ue_h, url_t *url,
attr_list_t *al)
{
return lm_extract_text_urls(ue_h, buf->ptr, buf->sz);
}
|
functions
|
M_CODE
lm_extract_text_urls(uehandle_t *ue_h, char *p, size_t sz)
{
int x;
char *s, *e = p+sz;
for (p = strstr(p, "://"); p && p<e; p = strstr(p+1, "://")) {
for (x=0;x<2;x++) {
if (p-e >= protocols[x].len
&& strncmp(p-protocols[x].len, protocols[x].name, protocols[x].len) == 0) {
for (s=p+3; s < e; s++) {
if (!isalnum(*s) && *s != '%' && *s != '?'
&& *s != '=' && *s != '&' && *s != '/'
&& *s != '.') {
ue_add(ue_h, p-protocols[x].len, (s-p)+protocols[x].len);
break;
}
|
functions
|
M_CODE
lm_parser_ftp(worker_t *w, iobuf_t *buf,
uehandle_t *ue_h, url_t *url,
attr_list_t *al)
{
char *p, *prev;
struct ftpparse info;
char name[128]; /* i'm pretty sure no filename will be longer than 127 chars... */
int len;
for (prev = p = buf->ptr; p<buf->ptr+buf->sz; p++) {
if (*p == '\n') {
if (p-prev) {
if (ftpparse(&info, prev, p-prev)) {
if (info.namelen >= 126) {
LM_WARNING(w->m, "file name too long");
continue;
}
|
includes
|
#include <unistd.h>
|
defines
|
#define write __write
|
functions
|
size_t __file_write(FILE* file, const unsigned char* p, size_t size) {
size_t written = 0;
while (written < size) {
ssize_t result = write(file->fd, p, size - written);
if (result < 0) {
file->flags |= FILE_FLAG_ERROR;
return written;
}
|
includes
|
#include <sys/types.h>
|
includes
|
#include <ctype.h>
|
includes
|
#include <errno.h>
|
includes
|
#include <devid.h>
|
includes
|
#include <fcntl.h>
|
includes
|
#include <libintl.h>
|
includes
|
#include <stdio.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <strings.h>
|
includes
|
#include <dlfcn.h>
|
includes
|
#include <unistd.h>
|
includes
|
#include <sys/efi_partition.h>
|
includes
|
#include <sys/vtoc.h>
|
includes
|
#include <sys/stat.h>
|
includes
|
#include <sys/zfs_ioctl.h>
|
includes
|
#include <syslog.h>
|
defines
|
#define BOOTCMD "installgrub(1M)"
|
defines
|
#define BOOTCMD "installboot(1M)"
|
defines
|
#define DISK_ROOT "/dev"
|
defines
|
#define RDISK_ROOT "/dev"
|
defines
|
#define BACKUP_SLICE "s2"
|
defines
|
#define NEW_START_BLOCK 256
|
defines
|
#define ZFSFUSE_BUSY_SLEEP_FACTOR 500000 // .5 seconds was chosen ater some tuning
|
defines
|
#define HIS_BUF_LEN (128*1024)
|
functions
|
int
zpool_get_all_props(zpool_handle_t *zhp)
{
zfs_cmd_t zc = { 0 }
|
functions
|
int
zpool_props_refresh(zpool_handle_t *zhp)
{
nvlist_t *old_props;
old_props = zhp->zpool_props;
if (zpool_get_all_props(zhp) != 0)
return (-1);
nvlist_free(old_props);
return (0);
}
|
functions
|
uint64_t
zpool_get_prop_int(zpool_handle_t *zhp, zpool_prop_t prop, zprop_source_t *src)
{
nvlist_t *nv, *nvl;
uint64_t value;
zprop_source_t source;
if (zhp->zpool_props == NULL && zpool_get_all_props(zhp)) {
/*
* zpool_get_all_props() has most likely failed because
* the pool is faulted, but if all we need is the top level
* vdev's guid then get it from the zhp config nvlist.
*/
if ((prop == ZPOOL_PROP_GUID) &&
(nvlist_lookup_nvlist(zhp->zpool_config,
ZPOOL_CONFIG_VDEV_TREE, &nv) == 0) &&
(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value)
== 0)) {
return (value);
}
|
functions
|
int
zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
zprop_source_t *srctype)
{
uint64_t intval;
const char *strval;
zprop_source_t src = ZPROP_SRC_NONE;
nvlist_t *nvroot;
vdev_stat_t *vs;
uint_t vsc;
if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
switch (prop) {
case ZPOOL_PROP_NAME:
(void) strlcpy(buf, zpool_get_name(zhp), len);
break;
case ZPOOL_PROP_HEALTH:
(void) strlcpy(buf, "FAULTED", len);
break;
case ZPOOL_PROP_GUID:
intval = zpool_get_prop_int(zhp, prop, &src);
(void) snprintf(buf, len, "%llu", (long long unsigned int)intval);
break;
case ZPOOL_PROP_ALTROOT:
case ZPOOL_PROP_CACHEFILE:
if (zhp->zpool_props != NULL ||
zpool_get_all_props(zhp) == 0) {
(void) strlcpy(buf,
zpool_get_prop_string(zhp, prop, &src),
len);
if (srctype != NULL)
*srctype = src;
return (0);
}
|
functions
|
boolean_t
bootfs_name_valid(const char *pool, char *bootfs)
{
int len = strlen(pool);
if (!zfs_name_valid(bootfs, ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT))
return (B_FALSE);
if (strncmp(pool, bootfs, len) == 0 &&
(bootfs[len] == '/' || bootfs[len] == '\0'))
return (B_TRUE);
return (B_FALSE);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.