| 314 | #endif |
| 315 | |
| 316 | extern "C" int SrtUserPasswordHook(void* , SRTSOCKET acpsock, int hsv, const sockaddr*, const char* streamid) |
| 317 | { |
| 318 | if (hsv < 5) |
| 319 | { |
| 320 | Verb("SrtUserPasswordHook: HS version 4 doesn't support extended handshake"); |
| 321 | return -1; |
| 322 | } |
| 323 | |
| 324 | static const map<string, string> passwd { |
| 325 | {"admin", "thelocalmanager"}, |
| 326 | {"user", "verylongpassword"} |
| 327 | }; |
| 328 | |
| 329 | // Try the "standard interpretation" with username at key u |
| 330 | string username; |
| 331 | |
| 332 | static const char stdhdr [] = "#!::"; |
| 333 | uint32_t* pattern = (uint32_t*)stdhdr; |
| 334 | |
| 335 | if (strlen(streamid) > 4 && *(uint32_t*)streamid == *pattern) |
| 336 | { |
| 337 | vector<string> items; |
| 338 | Split(streamid+4, ',', back_inserter(items)); |
| 339 | for (auto& i: items) |
| 340 | { |
| 341 | vector<string> kv; |
| 342 | Split(i, '=', back_inserter(kv)); |
| 343 | if (kv.size() == 2 && kv[0] == "u") |
| 344 | { |
| 345 | username = kv[1]; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | // By default the whole streamid is username |
| 352 | username = streamid; |
| 353 | } |
| 354 | |
| 355 | // This hook sets the password to the just accepted socket |
| 356 | // depending on the user |
| 357 | |
| 358 | string exp_pw = passwd.at(username); |
| 359 | |
| 360 | srt_setsockflag(acpsock, SRTO_PASSPHRASE, exp_pw.c_str(), int(exp_pw.size())); |
| 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | struct RejectData |
| 366 | { |
nothing calls this directly
no test coverage detected