static HttpHeader * make_http_header(char *r) { HttpHeader *h = NULL; HttpHeaderEntry *he = NULL; char *s = NULL; char *raw_header = NULL; char *raw_header_head = NULL; raw_header = strdup(r); /* Track this to free at the end */ raw_header_head = raw_header; h = malloc(sizeof(HttpHeader)); h->header_list = list_new(); /* Skip the first line: "HTTP/1.X NNN Comment\r?\n" */ s = raw_header; while (*s != '\0' && *s != '\r' && *s != '\n') { s++; } while (*s != '\0' && isspace(*s)) { s++; } raw_header = s; s = strstr(raw_header, ": "); while (s) { /* Set ':' to '\0' to terminate the key */ *s++ = '\0'; he = malloc(sizeof(HttpHeaderEntry)); he->key = strdup(raw_header); /* Make it lowercase so we can lookup case-insensitive */ string_lowercase(he->key); /* Now get the value */ s++; raw_header = s; while (*s != '\0' && *s != '\r' && *s != '\n') { s++; } *s++ = '\0'; he->value = strdup(raw_header); list_append(h->header_list, he); /* Go to the next line */ while (*s != '\0' && isspace(*s)) { s++; } raw_header = s; s = strstr(raw_header, ": "); } free(raw_header_head); return h; }
bool analyze_srt_timing(char *s, uint8_t * const flags) { char buf[MAXLINE + 1] = ""; strncpy(buf, s, MAXLINE); string_lowercase(buf, 0); /* these capabilities are mutually exclusive, therefore 'else if' * * see header for details and examples */ if (strstr(buf, "x1:") && strstr(buf, "y2:")) *flags |= SRT_E_HAVE_POSITION; else if (strstr(buf, "ssa:")) *flags |= SRT_E_HAVE_STYLE; return true; }
bool parse_srt_timing(srt_event *e, char *s, const uint8_t *flags) { char token[MAXLINE]; uint16_t i = 0; int *j; char *w_token = _("Can't get %s timing from this token: '%s' at line '%u'."); char *p = s, *v; bool result = true; struct point *xy; char *delim = ""; if ((i = _strtok(s, "-->")) <= 0) return false; strncpy(token, p, i); token[i] = '\0'; trim_spaces(token, LINE_START | LINE_END); if (!get_srt_timing(&e->start, token)) { log_msg(warn, w_token, "start", token, line_num); return false; } p = p + i + 3; /* " 00:00:00,000 " + "-->" */ while (*p == ' ') p++; /* " 00:00:00,000 --> |00:00:00,000" */ if ((i = _strtok(token, (flags) ? " " : "")) <= 0) return false; strncpy(token, p, i); if (!get_srt_timing(&e->end, token)) { log_msg(warn, w_token, "end", token, line_num); return false; } if (result && flags) { p += i; /* " 00:00:00,000 --> 00:00:00,000| ..." */ if (*flags & SRT_E_HAVE_POSITION) { delim = " "; trim_spaces(p, LINE_START); string_lowercase(p, 0); for (i = 0; (i = _strtok(p, delim)) > 0;) { strncpy(token, p, i); token[i] = '\0'; trim_spaces(token, LINE_END); v = strchr(token, ':'), v += 1; xy = (*(token + 1) == '1') ? &e->top_left : &e->bottom_right; j = (*token == 'x') ? &xy->x : &xy->y ; *j = atoi(v); p += i; trim_spaces(p, LINE_START); } } else if (*flags & SRT_E_HAVE_STYLE) { delim = ","; /* TODO: make it "implemented" */ log_msg(error, MSG_W_UNIMPL); } } return result; }