Exemple #1
0
void
parse_header (header the_header, register char *where)
{
  register header old = the_header;
  do
    {
      char *field;
      register char *keyword = get_keyword (the_header->text->string, &field);
      if (strcmp (keyword, "TO") == 0)
	where = add_field (the_header->text->continuation, field, where);
      else if (strcmp (keyword, "CC") == 0)
	where = add_field (the_header->text->continuation, field, where);
      else if (strcmp (keyword, "BCC") == 0)
	{
	  where = add_field (the_header->text->continuation, field, where);
	  the_header->previous->next = the_header->next;
	  the_header->next->previous = the_header->previous;
	}
      else if (strcmp (keyword, "FCC") == 0)
	setup_files (the_header->text->continuation, field);
      the_header = the_header->next;
    } while (the_header != old);
  *where = '\0';
  return;
}
Exemple #2
0
static unsigned int
__add_header(TfwFuzzContext *ctx, int type, char **p, char *end, int t, int n)
{
	unsigned int v = 0, i;

	BUG_ON(t < 0);
	BUG_ON(t >= TRANSFER_ENCODING_NUM);

	BUG_ON(!fld_data[t].key);

	add_string(p, end, fld_data[t].key);
	v |= add_field(ctx, type, p, end, SPACES);
	v |= add_field(ctx, type, p, end, t);
	for (i = 0; i < n; ++i) {
		addch(p, end, ',');
		v |= add_field(ctx, type, p, end, SPACES);
		v |= __add_field(ctx, type, p, end, t, (i * 256) %
			(gen_vector[t].size + gen_vector[t].over));
	}

	add_string(p, end, "\r\n");

	if (v & FUZZ_INVALID)
		TFW_DBG("generate invalid header %d\n", t);

	ctx->hdr_flags |= 1 << t;

	return v;
}
Exemple #3
0
static void
handle_type (MonoClass *klass, guint32 flags)
{
	int i;
	guint32 missing;
	MonoCustomAttrInfo* cattrs;
	gpointer val = NULL, oldkey = NULL;
	MonoProperty* prop;
	MonoEvent* event;
	MonoMethod* method;
	MonoClassField* field;
	gpointer iter;
	
	if (g_hash_table_lookup_extended (type_table, klass, &oldkey, &val)) {
		missing = flags & ~(GPOINTER_TO_UINT (val));
	} else {
		missing = flags;
	}
	if (!missing)
		return;
	g_hash_table_insert (type_table, klass, GUINT_TO_POINTER (missing));
	if (verbose)
		g_print ("#processing klass: %s.%s\n", klass->name_space, klass->name);
	mono_class_init (klass);
	if (klass->parent)
		add_type (klass->parent);
	if (klass->nested_in)
		add_type (klass->nested_in);
	iter = NULL;
	while ((method = mono_class_get_methods (klass, &iter))) {
		if ((missing & TYPE_METHODS) || strcmp (method->name, ".cctor") == 0)
			add_types_from_method (method);
	}
	if (klass->enumtype) {
		add_field (mono_class_get_field_from_name (klass, "value__"));
	}
	if (force_enums || (missing & TYPE_FIELDS)) {
		iter = NULL;
		while ((field = mono_class_get_fields (klass, &iter)))
			add_field (field);
	}
	iter = NULL;
	while ((prop = mono_class_get_properties (klass, &iter))) {
		cattrs = mono_custom_attrs_from_property (klass, prop);
		handle_cattrs (cattrs);
	}
	iter = NULL;
	while ((event = mono_class_get_events (klass, &iter))) {
		cattrs = mono_custom_attrs_from_event (klass, event);
		handle_cattrs (cattrs);
	}
	for (i = 0; i < klass->interface_count; ++i)
		add_type (klass->interfaces [i]);
	cattrs = mono_custom_attrs_from_class (klass);
	handle_cattrs (cattrs);
}
Exemple #4
0
static void create_tbl ()
{
  char tbl_name[30], field_name[30], field_type[4], separator[5];
  int len;
  if ( fscanf (in_s, " table %s (", tbl_name) != 1)
    {
      put_msg (ERROR, "Do not know what to create\n");
      return;
    }

  put_msg (DEBUG, "table name: \"%s\".\n", tbl_name);

  schema_p sch = get_schema (tbl_name);
  
  if ( sch != NULL )
    {
      put_msg (ERROR, "Table \"%s\" already exists.\n", tbl_name);
      skip_line ();
      return;      
    }
  sch = new_schema (tbl_name);
  while (!feof(in_s))
    {
      fscanf (in_s, "%s %3s", field_name, field_type);
      if ( strcmp (field_type, t_int) == 0 )
	{
	  add_field ( sch, new_int_field ( field_name ));
	}
      else if ( strcmp (field_type, t_str) == 0 )
	{
	  fscanf (in_s, "(%d)", &len);
	  add_field ( sch, new_str_field ( field_name, len ));
	}
      else
	{
	  strcat (field_name, " ");
	  strcat (field_name, field_type);
	  syntax_error (field_name);
	  remove_schema (sch);
	  return;
	}
      fscanf (in_s, "%s", separator);
      put_msg(DEBUG, "seperator: \"%s\".\n", separator);
      if (separator[0] == ')')
	{
	  skip_line ();
	  break;
	}
    }
}
Exemple #5
0
char *
declare_new_field(char *key, char *name, char *type, int accept_standard)
{
	abook_field *f;

	if(find_declared_field(key))
		return _("field already defined");

	if(find_standard_field(key, accept_standard))
		return accept_standard ? NULL /* ok, added */ :
			_("standard field does not need to be declared");

	f = xmalloc(sizeof(abook_field));
	f->key = xstrdup(key);
	f->name = xstrdup(name);

	if(!*type || (0 == strcasecmp("string", type)))
		f->type = FIELD_STRING;
	else if(0 == strcasecmp("emails", type))
		f->type = FIELD_EMAILS;
	else if(0 == strcasecmp("list", type))
		f->type = FIELD_LIST;
	else if(0 == strcasecmp("date", type))
		f->type = FIELD_DATE;
	else
		return _("unknown type");

	add_field(&fields_list, f);
	fields_count++;

	return NULL;
}
Exemple #6
0
            /**
            * Add a field to a shapefile.
            */
            void add_field(const std::string& name, ///< The name of the field (1 to 11 characters long)
                           const std::string& type, ///< The type of the field ("string", "integer", "double", or "bool")
                           int width=1,             ///< The width of the field (number of digits for ints and doubles)
                           int decimals=0           ///< The precision of double fields (otherwise ignored)
                          ) {

                DBFFieldType ftype;
                if (type == "string") {
                    ftype = FTString;
                    decimals = 0;
                } else if (type == "integer") {
                    ftype = FTInteger;
                    decimals = 0;
                } else if (type == "double") {
                    ftype = FTDouble;
                } else if (type == "bool") {
                    ftype = FTLogical;
                    width = 1;
                    decimals = 0;
                } else {
                    throw std::runtime_error("Unknown field type:" + type);
                }

                add_field(name, ftype, width, decimals);
            }
