Example #1
0
int timespec_parse(struct job_timespec* t, const char* s)
{
  int i;
  bitmap b;
  const char* start;
  start = s;
  if ((i = parse_field(s, &t->minutes, 0, 59, ALL_MINUTES, 0, 0)) <= 0
      || !isspace(s[i]))
    return 0;
  for (s += i; isspace(*s); ++s) ;
  if ((i = parse_field(s, &t->hours, 0, 23, ALL_HOURS, 0, 0)) <= 0
      || !isspace(s[i]))
    return 0;
  for (s += i; isspace(*s); ++s) ;
  if ((i = parse_field(s, &t->mdays, 1, 31, ALL_MDAYS, 0, 0)) <= 0
      || !isspace(s[i]))
    return 0;
  for (s += i; isspace(*s); ++s) ;
  if ((i = parse_field(s, &t->months, 0, 11, ALL_MONTHS, month_table, 1)) <= 0
      || !isspace(s[i]))
    return 0;
  for (s += i; isspace(*s); ++s) ;
  if ((i = parse_field(s, &t->wdays, 0, 7, ALL_WDAYS, wday_table, 0)) <= 0
      || !isspace(s[i]))
    return 0;
  s += i;
  if (t->wdays & (1 << 7)) {
    t->wdays |= 1;
    t->wdays &= ALL_WDAYS;
  }
  for (b = t->hours, i = 0; b != 0; b >>= 1)
    i += (unsigned)b & 1;
  t->hour_count = i;
  return s - start;
}
Example #2
0
static int parse_cronstring(cron_trigger_t *item, const char *str)
{
	char mins[MAX_MINS_LENGTH];
	char hrs[MAX_HRS_LENGTH];
	char days[MAX_DAYS_LENGTH];
	char mons[MAX_MONS_LENGTH];
	char dow[MAX_DOW_LENGTH];

	if (sscanf(str, " %"STRINGIFY(MAX_MINS_LENGTH)"[^ ] %"STRINGIFY(MAX_HRS_LENGTH)"[^ ] %"STRINGIFY(MAX_DAYS_LENGTH)"[^ ] %"STRINGIFY(MAX_MONS_LENGTH)"[^ ] %"STRINGIFY(MAX_DOW_LENGTH)"[^ \r\n]",
		(char *)&mins,
		(char *)&hrs,
		(char *)&days,
		(char *)&mons,
		(char *)&dow) == 5)
	{
		if (parse_field(item->cl.mins, 60, 0, NULL, (char *)&mins) != 0)
			return -1;
		if (parse_field(item->cl.hrs, 24, 0, NULL, (char *)&hrs) != 0)
			return -1;
		if (parse_field(item->cl.days, 32, 0, NULL, (char *)&days) != 0)
			return -1;
		if (parse_field(item->cl.mons, 12, -1, MonAry, (char *)&mons) != 0)
			return -1;
		if (parse_field(item->cl.dow, 7, 0, DowAry, (char *)&dow) != 0)
			return -1;
		fix_day_dow(&item->cl);
		return 0;
	}
	return -1;
}
Example #3
0
/*
 * Read the list of file-entries
 */
