本文整理汇总了C++中send_error_response函数的典型用法代码示例。如果您正苦于以下问题:C++ send_error_response函数的具体用法?C++ send_error_response怎么用?C++ send_error_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_error_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dispatch_command
bool dispatch_command(struct watchman_client *client, json_t *args)
{
watchman_command_func func;
const char *cmd_name;
w_string_t *cmd;
if (!json_array_size(args)) {
send_error_response(client,
"invalid command (expected an array with some elements!)");
return false;
}
cmd_name = json_string_value(json_array_get(args, 0));
if (!cmd_name) {
send_error_response(client,
"invalid command: expected element 0 to be the command name");
return false;
}
cmd = w_string_new(cmd_name);
func = (watchman_command_func)w_ht_get(command_funcs, (w_ht_val_t)cmd);
w_string_delref(cmd);
if (func) {
func(client, args);
return true;
}
send_error_response(client, "unknown command %s", cmd_name);
return false;
}
开发者ID:baeeq,项目名称:watchman,代码行数:30,代码来源:listener.c
示例2: handle_flush
static void handle_flush(const char *req, int *req_index)
{
char dirstr[MAXATOMLEN];
if (ei_decode_atom(req, req_index, dirstr) < 0) {
send_error_response("einval");
return;
}
enum uart_direction direction;
if (strcmp(dirstr, "receive") == 0)
direction = UART_DIRECTION_RECEIVE;
else if (strcmp(dirstr, "transmit") == 0)
direction = UART_DIRECTION_TRANSMIT;
else if (strcmp(dirstr, "both") == 0)
direction = UART_DIRECTION_BOTH;
else {
send_error_response("einval");
return;
}
if (!uart_is_open(uart)) {
send_error_response("ebadf");
return;
}
if (uart_flush(uart, direction) >= 0)
send_ok_response();
else
send_error_response(uart_last_error());
}
开发者ID:nerves-project,项目名称:nerves_uart,代码行数:30,代码来源:circuits_uart.c
示例3: cmd_since
/* since /root <timestamp> [patterns] */
static void cmd_since(struct watchman_client* client, const json_ref& args) {
const char *clockspec;
/* resolve the root */
if (json_array_size(args) < 3) {
send_error_response(client, "not enough arguments for 'since'");
return;
}
auto root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
auto clock_ele = json_array_get(args, 2);
clockspec = json_string_value(clock_ele);
if (!clockspec) {
send_error_response(client,
"expected argument 2 to be a valid clockspec");
return;
}
auto query = w_query_parse_legacy(root, args, 3, nullptr, clockspec, nullptr);
auto res = w_query_execute(query.get(), root, nullptr);
auto response = make_response();
response.set({{"is_fresh_instance", json_boolean(res.is_fresh_instance)},
{"clock", res.clockAtStartOfQuery.toJson()},
{"files", std::move(res.resultsArray)}});
add_root_warnings_to_response(response, root);
send_and_dispose_response(client, std::move(response));
}
开发者ID:niclasr,项目名称:watchman,代码行数:34,代码来源:since.cpp
示例4: handle_signals
static void handle_signals(const char *req, int *req_index)
{
// No arguments
(void) req;
(void) req_index;
if (!uart_is_open(uart)) {
send_error_response("ebadf");
return;
}
struct uart_signals sig;
if (uart_get_signals(uart, &sig) >= 0) {
char resp[128];
int resp_index = sizeof(uint16_t);
resp[resp_index++] = response_id;
ei_encode_version(resp, &resp_index);
ei_encode_tuple_header(resp, &resp_index, 2);
ei_encode_atom(resp, &resp_index, "ok");
ei_encode_map_header(resp, &resp_index, 8);
encode_kv_bool(resp, &resp_index, "dsr", sig.dsr);
encode_kv_bool(resp, &resp_index, "dtr", sig.dtr);
encode_kv_bool(resp, &resp_index, "rts", sig.rts);
encode_kv_bool(resp, &resp_index, "st", sig.st);
encode_kv_bool(resp, &resp_index, "sr", sig.sr);
encode_kv_bool(resp, &resp_index, "cts", sig.cts);
encode_kv_bool(resp, &resp_index, "cd", sig.cd);
encode_kv_bool(resp, &resp_index, "rng", sig.rng);
erlcmd_send(resp, resp_index);
} else
send_error_response(uart_last_error());
}
开发者ID:nerves-project,项目名称:nerves_uart,代码行数:32,代码来源:circuits_uart.c
示例5: handle_query_variable
/*!
* \brief Handles the SOAP requests to querry the state variables.
* This functionality has been deprecated in the UPnP V1.0 architecture.
*/
static UPNP_INLINE void handle_query_variable(
IN SOCKINFO *info,
IN http_message_t *request,
IN IXML_Document *xml_doc)
{
UpnpStateVarRequest *variable = UpnpStateVarRequest_new();
Upnp_FunPtr soap_event_callback;
void *cookie;
char var_name[LINE_SIZE];
const char *err_str;
int err_code;
if (get_var_name(xml_doc, var_name) != 0) {
send_error_response(info, SOAP_INVALID_VAR,
Soap_Invalid_Var, request);
return;
}
/* get info for event */
err_code = get_device_info(request, 1, xml_doc,
info->foreign_sockaddr.ss_family,
(UpnpString *)UpnpStateVarRequest_get_DevUDN(variable),
(UpnpString *)UpnpStateVarRequest_get_ServiceID(variable),
&soap_event_callback, &cookie);
if (err_code != 0) {
send_error_response(info, SOAP_INVALID_VAR,
Soap_Invalid_Var, request);
return;
}
UpnpStateVarRequest_set_ErrCode(variable, UPNP_E_SUCCESS);
UpnpStateVarRequest_strcpy_StateVarName(variable, var_name);
UpnpStateVarRequest_set_CtrlPtIPAddr(variable, &info->foreign_sockaddr);
/* send event */
soap_event_callback(UPNP_CONTROL_GET_VAR_REQUEST, variable, cookie);
UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__,
"Return from callback for var request\n");
/* validate, and handle result */
if (UpnpStateVarRequest_get_CurrentVal(variable) == NULL) {
err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed;
send_error_response(info, SOAP_INVALID_VAR, Soap_Invalid_Var,
request);
return;
}
if (UpnpStateVarRequest_get_ErrCode(variable) != UPNP_E_SUCCESS) {
if (UpnpString_get_Length(UpnpStateVarRequest_get_ErrStr(variable)) > 0) {
err_code = SOAP_INVALID_VAR;
err_str = Soap_Invalid_Var;
} else {
err_code = UpnpStateVarRequest_get_ErrCode(variable);
err_str = UpnpStateVarRequest_get_ErrStr_cstr(variable);
}
send_error_response(info, err_code, err_str, request);
return;
}
/* send response */
send_var_query_response(info, UpnpStateVarRequest_get_CurrentVal(variable), request);
UpnpStateVarRequest_delete(variable);
}
开发者ID:rxwen,项目名称:pupnp,代码行数:63,代码来源:soap_device.c
示例6: cmd_find
/* find /root [patterns] */
static void cmd_find(struct watchman_client *client, json_t *args)
{
w_root_t *root;
w_query *query;
char *errmsg = NULL;
struct w_query_field_list field_list;
w_query_res res;
json_t *response;
json_t *file_list;
char clockbuf[128];
/* resolve the root */
if (json_array_size(args) < 2) {
send_error_response(client, "not enough arguments for 'find'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
query = w_query_parse_legacy(root, args, &errmsg, 2, NULL, NULL, NULL);
if (errmsg) {
send_error_response(client, "%s", errmsg);
free(errmsg);
w_root_delref(root);
return;
}
w_query_legacy_field_list(&field_list);
if (client->client_mode) {
query->sync_timeout = 0;
}
if (!w_query_execute(query, root, &res, NULL, NULL)) {
send_error_response(client, "query failed: %s", res.errmsg);
w_query_result_free(&res);
w_root_delref(root);
w_query_delref(query);
return;
}
w_query_delref(query);
file_list = w_query_results_to_json(&field_list,
res.num_results, res.results);
w_query_result_free(&res);
response = make_response();
if (clock_id_string(res.root_number, res.ticks, clockbuf, sizeof(clockbuf))) {
set_prop(response, "clock", json_string_nocheck(clockbuf));
}
set_prop(response, "files", file_list);
send_and_dispose_response(client, response);
w_root_delref(root);
}
开发者ID:0-wiz-0,项目名称:watchman,代码行数:60,代码来源:find.c
示例7: cmd_trigger
/* trigger /root triggername [watch patterns] -- cmd to run
* Sets up a trigger so that we can execute a command when a change
* is detected */
void cmd_trigger(struct watchman_client *client, json_t *args)
{
w_root_t *root;
struct watchman_trigger_command *cmd;
json_t *resp;
json_t *trig;
char *errmsg = NULL;
root = resolve_root_or_err(client, args, 1, true);
if (!root) {
return;
}
if (json_array_size(args) < 3) {
send_error_response(client, "not enough arguments");
goto done;
}
trig = json_array_get(args, 2);
if (json_is_string(trig)) {
trig = build_legacy_trigger(client, args);
if (!trig) {
goto done;
}
} else {
// Add a ref so that we don't need to conditionally decref later
// for the legacy case later
json_incref(trig);
}
cmd = w_build_trigger_from_def(root, trig, &errmsg);
json_decref(trig);
if (!cmd) {
send_error_response(client, "%s", errmsg);
goto done;
}
w_root_lock(root);
w_ht_replace(root->commands, w_ht_ptr_val(cmd->triggername),
w_ht_ptr_val(cmd));
w_root_unlock(root);
w_state_save();
resp = make_response();
set_prop(resp, "triggerid", json_string_nocheck(cmd->triggername->buf));
send_and_dispose_response(client, resp);
done:
if (errmsg) {
free(errmsg);
}
w_root_delref(root);
}
开发者ID:jadedgnome,项目名称:watchman,代码行数:58,代码来源:trigger.c
示例8: json_pack
static json_t *build_legacy_trigger(
w_root_t *root,
struct watchman_client *client,
json_t *args)
{
json_t *trig, *expr;
json_t *command;
char *errmsg;
uint32_t next_arg = 0;
uint32_t i;
size_t n;
w_query *query;
trig = json_pack("{s:O, s:b, s:[s, s, s, s, s]}",
"name", json_array_get(args, 2),
"append_files", true,
"stdin",
// [
"name", "exists", "new", "size", "mode"
// ]
);
query = w_query_parse_legacy(root, args, &errmsg, 3, &next_arg, NULL, &expr);
if (!query) {
send_error_response(client, "invalid rule spec: %s", errmsg);
free(errmsg);
json_decref(trig);
return NULL;
}
w_query_delref(query);
json_object_set(trig, "expression", json_object_get(expr, "expression"));
json_decref(expr);
if (next_arg >= json_array_size(args)) {
send_error_response(client, "no command was specified");
json_decref(trig);
return NULL;
}
n = json_array_size(args) - next_arg;
command = json_array_of_size(n);
for (i = 0; i < n; i++) {
json_t *ele = json_array_get(args, i + next_arg);
if (!json_is_string(ele)) {
send_error_response(client, "expected argument %d to be a string", i);
json_decref(trig);
return NULL;
}
json_array_append(command, ele);
}
json_object_set_new(trig, "command", command);
return trig;
}
开发者ID:1514louluo,项目名称:watchman,代码行数:55,代码来源:trigger.c
示例9: dispatch_command
bool dispatch_command(struct watchman_client *client, json_t *args, int mode)
{
struct watchman_command_handler_def *def;
char *errmsg = NULL;
bool result = false;
char sample_name[128];
// Stash a reference to the current command to make it easier to log
// the command context in some of the error paths
client->current_command = args;
json_incref(client->current_command);
def = lookup(args, &errmsg, mode);
if (!def) {
send_error_response(client, "%s", errmsg);
goto done;
}
if (poisoned_reason && (def->flags & CMD_POISON_IMMUNE) == 0) {
send_error_response(client, "%s", poisoned_reason);
goto done;
}
if (!client->client_is_owner && (def->flags & CMD_ALLOW_ANY_USER) == 0) {
send_error_response(client, "you must be the process owner to execute '%s'",
def->name);
return false;
}
w_log(W_LOG_DBG, "dispatch_command: %s\n", def->name);
snprintf(sample_name, sizeof(sample_name), "dispatch_command:%s", def->name);
w_perf_start(&client->perf_sample, sample_name);
w_perf_set_wall_time_thresh(
&client->perf_sample,
cfg_get_double(NULL, "slow_command_log_threshold_seconds", 1.0));
result = true;
def->func(client, args);
if (w_perf_finish(&client->perf_sample)) {
json_incref(args);
w_perf_add_meta(&client->perf_sample, "args", args);
w_perf_log(&client->perf_sample);
} else {
w_log(W_LOG_DBG, "dispatch_command: %s (completed)\n", def->name);
}
done:
free(errmsg);
json_decref(client->current_command);
client->current_command = NULL;
w_perf_destroy(&client->perf_sample);
return result;
}
开发者ID:1514louluo,项目名称:watchman,代码行数:55,代码来源:reg.c
示例10: handle_drain
static void handle_drain(const char *req, int *req_index)
{
(void) req;
(void) req_index;
if (!uart_is_open(uart)) {
send_error_response("ebadf");
return;
}
if (uart_drain(uart) >= 0)
send_ok_response();
else
send_error_response(uart_last_error());
}
开发者ID:johnhamelink,项目名称:nerves_uart,代码行数:14,代码来源:nerves_uart.c
示例11: handle_configure
static void handle_configure(const char *req, int *req_index)
{
struct uart_config config = current_config;
if (parse_option_list(req, req_index, &config) < 0) {
send_error_response("einval");
return;
}
if (uart_configure(uart, &config) >= 0) {
current_config = config;
send_ok_response();
} else {
send_error_response(uart_last_error());
}
}
开发者ID:johnhamelink,项目名称:nerves_uart,代码行数:15,代码来源:nerves_uart.c
示例12: cmd_unsubscribe
/* unsubscribe /root subname
* Cancels a subscription */
static void cmd_unsubscribe(
struct watchman_client* clientbase,
const json_ref& args) {
const char *name;
bool deleted{false};
struct watchman_user_client *client =
(struct watchman_user_client *)clientbase;
auto root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
auto jstr = json_array_get(args, 2);
name = json_string_value(jstr);
if (!name) {
send_error_response(
client, "expected 2nd parameter to be subscription name");
return;
}
auto sname = json_to_w_string(jstr);
deleted = client->unsubByName(sname);
auto resp = make_response();
resp.set({{"unsubscribe", typed_string_to_json(name)},
{"deleted", json_boolean(deleted)}});
send_and_dispose_response(client, std::move(resp));
}
开发者ID:otrempe,项目名称:watchman,代码行数:32,代码来源:subscribe.cpp
示例13: cmd_debug_ageout
/* debug-ageout */
static void cmd_debug_ageout(
struct watchman_client* client,
const json_ref& args) {
/* resolve the root */
if (json_array_size(args) != 3) {
send_error_response(client,
"wrong number of arguments for 'debug-ageout'");
return;
}
auto root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
std::chrono::seconds min_age(json_integer_value(json_array_get(args, 2)));
auto resp = make_response();
root->performAgeOut(min_age);
resp.set("ageout", json_true());
send_and_dispose_response(client, std::move(resp));
}
开发者ID:niclasr,项目名称:watchman,代码行数:26,代码来源:debug.cpp
示例14: cmd_find
/* find /root [patterns] */
static void cmd_find(struct watchman_client* client, const json_ref& args) {
/* resolve the root */
if (json_array_size(args) < 2) {
send_error_response(client, "not enough arguments for 'find'");
return;
}
auto root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
auto query = w_query_parse_legacy(root, args, 2, nullptr, nullptr, nullptr);
if (client->client_mode) {
query->sync_timeout = std::chrono::milliseconds(0);
}
auto res = w_query_execute(query.get(), root, nullptr);
auto response = make_response();
response.set({{"clock", res.clockAtStartOfQuery.toJson()},
{"files", std::move(res.resultsArray)}});
send_and_dispose_response(client, std::move(response));
}
开发者ID:niclasr,项目名称:watchman,代码行数:26,代码来源:find.cpp
示例15: cmd_watch
/* watch /root */
static void cmd_watch(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client, "wrong number of arguments to 'watch'");
return;
}
root = resolve_root_or_err(client, args, 1, true);
if (!root) {
return;
}
resp = make_response();
w_root_lock(root);
if (root->failure_reason) {
set_prop(resp, "error", json_string_nocheck(root->failure_reason->buf));
} else if (root->cancelled) {
set_prop(resp, "error", json_string_nocheck("root was cancelled"));
} else {
set_prop(resp, "watch", json_string_nocheck(root->root_path->buf));
}
send_and_dispose_response(client, resp);
w_root_unlock(root);
w_root_delref(root);
}
开发者ID:Kingside,项目名称:watchman,代码行数:31,代码来源:watch.c
示例16: cmd_debug_ageout
/* debug-ageout */
static void cmd_debug_ageout(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
int min_age;
/* resolve the root */
if (json_array_size(args) != 3) {
send_error_response(client,
"wrong number of arguments for 'debug-ageout'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
min_age = json_integer_value(json_array_get(args, 2));
resp = make_response();
w_root_lock(root);
w_root_perform_age_out(root, min_age);
w_root_unlock(root);
set_prop(resp, "ageout", json_true());
send_and_dispose_response(client, resp);
w_root_delref(root);
}
开发者ID:niclasr,项目名称:watchman,代码行数:32,代码来源:debug.c
示例17: cmd_debug_recrawl
static void cmd_debug_recrawl(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client,
"wrong number of arguments for 'debug-recrawl'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
resp = make_response();
w_root_lock(root);
w_root_schedule_recrawl(root, "debug-recrawl");
w_root_unlock(root);
set_prop(resp, "recrawl", json_true());
send_and_dispose_response(client, resp);
w_root_delref(root);
}
开发者ID:niclasr,项目名称:watchman,代码行数:28,代码来源:debug.c
示例18: cmd_debug_show_cursors
static void cmd_debug_show_cursors(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp, *cursors;
w_ht_iter_t i;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client,
"wrong number of arguments for 'debug-show-cursors'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
resp = make_response();
w_root_lock(root);
cursors = json_object_of_size(w_ht_size(root->cursors));
if (w_ht_first(root->cursors, &i)) do {
w_string_t *name = w_ht_val_ptr(i.key);
set_prop(cursors, name->buf, json_integer(i.value));
} while (w_ht_next(root->cursors, &i));
w_root_unlock(root);
set_prop(resp, "cursors", cursors);
send_and_dispose_response(client, resp);
w_root_delref(root);
}
开发者ID:niclasr,项目名称:watchman,代码行数:33,代码来源:debug.c
示例19: printfile
static void
printfile(const char *path, pConnInfo conn_info)
{
char *mod_time_str ;
char *file_mod_time = get_file_time(path);
if((mod_time_str = get_header_param("If-Modified-Since", conn_info->request_header))) {
if(!is_expire(mod_time_str, file_mod_time)) {
conn_info->status_code = 304;
send_error_response(conn_info);
return;
}
}
FILE* file = fopen(path, "r");
fseek(file, 0, SEEK_END);
header_body.content_len = ftell(file);
rewind(file);
add_header_param("Last-Modified", file_mod_time, conn_info->response_header);
uws_free(file_mod_time);
header_body.content = (char*) uws_malloc (header_body.content_len * sizeof(char));
size_t read_size = fread(header_body.content, sizeof(char), header_body.content_len, file);
fclose(file);
}
开发者ID:codesaler,项目名称:uws,代码行数:26,代码来源:uws_http.c
示例20: handle_write
static void handle_write(const char *req, int *req_index)
{
if (!uart_is_open(uart)) {
send_error_response("ebadf");
return;
}
int term_size;
if (ei_decode_tuple_header(req, req_index, &term_size) < 0 ||
term_size != 2)
errx(EXIT_FAILURE, "expecting {data, timeout}");
int term_type;
if (ei_get_type(req, req_index, &term_type, &term_size) < 0 ||
term_type != ERL_BINARY_EXT)
errx(EXIT_FAILURE, "expecting data as a binary");
uint8_t *to_write = malloc(term_size);
long amount_to_write;
if (ei_decode_binary(req, req_index, to_write, &amount_to_write) < 0)
errx(EXIT_FAILURE, "decode binary error?");
long timeout;
if (ei_decode_long(req, req_index, &timeout) < 0)
errx(EXIT_FAILURE, "expecting timeout");
// uart_write always invokes a callback when it completes (error or no error).
uart_write(uart, to_write, amount_to_write, timeout);
}
开发者ID:johnhamelink,项目名称:nerves_uart,代码行数:29,代码来源:nerves_uart.c
注:本文中的send_error_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论