| 28 | /* ── extractPathFromURL ──────────────────────────────────────────── */ |
| 29 | |
| 30 | const char *cbm_extract_path_from_url(const char *url, char *buf, size_t buf_sz) { |
| 31 | if (!url || !buf || buf_sz == 0) { |
| 32 | if (buf) { |
| 33 | buf[0] = '\0'; |
| 34 | } |
| 35 | return buf ? buf : ""; |
| 36 | } |
| 37 | |
| 38 | /* Find the third '/' which starts the path: https://host/path */ |
| 39 | int slashes = 0; |
| 40 | int idx = TRACE_NOT_FOUND; |
| 41 | for (int i = 0; url[i]; i++) { |
| 42 | if (url[i] == '/') { |
| 43 | slashes++; |
| 44 | if (slashes == TRACE_PATH_SLASHES) { |
| 45 | idx = i; |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | if (idx < 0) { |
| 51 | buf[0] = '\0'; |
| 52 | return buf; |
| 53 | } |
| 54 | |
| 55 | /* Copy path, stopping at '?' */ |
| 56 | size_t j = 0; |
| 57 | for (int i = idx; url[i] && url[i] != '?' && j < buf_sz - SKIP_ONE; i++) { |
| 58 | buf[j++] = url[i]; |
| 59 | } |
| 60 | buf[j] = '\0'; |
| 61 | return buf; |
| 62 | } |
| 63 | |
| 64 | /* ── parseDuration ───────────────────────────────────────────────── */ |
| 65 |
no outgoing calls
no test coverage detected