static int sgen_parse_param(struct sgen_generator *g, struct codec *c, const char *type, const char *key, char *value) { char *endptr, *value1; switch (g->type) { case SGEN_TYPE_DELTA: if (strcmp(key, "offset") == 0) { g->offset = parse_len(value, c->fs, &endptr); if (check_endptr(type, value, endptr, key)) return -1; if (g->offset < 0 || (c->frames > 0 && g->offset >= c->frames)) { LOG(LL_ERROR, "%s: %s: error: %s out of range\n", dsp_globals.prog_name, type, key); return -1; } } else return 1; break; case SGEN_TYPE_SINE: if (strcmp(key, "freq") == 0) { value1 = isolate(value, '-'); SGEN_PARSE_FREQ_PARAM(g->freq0, c->fs, type, key, value, endptr); g->freq1 = g->freq0; if (*value1 != '\0') SGEN_PARSE_FREQ_PARAM(g->freq1, c->fs, type, key, value1, endptr); } else return 1; break; } return 0; }
void log_get_values_result(in_segment_t const &data) { in_t::ptr_t ptr = data; while(ptr) { size_t key_len = parse_len(ptr); size_t val_len = parse_len(ptr); string_t key(ptr, key_len); ptr += key_len; string_t val(ptr, val_len); ptr += val_len; log_info( "\"%.*s\" -> \"%.*s\"", (int)key.size(), key.ptr(), (int)val.size(), val.ptr() ); } }
/** @param buf_ptr the raw data from the simple tunnel connection * * Parses a journal subcription using simple tunnel format and * fires Events on the specified CKNServer object as they are * found. Data is passed in in an mb_buf_ptr structure. The object * copies any data it needs from the buffer. It returns an * mb_buf_ptr struct that points to the unparsed portion of the buffer. * it should be called again with the return value until the returned * mb_buf_ptr.len == 0. * */ mb_buf_ptr SimpleParser::parse(mb_buf_ptr buf_ptr) { //if it is not found, look for the length first if (!len_found) buf_ptr = parse_len(buf_ptr); if (len_found) buf_ptr = parse_event(buf_ptr); //return wherever we have gotten to in the buffer return buf_ptr; }
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t bufflen) { int error = GIT_SUCCESS; size_t len; /* Not even enough for the length */ if (bufflen > 0 && bufflen < PKT_LEN_SIZE) return GIT_ESHORTBUFFER; error = parse_len(line); if (error < GIT_SUCCESS) { return git__throw(error, "Failed to parse pkt length"); } len = error; /* * If we were given a buffer length, then make sure there is * enough in the buffer to satisfy this line */ if (bufflen > 0 && bufflen < len) return GIT_ESHORTBUFFER; line += PKT_LEN_SIZE; /* * TODO: How do we deal with empty lines? Try again? with the next * line? */ if (len == PKT_LEN_SIZE) { *out = line; return GIT_SUCCESS; } if (len == 0) { /* Flush pkt */ *out = line; return flush_pkt(head); } len -= PKT_LEN_SIZE; /* the encoded length includes its own size */ /* * For now, we're just going to assume we're parsing references */ error = ref_pkt(head, line, len); *out = line + len; return error; }
int git_pkt_parse_line( git_pkt **head, const char *line, const char **out, size_t bufflen) { int ret; int32_t len; /* Not even enough for the length */ if (bufflen > 0 && bufflen < PKT_LEN_SIZE) return GIT_EBUFS; len = parse_len(line); if (len < 0) { /* * If we fail to parse the length, it might be because the * server is trying to send us the packfile already. */ if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) { giterr_clear(); *out = line; return pack_pkt(head); } return (int)len; } /* * If we were given a buffer length, then make sure there is * enough in the buffer to satisfy this line */ if (bufflen > 0 && bufflen < (size_t)len) return GIT_EBUFS; /* * The length has to be exactly 0 in case of a flush * packet or greater than PKT_LEN_SIZE, as the decoded * length includes its own encoded length of four bytes. */ if (len != 0 && len < PKT_LEN_SIZE) return GIT_ERROR; line += PKT_LEN_SIZE; /* * The Git protocol does not specify empty lines as part * of the protocol. Not knowing what to do with an empty * line, we should return an error upon hitting one. */ if (len == PKT_LEN_SIZE) { giterr_set_str(GITERR_NET, "Invalid empty packet"); return GIT_ERROR; } if (len == 0) { /* Flush pkt */ *out = line; return flush_pkt(head); } len -= PKT_LEN_SIZE; /* the encoded length includes its own size */ if (*line == GIT_SIDE_BAND_DATA) ret = data_pkt(head, line, len); else if (*line == GIT_SIDE_BAND_PROGRESS) ret = sideband_progress_pkt(head, line, len); else if (*line == GIT_SIDE_BAND_ERROR) ret = sideband_error_pkt(head, line, len); else if (!git__prefixcmp(line, "ACK")) ret = ack_pkt(head, line, len); else if (!git__prefixcmp(line, "NAK")) ret = nak_pkt(head); else if (!git__prefixcmp(line, "ERR ")) ret = err_pkt(head, line, len); else if (*line == '#') ret = comment_pkt(head, line, len); else if (!git__prefixcmp(line, "ok")) ret = ok_pkt(head, line, len); else if (!git__prefixcmp(line, "ng")) ret = ng_pkt(head, line, len); else if (!git__prefixcmp(line, "unpack")) ret = unpack_pkt(head, line, len); else ret = ref_pkt(head, line, len); *out = line + len; return ret; }
struct codec * sgen_codec_init(const char *path, const char *type, const char *enc, int fs, int channels, int endian, int mode) { char *args = NULL, *arg, *gen_type, *len_str, *next_arg, *next_type, *value, *endptr; int parse_ret; struct codec *c; struct sgen_state *state; struct sgen_generator *g; c = calloc(1, sizeof(struct codec)); c->path = path; c->type = type; c->enc = "sample_t"; c->fs = fs; c->channels = channels; c->prec = 53; c->frames = -1; c->read = sgen_read; c->write = sgen_write; c->seek = sgen_seek; c->delay = sgen_delay; c->drop = sgen_drop; c->pause = sgen_pause; c->destroy = sgen_destroy; state = calloc(1, sizeof(struct sgen_state)); state->n = 0; c->data = state; args = arg = strdup(path); len_str = isolate(arg, '+'); if (*len_str != '\0') { c->frames = parse_len(len_str, fs, &endptr); if (check_endptr(type, len_str, endptr, "length")) goto fail; if (c->frames <= 0) { LOG(LL_ERROR, "%s: %s: error: length cannot be <= 0\n", dsp_globals.prog_name, type); goto fail; } /* LOG(LL_VERBOSE, "%s: %s: info: length=%zd\n", dsp_globals.prog_name, type, c->frames); */ } while (*arg != '\0') { next_type = isolate(arg, '/'); next_arg = isolate(arg, ':'); value = isolate(arg, '@'); /* LOG(LL_VERBOSE, "%s: %s: info: type=%s channel_selector=%s\n", dsp_globals.prog_name, type, arg, value); */ state->g = realloc(state->g, (state->n + 1) * sizeof(struct sgen_generator)); g = &state->g[state->n]; memset(g, 0, sizeof(struct sgen_generator)); g->channel_selector = NEW_SELECTOR(channels); SET_SELECTOR(g->channel_selector, channels); ++state->n; gen_type = arg; if (strcmp(gen_type, "delta") == 0) g->type = SGEN_TYPE_DELTA; else if (strcmp(gen_type, "sine") == 0) g->type = SGEN_TYPE_SINE; else { LOG(LL_ERROR, "%s: %s: error: illegal type: %s\n", dsp_globals.prog_name, type, gen_type); goto fail; } sgen_init_generator(g, c); if (*value != '\0' && parse_selector(value, g->channel_selector, channels)) goto fail; arg = next_arg; while (*arg != '\0') { next_arg = isolate(arg, ':'); value = isolate(arg, '='); /* LOG(LL_VERBOSE, "%s: %s: %s: arg: key=%s value=%s\n", dsp_globals.prog_name, type, gen_type, arg, value); */ parse_ret = sgen_parse_param(g, c, type, arg, value); if (parse_ret == 1) { LOG(LL_ERROR, "%s: %s: %s: error: illegal parameter: %s\n", dsp_globals.prog_name, type, gen_type, arg); goto fail; } else if (parse_ret == -1) goto fail; arg = next_arg; } sgen_prepare_generator(g, c); arg = next_type; } done: free(args); return c; fail: sgen_destroy(c); free(c); c = NULL; goto done; }
int git_pkt_parse_line( git_pkt **head, const char *line, const char **out, size_t bufflen) { int ret; int32_t len; /* Not even enough for the length */ if (bufflen > 0 && bufflen < PKT_LEN_SIZE) return GIT_EBUFS; len = parse_len(line); if (len < 0) { /* * If we fail to parse the length, it might be because the * server is trying to send us the packfile already. */ if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) { giterr_clear(); *out = line; return pack_pkt(head); } return (int)len; } /* * If we were given a buffer length, then make sure there is * enough in the buffer to satisfy this line */ if (bufflen > 0 && bufflen < (size_t)len) return GIT_EBUFS; line += PKT_LEN_SIZE; /* * TODO: How do we deal with empty lines? Try again? with the next * line? */ if (len == PKT_LEN_SIZE) { *out = line; return 0; } if (len == 0) { /* Flush pkt */ *out = line; return flush_pkt(head); } len -= PKT_LEN_SIZE; /* the encoded length includes its own size */ /* Assming the minimal size is actually 4 */ if (!git__prefixcmp(line, "ACK")) ret = ack_pkt(head, line, len); else if (!git__prefixcmp(line, "NAK")) ret = nak_pkt(head); else if (!git__prefixcmp(line, "ERR ")) ret = err_pkt(head, line, len); else if (*line == '#') ret = comment_pkt(head, line, len); else ret = ref_pkt(head, line, len); *out = line + len; return ret; }