static void handle_get_play_status(const void *buf, uint16_t len) { const struct hal_cmd_avrcp_get_play_status *cmd = buf; uint8_t status; struct avrcp_request *req; int ret; DBG(""); req = pop_request(AVRCP_GET_PLAY_STATUS, 0, false); if (!req) { status = HAL_STATUS_FAILED; goto done; } ret = avrcp_get_play_status_rsp(req->dev->session, req->transaction, cmd->position, cmd->duration, cmd->status); if (ret < 0) { status = HAL_STATUS_FAILED; g_free(req); goto done; } status = HAL_STATUS_SUCCESS; g_free(req); done: ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_PLAY_STATUS, status); }
void h2_mplx_request_done(h2_mplx **pm, int stream_id, const h2_request **preq) { h2_mplx *m = *pm; int acquired; if (enter_mutex(m, &acquired) == APR_SUCCESS) { h2_io *io = h2_io_set_get(m->stream_ios, stream_id); ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, m->c, "h2_mplx(%ld): request(%d) done", m->id, stream_id); if (io) { io->worker_done = 1; if (io->orphaned) { io_destroy(m, io, 0); if (m->join_wait) { apr_thread_cond_signal(m->join_wait); } } else { /* hang around until the stream deregisteres */ } } if (preq) { /* someone wants another request, if we have */ *preq = pop_request(m); } if (!preq || !*preq) { /* No request to hand back to the worker, NULLify reference * and decrement count */ *pm = NULL; } leave_mutex(m, acquired); } }
static int fn(void *d) { struct l4fdx_client *client = d; int err; err = sys_setregid(client->gid, client->gid); err = sys_setreuid(client->uid, client->uid); err = sys_setsid(); if (client->capname) snprintf(current->comm, sizeof(current->comm), "l4xfdx-%s", client->capname); else snprintf(current->comm, sizeof(current->comm), "l4xfdx-%lx", client->cap >> L4_CAP_SHIFT); current->comm[sizeof(current->comm) - 1] = 0; set_user_nice(current, -20); while (!should_stop || !list_empty(&client->req_list)) { struct internal_request *r; wait_event_interruptible(client->event, !list_empty(&client->req_list) || should_stop); r = pop_request(client->srv_obj); switch (r->type) { case L4FS_REQ_OPEN: fn_open(client->srv_obj, r); break; case L4FS_REQ_READ: fn_read(client->srv_obj, r); break; case L4FS_REQ_WRITE: fn_write(client->srv_obj, r); break; case L4FS_REQ_CLOSE: fn_close(client->srv_obj, r); break; case L4FS_REQ_FSTAT64: fn_fstat64(client->srv_obj, r); break; default: pr_err("l4fdx: Invalid type=%d\n", r->type); break; } } return 0; }
void free_request(jsonrpc_request_t* req) { if(!req) return; pop_request(req->id); CHECK_AND_FREE_EV(req->retry_ev); CHECK_AND_FREE_EV(req->timeout_ev); if(req->payload) json_decref(req->payload); pkg_free(req); }
const h2_request *h2_mplx_pop_request(h2_mplx *m, int *has_more) { const h2_request *req = NULL; apr_status_t status; int acquired; AP_DEBUG_ASSERT(m); if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) { if (m->aborted) { req = NULL; *has_more = 0; } else { req = pop_request(m); *has_more = !h2_tq_empty(m->q); } leave_mutex(m, acquired); } return req; }
static void handle_get_element_attrs_text(const void *buf, uint16_t len) { struct hal_cmd_avrcp_get_element_attrs_text *cmd = (void *) buf; uint8_t status; struct avrcp_request *req; uint8_t pdu[IPC_MTU]; uint8_t *ptr; size_t pdu_len; int ret; DBG(""); req = pop_request(AVRCP_GET_ELEMENT_ATTRIBUTES, 0, false); if (!req) { status = HAL_STATUS_FAILED; goto done; } ptr = (uint8_t *) &cmd->values[0]; pdu_len = 0; write_element_attrs(ptr, cmd->number, pdu, &pdu_len); ret = avrcp_get_element_attrs_rsp(req->dev->session, req->transaction, pdu, pdu_len); if (ret < 0) { status = HAL_STATUS_FAILED; g_free(req); goto done; } status = HAL_STATUS_SUCCESS; g_free(req); done: ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_ELEMENT_ATTRS_TEXT, status); }
static void handle_register_notification(const void *buf, uint16_t len) { struct hal_cmd_avrcp_register_notification *cmd = (void *) buf; uint8_t status; struct avrcp_request *req; uint8_t pdu[IPC_MTU]; size_t pdu_len; uint8_t code; bool peek = false; int ret; DBG(""); switch (cmd->type) { case HAL_AVRCP_EVENT_TYPE_INTERIM: code = AVC_CTYPE_INTERIM; peek = true; break; case HAL_AVRCP_EVENT_TYPE_CHANGED: code = AVC_CTYPE_CHANGED; break; default: status = HAL_STATUS_FAILED; goto done; } req = pop_request(AVRCP_REGISTER_NOTIFICATION, cmd->event, peek); if (!req) { status = HAL_STATUS_FAILED; goto done; } pdu[0] = cmd->event; pdu_len = 1; switch (cmd->event) { case AVRCP_EVENT_STATUS_CHANGED: case AVRCP_EVENT_TRACK_CHANGED: case AVRCP_EVENT_PLAYBACK_POS_CHANGED: memcpy(&pdu[1], cmd->data, cmd->len); pdu_len += cmd->len; break; default: status = HAL_STATUS_FAILED; goto done; } ret = avrcp_register_notification_rsp(req->dev->session, req->transaction, code, pdu, pdu_len); if (ret < 0) { status = HAL_STATUS_FAILED; if (!peek) g_free(req); goto done; } status = HAL_STATUS_SUCCESS; if (!peek) g_free(req); done: ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_REGISTER_NOTIFICATION, status); }
int handle_response(json_t* response) { int retval = 0; jsonrpc_request_t* req = NULL; json_t* return_obj = NULL; json_t* internal = NULL; char* freeme = NULL; /* check if json object */ if(!json_is_object(response)){ WARN("jsonrpc response is not an object\n"); return -1; } /* check version */ json_t* version = json_object_get(response, "jsonrpc"); if(!version) { WARN("jsonrpc response does not have a version.\n"); retval = -1; goto end; } const char* version_s = json_string_value(version); if(!version_s){ WARN("jsonrpc response version is not a string.\n"); retval = -1; goto end; } if (strlen(version_s) != (sizeof(JSONRPC_VERSION)-1) || strncmp(version_s, JSONRPC_VERSION, sizeof(JSONRPC_VERSION)-1) != 0) { WARN("jsonrpc response version is not %s. version: %s\n", JSONRPC_VERSION, version_s); retval = -1; goto end; } /* check for an id */ json_t* _id = json_object_get(response, "id"); if(!_id) { WARN("jsonrpc response does not have an id.\n"); retval = -1; goto end; } int id = json_integer_value(_id); if (!(req = pop_request(id))) { /* don't fail the server for an unrecognized id */ retval = 0; goto end; } return_obj = json_object(); json_t* error = json_object_get(response, "error"); // if the error value is null, we don't care bool _error = error && (json_typeof(error) != JSON_NULL); json_t* result = json_object_get(response, "result"); if(_error) { json_object_set(return_obj, "error", error); } if(result) { json_object_set(return_obj, "result", result); } if ((!result && !_error) || (result && _error)) { WARN("bad response\n"); internal = internal_error(JRPC_ERR_BAD_RESP, req->payload); json_object_update(return_obj, internal); if(internal) json_decref(internal); } pv_value_t val; if(jsontoval(&val, &freeme, return_obj)<0) { fail_request( JRPC_ERR_TO_VAL, req, "Failed to convert response json to pv\n"); retval = -1; goto end; } char* error_s = NULL; if(send_to_script(&val, req->cmd)>=0) { goto free_and_end; } if(_error) { // get code from error json_t* _code = json_object_get(error, "code"); if(_code) { int code = json_integer_value(_code); // check if code is in global_retry_ranges retry_range_t* tmpr; for(tmpr = global_retry_ranges; tmpr != NULL; tmpr = tmpr->next) { if((tmpr->start < tmpr->end && tmpr->start <= code && code <= tmpr->end) || (tmpr->end < tmpr->start && tmpr->end <= code && code <= tmpr->start) || (tmpr->start == tmpr->end && tmpr->start == code)) { if(schedule_retry(req)==0) { goto end; } break; } } } error_s = json_dumps(error, JSON_COMPACT); if(error_s) { WARN("Request received an error: \n%s\n", error_s); free(error_s); } else { fail_request( JRPC_ERR_BAD_RESP, req, "Could not convert 'error' response to string"); retval = -1; goto end; } } free_and_end: free_req_cmd(req->cmd); free_request(req); end: if(freeme) free(freeme); if(return_obj) json_decref(return_obj); return retval; }