static int on_body_parse_response(http_parser *parser, const char *str, size_t len) { transport_http *t = (transport_http *) parser->data; git_buf *buf = &t->buf; git_vector *common = &t->common; int error; const char *line_end, *ptr; if (len == 0) { /* EOF */ if (git_buf_len(buf) != 0) { giterr_set(GITERR_NET, "Unexpected EOF"); return t->error = -1; } else { return 0; } } git_buf_put(buf, str, len); ptr = buf->ptr; while (1) { git_pkt *pkt; if (git_buf_len(buf) == 0) return 0; error = git_pkt_parse_line(&pkt, ptr, &line_end, git_buf_len(buf)); if (error == GIT_EBUFS) { return 0; /* Ask for more */ } if (error < 0) return t->error = -1; git_buf_consume(buf, line_end); if (pkt->type == GIT_PKT_PACK) { git__free(pkt); t->pack_ready = 1; return 0; } if (pkt->type == GIT_PKT_NAK) { git__free(pkt); return 0; } if (pkt->type != GIT_PKT_ACK) { git__free(pkt); continue; } if (git_vector_insert(common, pkt) < 0) return -1; } return error; }
int parse_pkt_line(git_repository *repo, int argc, char **argv) { char *line = argv[1]; char oid[GIT_OID_HEXSZ+1] = {0}; const char *after = line; int error; unsigned int len; git_pkt *pkt; /* * Assume that the user has piped a file in */ fseek(stdin, 0, SEEK_END); len = ftell(stdin); fseek(stdin, 0, SEEK_SET); line = malloc(len+1); if(line == NULL) return GIT_ENOMEM; memset(line, 0, len+1); fread(line, len, sizeof(char), stdin); after = line; while(*after != '\0'){ error = git_pkt_parse_line(&pkt, line, &after, len); if (error < GIT_SUCCESS) return error; line = (char *) after; switch(pkt->type){ case GIT_PKT_REF: { git_remote_head *h = &(((git_pkt_ref *)pkt)->head); const char *caps = ((git_pkt_ref *)pkt)->capabilities; //puts("Found a ref pkt"); git_oid_fmt(oid, &h->oid); printf("%s\t%s\n", oid, h->name); if(caps != NULL) printf(" Capabilities: %s\n", caps); break; } case GIT_PKT_FLUSH: puts("flush! do something!"); default: printf("default: %d\n", *after); } } return error; }