Exemple #7
0
static int parse_message_header(http_parser_t *parser)
{
    int field_num;
    http_header_field_t *field;

    field_num = add_field(parser);
    field = &parser->req.fields[field_num];

    field->valid = 0;
    parse_crlf(parser);
    field->name = parse_token(parser);
    if (!field)
        return 1;

    if (parse_char(parser, ':')) {
        free(field->name);
        return 1;
    }

    // optional
    while (parse_char(parser, ' ') == 0)
        ;
    field->value = parse_field_content(parser);
    if (!field->value)
        return 1;
    while (parse_char(parser, ' ') == 0)
        ;

    field->valid = 1;
    return 0;
}
Exemple #8
0
void write_insert_line_one(FILE *file, char *field_name, FIELD_TYPE field_type)
{
  /*
   * Creates the list of fieldnames for the insert statement
   */
  static char is_first_line = TRUE;
  char is_default;

  if (find_field_on_list(field_name, defaults, field_type))
    is_default = TRUE;
  else 
    is_default = FALSE;
  if (!is_default)
    fprintf(file, "  if (IS_SET(data->bitfields[%d])) {\n", n_fields);
  if (is_first_line) {
    fprintf(file, "%s  tmp += sprintf(tmp, \"%%s\", \"%s\");\n", 
	    is_default ? "" : "  ", /* non-defaults are inside an 'if' */
	    field_name);
    is_first_line = FALSE;
  }
  else 
    fprintf(file, "%s  tmp += sprintf(tmp, \"%%s%%s\", separator, \"%s\");\n", 
	    is_default ? "" : "  ",
	    field_name);
  fprintf(file, "%s  separator = &comma[0];\n%s", 
	  is_default ? "" : "  ",
	  is_default ? "" : "  }\n");
  add_field(field_name, field_type, &all_fields);
}
Exemple #9
0
static int add_field_to_array(HTable table, char *token, char *buf, long int *pos)
{
    int idx = get_next_index(table);
    char b[100];
    sprintf(b, "%i", idx);
    return add_field(table, b, token, buf, pos);
}
Exemple #10
0
void MsgHandler::parse_format_fields()
{
    char *labels = xstrdup(f.labels);
    char * arg = labels;
    uint8_t label_offset = 0;
    char *next_label;
    uint8_t msg_offset = 3; // 3 bytes for the header

    while ((next_label = strtok(arg, ",")) != NULL) {
        if (label_offset > strlen(f.format)) {
            free(labels);
            printf("too few field times for labels %s (format=%s) (labels=%s)\n",
                   f.name, f.format, f.labels);
            exit(1);
        }
        uint8_t field_type = f.format[label_offset];
        uint8_t length = size_for_type(field_type);
        add_field(next_label, field_type, msg_offset, length);
        arg = NULL;
        msg_offset += length;
        label_offset++;
    }

    if (label_offset != strlen(f.format)) {
        free(labels);
        printf("too few labels for format (format=%s) (labels=%s)\n",
               f.format, f.labels);
    }

    free(labels);
}
bool Data_logging::add_field(const bool* val, const char* param_name)
{
    bool add_success = true;

    add_success = add_field((uint8_t*)val, param_name);

    return add_success;
}
Exemple #12
0
 /**
 * Add a field to a shapefile.
 */
 void add_field(const std::string& name, ///< The name of the field (1 to 11 characters long)
                DBFFieldType type,       ///< The type of the field (FT_STRING, FT_INTEGER, FT_DOUBLE, or FT_BOOL)
                int width=1,             ///< The width of the field (number of digits for ints and doubles)
                int decimals=0           ///< The precision of double fields (otherwise ignored)
               ) {
     Field field(name, type, width, decimals);
     add_field(field);
 }
