| 420 | } |
| 421 | |
| 422 | void CRegister::CProtocol::CJob::Run() |
| 423 | { |
| 424 | m_pHttp->Run(m_pRegister); |
| 425 | m_pRegister->Wait(); |
| 426 | if(m_pRegister->State() != EHttpState::DONE) |
| 427 | { |
| 428 | // TODO: exponential backoff |
| 429 | log_error(ProtocolToSystem(m_Protocol), "error sending request to master"); |
| 430 | return; |
| 431 | } |
| 432 | json_value *pJson = m_pRegister->ResultJson(); |
| 433 | if(!pJson) |
| 434 | { |
| 435 | log_error(ProtocolToSystem(m_Protocol), "non-JSON response from master"); |
| 436 | return; |
| 437 | } |
| 438 | const json_value &Json = *pJson; |
| 439 | const json_value &StatusString = Json["status"]; |
| 440 | if(StatusString.type != json_string) |
| 441 | { |
| 442 | json_value_free(pJson); |
| 443 | log_error(ProtocolToSystem(m_Protocol), "invalid JSON response from master"); |
| 444 | return; |
| 445 | } |
| 446 | int Status; |
| 447 | if(StatusFromString(&Status, StatusString)) |
| 448 | { |
| 449 | log_error(ProtocolToSystem(m_Protocol), "invalid status from master: %s", (const char *)StatusString); |
| 450 | json_value_free(pJson); |
| 451 | return; |
| 452 | } |
| 453 | if(Status == STATUS_ERROR) |
| 454 | { |
| 455 | const json_value &Message = Json["message"]; |
| 456 | if(Message.type != json_string) |
| 457 | { |
| 458 | json_value_free(pJson); |
| 459 | log_error(ProtocolToSystem(m_Protocol), "invalid JSON error response from master"); |
| 460 | return; |
| 461 | } |
| 462 | log_error(ProtocolToSystem(m_Protocol), "error response from master: %d: %s", m_pRegister->StatusCode(), (const char *)Message); |
| 463 | json_value_free(pJson); |
| 464 | return; |
| 465 | } |
| 466 | if(m_pRegister->StatusCode() >= 400) |
| 467 | { |
| 468 | log_error(ProtocolToSystem(m_Protocol), "non-success status code %d from master without error code", m_pRegister->StatusCode()); |
| 469 | json_value_free(pJson); |
| 470 | return; |
| 471 | } |
| 472 | { |
| 473 | const CLockScope LockScope(m_pShared->m_Lock); |
| 474 | if(Status != m_pShared->m_LatestResponseStatus) |
| 475 | { |
| 476 | if(Status != STATUS_OK) |
| 477 | { |
| 478 | log_debug(ProtocolToSystem(m_Protocol), "status: %s", (const char *)StatusString); |
| 479 | } |
no test coverage detected