static void
read_entries(CVS_WORK * cache)
{
    char name[MAXPATHLEN];
    char **list = 0;
    int j, k;

    if ((k = file2argv(admin_filename(name, cache, NAME_LIST), &list)) > 0) {
	cache->Entries = DOALLOC(0, CVS_ENTRY, (size_t) k);
	for (j = k = 0; list[j] != 0; ++j) {
	    char *s = list[j];
	    char *t;

	    cache->Entries[j].filename = 0;
	    cache->Entries[j].version = 0;
	    cache->Entries[j].status = 0;
	    cache->Entries[j].timestamp = 0;

	    if (s[0] == '/' && s[1] != '/') {
		++s;
		cache->Entries[k].filename = copy_field(parse_field(&s));
		cache->Entries[k].version = copy_field(parse_field(&s));
		if ((t = parse_field(&s)) != 0)
		    cache->Entries[k].timestamp = string2time(t);
		cache->Entries[k].status = copy_field(parse_field(&s));
		++k;
	    }
	}
	cache->num_entries = k;
    }
    if (list)
	vecfree(list);
}
xmlNodePtr
id3v1_parse(FILE *fp)
{
    xmlNodePtr tag_node;
    ID3v1Tag tag;
    gchar *tmp;

    rewind(fp);

    if (fseek(fp, -ID3V1_TAG_LENGTH, SEEK_END) != 0 ||
            fread(&tag, sizeof tag, 1, fp) != 1 ||
            strncmp(tag.tag, "TAG", 3) != 0)
        return NULL;

    tag_node = xmlNewNode(NULL, "tag");
    xmlNewProp(tag_node, "format", "ID3");

    if ((tmp = parse_field(tag.title, sizeof tag.title)) != NULL) {
        xmlNewTextChild(tag_node, NULL, "title", tmp);
        g_free(tmp);
    }

    if ((tmp = parse_field(tag.artist, sizeof tag.artist)) != NULL) {
        xmlNewTextChild(tag_node, NULL, "artist", tmp);
        g_free(tmp);
    }

    if ((tmp = parse_field(tag.album, sizeof tag.album)) != NULL) {
        xmlNewTextChild(tag_node, NULL, "album", tmp);
        g_free(tmp);
    }

    if ((tmp = parse_field(tag.year, sizeof tag.year)) != NULL) {
        xmlNewTextChild(tag_node, NULL, "year", tmp);
        g_free(tmp);
    }

    if (tag.genre < ID3_NR_OF_V1_GENRES)
        xmlNewTextChild(tag_node, NULL, "genre",
                        ID3_v1_genre_description[tag.genre]);

    if ((tmp = parse_field(tag.comment, sizeof tag.comment)) != NULL) {
        xmlNewTextChild(tag_node, NULL, "comment", tmp);
        g_free(tmp);
    }

    return tag_node;
}
Example #5
0
/* `struct` or `table` must already be matched. */
static void parse_compound_type(fb_parser_t *P, fb_compound_type_t *ct)
{
    fb_token_t *t = 0;

    if (!(t = match(P, LEX_TOK_ID, "Declaration expected an identifier"))) {
        goto fail;
    }
    ct->symbol.ident = t;
    ct->metadata = parse_metadata(P);
    if (!(match(P, '{', "Declaration expected '{'"))) {
        goto fail;
    }
    t = P->token;

/* Allow empty tables and structs. */
#if 0
    if (P->token->id == '}') {
        error_tok(P, t, "table / struct declaration cannot be empty");
    }
#endif
    while (P->token->id != '}') {
        parse_field(P, fb_add_member(P, &ct->members));
        if (P->failed >= FLATCC_MAX_ERRORS) {
            goto fail;
        }
    }
    if (!optional(P, '}') && t) {
        error_tok_2(P, P->token, "Declaration missing closing '}' to match", t);
    }
    revert_symbols(&ct->members);
    return;
fail:
    recover(P, '}', 1);
}
Example #6
0
/*
 * The function assumes that the following patterns have fixed sizes:
 * - "BeginString=" ("8=") is 2 bytes long
 * - "CheckSum=" ("10=") is 3 bytes long
 * - "MsgType=" ("35=") is 3 bytes long
 */
static bool checksum(struct fix_message *self, struct buffer *buffer)
{
	const char *start;
	int offset;

	start = buffer_start(buffer);

	/* The number of bytes between tag MsgType and buffer's start */
	offset = start - (self->msg_type - 3);

	/*
	 * Checksum tag and its trailing delimiter increase
	 * the message's length by seven bytes - "10=***\x01"
	 */
	if (buffer_size(buffer) + offset < self->body_length + 7)
		return false;

	/* Buffer's start will point to the CheckSum tag */
	buffer_advance(buffer, self->body_length - offset);

	self->check_sum = parse_field(buffer, CheckSum);
	if (!self->check_sum)
		return false;

	if (!verify_checksum(self, buffer))
		return false;

	/* Go back to analyze other fields */
	buffer_advance(buffer, start - buffer_start(buffer));

	return true;
}
Example #7
0
static int parse_begin_string(struct fix_message *self)
{
	// if first field is not BeginString -> garbled
	// if BeginString is invalid or empty -> garbled

	return parse_field(self->head_buf, BeginString, &self->begin_string);
}
Example #8
0
/* Convert 'str_' (as described in the documentation for the "monitor" command
 * in the ovs-ofctl man page) into 'fmr'. */