Exemple #13
0
static void field_new_cb(Fl_Widget *w, void *data)
{
  Fl_Menu_Button* mb = ((Fl_Menu_Button*)w);
  FieldManager *fields = GModel::current()->getFields();
  int id = fields->newId();
  add_field(id, mb->text(), GModel::current()->getFileName());
  if((*fields)[id])
    FlGui::instance()->fields->editField((*fields)[id]);
}
Exemple #14
0
static schema_p copy_schema ( schema_p s, const char *dest_name )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = s->first;
  for ( ; f != NULL; f = f->next)
    add_field (dest, copy_field (f));
  return dest;
}
Exemple #15
0
int ConstantSet::set(
	std::string const &name,
	double val,
	std::string const &units,
	std::string const &description)
{
	int ix = add_field(name, units, description);
	vals[ix] = val;
	return ix;
}
Exemple #16
0
void buzzvstig_onconflictlost_call(buzzvm_t vm,
                                   buzzvstig_t vs,
                                   buzzobj_t k,
                                   buzzvstig_elem_t lv) {
   /* Was a conflict manager defined? */
   if(vs->onconflictlost) {
      /* Push closure */
      buzzvm_push(vm, vs->onconflictlost);
      /* Push key */
      buzzvm_push(vm, k);
      /* Make table for local value */
      buzzvm_pusht(vm);
      add_field(robot, lv, pushi);
      add_field(data, lv, push);
      add_field(timestamp, lv, pushi);
      /* Call closure (key and table are on the stack) */
      buzzvm_closure_call(vm, 2);
   }
}
static void
_cs_snmp_rrp_faulty_event(char *nodename, uint32_t nodeid,
		uint32_t iface_no, const char *state)
{
	int ret;
	char csysuptime[20];
	static oid snmptrap_oid[]  = { 1,3,6,1,6,3,1,1,4,1,0 };
	static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
	time_t now = time (NULL);

	netsnmp_pdu *trap_pdu;
	netsnmp_session *session = snmp_init (snmp_manager);
	if (session == NULL) {
		qb_log(LOG_NOTICE, "Failed to init SNMP session.");
		return ;
	}

	trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
	if (!trap_pdu) {
		qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
		return ;
	}

	/* send uptime */
	sprintf (csysuptime, "%ld", now);
	snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
	snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_RRP);

	/* Add extries to the trap */
	add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
	add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
	add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_RRP_IFACE_NO, (void*)&iface_no, sizeof (iface_no));
	add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_RRP_STATUS, (void*)state, strlen (state));

	/* Send and cleanup */
	ret = snmp_send (session, trap_pdu);
	if (ret == 0) {
		/* error */
		qb_log(LOG_ERR, "Could not send SNMP trap");
		snmp_free_pdu (trap_pdu);
	}
}
static int *add_dynamic_field(const header_field_info *info)
{
    int *p_id;

    /* cannot put these in a reallocated array, as we keep refs on them */
    p_id = (int *)malloc(sizeof(*p_id));
    assert(p_id);
    *p_id = -1;
    add_field(info, p_id);

    return p_id;
}
Exemple #19
0
/** Copy a constant's value and units to another constant
@return Index of the new constant. */
int ConstantSet::copy(std::string const &dst_name,
	std::string const &src_name,
	std::string const &description)
{
	int src_ix = fields.index(src_name);
	CoupledField const &src_field(fields.field(src_ix));
	
	int dst_ix = add_field(dst_name, src_field.units, description);
	vals[dst_ix] = vals[src_ix];

	return dst_ix;
}
Exemple #20
0
void
trkproperties_fill_meta (GtkListStore *store, DB_playItem_t **tracks, int numtracks) {
    gtk_list_store_clear (store);
    if (!tracks) {
        return;
    }

    const char **keys = NULL;
    int nkeys = build_key_list (&keys, 0, tracks, numtracks);

    int k;

    // add "standard" fields
    for (int i = 0; types[i]; i += 2) {
        add_field (store, types[i], _(types[i+1]), 0, tracks, numtracks);
    }

    // add all other fields
    for (int k = 0; k < nkeys; k++) {
        int i;
        for (i = 0; types[i]; i += 2) {
            if (!strcasecmp (keys[k], types[i])) {
                break;
            }
        }
        if (types[i]) {
            continue;
        }

        char title[MAX_GUI_FIELD_LEN];
        if (!types[i]) {
            snprintf (title, sizeof (title), "<%s>", keys[k]);
        }
        add_field (store, keys[k], title, 0, tracks, numtracks);
    }
    if (keys) {
        free (keys);
    }
}
Exemple #21
0
static int
add_field_list ( char *str )
{
  int added = 0;
  int file = -1, field = -1;
  int dot_found = 0;

  for (; *str; str++)
    {
      if (*str == ',' || isblank (*str))
	{
	  added += add_field (file, field);
	  file = field = -1;
	  dot_found = 0;
	}
      else if (*str == '.')
	dot_found = 1;
      else if (ISDIGIT (*str))
	{
	  if (!dot_found)
	    {
	      if (file == -1)
		file = 0;
	      file = file * 10 + *str - '0';
	    }
	  else
	    {
	      if (field == -1)
		field = 0;
	      field = field * 10 + *str - '0';
	    }
	}
      else
	return 0;
    }

  added += add_field (file, field);
  return added;
}
Exemple #22
0
	void process_file_info( const file_info * p_info)
	{
		t_size index_field, count_field = p_info->meta_get_count();
		for (index_field=0; index_field<count_field; index_field++)
		{
			const char * p_field = p_info->meta_enum_name(index_field);
			t_size index_value, value_count = p_info->meta_enum_value_count(index_field);
			for (index_value=0; index_value<value_count; index_value++)
			{
				add_field(p_field, p_info->meta_enum_value(index_field, index_value));
			}
		}
	}
