本文整理汇总了C++中parse_response函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_response函数的具体用法?C++ parse_response怎么用?C++ parse_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newsnntp_post
int newsnntp_post(newsnntp * f, const char * message, size_t size)
{
char command[NNTP_STRING_SIZE];
int r;
char * response;
snprintf(command, NNTP_STRING_SIZE, "POST\r\n");
r = send_command(f, command);
if (r == -1)
return NEWSNNTP_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return NEWSNNTP_ERROR_STREAM;
r = parse_response(f, response);
switch (r) {
case 480:
return NEWSNNTP_ERROR_REQUEST_AUTHORIZATION_USERNAME;
case 381:
return NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD;
case 340:
break;
case 440:
return NEWSNNTP_ERROR_POSTING_NOT_ALLOWED;
default:
return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
}
send_data(f, message, size);
response = read_line(f);
if (response == NULL)
return NEWSNNTP_ERROR_STREAM;
r = parse_response(f, response);
switch (r) {
case 480:
return NEWSNNTP_ERROR_REQUEST_AUTHORIZATION_USERNAME;
case 381:
return NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD;
case 240:
return NEWSNNTP_NO_ERROR;
return 1;
case 441:
return NEWSNNTP_ERROR_POSTING_FAILED;
default:
return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
}
}
示例2: signup_signin
void signup_signin() {
int i, authen = 0;
char action[10], input[50], request[256];
char **response;
printf("signup/signin? ");
scanf(" %s", action);
while(!authen) {
sprintf(request, "%s,", action);
if (strcmp(action, "signup") == 0) {
printf("[username] [nickname] [password]: ");
for (i = 0; i < L_SIGNUP_REQ; i++) {
scanf(" %s", input);
strcat(request, input);
strcat(request, ",");
}
getchar();
if(send(sock, request, strlen(request) , 0) < 0)
ERR_EXIT("Send failed");
response = parse_response(L_SIGN_RES);
if (strcmp(response[0], "success") == 0) {
strcpy(user->username, response[1]);
strcpy(user->nickname, response[2]);
authen = 1;
}
else
printf("%s\n", response[0]);
} else if (strcmp(action, "signin") == 0) {
printf("[username] [password]: ");
for (i = 0; i < L_SIGNIN_REQ; i++) {
scanf(" %s", input);
strcat(request, input);
strcat(request, ",");
}
getchar();
if(send(sock, request, strlen(request) , 0) < 0)
ERR_EXIT("Send failed");
response = parse_response(L_SIGN_RES);
if (strcmp(response[0], "success") == 0) {
strcpy(user->username, response[1]);
strcpy(user->nickname, response[2]);
authen = 1;
}
else
printf("%s\n", response[0]);
}
}
free(response);
}
示例3: phr_parse_response
int phr_parse_response(const char* buf_start, size_t len, int* minor_version,
int* status, const char** msg, size_t* msg_len,
struct phr_header* headers, size_t* num_headers,
size_t last_len)
{
const char * buf = buf_start, * buf_end = buf + len;
size_t max_headers = *num_headers;
int r;
*minor_version = -1;
*status = 0;
*msg = NULL;
*msg_len = 0;
*num_headers = 0;
/* if last_len != 0, check if the response is complete (a fast countermeasure
against slowloris */
if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) {
return r;
}
if ((buf = parse_response(buf, buf_end, minor_version, status, msg, msg_len,
headers, num_headers, max_headers, &r))
== NULL) {
return r;
}
return buf - buf_start;
}
示例4: newsnntp_connect
int newsnntp_connect(newsnntp * f, mailstream * s)
{
char * response;
int r;
if (f->nntp_stream != NULL)
return NEWSNNTP_ERROR_BAD_STATE;
f->nntp_stream = s;
response = read_line(f);
if (response == NULL)
return NEWSNNTP_ERROR_STREAM;
r = parse_response(f, response);
switch (r) {
case 200:
f->nntp_readonly = FALSE;
return NEWSNNTP_NO_ERROR;
case 201:
f->nntp_readonly = TRUE;
return NEWSNNTP_NO_ERROR;
default:
f->nntp_stream = NULL;
return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
}
}
示例5: send_http_reply
//LCOV_EXCL_START - don't want to actually run the handlers in the UT
void RegistrationTimeoutTask::run()
{
if (_req.method() != htp_method_POST)
{
send_http_reply(HTTP_BADMETHOD);
delete this;
return;
}
HTTPCode rc = parse_response(_req.get_rx_body());
if (rc != HTTP_OK)
{
LOG_DEBUG("Unable to parse response from Chronos");
send_http_reply(rc);
delete this;
return;
}
send_http_reply(HTTP_OK);
SAS::Marker start_marker(trail(), MARKER_ID_START, 1u);
SAS::report_marker(start_marker);
handle_response();
SAS::Marker end_marker(trail(), MARKER_ID_END, 1u);
SAS::report_marker(end_marker);
delete this;
}
示例6: mailpop3_pass
int mailpop3_pass(mailpop3 * f, const char * password)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_AUTHORIZATION)
return MAILPOP3_ERROR_BAD_STATE;
/* send password command */
snprintf(command, POP3_STRING_SIZE, "PASS %s\r\n", password);
r = send_command_private(f, command, 0);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_BAD_PASSWORD;
f->pop3_state = POP3_STATE_TRANSACTION;
return MAILPOP3_NO_ERROR;
}
示例7: newsnntp_mode_reader
int newsnntp_mode_reader(newsnntp * f)
{
char command[NNTP_STRING_SIZE];
char * response;
int r;
snprintf(command, NNTP_STRING_SIZE, "MODE READER\r\n");
r = send_command(f, command);
if (r == -1)
return NEWSNNTP_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return NEWSNNTP_ERROR_STREAM;
r = parse_response(f, response);
switch (r) {
case 480:
return NEWSNNTP_ERROR_REQUEST_AUTHORIZATION_USERNAME;
case 381:
return NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD;
case 200:
case 201:
return NEWSNNTP_NO_ERROR;
default:
return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
}
}
示例8: newsnntp_quit
int newsnntp_quit(newsnntp * f)
{
char command[NNTP_STRING_SIZE];
char * response;
int r;
int res;
if (f->nntp_stream == NULL)
return NEWSNNTP_ERROR_BAD_STATE;
snprintf(command, NNTP_STRING_SIZE, "QUIT\r\n");
r = send_command(f, command);
if (r == -1) {
res = NEWSNNTP_ERROR_STREAM;
goto close;
}
response = read_line(f);
if (response == NULL) {
res = NEWSNNTP_ERROR_STREAM;
goto close;
}
parse_response(f, response);
res = NEWSNNTP_NO_ERROR;
close:
mailstream_close(f->nntp_stream);
f->nntp_stream = NULL;
return res;
}
示例9: send_http_reply
//LCOV_EXCL_START - don't want to actually run the handlers in the UT
void RegistrationTimeoutHandler::run()
{
if (_req.method() != htp_method_POST)
{
send_http_reply(HTTP_BADMETHOD);
delete this;
return;
}
HTTPCode rc = parse_response(_req.body());
if (rc != HTTP_OK)
{
LOG_DEBUG("Unable to parse response from Chronos");
send_http_reply(rc);
delete this;
return;
}
send_http_reply(HTTP_OK);
SAS::Marker start_marker(trail(), MARKER_ID_START, 1u);
SAS::report_marker(start_marker);
SAS::Marker calling_dn(trail(), MARKER_ID_CALLING_DN, 1u);
calling_dn.add_var_param(_aor_id);
SAS::report_marker(calling_dn);
handle_response();
SAS::Marker end_marker(trail(), MARKER_ID_END, 1u);
SAS::report_marker(end_marker);
delete this;
}
示例10: mailpop3_dele
int mailpop3_dele(mailpop3 * f, unsigned int indx)
{
char command[POP3_STRING_SIZE];
struct mailpop3_msg_info * msginfo;
char * response;
int r;
if (f->pop3_state != POP3_STATE_TRANSACTION)
return MAILPOP3_ERROR_BAD_STATE;
msginfo = find_msg(f, indx);
if (msginfo == NULL) {
f->pop3_response = NULL;
return MAILPOP3_ERROR_NO_SUCH_MESSAGE;
}
snprintf(command, POP3_STRING_SIZE, "DELE %i\r\n", indx);
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_NO_SUCH_MESSAGE;
msginfo->msg_deleted = TRUE;
f->pop3_deleted_count ++;
return MAILPOP3_NO_ERROR;
}
示例11: mailpop3_rset
int mailpop3_rset(mailpop3 * f)
{
char command[POP3_STRING_SIZE];
char * response;
int r;
if (f->pop3_state != POP3_STATE_TRANSACTION)
return MAILPOP3_ERROR_BAD_STATE;
snprintf(command, POP3_STRING_SIZE, "RSET\r\n");
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
parse_response(f, response);
if (f->pop3_msg_tab != NULL) {
mailpop3_msg_info_tab_reset(f->pop3_msg_tab);
f->pop3_deleted_count = 0;
}
return MAILPOP3_NO_ERROR;
}
示例12: handle_response
static void handle_response(GObex *obex, GError *err, GObexPacket *rsp)
{
struct pending_pkt *p = obex->pending_req;
gboolean disconn = err ? TRUE : FALSE, final_rsp = TRUE;
if (rsp != NULL)
final_rsp = parse_response(obex, rsp);
if (p->cancelled)
err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,
"The operation was cancelled");
if (err)
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
if (p->rsp_func) {
p->rsp_func(obex, err, rsp, p->rsp_data);
/* Check if user callback removed the request */
if (p != obex->pending_req)
return;
}
if (p->cancelled)
g_error_free(err);
if (final_rsp) {
pending_pkt_free(p);
obex->pending_req = NULL;
}
if (!disconn && g_queue_get_length(obex->tx_queue) > 0)
enable_tx(obex);
}
示例13: mailpop3_capa
int mailpop3_capa(mailpop3 * f, clist ** result)
{
clist * capa_list;
char command[POP3_STRING_SIZE];
int r;
char * response;
snprintf(command, POP3_STRING_SIZE, "CAPA\r\n");
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
if (r != RESPONSE_OK)
return MAILPOP3_ERROR_CAPA_NOT_SUPPORTED;
capa_list = NULL;
r = read_capa_resp(f, &capa_list);
if (r != MAILPOP3_NO_ERROR)
return r;
* result = capa_list;
return MAILPOP3_NO_ERROR;
}
示例14: suspend
static int suspend(const struct ether_addr *mac, struct message_buffer *buf)
{
struct response *response = &buf->u.response;
struct agent *agent = find_agent_by_mac(list, mac);
int n;
if (agent == NULL)
return 404;
if (agent->state == SUSPENDED)
return 409;
if (agent->fd2 < 0) // no connection to the agent
return 500;
send_request(agent->fd2, SUSP, NULL, NULL, buf);
n = read(agent->fd2, buf->chars, sizeof(buf->chars) - 1);
if (n <= 0) {
if (n < 0)
WARNING("read() failed: %m");
else
WARNING("unexpected EOF while waiting for a response");
return 500;
}
buf->chars[n] = 0;
if (parse_response(buf->chars, response)) {
WARNING("invalid response");
return 500;
}
switch (response->status) {
case 200:
return 200;
default:
WARNING("got unexpected response status code: %d", response->status);
return 500;
}
}
示例15: newsnntp_xover_resp
static int newsnntp_xover_resp(newsnntp * f, clist ** result)
{
int r;
char * response;
response = read_line(f);
if (response == NULL)
return NEWSNNTP_ERROR_STREAM;
r = parse_response(f, response);
switch (r) {
case 480:
return NEWSNNTP_ERROR_REQUEST_AUTHORIZATION_USERNAME;
case 381:
return NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD;
case 224:
* result = read_xover_resp_list(f);
return NEWSNNTP_NO_ERROR;
case 412:
return NEWSNNTP_ERROR_NO_NEWSGROUP_SELECTED;
case 420:
return NEWSNNTP_ERROR_NO_ARTICLE_SELECTED;
case 502:
return NEWSNNTP_ERROR_NO_PERMISSION;
default:
return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
}
}