void
parse_flow_monitor_request(struct ofputil_flow_monitor_request *fmr,
                           const char *str_)
{
    static uint32_t id;

    char *string = xstrdup(str_);
    char *save_ptr = NULL;
    char *name;

    fmr->id = id++;
    fmr->flags = (NXFMF_INITIAL | NXFMF_ADD | NXFMF_DELETE | NXFMF_MODIFY
                  | NXFMF_OWN | NXFMF_ACTIONS);
    fmr->out_port = OFPP_NONE;
    fmr->table_id = 0xff;
    match_init_catchall(&fmr->match);

    for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
         name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
        const struct protocol *p;

        if (!strcmp(name, "!initial")) {
            fmr->flags &= ~NXFMF_INITIAL;
        } else if (!strcmp(name, "!add")) {
            fmr->flags &= ~NXFMF_ADD;
        } else if (!strcmp(name, "!delete")) {
            fmr->flags &= ~NXFMF_DELETE;
        } else if (!strcmp(name, "!modify")) {
            fmr->flags &= ~NXFMF_MODIFY;
        } else if (!strcmp(name, "!actions")) {
            fmr->flags &= ~NXFMF_ACTIONS;
        } else if (!strcmp(name, "!own")) {
            fmr->flags &= ~NXFMF_OWN;
        } else if (parse_protocol(name, &p)) {
            match_set_dl_type(&fmr->match, htons(p->dl_type));
            if (p->nw_proto) {
                match_set_nw_proto(&fmr->match, p->nw_proto);
            }
        } else {
            char *value;

            value = strtok_r(NULL, ", \t\r\n", &save_ptr);
            if (!value) {
                ovs_fatal(0, "%s: field %s missing value", str_, name);
            }

            if (!strcmp(name, "table")) {
                fmr->table_id = str_to_u8(value, name);
            } else if (!strcmp(name, "out_port")) {
                fmr->out_port = u16_to_ofp(atoi(value));
            } else if (mf_from_name(name)) {
                parse_field(mf_from_name(name), value, &fmr->match);
            } else {
                ovs_fatal(0, "%s: unknown keyword %s", str_, name);
            }
        }
    }
    free(string);
}
Example #9
0
static bool parse_msg_type(struct fix_message *self)
{
	self->msg_type = parse_field(self->head_buf, MsgType);

	// if third field is not MsgType -> garbled

	return self->msg_type != NULL;
}
static void
face_props_parse (twin_face_properties_t *props,
	     const char *s)
{
    const char *start, *end;

    for (start = end = s; *end; end++) {
	if (*end != ' ' && *end != ':')
	    continue;

	if (start < end)
		parse_field (props, start, end - start);
	start = end + 1;
    }
    if (start < end)
	    parse_field (props, start, end - start);
}
Example #11
0
void game_function(){
	
/*	request_t response;
	strcpy(response.name,client_name);
	response.lobby = GAME;
	response.action = START_GAME;	
	pthread_mutex_lock(&mutex);
	if(send(socket_fd, (void*) &response, sizeof(response), 0) == -1)
			error("send() redy");
	pthread_mutex_unlock(&mutex);
*/	
	
	pthread_mutex_lock(&game_mutex);
	while(wait==0)
		pthread_cond_wait(&waiting_cond, &game_mutex);
	pthread_mutex_unlock(&game_mutex);
	init_fields();
	char bufor[2];
	
	pthread_mutex_lock(&game_mutex);
	printf("Oczekiwanie na gotowosc przeciwnika..\n");
	while(enemy_ready==0)
		pthread_cond_wait(&waiting_cond, &game_mutex);
	pthread_mutex_unlock(&game_mutex);
	printf("Przeciwnik gotowy - gra rozpoczyna sie!\n");
	int x,y;
	while(!my_turn)
		pthread_cond_wait(&waiting_cond, &game_mutex);
	while(game_state==1&&thread_is_alive==1){
			printf("Podaj pole do zaatakowania: ");
			do{					
				scanf("%s",bufor);	
			}while(parse_field(bufor,&x,&y)==0);
			request_t response;
			strcpy(response.name,client_name);
			response.lobby = GAME;
			response.action = FIELD;
			response.field.x=x;
			response.field.y=y;	
			response.opponent_socket=opponent_socket;
			pthread_mutex_lock(&mutex);
			if(send(socket_fd, (void*) &response, sizeof(response), 0) == -1)
					error("send() game");
			pthread_mutex_unlock(&mutex);
			
		pthread_mutex_lock(&game_mutex);
		do {
			pthread_cond_wait(&waiting_cond, &game_mutex);
		} while(!my_turn);
		pthread_mutex_unlock(&game_mutex);
		if(game_state==1)
			game_state=status();
	}
	printf("Koniec gry\n");

	return ;
}
Example #12
0
static bool parse_begin_string(struct fix_message *self)
{
	self->begin_string = parse_field(self->head_buf, BeginString);

	// if first field is not BeginString -> garbled
	// if BeginString is invalid or empty -> garbled

	return self->begin_string != NULL;
}
Example #13
0
/*=== parse_table_file ======================================================
 * <Description Text> 
 *
 * Assumes:    ?
 *
 * Returns:    (value) when X
 *             (value) when Y
 *
 * Modifies:   ?
 *
 * Calls:      nothing
 *
 * Called By:  ?
 *
 * History:    MM/DD/YY  MRH  Created initial version based on function
 *                            'func()' in motif/csr/file.c
 */
