| 1229 | } |
| 1230 | |
| 1231 | static bool runtime_worker_handle_subscribe(cbm_daemon_runtime_worker_t *worker, |
| 1232 | const uint8_t *payload, uint32_t length) { |
| 1233 | if (!runtime_worker_service_running(worker) || !payload || |
| 1234 | length < SUBSCRIBE_REQUEST_PREFIX_SIZE) { |
| 1235 | return false; |
| 1236 | } |
| 1237 | uint32_t key_length = runtime_get_u32(payload); |
| 1238 | if (key_length == 0 || key_length > CBM_DAEMON_RUNTIME_PROJECT_KEY_MAX || |
| 1239 | length != SUBSCRIBE_REQUEST_PREFIX_SIZE + key_length) { |
| 1240 | return false; |
| 1241 | } |
| 1242 | char project_key[CBM_DAEMON_RUNTIME_PROJECT_KEY_MAX + 1]; |
| 1243 | memcpy(project_key, payload + SUBSCRIBE_REQUEST_PREFIX_SIZE, key_length); |
| 1244 | project_key[key_length] = '\0'; |
| 1245 | if (memchr(project_key, '\0', key_length) != NULL) { |
| 1246 | return false; |
| 1247 | } |
| 1248 | cbm_daemon_subscription_id_t subscription_id = CBM_DAEMON_SUBSCRIPTION_ID_INVALID; |
| 1249 | cbm_daemon_subscription_result_t result = cbm_daemon_job_subscribe( |
| 1250 | worker->service->coordinator, worker->client_id, project_key, &subscription_id); |
| 1251 | uint8_t response[SUBSCRIBE_RESPONSE_SIZE]; |
| 1252 | runtime_put_u32(response, (uint32_t)result); |
| 1253 | runtime_put_u64(response + 4, subscription_id); |
| 1254 | return runtime_worker_send_frame(worker, CBM_DAEMON_FRAME_RESPONSE, |
| 1255 | CBM_DAEMON_RUNTIME_OP_JOB_SUBSCRIBE, response, |
| 1256 | (uint32_t)sizeof(response)); |
| 1257 | } |
| 1258 | |
| 1259 | static bool runtime_worker_handle_unsubscribe(cbm_daemon_runtime_worker_t *worker, |
| 1260 | const uint8_t *payload, uint32_t length) { |
no test coverage detected