| 47 | }; |
| 48 | |
| 49 | TSRemapStatus |
| 50 | TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri) |
| 51 | { |
| 52 | TSRemapStatus status{TSREMAP_ERROR}; |
| 53 | int i, len; |
| 54 | time_t t, e; |
| 55 | EVP_MD_CTX *ctx; |
| 56 | struct sockaddr_in *in; |
| 57 | const char *qh, *ph, *ip; |
| 58 | unsigned char md[MD5_DIGEST_LENGTH]; |
| 59 | secure_link_info *sli = static_cast<secure_link_info *>(ih); |
| 60 | char *token = nullptr, *tokenptr = nullptr, *expire = nullptr, *expireptr = nullptr, *path = nullptr; |
| 61 | char *s, *ptr, *saveptr = nullptr, *val, hash[32] = ""; |
| 62 | |
| 63 | in = (struct sockaddr_in *)TSHttpTxnClientAddrGet(rh); |
| 64 | ip = inet_ntoa(in->sin_addr); |
| 65 | s = TSUrlStringGet(rri->requestBufp, rri->requestUrl, &len); |
| 66 | Dbg(dbg_ctl, "request [%.*s] from [%s]", len, s, ip); |
| 67 | TSfree(s); |
| 68 | |
| 69 | qh = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &len); |
| 70 | if (qh && len > 0) { |
| 71 | s = TSstrndup(qh, len); |
| 72 | if ((ptr = strtok_r(s, "&", &saveptr)) != nullptr) { |
| 73 | do { |
| 74 | if ((val = strchr(ptr, '=')) != nullptr) { |
| 75 | *val++ = '\0'; |
| 76 | if (strcmp(ptr, "st") == 0) { |
| 77 | tokenptr = val; |
| 78 | } else if (strcmp(ptr, "ex") == 0) { |
| 79 | expireptr = val; |
| 80 | } |
| 81 | } else { |
| 82 | TSError("[%s] Invalid parameter [%s]", PLUGIN_NAME, ptr); |
| 83 | break; |
| 84 | } |
| 85 | } while ((ptr = strtok_r(nullptr, "&", &saveptr)) != nullptr); |
| 86 | token = (nullptr == tokenptr ? nullptr : TSstrdup(tokenptr)); |
| 87 | expire = (nullptr == expireptr ? nullptr : TSstrdup(expireptr)); |
| 88 | } else { |
| 89 | TSError("[%s] strtok didn't find a & in the query string", PLUGIN_NAME); |
| 90 | /* this is just example, so set fake params to prevent plugin crash */ |
| 91 | token = TSstrdup("d41d8cd98f00b204e9800998ecf8427e"); |
| 92 | expire = TSstrdup("00000000"); |
| 93 | } |
| 94 | TSfree(s); |
| 95 | } else { |
| 96 | TSError("[%s] TSUrlHttpQueryGet returns empty value", PLUGIN_NAME); |
| 97 | } |
| 98 | |
| 99 | ph = TSUrlPathGet(rri->requestBufp, rri->requestUrl, &len); |
| 100 | if (ph && len > 0) { |
| 101 | s = TSstrndup(ph, len); |
| 102 | if ((ptr = strrchr(s, '/')) != nullptr) { |
| 103 | *++ptr = '\0'; |
| 104 | } |
| 105 | path = TSstrdup(s); |
| 106 | TSfree(s); |
nothing calls this directly
no test coverage detected