| 1 | #include "fep.h" |
|---|
| 2 | #include "fep_print.cpp" |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | |
|---|
| 6 | /* Author: John A. Torres |
|---|
| 7 | The fep_program_32 function creates a new RPC Client which |
|---|
| 8 | sends an fep_reply structure to the ATMS Server. After the |
|---|
| 9 | reply is sent, the ATMS Sends a response and the RPC Client |
|---|
| 10 | is destroyed. |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | /* Handles the ATMS's response to RPC Call */ |
|---|
| 14 | void handle_ATMS_response(CLIENT *clnt, void *response) |
|---|
| 15 | { |
|---|
| 16 | /* If ATMS reply call fails */ |
|---|
| 17 | if (response == NULL) |
|---|
| 18 | { |
|---|
| 19 | clnt_perror(clnt, "RPC call failed"); |
|---|
| 20 | } |
|---|
| 21 | /* If ATMS reply is successful */ |
|---|
| 22 | else |
|---|
| 23 | { |
|---|
| 24 | printf("Successful RPC call to ATMS...\n"); |
|---|
| 25 | printf("Printing ATMS RPC Call response...\n"); |
|---|
| 26 | print_reply_ret(*(reply_ret *) (&response)); |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | fep_reply generate_reply() |
|---|
| 31 | { |
|---|
| 32 | /* Declarations to construct an fep_reply */ |
|---|
| 33 | fep_answer_info fai; |
|---|
| 34 | fep_pollerror fpe; |
|---|
| 35 | fep_answer_short_msg fasm; |
|---|
| 36 | fep_shortanswer fsa; |
|---|
| 37 | fep_reply fep_reply_xfer_32_arg; // the reply to be sent to ATMS |
|---|
| 38 | |
|---|
| 39 | /* Populate fep_shortmessage data */ |
|---|
| 40 | printf("Setting fep_reply values...\n"); |
|---|
| 41 | |
|---|
| 42 | fasm.message_len = 5; |
|---|
| 43 | fasm.message[0] = 0x0a; |
|---|
| 44 | fasm.message[1] = 0x0d; |
|---|
| 45 | fasm.message[2] = 0x11; |
|---|
| 46 | fasm.message[3] = 0x12; |
|---|
| 47 | fasm.message[4] = 0x13; |
|---|
| 48 | |
|---|
| 49 | fpe.msgerror = (enum answererror) 0; |
|---|
| 50 | fpe.state = (enum Polling_FSM_States) 0x00; |
|---|
| 51 | fpe.perrno = 0; |
|---|
| 52 | fpe.termination = 0; |
|---|
| 53 | fpe.count = 0; |
|---|
| 54 | |
|---|
| 55 | fai.poll_time = 1111443466; |
|---|
| 56 | fai.status = (enum replystatus) 1; |
|---|
| 57 | fai.poll_user_info1 = 1; |
|---|
| 58 | fai.poll_user_info2 = 2; |
|---|
| 59 | fai.retries = 0; |
|---|
| 60 | fai.poll_error_count = 1; |
|---|
| 61 | fai.pollerror[0] = fpe; |
|---|
| 62 | |
|---|
| 63 | fsa.info = fai; |
|---|
| 64 | fsa.msg = fasm; |
|---|
| 65 | |
|---|
| 66 | fep_reply_xfer_32_arg.reply = 0; |
|---|
| 67 | fep_reply_xfer_32_arg.schedule = 0; |
|---|
| 68 | fep_reply_xfer_32_arg.lineinfo = 0; |
|---|
| 69 | fep_reply_xfer_32_arg.kind = (enum polltype)0; |
|---|
| 70 | fep_reply_xfer_32_arg.flag = (enum replykind) 0; |
|---|
| 71 | fep_reply_xfer_32_arg.schedule_sequence = 0; |
|---|
| 72 | fep_reply_xfer_32_arg.global_sequence = 0; |
|---|
| 73 | fep_reply_xfer_32_arg.schedule_time = 1111443466; |
|---|
| 74 | fep_reply_xfer_32_arg.user_info1 = 0; |
|---|
| 75 | fep_reply_xfer_32_arg.user_info2 = 0; |
|---|
| 76 | fep_reply_xfer_32_arg.system_key = 0; |
|---|
| 77 | fep_reply_xfer_32_arg.answers.size = 1; |
|---|
| 78 | fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.count = 1; |
|---|
| 79 | fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.answers[0] = fsa; |
|---|
| 80 | |
|---|
| 81 | return fep_reply_xfer_32_arg; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /* Creates an RPC client, populates the fep_reply data structure, |
|---|
| 85 | makes an RPC Call to the ATMS Server to pass the fep_reply, |
|---|
| 86 | destroys the RPC Client and returns |
|---|
| 87 | */ |
|---|
| 88 | void fep_program_32(char *host) |
|---|
| 89 | { |
|---|
| 90 | CLIENT *clnt; |
|---|
| 91 | |
|---|
| 92 | /* Var to recieve message back from ATMS */ |
|---|
| 93 | void *rv; |
|---|
| 94 | |
|---|
| 95 | /* Create RPC Client to communicate with ATMS */ |
|---|
| 96 | printf("Preparing to create RPC client...\n"); |
|---|
| 97 | clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp"); |
|---|
| 98 | |
|---|
| 99 | /* Check if client creation failed */ |
|---|
| 100 | if (clnt == (CLIENT *) NULL) |
|---|
| 101 | { |
|---|
| 102 | fprintf(stderr, "Can't create client to %s\n", host); |
|---|
| 103 | exit(1); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /* Make RPC Call to transfer reply to ATMS */ |
|---|
| 107 | printf("Transferring data to ATMS Server...\n"); |
|---|
| 108 | fep_reply reply = generate_reply(); |
|---|
| 109 | rv = fep_reply_xfer_32(&reply, clnt); |
|---|
| 110 | |
|---|
| 111 | /* Handle ATMS response to RPC Call */ |
|---|
| 112 | printf("Handling ATMS response...\n"); |
|---|
| 113 | handle_ATMS_response(clnt, rv); |
|---|
| 114 | |
|---|
| 115 | /* Destroy client */ |
|---|
| 116 | printf("Destroying client...\n"); |
|---|
| 117 | clnt_destroy(clnt); |
|---|
| 118 | printf("Returning to main...\n"); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | /* Main driver function to create an RPC Client, make a single RPC Call to the |
|---|
| 122 | ATMS Server */ |
|---|
| 123 | int main(int argc, char *argv[]) { |
|---|
| 124 | char *host; |
|---|
| 125 | |
|---|
| 126 | if (argc < 2) |
|---|
| 127 | { |
|---|
| 128 | printf("usage: %s server_host\n", argv[0]); |
|---|
| 129 | exit(1); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /* Create RPC Client to send an fep_reply to ATMS */ |
|---|
| 133 | host = argv[1]; |
|---|
| 134 | fep_program_32(host); |
|---|
| 135 | |
|---|
| 136 | return 0; |
|---|
| 137 | } |
|---|