static PARSE_ERROR_TYPE
parse_table_file(FILE   *infile,
                 FIELD **fields,
                 char   *table_name,
                 TABLE  *tables)
{
  PARSE_TABLE_TYPE status;
  char       *create_table = "create table";
  char        line[256];
  char        field_name[256];
  FIELD_TYPE  field_type;
  int         field_length;
  char        null_allowable;
  
  /*
   * First, skip to the first open paren following a 'create table' string
   * in the file.
   */
  while (fgets(line, sizeof(line), infile))
    if (!strncmp(line, create_table, strlen(create_table)))
      break;
  
  if (! strchr(line, '('))
  {
    while (fgetc(infile) != '(')
      ;
  }
  
  while (! feof(infile))
  {
    status = parse_field(infile, field_name, &field_type, &field_length,
                         &null_allowable);

    if (status == TABLE_END)
      break;                 /* Only a single close paren */
    if (status == TABLE_COMMENT)
      continue;              /* The line is a comment     */

    if (status == TABLE_PARSE_ERROR)
    {
      fprintf(stderr, "Problem parsing %s.table file.\n", table_name);
      return PARSE_ERROR;
    }

    if (append_field(fields, table_name, field_name, field_type,
                     field_length, null_allowable, tables) == FALSE)
      return PARSE_ERROR;

    if (status == TABLE_DONE)
      break;                  /* Had a valid field *and* a close paren */
  }
  
  return OK;
}
Example #14
0
/****************
 * Find and parse a header field.
 * WHICH indicates what to do if there are multiple instance of the same
 * field (like "Received"); the following value are defined:
 *  -1 := Take the last occurence
 *   0 := Reserved
 *   n := Take the n-th one.
 * Returns a handle for further operations on the parse context of the field
 * or NULL if the field was not found.
 */
rfc822parse_field_t
rfc822parse_parse_field (rfc822parse_t msg, const char *name, int which)
{
  HDR_LINE hdr;

  if (!which)
    return NULL;

  hdr = find_header (msg, name, which, NULL);
  if (!hdr)
    return NULL;
  return parse_field (hdr);
}
Example #15
0
File: rfc822.c Project: gpg/geam
/****************
 * Find and parse a header field.
 * which indicates what to do if there are multiple instance of the same
 * field (like "Received"); the followinf value are defined:
 *  -1 := Take the last occurence
 *   0 := Reserved
 *   n := Take the n-th one.
 * Returns a handle for further operations on the parse context of the field
 * or NULL if the field was not found.
 */
