| 1479 | } |
| 1480 | |
| 1481 | static bool runtime_worker_handle_subscribe(cbm_daemon_runtime_worker_t *worker, |
| 1482 | const uint8_t *payload, uint32_t length) { |
| 1483 | if (!runtime_worker_service_running(worker) || !payload || |
| 1484 | length < SUBSCRIBE_REQUEST_PREFIX_SIZE) { |
| 1485 | return false; |
| 1486 | } |
| 1487 | uint32_t key_length = runtime_get_u32(payload); |
| 1488 | if (key_length == 0 || key_length > CBM_DAEMON_RUNTIME_PROJECT_KEY_MAX || |
| 1489 | length != SUBSCRIBE_REQUEST_PREFIX_SIZE + key_length) { |
| 1490 | return false; |
| 1491 | } |
| 1492 | char project_key[CBM_DAEMON_RUNTIME_PROJECT_KEY_MAX + 1]; |
| 1493 | memcpy(project_key, payload + SUBSCRIBE_REQUEST_PREFIX_SIZE, key_length); |
| 1494 | project_key[key_length] = '\0'; |
| 1495 | if (memchr(project_key, '\0', key_length) != NULL) { |
| 1496 | return false; |
| 1497 | } |
| 1498 | cbm_daemon_subscription_id_t subscription_id = CBM_DAEMON_SUBSCRIPTION_ID_INVALID; |
| 1499 | cbm_daemon_subscription_result_t result = cbm_daemon_job_subscribe( |
| 1500 | worker->service->coordinator, worker->client_id, project_key, &subscription_id); |
| 1501 | uint8_t response[SUBSCRIBE_RESPONSE_SIZE]; |
| 1502 | runtime_put_u32(response, (uint32_t)result); |
| 1503 | runtime_put_u64(response + 4, subscription_id); |
| 1504 | return runtime_worker_send_frame(worker, CBM_DAEMON_FRAME_RESPONSE, |
| 1505 | CBM_DAEMON_RUNTIME_OP_JOB_SUBSCRIBE, response, |
| 1506 | (uint32_t)sizeof(response)); |
| 1507 | } |
| 1508 | |
| 1509 | static bool runtime_worker_handle_unsubscribe(cbm_daemon_runtime_worker_t *worker, |
| 1510 | const uint8_t *payload, uint32_t length) { |
no test coverage detected