static void parser_include_line(struct at_parser *parser) { /* Append a newline. */ parser_append(parser, '\n'); /* Advance the current command pointer to the new position. */ parser->buf_current = parser->buf_used; }
/************************************************************************ * Function : process_reply * * Parameters: * IN char* request_buf: the response came from the device * IN int buf_len: The length of the response buffer * IN struct sockaddr_in* dest_addr: The address of the device * IN void *cookie : cookie passed by the control point application * at the time of sending search message * * Description: * This function processes reply recevied from a search * * Returns: void * ***************************************************************************/ static XINLINE void process_reply( IN char *request_buf, IN int buf_len, IN struct sockaddr_in *dest_addr, IN void *cookie ) { http_parser_t parser; parser_response_init( &parser, HTTPMETHOD_MSEARCH ); // parse if( parser_append( &parser, request_buf, buf_len ) != PARSE_SUCCESS ) { httpmsg_destroy( &parser.msg ); return; } // handle reply ssdp_handle_ctrlpt_msg( &parser.msg, dest_addr, FALSE, cookie ); // done httpmsg_destroy( &parser.msg ); }
void at_parser_feed(struct at_parser *parser, const void *data, size_t len) { const uint8_t *buf = data; while (len > 0) { /* Fetch next character. */ uint8_t ch = *buf++; len--; switch (parser->state) { case STATE_IDLE: case STATE_READLINE: case STATE_DATAPROMPT: { if ((ch != '\r') && (ch != '\n')) { /* Append the character if it's not a newline. */ parser_append(parser, ch); } /* Handle a single character. */ if (parser->character_handler) { ch = parser->character_handler(ch, parser->buf + parser->buf_current, parser->buf_used - parser->buf_current, parser->priv); } /* Handle full lines. */ if ((ch == '\n') || (parser->state == STATE_DATAPROMPT && parser->buf_used == 2 && !memcmp(parser->buf, "> ", 2))) { parser_handle_line(parser); } } break; case STATE_RAWDATA: { if (parser->data_left > 0) { parser_append(parser, ch); parser->data_left--; } if (parser->data_left == 0) { parser_include_line(parser); parser->state = STATE_READLINE; } } break; case STATE_HEXDATA: { if (parser->data_left > 0) { int value = hex2int(ch); if (value != -1) { if (parser->nibble == -1) { parser->nibble = value; } else { value |= (parser->nibble << 4); parser->nibble = -1; parser_append(parser, value); parser->data_left--; } } } if (parser->data_left == 0) { parser_include_line(parser); parser->state = STATE_READLINE; } } break; } } }