Exemple #23
0
void
trkproperties_fill_metadata (void) {
    if (!trackproperties) {
        return;
    }
    trkproperties_modified = 0;
    deadbeef->pl_lock ();

    trkproperties_fill_meta (store, tracks, numtracks);
    gtk_list_store_clear (propstore);

    // hardcoded properties
    for (int i = 0; trkproperties_hc_props[i]; i += 1) {
        add_field (propstore, trkproperties_hc_props[i], _(trkproperties_hc_props[i+1]), 1, tracks, numtracks);
    }
    // properties
    const char **keys = NULL;
    int nkeys = trkproperties_build_key_list (&keys, 1, tracks, numtracks);
    for (int k = 0; k < nkeys; k++) {
        int i;
        for (i = 0; trkproperties_hc_props[i]; i += 2) {
            if (!strcasecmp (keys[k], trkproperties_hc_props[i])) {
                break;
            }
        }
        if (trkproperties_hc_props[i]) {
            continue;
        }
        size_t l = strlen (keys[k]);
        char title[l + 3];
        snprintf (title, sizeof (title), "<%s>", keys[k]+1);
        add_field (propstore, keys[k], title, 1, tracks, numtracks);
    }
    if (keys) {
        free (keys);
    }

    deadbeef->pl_unlock ();
}
Exemple #24
0
static int make_cal_region(bladerf_fpga_size size, uint16_t vctcxo_trim,
                           uint8_t *buf, size_t len)
{
    int rv;
    static const char fpga_size_40[] = "40";
    static const char fpga_size_115[] = "115";
    const char *fpga_size;
    char dac[7] = {0};

    if (size == BLADERF_FPGA_40KLE) {
        fpga_size = fpga_size_40;
    } else if (size == BLADERF_FPGA_115KLE) {
        fpga_size = fpga_size_115;
    } else {
        assert(0); /* Bug catcher */
        return BLADERF_ERR_INVAL;
    }

    memset(buf, 0xff, len);

    assert(len < INT_MAX);
    rv = add_field((char*)buf, (int)len, "B", fpga_size);

    if (rv < 0) {
        return rv;
    }

    sprintf(dac, "%u", vctcxo_trim);

    rv = add_field((char*)buf, (int)len, "DAC", dac);
    if (rv < 0) {
        return rv;
    }

    return 0;
}
Exemple #25
0
static abook_field *
declare_standard_field(int i)
{
	abook_field *f = xmalloc(sizeof(abook_field));

	f = memcpy(f, &standard_fields[i], sizeof(abook_field));
	f->name = xstrdup(gettext(f->name));

	add_field(&fields_list, f);

	assert(standard_fields_indexed[i] == -1);
	standard_fields_indexed[i] = fields_count++;

	return f;
}
Exemple #26
0
//-------------------------------------------------------------------------------------------------
unsigned MessageBase::decode(const f8String& from, const unsigned offset)
{
	unsigned s_offset(offset), result;
	const unsigned fsize(from.size());
	const char *dptr(from.data());
	char tag[MAX_FLD_LENGTH], val[MAX_FLD_LENGTH];

	for (unsigned pos(_pos.size()); s_offset <= fsize && (result = extract_element(dptr + s_offset, fsize - s_offset, tag, val));)
	{
		const unsigned tv(fast_atoi<unsigned>(tag));
		const BaseEntry *be(_ctx._be.find_ptr(tv));
#if defined PERMIT_CUSTOM_FIELDS
		if (!be && (!_ctx._ube || (be = _ctx._ube->find_ptr(tv)) == 0))
#else
		if (!be)
#endif
			throw InvalidField(tv);
		Presence::const_iterator itr(_fp.get_presence().end());
		if (!_fp.has(tv, itr))
			break;
		s_offset += result;
		if (_fp.get(tv, itr, FieldTrait::present))
		{
			if (!_fp.get(tv, itr, FieldTrait::automatic))
				throw DuplicateField(tv);
		}
		else
		{
			add_field(tv, itr, ++pos, be->_create(val, be->_rlm, -1), false);
			if (_fp.is_group(tv, itr))
				s_offset = decode_group(tv, from, s_offset);
		}
	}

	const unsigned short missing(_fp.find_missing());
	if (missing)
	{
		const BaseEntry& tbe(_ctx._be.find_ref(missing));
		ostringstream ostr;
		ostr << tbe._name << " (" << missing << ')';
		throw MissingMandatoryField(ostr.str());
	}

	return s_offset;
}
Exemple #27
0
            v8::Handle<v8::Value> js_add_field(const v8::Arguments& args) {
                if (args.Length() < 3 || args.Length() > 4) {
                    throw std::runtime_error("Wrong number of arguments to add_field method.");
                }

                v8::String::Utf8Value name(args[0]);
                std::string sname(*name);

                v8::String::Utf8Value type(args[1]);
                std::string stype(*type);

                int width = args[2]->Int32Value();
                int decimals = (args.Length() == 4) ? args[3]->Int32Value() : 0;

                add_field(sname, stype, width, decimals);

                return v8::Integer::New(1);
            }