RFC822_PARSE_CTX
rfc822_parse_header( RFC822 msg, const char *name, int which )
{
    HDR_LINE hdr;

    if( !which )
        return NULL;

    hdr = find_header( msg, name, which, NULL );
    if( !hdr )
        return NULL;
    return parse_field( hdr );
}
Example #16
0
void ProguardMap::parse_line(const std::string& line) {
  if (parse_class(line)) {
    return;
  }
  if (parse_field(line)) {
    return;
  }
  if (parse_method(line)) {
    return;
  }
  always_assert_log(false,
                    "Bogus line encountered in proguard map: %s\n",
                    line.c_str());
}
Example #17
0
int
parse_cookie(struct cookie *c, const char *cookie_str, size_t n)
{
    char *str, *tok;

    str = strndup(cookie_str, n);
    str = discard_setcookie(str);

    c->httpOnly = 0;

    while (tok = strsep(&str, ";")) {
        parse_field(c, skip_spaces(tok), n);
    }
    //Assuming a cookie looks like this:
}
Example #18
0
static bool parse_body_length(struct fix_message *self)
{
	int len;
	const char *ptr = parse_field(self->head_buf, BodyLength);

	if (!ptr)
		return false;

	len = strtol(ptr, NULL, 10);
	self->body_length = len;

	if (len <= 0 || len > FIX_MAX_MESSAGE_SIZE)
		return false;

	return true;
}
Example #19
0
static int parse_fieldv(const void *data, size_t length, const ParseFieldVec *fields, unsigned n_fields) {
        unsigned i;

        for (i = 0; i < n_fields; i++) {
                const ParseFieldVec *f = &fields[i];
                int r;

                r = parse_field(data, length, f->field, f->field_len, f->target, f->target_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        break;
        }

        return 0;
}
static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
{
    char fn[128];
    FILE *fp;
    char line[1024];
    mapinfo *head = NULL;
    mapinfo *current = NULL;
    int len;

    snprintf(fn, sizeof(fn), "/proc/%d/smaps", pid);
    fp = fopen(fn, "r");
    if (fp == 0) {
        if (!quiet) fprintf(stderr, "cannot open /proc/%d/smaps: %s\n", pid, strerror(errno));
        return NULL;
    }

    while (fgets(line, sizeof(line), fp) != 0) {
        len = strlen(line);
        if (line[len - 1] == '\n') {
            line[--len] = 0;
        }

        if (current != NULL && !parse_field(current, line)) {
            continue;
        }

        mapinfo *next;
        if (!parse_header(line, current, &next)) {
            enqueue_map(&head, current, sort_by_address, coalesce_by_name);
            current = next;
            continue;
        }

        fprintf(stderr, "warning: could not parse map info line: %s\n", line);
    }

    enqueue_map(&head, current, sort_by_address, coalesce_by_name);

    fclose(fp);

    if (!head) {
        if (!quiet) fprintf(stderr, "could not read /proc/%d/smaps\n", pid);
        return NULL;
    }

    return head;
}
Example #21
0
static int parse_msg_type(struct fix_message *self)
{
	int ret;

	ret = parse_field(self->head_buf, MsgType, &self->msg_type);

	if (ret)
		goto exit;

	self->type = fix_msg_type_parse(self->msg_type);

	// if third field is not MsgType -> garbled

	if (fix_message_type_is(self, FIX_MSG_TYPE_UNKNOWN))
		ret = FIX_MSG_STATE_GARBLED;

exit:
	return ret;
}
Example #22
0
static int parse_body_length(struct fix_message *self)
{
	int len, ret;
	const char *ptr;

	ret = parse_field(self->head_buf, BodyLength, &ptr);

	if (ret)
		goto exit;

	len = strtol(ptr, NULL, 10);
	self->body_length = len;

	if (len <= 0 || len > FIX_MAX_MESSAGE_SIZE)
		ret = FIX_MSG_STATE_GARBLED;

exit:
	return ret;
}
Example #23
0
/**
 * @brief ggs_parse_clock
 *
 * Translate input word into a GGS clock time.
 *
 * @param ggsclock GGS clock.
 * @param line Text.
 * @return true if parsing succeed.
 */
static bool ggs_parse_clock(GGSClock *ggsclock, const char *line) {
	char time[WORD_SIZE];
	const char *move;
	char word[WORD_SIZE];

	errno = 0;
	*ggsclock = GGS_CLOCK_INI;
	line = parse_field(line, word, WORD_SIZE, '/');
	if (*word) {
		move = parse_field(word, time, WORD_SIZE, ',');
		if (!ggs_parse_time(&ggsclock->ini_time, time)) return false;
		if (*move) {
			if (*move == 'N') {
				ggsclock->ini_flag = 1;
				move++;
			}
			if (!ggs_parse_int(&ggsclock->ini_move, move)) return false;
		}
	}

	line = parse_field(line, word, WORD_SIZE, '/');
	if (*word) {
		move = parse_field(word, time, WORD_SIZE, ',');
		if (!ggs_parse_time(&ggsclock->inc_time, time)) return false;
		if (*move) {
			if (*move == 'N') {
				ggsclock->inc_flag = 1;
				move++;
			}
			if (!ggs_parse_int(&ggsclock->inc_move, move)) return false;
		}
	}

	line = parse_field(line, word, WORD_SIZE, '\0');
	if (*word) {
		move = parse_field(word, time, WORD_SIZE, ',');
		if (!ggs_parse_time(&ggsclock->ext_time, time)) return false;
		if (*move) {
			if (*move == 'N') {
				ggsclock->ext_flag = 1;
				move++;
			}
			if (!ggs_parse_int(&ggsclock->ext_move, move)) return false;
		}
	}

	return true;
}
Example #24
0
// Parse message populating fields and return Method
Method Parser::parse(char* buffer, int buffer_size) {
    data.clear();
    tokenize(buffer, buffer_size);
    Errcode errcode = parse_method(_lines[0]);
    for (unsigned int line = 1; line < _lines.size(); ++line) {
        Errcode ec = parse_field(_lines[line]);
        // We always throw the first error we find
        if (errcode == OK)
            errcode = ec;
    }
    switch (_state) {
        case INIT:      if (data.method == SETUP)    _state = READY;     
                   else if (data.method == PLAY)     throw METHOD_NOT_VALID_IN_THIS_STATE;
                        break;
        case READY:     if (data.method == PLAY)     _state = PLAYING;
                   else if (data.method == TEARDOWN) _state = INIT;      break;
        case PLAYING:   if (data.method == TEARDOWN) _state = INIT;      break;
    }
    if (errcode != OK)
        throw errcode;
    return data.method;
}
Example #25
0
    static void rest_of_message(struct fix_message *self, struct fix_dialect *dialect, struct buffer *buffer)
{
    int tag = 0;
    const char *tag_ptr = NULL;
    unsigned long nr_fields = 0;
    enum fix_type type;

    self->nr_fields = 0;

retry:
    if (parse_field(buffer, &tag, &tag_ptr))
        return;

    type = dialect->tag_type(tag);

    switch (type) {
    case FIX_TYPE_INT:
        self->fields[nr_fields++] = FIX_INT_FIELD(tag, fix_atoi64(tag_ptr, NULL));
        goto retry;
    case FIX_TYPE_FLOAT:
        self->fields[nr_fields++] = FIX_FLOAT_FIELD(tag, strtod(tag_ptr, NULL));
        goto retry;
    case FIX_TYPE_CHAR:
        self->fields[nr_fields++] = FIX_CHAR_FIELD(tag, tag_ptr[0]);
        goto retry;
    case FIX_TYPE_STRING:
        self->fields[nr_fields++] = FIX_STRING_FIELD(tag, tag_ptr);
        goto retry;
    case FIX_TYPE_CHECKSUM:
        break;
    case FIX_TYPE_MSGSEQNUM:
        self->msg_seq_num = fix_uatoi(tag_ptr, NULL);
        goto retry;
    default:
        goto retry;
    }

    self->nr_fields = nr_fields;
}
Example #26
0
void mail_header_append (mbox_t *mbox, mbox_mail_t *mail, char *row,
                         size_t rowlen)
{
    char *key, *value;

    if (isspace(row[0]) && mbox->aux.status != STATUS_NODATA) {
        /* Part of a previous header */
        dstrbuf_insert(mbox->aux.multiline, row, rowlen);
    } else {
        mail_header_end(mbox, mail);    // store any previous open header.
        if (parse_trace(&mbox->parse, row, &value)) {
            /* A new trace field */
            mbox->aux.status = STATUS_TRACE;
        } else if (parse_field(&mbox->parse, row, &key, &value)) {
            /* A new generic field */
            mbox->aux.key = key;
            mbox->aux.status = STATUS_FIELD;
        }
        dstrbuf_insert(mbox->aux.multiline, value, 0);
    }
    /* Any other line is considered garbage. */
}
Example #27
0
/*
 * The function assumes that the following patterns have fixed sizes:
 * - "BeginString=" ("8=") is 2 bytes long
 * - "CheckSum=" ("10=") is 3 bytes long
 * - "MsgType=" ("35=") is 3 bytes long
 */
static int checksum(struct fix_message *self, struct buffer *buffer)
{
	const char *start;
	int offset;
	int ret;

	start = buffer_start(buffer);

	/* The number of bytes between tag MsgType and buffer's start */
	offset = start - (self->msg_type - 3);

	/*
	 * Checksum tag and its trailing delimiter increase
	 * the message's length by seven bytes - "10=***\x01"
	 */
	if (buffer_size(buffer) + offset < self->body_length + 7) {
		ret = FIX_MSG_STATE_PARTIAL;
		goto exit;
	}

	/* Buffer's start will point to the CheckSum tag */
	buffer_advance(buffer, self->body_length - offset);

	ret = parse_field(buffer, CheckSum, &self->check_sum);
	if (ret)
		goto exit;

	if (!verify_checksum(self, buffer)) {
		ret = FIX_MSG_STATE_GARBLED;
		goto exit;
	}

	/* Go back to analyze other fields */
	buffer_advance(buffer, start - buffer_start(buffer));

exit:
	return ret;
}
Example #28
0
static int output_short(
                FILE *f,
                sd_journal *j,
                OutputMode mode,
                unsigned n_columns,
                OutputFlags flags) {

        int r;
        const void *data;
        size_t length;
        size_t n = 0;
        _cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL;
        size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0;
        int p = LOG_INFO;
        bool ellipsized = false;

        assert(f);
        assert(j);

        /* Set the threshold to one bigger than the actual print
         * threshold, so that if the line is actually longer than what
         * we're willing to print, ellipsization will occur. This way
         * we won't output a misleading line without any indication of
         * truncation.
         */
        sd_journal_set_data_threshold(j, flags & (OUTPUT_SHOW_ALL|OUTPUT_FULL_WIDTH) ? 0 : PRINT_CHAR_THRESHOLD + 1);

        JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {

                r = parse_field(data, length, "PRIORITY=", &priority, &priority_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "_HOSTNAME=", &hostname, &hostname_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "SYSLOG_IDENTIFIER=", &identifier, &identifier_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "_COMM=", &comm, &comm_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "_PID=", &pid, &pid_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "SYSLOG_PID=", &fake_pid, &fake_pid_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "_SOURCE_REALTIME_TIMESTAMP=", &realtime, &realtime_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "_SOURCE_MONOTONIC_TIMESTAMP=", &monotonic, &monotonic_len);
                if (r < 0)
                        return r;
                else if (r > 0)
                        continue;

                r = parse_field(data, length, "MESSAGE=", &message, &message_len);
                if (r < 0)
                        return r;
        }
Example #29
0
/* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
 * page) into 'fm' for sending the specified flow_mod 'command' to a switch.
 * If 'actions' is specified, an action must be in 'string' and may be expanded
 * or reallocated.
 *
 * To parse syntax for an OFPT_FLOW_MOD (or NXT_FLOW_MOD), use an OFPFC_*
 * constant for 'command'.  To parse syntax for an OFPST_FLOW or
 * OFPST_AGGREGATE (or NXST_FLOW or NXST_AGGREGATE), use -1 for 'command'. */
void
parse_ofp_str(struct ofputil_flow_mod *fm, int command, const char *str_,
              bool verbose)
{
    enum {
        F_OUT_PORT = 1 << 0,
        F_ACTIONS = 1 << 1,
        F_TIMEOUT = 1 << 3,
        F_PRIORITY = 1 << 4,
        F_FLAGS = 1 << 5,
    } fields;
    char *string = xstrdup(str_);
    char *save_ptr = NULL;
    char *act_str = NULL;
    char *name;

    switch (command) {
    case -1:
        fields = F_OUT_PORT;
        break;

    case OFPFC_ADD:
        fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS;
        break;

    case OFPFC_DELETE:
        fields = F_OUT_PORT;
        break;

    case OFPFC_DELETE_STRICT:
        fields = F_OUT_PORT | F_PRIORITY;
        break;

    case OFPFC_MODIFY:
        fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS;
        break;

    case OFPFC_MODIFY_STRICT:
        fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS;
        break;

    default:
        NOT_REACHED();
    }

    match_init_catchall(&fm->match);
    fm->priority = OFP_DEFAULT_PRIORITY;
    fm->cookie = htonll(0);
    fm->cookie_mask = htonll(0);
    if (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT) {
        /* For modify, by default, don't update the cookie. */
        fm->new_cookie = htonll(UINT64_MAX);
    } else{
        fm->new_cookie = htonll(0);
    }
    fm->table_id = 0xff;
    fm->command = command;
    fm->idle_timeout = OFP_FLOW_PERMANENT;
    fm->hard_timeout = OFP_FLOW_PERMANENT;
    fm->buffer_id = UINT32_MAX;
    fm->out_port = OFPP_ANY;
    fm->flags = 0;
    if (fields & F_ACTIONS) {
        act_str = strstr(string, "action");
        if (!act_str) {
            ofp_fatal(str_, verbose, "must specify an action");
        }
        *act_str = '\0';

        act_str = strchr(act_str + 1, '=');
        if (!act_str) {
            ofp_fatal(str_, verbose, "must specify an action");
        }

        act_str++;
    }
    for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
         name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
        const struct protocol *p;

        if (parse_protocol(name, &p)) {
            match_set_dl_type(&fm->match, htons(p->dl_type));
            if (p->nw_proto) {
                match_set_nw_proto(&fm->match, p->nw_proto);
            }
        } else if (fields & F_FLAGS && !strcmp(name, "send_flow_rem")) {
            fm->flags |= OFPFF_SEND_FLOW_REM;
        } else if (fields & F_FLAGS && !strcmp(name, "check_overlap")) {
            fm->flags |= OFPFF_CHECK_OVERLAP;
        } else if (fields & F_FLAGS && !strcmp(name, "reset_counts")) {
            fm->flags |= OFPFF12_RESET_COUNTS;
        } else if (fields & F_FLAGS && !strcmp(name, "no_packet_counts")) {
            fm->flags |= OFPFF13_NO_PKT_COUNTS;
        } else if (fields & F_FLAGS && !strcmp(name, "no_byte_counts")) {
            fm->flags |= OFPFF13_NO_BYT_COUNTS;
        } else {
            char *value;

            value = strtok_r(NULL, ", \t\r\n", &save_ptr);
            if (!value) {
                ofp_fatal(str_, verbose, "field %s missing value", name);
            }

            if (!strcmp(name, "table")) {
                fm->table_id = str_to_u8(value, name);
            } else if (!strcmp(name, "out_port")) {
                if (!ofputil_port_from_string(value, &fm->out_port)) {
                    ofp_fatal(str_, verbose, "%s is not a valid OpenFlow port",
                              name);
                }
            } else if (fields & F_PRIORITY && !strcmp(name, "priority")) {
                fm->priority = str_to_u16(value, name);
            } else if (fields & F_TIMEOUT && !strcmp(name, "idle_timeout")) {
                fm->idle_timeout = str_to_u16(value, name);
            } else if (fields & F_TIMEOUT && !strcmp(name, "hard_timeout")) {
                fm->hard_timeout = str_to_u16(value, name);
            } else if (!strcmp(name, "cookie")) {
                char *mask = strchr(value, '/');

                if (mask) {
                    /* A mask means we're searching for a cookie. */
                    if (command == OFPFC_ADD) {
                        ofp_fatal(str_, verbose, "flow additions cannot use "
                                  "a cookie mask");
                    }
                    *mask = '\0';
                    fm->cookie = htonll(str_to_u64(value));
                    fm->cookie_mask = htonll(str_to_u64(mask+1));
                } else {
                    /* No mask means that the cookie is being set. */
                    if (command != OFPFC_ADD && command != OFPFC_MODIFY
                            && command != OFPFC_MODIFY_STRICT) {
                        ofp_fatal(str_, verbose, "cannot set cookie");
                    }
                    fm->new_cookie = htonll(str_to_u64(value));
                }
            } else if (mf_from_name(name)) {
                parse_field(mf_from_name(name), value, &fm->match);
            } else if (!strcmp(name, "duration")
                       || !strcmp(name, "n_packets")
                       || !strcmp(name, "n_bytes")
                       || !strcmp(name, "idle_age")
                       || !strcmp(name, "hard_age")) {
                /* Ignore these, so that users can feed the output of
                 * "ovs-ofctl dump-flows" back into commands that parse
                 * flows. */
            } else {
                ofp_fatal(str_, verbose, "unknown keyword %s", name);
            }
        }
    }
    if (!fm->cookie_mask && fm->new_cookie == htonll(UINT64_MAX)
            && (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT)) {
        /* On modifies without a mask, we are supposed to add a flow if
         * one does not exist.  If a cookie wasn't been specified, use a
         * default of zero. */
        fm->new_cookie = htonll(0);
    }
    if (fields & F_ACTIONS) {
        struct ofpbuf ofpacts;
        enum ofperr err;

        ofpbuf_init(&ofpacts, 32);
        str_to_inst_ofpacts(act_str, &ofpacts);
        fm->ofpacts_len = ofpacts.size;
        fm->ofpacts = ofpbuf_steal_data(&ofpacts);

        err = ofpacts_check(fm->ofpacts, fm->ofpacts_len, &fm->match.flow,
                            OFPP_MAX, 0);
        if (err) {
            exit(EXIT_FAILURE);
        }

    } else {
        fm->ofpacts_len = 0;
        fm->ofpacts = NULL;
    }

    free(string);
}
Example #30
0
int load_po(FILE *f)
{
	unsigned char buf[1024];
	unsigned char msgid[1024];
	unsigned char msgstr[1024];
	unsigned char bf[8192];
	struct charmap *po_map = locale_map;
	int preload_flag = 0;
	msgid[0] = 0;
	msgstr[0] = 0;
	while (preload_flag || fgets((char *)buf,sizeof(buf)-1,f)) {
		unsigned char *p;
		preload_flag = 0;
		p = buf;
		parse_ws(&p, '#');
		if (!parse_field(&p, "msgid")) {
			int ofst = 0;
			int len;
			msgid[0] = 0;
			parse_ws(&p, '#');
			while ((len = parse_string(&p, msgid + ofst, sizeof(msgid)-ofst)) >= 0) {
				preload_flag = 0;
				ofst += len;
				parse_ws(&p, '#');
				if (!*p) {
					if (fgets((char *)buf,sizeof(buf) - 1,f)) {
						p = buf;
						preload_flag = 1;
						parse_ws(&p, '#');
					} else {
						goto bye;
					}
				}
			}
		} else if (!parse_field(&p, "msgstr")) {
			int ofst = 0;
			int len;
			msgstr[0] = 0;
			parse_ws(&p, '#');
			while ((len = parse_string(&p, msgstr + ofst, sizeof(msgstr)-ofst)) >= 0) {
				preload_flag = 0;
				ofst += len;
				parse_ws(&p, '#');
				if (!*p) {
					if (fgets((char *)buf,sizeof(buf) - 1,f)) {
						p = buf;
						preload_flag = 1;
						parse_ws(&p, '#');
					} else {
						break;
					}
				}
			}
			if (msgid[0] && msgstr[0]) {
				/* Convert to locale character map */
				my_iconv(bf,locale_map,msgstr,po_map);
				/* Add to hash table */
				htadd(gettext_ht, strdup(msgid), strdup(bf));
			} else if (!msgid[0] && msgstr[0]) {
				unsigned char *p = (unsigned char *)strstr((char *)msgstr, "charset=");
				if (p) {
					/* Copy character set name up to next delimiter */
					int x;
					p += sizeof("charset=") - 1;
					while (*p == ' ' || *p == '\t') ++p;
					for (x = 0; p[x] && p[x] !='\n' && p[x] != '\r' && p[x] != ' ' &&
					            p[x] != '\t' && p[x] != ';' && p[x] != ','; ++x)
					            msgid[x] = p[x];
					msgid[x] = 0;
					po_map = find_charmap(msgid);
					if (!po_map)
						po_map = locale_map;
				}
			}
		}
	}
	bye:
	fclose(f);
	return 0;
}