ID3v2_frame* parse_frame(char* bytes, int offset, int version) { ID3v2_frame* frame = new_frame(); // Parse frame header memcpy(frame->frame_id, bytes + offset, ID3_FRAME_ID); // Check if we are into padding if(memcmp(frame->frame_id, "\0\0\0\0", 4) == 0) { return NULL; } frame->size = btoi(bytes, 4, offset += ID3_FRAME_ID); if(version == ID3v24) { frame->size = syncint_decode(frame->size); } memcpy(frame->flags, bytes + (offset += ID3_FRAME_SIZE), 2); // Load frame data frame->data = (char*) malloc(frame->size * sizeof(char*)); memcpy(frame->data, bytes + (offset += ID3_FRAME_FLAGS), frame->size); return frame; }
ID3v2_header* get_tag_header(const char* file_name) { char buffer[ID3_HEADER]; FILE* file = fopen(file_name, "rb"); if(file == NULL) { perror("Error opening file"); return NULL; } fread(buffer, ID3_HEADER, 1, file); fclose(file); ID3v2_header* tag_header = new_header(); if( ! _has_id3v2tag(buffer)) { if (tag_header != NULL) free (tag_header); return NULL; } int position = 0; memcpy(tag_header->tag, buffer, ID3_HEADER_TAG); tag_header->major_version = buffer[position += ID3_HEADER_TAG]; tag_header->minor_version = buffer[position += ID3_HEADER_VERSION]; tag_header->flags = buffer[position += ID3_HEADER_REVISION]; tag_header->tag_size = syncint_decode(btoi(buffer, ID3_HEADER_SIZE, position += ID3_HEADER_FLAGS)); return tag_header; }