/* structure of the print argument bitmap: * SHOW_NO_OUTPUT (0x0) - don't print anything for the command * SHOW_OUTPUT (0x01) - print output for the command * SHOW_RAW (0x02) - print the raw clif command messages * SHOW_RAW_ONLY (0x04) - print only the raw clif command messages */ static int _clif_command(struct clif *clif, char *cmd, int print) { char buf[MAX_CLIF_MSGBUF]; size_t len; int ret; print_raw_message(cmd, print); if (clif_conn == NULL) { printf("Not connected to lldpad - command dropped.\n"); return -1; } len = sizeof(buf) - 1; ret = clif_request(clif, cmd, strlen(cmd), buf, &len, cli_msg_cb); if (ret == -2) { printf("'%s' command timed out.\n", cmd); return -2; } else if (ret < 0) { printf("'%s' command failed.\n", cmd); return -1; } if (print) { buf[len] = '\0'; ret = parse_print_message(buf, print); } return ret; }
int parse_print_message(char *msg, int print) { int status = 0; status = parse_response(msg); print_raw_message(msg, print); if (print & SHOW_RAW_ONLY) return status; if (msg[MSG_TYPE] == CMD_RESPONSE) print_response(msg, status); else if (msg[MSG_TYPE] == EVENT_MSG) print_event_msg(msg); return status; }
static bool simple_random_messages_test() { bool ret = false; char* str; unsigned len; // construct messages const fix_message_data* const messages = make_n_messages(NUM_MESSAGES, &str, &len); // construct parser fix_parser* const parser = create_FIX44_parser(); if(!parser) { REPORT_FAILURE("NULL parser"); goto EXIT; } // parser loop unsigned i = 0; for(const fix_parser_result* res = get_first_fix_message(parser, str, len); res; res = get_next_fix_message(parser)) { // check for errors if(!parser_result_ok(res, __FILE__, __LINE__)) { print_raw_message(parser); goto EXIT; } // check message index if(i == NUM_MESSAGES) { REPORT_FAILURE("Parser unexpectedly produced too many messages"); goto EXIT; } // validate message if(!valid_fix_message(res->root, messages + i)) { print_raw_message(parser); goto EXIT; } ++i; } // check for fatal errors const fix_error_details* const error = get_fix_parser_error_details(parser); if(error->code > FE_OTHER) { report_error_details(error, __FILE__, __LINE__); goto EXIT; } // final check of message index if(i != NUM_MESSAGES) { REPORT_FAILURE("Parser produced %u messages instead of %u", i, (unsigned)NUM_MESSAGES); goto EXIT; } // all clear ret = true; EXIT: // clean-up free(str); free((void*)messages); free_fix_parser(parser); TEST_END(ret); }