Exemple #28
0
static schema_p make_sub_schema ( schema_p s, const char *dest_name,
				  int num_fields, char *fields[] )
{
  if (s == NULL ) return NULL;
  schema_p dest = new_schema (dest_name);
  field_desc_p f = NULL;
  int i = 0;
  for ( i= 0; i < num_fields; i++)
    {
      f = get_field ( s, fields[i] );
      if ( f != NULL)
	add_field (dest, copy_field (f));
      else
	{
	  put_msg (ERROR, "\"%s\" has no \"%s\" field\n",
		   s->name, fields[i]);
	  remove_schema (dest);
	  return NULL;
	}
    }
  return dest;
}
/*----------------------------------------------------------------*/
static void add_to_fields(char *uf,
			  Mandatory_header_block *m,
			  Field_header *f, char *name)
{
    data_range_t *d;
    signed short *spt;        /* pointer to short */
    int i; /*, j, j0, j1;*/
    double value;

    d = find_field(name);
    if (d == NULL)
        d = add_field(name);

    spt = (signed short *)(POSITION(uf, f->position));
    for (i=0; i<f->num_samples; ++i, ++spt)
    {
	if (*spt == m->missing)
	    continue;
	value = (double)(*spt)/(double)(f->scale_factor);
	add_to_field(d, value);
    }
    return;
}
Exemple #30
0
static void read_tbl_descs ()
{
  
  FILE *fp = fopen (tables_desc_file, "r");
  if ( fp == NULL ) return;
  char name[30] = "";
  schema_p sch;
  field_desc_p fld;
  int num_flds = 0, fld_type, fld_len;
  while ( !feof(fp) )
    {
      if ( fscanf ( fp, "%s %d\n", name, &num_flds ) < 2 )
	{
	  fclose (fp);
	  return;
	}
      sch = new_schema ( name );
      int i;
      for (i = 0; i < num_flds; i++ )
	{
	  fscanf ( fp, "%s %d %d", name, &(fld_type), &(fld_len) );
	  switch (fld_type) {
	  case INT_TYPE:
	    fld = new_int_field ( name );
	    break;
	  case STR_TYPE:
	    fld = new_str_field ( name, fld_len );
	    break;
	  }
	  fscanf (fp, "%d\n", &(fld->offset));
	  add_field ( sch, fld );
	}
      fscanf ( fp, "%d\n",  &(sch->tbl->num_records)  );
    }
  db_tables = sch->tbl;
  fclose (fp);
}