home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CPI-C.ZIP / BUILD.C < prev    next >
Text File  |  1992-06-24  |  33KB  |  1,101 lines

  1. /*
  2.  *  PROGRAM:   JQCPIC -- John Q's Portable CPI-C Abuser
  3.  *
  4.  *  MODULE:    BUILD.C -- one procedure for each CPI-C call/state entry
  5.  *
  6.  *  COPYRIGHTS:
  7.  *             This module contains code made available by IBM
  8.  *             Corporation on an AS IS basis.  Any one receiving the
  9.  *             module is considered to be licensed under IBM copyrights
  10.  *             to use the IBM-provided source code in any way he or she
  11.  *             deems fit, including copying it, compiling it, modifying
  12.  *             it, and redistributing it, with or without
  13.  *             modifications.  No license under any IBM patents or
  14.  *             patent applications is to be implied from this copyright
  15.  *             license.
  16.  *
  17.  *             A user of the module should understand that IBM cannot
  18.  *             provide technical support for the module and will not be
  19.  *             responsible for any consequences of use of the program.
  20.  *
  21.  *             Any notices, including this one, are not to be removed
  22.  *             from the module without the prior written consent of
  23.  *             IBM.
  24.  *
  25.  *  AUTHOR:    Dr. John Q. Walker II
  26.  *             IBM VNET: JOHNQ at RALVM6          IBM tie line: 444-4414
  27.  *             Internet: johnq@vnet.ibm.com        phone: (919) 254-4414
  28.  *
  29.  *  RELATED FILES:
  30.  *             See file JQCPIC.DOC for detailed information.
  31.  *
  32.  *  CHANGE HISTORY:
  33.  *  Date       Description
  34.  *  05/12/92   - Added prologue.
  35.  *             - Provided default values for Set calls.
  36.  *  06/20/92   - Added check_receive() & check_rts() calls.
  37.  */
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42.  
  43. #include "jqcpic.h"
  44. #include "calls.h"
  45.  
  46.  
  47.  
  48. CM_CONVERSATION_STATE build_cmaccp (CPIC_CONV_ATTRIB *current)
  49. {
  50.     /*=========================================================================
  51.      * Accept Conversation
  52.      *=======================================================================*/
  53.  
  54. #ifndef NOCPIC
  55.     cmaccp(current->conversation_ID,
  56.            &(current->return_code));
  57. #endif
  58.  
  59.     return get_new_conversation_state(current);
  60. }
  61.  
  62.  
  63. CM_CONVERSATION_STATE build_cmallc (CPIC_CONV_ATTRIB *current)
  64. {
  65.     /*=========================================================================
  66.      * Allocate
  67.      *=======================================================================*/
  68.  
  69. #ifndef NOCPIC
  70.     cmallc(current->conversation_ID,
  71.            &(current->return_code));
  72. #endif
  73.  
  74.     return get_new_conversation_state(current);
  75. }
  76.  
  77.  
  78. CM_CONVERSATION_STATE build_cmcfm  (CPIC_CONV_ATTRIB *current)
  79. {
  80.     /*=========================================================================
  81.      * Confirm
  82.      *=======================================================================*/
  83.  
  84. #ifndef NOCPIC
  85.     cmcfm(current->conversation_ID,
  86.           &(current->request_to_send_received),
  87.           &(current->return_code));
  88. #endif
  89.  
  90.     /* validate the returned request_to_send_received value */
  91.     (void)check_rts(current);
  92.  
  93.     return get_new_conversation_state(current);
  94. }
  95.  
  96.  
  97. CM_CONVERSATION_STATE build_cmcfmd (CPIC_CONV_ATTRIB *current)
  98. {
  99.     /*=========================================================================
  100.      * Confirmed
  101.      *=======================================================================*/
  102.  
  103. #ifndef NOCPIC
  104.     cmcfmd(current->conversation_ID,
  105.            &(current->return_code));
  106. #endif
  107.  
  108.     return get_new_conversation_state(current);
  109. }
  110.  
  111.  
  112. CM_CONVERSATION_STATE build_cmdeala(CPIC_CONV_ATTRIB *current)
  113. {
  114.     /*=========================================================================
  115.      * Deallocate Abend
  116.      *=======================================================================*/
  117.  
  118.     current->deallocate_type = CM_DEALLOCATE_ABEND;
  119.  
  120. #ifndef NOCPIC
  121.     cmsdt (current->conversation_ID,
  122.            &(current->deallocate_type),
  123.            &(current->return_code));
  124.     cmdeal(current->conversation_ID,
  125.            &(current->return_code));
  126. #endif
  127.  
  128.     return get_new_conversation_state(current);
  129. }
  130.  
  131.  
  132. CM_CONVERSATION_STATE build_cmdealc(CPIC_CONV_ATTRIB *current)
  133. {
  134.     /*=========================================================================
  135.      * Deallocate Confirm
  136.      *=======================================================================*/
  137.  
  138.     current->deallocate_type = CM_DEALLOCATE_CONFIRM;
  139.  
  140. #ifndef NOCPIC
  141.     cmsdt (current->conversation_ID,
  142.            &(current->deallocate_type),
  143.            &(current->return_code));
  144.     cmdeal(current->conversation_ID,
  145.            &(current->return_code));
  146. #endif
  147.  
  148.     return get_new_conversation_state(current);
  149. }
  150.  
  151.  
  152. CM_CONVERSATION_STATE build_cmdealf(CPIC_CONV_ATTRIB *current)
  153. {
  154.     /*=========================================================================
  155.      * Deallocate Flush
  156.      *=======================================================================*/
  157.  
  158.     current->deallocate_type = CM_DEALLOCATE_FLUSH;
  159.  
  160. #ifndef NOCPIC
  161.     cmsdt (current->conversation_ID,
  162.            &(current->deallocate_type),
  163.            &(current->return_code));
  164.     cmdeal(current->conversation_ID,
  165.            &(current->return_code));
  166. #endif
  167.  
  168.     return get_new_conversation_state(current);
  169. }
  170.  
  171.  
  172. CM_CONVERSATION_STATE build_cmdeals(CPIC_CONV_ATTRIB *current)
  173. {
  174.     /*=========================================================================
  175.      * Deallocate Sync Level
  176.      *=======================================================================*/
  177.  
  178.     current->deallocate_type = CM_DEALLOCATE_SYNC_LEVEL;
  179.  
  180. #ifndef NOCPIC
  181.     cmsdt (current->conversation_ID,
  182.            &(current->deallocate_type),
  183.            &(current->return_code));
  184.     cmdeal(current->conversation_ID,
  185.            &(current->return_code));
  186. #endif
  187.  
  188.     return get_new_conversation_state(current);
  189. }
  190.  
  191.  
  192. CM_CONVERSATION_STATE build_cmecs  (CPIC_CONV_ATTRIB *current)
  193. {
  194.     /*=========================================================================
  195.      * Extract Conversation State
  196.      *=======================================================================*/
  197.  
  198. #ifndef NOCPIC
  199.     cmecs (current->conversation_ID,
  200.            &(current->conversation_state),
  201.            &(current->return_code));
  202. #endif
  203.  
  204.     return get_new_conversation_state(current);
  205. }
  206.  
  207.  
  208. CM_CONVERSATION_STATE build_cmect  (CPIC_CONV_ATTRIB *current)
  209. {
  210.     /*=========================================================================
  211.      * Extract Conversation Type
  212.      *=======================================================================*/
  213.  
  214. #ifndef NOCPIC
  215.     cmect (current->conversation_ID,
  216.            &(current->conversation_type),
  217.            &(current->return_code));
  218. #endif
  219.  
  220.     return get_new_conversation_state(current);
  221. }
  222.  
  223.  
  224. CM_CONVERSATION_STATE build_cmemn  (CPIC_CONV_ATTRIB *current)
  225. {
  226.     /*=========================================================================
  227.      * Extract Mode Name
  228.      *=======================================================================*/
  229.  
  230. #ifndef NOCPIC
  231.     cmemn (current->conversation_ID,
  232.            current->mode_name,
  233.            &(current->mode_name_length),
  234.            &(current->return_code));
  235. #endif
  236.  
  237.     return get_new_conversation_state(current);
  238. }
  239.  
  240.  
  241. CM_CONVERSATION_STATE build_cmepln (CPIC_CONV_ATTRIB *current)
  242. {
  243.     /*=========================================================================
  244.      * Extract Partner LU Name
  245.      *=======================================================================*/
  246.  
  247. #ifndef NOCPIC
  248.     cmepln(current->conversation_ID,
  249.            current->partner_LU_name,
  250.            &(current->partner_LU_name_length),
  251.            &(current->return_code));
  252. #endif
  253.  
  254.     return get_new_conversation_state(current);
  255. }
  256.  
  257.  
  258. CM_CONVERSATION_STATE build_cmesl  (CPIC_CONV_ATTRIB *current)
  259. {
  260.     /*=========================================================================
  261.      * Extract Sync Level
  262.      *=======================================================================*/
  263.  
  264. #ifndef NOCPIC
  265.     cmesl (current->conversation_ID,
  266.            &(current->sync_level),
  267.            &(current->return_code));
  268. #endif
  269.  
  270.     return get_new_conversation_state(current);
  271. }
  272.  
  273.  
  274. CM_CONVERSATION_STATE build_cmflus (CPIC_CONV_ATTRIB *current)
  275. {
  276.     /*=========================================================================
  277.      * Flush
  278.      *=======================================================================*/
  279.  
  280. #ifndef NOCPIC
  281.     cmflus(current->conversation_ID,
  282.            &(current->return_code));
  283. #endif
  284.  
  285.     return get_new_conversation_state(current);
  286. }
  287.  
  288.  
  289. CM_CONVERSATION_STATE build_cminit (CPIC_CONV_ATTRIB *current)
  290. {
  291.     /*=========================================================================
  292.      * Initialize Conversation
  293.      *=======================================================================*/
  294.  
  295.     unsigned char local_sym_dest_name[SYM_DEST_NAME_LENGTH];
  296.  
  297.     if (TRUE == generate_valid_parm()) {
  298.         unsigned i;
  299.         for (i = 0; i < SYM_DEST_NAME_LENGTH; i++)
  300.             local_sym_dest_name[i] = current->sym_dest_name[i];
  301.     }
  302.     else {
  303.         /* fill the field with random data */
  304.         fill_field((char *)local_sym_dest_name,
  305.                    (size_t)SYM_DEST_NAME_LENGTH);
  306.     }
  307.  
  308. #ifndef NOCPIC
  309.     cminit(current->conversation_ID,
  310.            local_sym_dest_name,
  311.            &(current->return_code));
  312. #endif
  313.  
  314.     return get_new_conversation_state(current);
  315. }
  316.  
  317.  
  318. CM_CONVERSATION_STATE build_cmptrc (CPIC_CONV_ATTRIB *current)
  319. {
  320.     /*=========================================================================
  321.      * Prepare To Receive Confirm
  322.      *=======================================================================*/
  323.  
  324.     current->prepare_to_receive_type = CM_PREP_TO_RECEIVE_CONFIRM;
  325.  
  326. #ifndef NOCPIC
  327.     cmsptr(current->conversation_ID,
  328.            &(current->prepare_to_receive_type),
  329.            &(current->return_code));
  330.  
  331.     cmptr (current->conversation_ID,
  332.            &(current->return_code));
  333. #endif
  334.  
  335.     return get_new_conversation_state(current);
  336. }
  337.  
  338.  
  339. CM_CONVERSATION_STATE build_cmptrf (CPIC_CONV_ATTRIB *current)
  340. {
  341.     /*=========================================================================
  342.      * Prepare To Receive Flush
  343.      *=======================================================================*/
  344.  
  345.     current->prepare_to_receive_type = CM_PREP_TO_RECEIVE_FLUSH;
  346.  
  347. #ifndef NOCPIC
  348.     cmsptr(current->conversation_ID,
  349.            &(current->prepare_to_receive_type),
  350.            &(current->return_code));
  351.  
  352.     cmptr (current->conversation_ID,
  353.            &(current->return_code));
  354. #endif
  355.  
  356.     return get_new_conversation_state(current);
  357. }
  358.  
  359.  
  360. CM_CONVERSATION_STATE build_cmptrs (CPIC_CONV_ATTRIB *current)
  361. {
  362.     /*=========================================================================
  363.      * Prepare To Receive Sync Level
  364.      *=======================================================================*/
  365.  
  366.     current->prepare_to_receive_type = CM_PREP_TO_RECEIVE_SYNC_LEVEL;
  367.  
  368. #ifndef NOCPIC
  369.     cmsptr(current->conversation_ID,
  370.            &(current->prepare_to_receive_type),
  371.            &(current->return_code));
  372.  
  373.     cmptr (current->conversation_ID,
  374.            &(current->return_code));
  375. #endif
  376.  
  377.     return get_new_conversation_state(current);
  378. }
  379.  
  380.  
  381. CM_CONVERSATION_STATE build_cmrcvi (CPIC_CONV_ATTRIB *current)
  382. {
  383.     /*=========================================================================
  384.      * Receive Immediate
  385.      *=======================================================================*/
  386.  
  387.     unsigned char *local_buffer = (unsigned char *)NULL;
  388.  
  389.     if (TRUE == generate_valid_parm()) {
  390.         current->requested_length = (CM_INT32)rand() % 32768;
  391.     }
  392.     else {
  393.         current->requested_length = get_random_CM_INT32();
  394.     }
  395.  
  396.     local_buffer = (unsigned char *)
  397.                        get_memory((size_t)current->requested_length);
  398.     current->receive_type = CM_RECEIVE_IMMEDIATE;
  399.  
  400. #ifndef NOCPIC
  401.     cmsrt (current->conversation_ID,
  402.            &(current->receive_type),
  403.            &(current->return_code));
  404.  
  405.     cmrcv (current->conversation_ID,
  406.            (unsigned char CM_PTR)local_buffer,
  407.            &(current->requested_length),
  408.            &(current->data_received),
  409.            &(current->received_length),
  410.            &(current->status_received),
  411.            &(current->request_to_send_received),
  412.            &(current->return_code));
  413. #endif
  414.  
  415.     free_memory((void *)local_buffer);
  416.  
  417.     /* validate the returned request_to_send_received value */
  418.     (void)check_rts(current);
  419.  
  420.     /* validate whether everything returned by the Receive was right */
  421.     (void)check_receive(current);
  422.  
  423.     return get_new_conversation_state(current);
  424. }
  425.  
  426.  
  427. CM_CONVERSATION_STATE build_cmrcvw (CPIC_CONV_ATTRIB *current)
  428. {
  429.     /*=========================================================================
  430.      * Receive and Wait
  431.      *=======================================================================*/
  432.  
  433.     unsigned char *local_buffer = (unsigned char *)NULL;
  434.  
  435.     if (TRUE == generate_valid_parm()) {
  436.         current->requested_length = (CM_INT32)rand() % 32768;
  437.     }
  438.     else {
  439.         current->requested_length = get_random_CM_INT32();
  440.     }
  441.  
  442.     local_buffer = (unsigned char *)
  443.                       get_memory((size_t)current->requested_length);
  444.  
  445.     current->receive_type = CM_RECEIVE_AND_WAIT;
  446.  
  447. #ifndef NOCPIC
  448.     cmsrt (current->conversation_ID,
  449.            &(current->receive_type),
  450.            &(current->return_code));
  451.  
  452.     cmrcv (current->conversation_ID,
  453.            (unsigned char CM_PTR)local_buffer,
  454.            &(current->requested_length),
  455.            &(current->data_received),
  456.            &(current->received_length),
  457.            &(current->status_received),
  458.            &(current->request_to_send_received),
  459.            &(current->return_code));
  460. #endif
  461.  
  462.     free_memory((void *)local_buffer);
  463.  
  464.     /* validate the returned request_to_send_received value */
  465.     (void)check_rts(current);
  466.  
  467.     /* validate whether everything returned by the Receive was right */
  468.     (void)check_receive(current);
  469.  
  470.     return get_new_conversation_state(current);
  471. }
  472.  
  473.  
  474. CM_CONVERSATION_STATE build_cmrts  (CPIC_CONV_ATTRIB *current)
  475. {
  476.     /*=========================================================================
  477.      * Request To Send
  478.      *=======================================================================*/
  479.  
  480. #ifndef NOCPIC
  481.     cmrts (current->conversation_ID,
  482.            &(current->return_code));
  483. #endif
  484.  
  485.     return get_new_conversation_state(current);
  486. }
  487.  
  488.  
  489. CM_CONVERSATION_STATE build_cmsct  (CPIC_CONV_ATTRIB *current)
  490. {
  491.     /*=========================================================================
  492.      * Set Conversation Type
  493.      *=======================================================================*/
  494.  
  495.     CM_CONVERSATION_TYPE local_conversation_type= 0;
  496.  
  497.     if (TRUE == generate_valid_parm()) {
  498.         switch (rand() % 2) {
  499.             case 0:
  500.                 local_conversation_type = CM_BASIC_CONVERSATION;
  501.                 break;
  502.             case 1:
  503.                 local_conversation_type = CM_MAPPED_CONVERSATION;
  504.                 break;
  505.         }
  506.     }
  507.     else {
  508.         local_conversation_type = (CM_CONVERSATION_TYPE)get_random_CM_INT32();
  509.     }
  510.  
  511. #ifndef NOCPIC
  512.     cmsct (current->conversation_ID,
  513.            (CM_INT32 CM_PTR)&(local_conversation_type),
  514.            &(current->return_code));
  515. #endif
  516.  
  517.     if (CM_OK == current->return_code)
  518.         current->conversation_type = local_conversation_type;
  519.  
  520.     return get_new_conversation_state(current);
  521. }
  522.  
  523.  
  524. CM_CONVERSATION_STATE build_cmsdt  (CPIC_CONV_ATTRIB *current)
  525. {
  526.     /*=========================================================================
  527.      * Set Deallocate Type
  528.      *=======================================================================*/
  529.  
  530.     CM_DEALLOCATE_TYPE local_deallocate_type;
  531.  
  532.     if (TRUE == generate_valid_parm()) {
  533.         switch (rand() % 4) {
  534.             case 1:
  535.                 local_deallocate_type = CM_DEALLOCATE_FLUSH;
  536.                 break;
  537.             case 2:
  538.                 local_deallocate_type = CM_DEALLOCATE_CONFIRM;
  539.                 break;
  540.             case 3:
  541.                 local_deallocate_type = CM_DEALLOCATE_ABEND;
  542.                 break;
  543.             default:
  544.                 local_deallocate_type = CM_DEALLOCATE_SYNC_LEVEL;
  545.                 break;
  546.         }
  547.     }
  548.     else {
  549.         local_deallocate_type = (CM_DEALLOCATE_TYPE)get_random_CM_INT32();
  550.     }
  551.  
  552. #ifndef NOCPIC
  553.     cmsdt (current->conversation_ID,
  554.            (CM_INT32 CM_PTR)&(local_deallocate_type),
  555.            &(current->return_code));
  556. #endif
  557.  
  558.     if (CM_OK == current->return_code)
  559.         current->deallocate_type = local_deallocate_type;
  560.  
  561.     return get_new_conversation_state(current);
  562. }
  563.  
  564.  
  565. CM_CONVERSATION_STATE build_cmsed  (CPIC_CONV_ATTRIB *current)
  566. {
  567.     /*=========================================================================
  568.      * Set Error Direction
  569.      *=======================================================================*/
  570.  
  571.     CM_ERROR_DIRECTION local_error_direction;
  572.  
  573.     if (TRUE == generate_valid_parm()) {
  574.         switch (rand() % 2) {
  575.             case 1:
  576.                 local_error_direction = CM_SEND_ERROR;
  577.                 break;
  578.             default:
  579.                 local_error_direction = CM_RECEIVE_ERROR;
  580.                 break;
  581.         }
  582.     }
  583.     else {
  584.         local_error_direction = (CM_ERROR_DIRECTION)get_random_CM_INT32();
  585.     }
  586.  
  587. #ifndef NOCPIC
  588.     cmsed (current->conversation_ID,
  589.            (CM_INT32 CM_PTR)&(local_error_direction),
  590.            &(current->return_code));
  591. #endif
  592.  
  593.     if (CM_OK == current->return_code)
  594.         current->error_direction = local_error_direction;
  595.  
  596.     return get_new_conversation_state(current);
  597. }
  598.  
  599.  
  600. CM_CONVERSATION_STATE build_cmsend (CPIC_CONV_ATTRIB *current)
  601. {
  602.     /*=========================================================================
  603.      * Send Data
  604.      *=======================================================================*/
  605.  
  606.     unsigned char *local_send_data;
  607.     CM_INT32 local_send_data_length;
  608.  
  609.     if (TRUE == generate_valid_parm()) {
  610.         local_send_data_length = (CM_INT32)rand();
  611.     }
  612.     else {
  613.         local_send_data_length = get_random_CM_INT32();
  614.     }
  615.  
  616.     local_send_data = (unsigned char *)
  617.                          get_memory((size_t)local_send_data_length);
  618.  
  619.     /* fill the field with random data */
  620.     fill_field((char *)local_send_data,
  621.                (size_t)local_send_data_length);
  622.  
  623. #ifndef NOCPIC
  624.     cmsend(current->conversation_ID,
  625.            local_send_data,
  626.            &(local_send_data_length),
  627.            &(current->request_to_send_received),
  628.            &(current->return_code));
  629. #endif
  630.  
  631.     if (CM_OK == current->return_code)
  632.         current->send_length = local_send_data_length;
  633.  
  634.     free_memory((void *)local_send_data);
  635.  
  636.     /* validate the returned request_to_send_received value */
  637.     (void)check_rts(current);
  638.  
  639.     return get_new_conversation_state(current);
  640. }
  641.  
  642.  
  643. CM_CONVERSATION_STATE build_cmserr (CPIC_CONV_ATTRIB *current)
  644. {
  645.     /*=========================================================================
  646.      * Send Error
  647.      *=======================================================================*/
  648.  
  649. #ifndef NOCPIC
  650.     cmserr(current->conversation_ID,
  651.            &(current->request_to_send_received),
  652.            &(current->return_code));
  653. #endif
  654.  
  655.     /* validate the returned request_to_send_received value */
  656.     (void)check_rts(current);
  657.  
  658.     return get_new_conversation_state(current);
  659. }
  660.  
  661.  
  662. CM_CONVERSATION_STATE build_cmsf   (CPIC_CONV_ATTRIB *current)
  663. {
  664.     /*=========================================================================
  665.      * Set Fill (there is no Extract_Fill call)
  666.      *=======================================================================*/
  667.  
  668.     CM_FILL local_fill;
  669.  
  670.     if (TRUE == generate_valid_parm()) {
  671.         switch (rand() % 2) {
  672.             case 1:
  673.                 local_fill = CM_FILL_BUFFER;
  674.                 break;
  675.             default:
  676.                 local_fill = CM_FILL_LL;
  677.                 break;
  678.         }
  679.     }
  680.     else {
  681.         local_fill = (CM_FILL)get_random_CM_INT32();
  682.     }
  683.  
  684. #ifndef NOCPIC
  685.     cmsf  (current->conversation_ID,
  686.            (CM_INT32 CM_PTR)&(local_fill),
  687.            &(current->return_code));
  688. #endif
  689.  
  690.     if (CM_OK == current->return_code)
  691.         current->fill = local_fill;
  692.  
  693.     return get_new_conversation_state(current);
  694. }
  695.  
  696.  
  697. CM_CONVERSATION_STATE build_cmsld  (CPIC_CONV_ATTRIB *current)
  698. {
  699.     /*=========================================================================
  700.      * Set Log Data
  701.      *=======================================================================*/
  702.  
  703.     unsigned char *local_log_data;
  704.     CM_INT32 local_log_data_length;
  705.  
  706.     if (TRUE == generate_valid_parm()) {
  707.         local_log_data_length = rand() % 513;
  708.     }
  709.     else {
  710.         local_log_data_length = get_random_CM_INT32();
  711.     }
  712.  
  713.     local_log_data = (unsigned char *)
  714.                         get_memory((size_t)local_log_data_length);
  715.     /* fill the field with random data */
  716.     fill_field((char *)local_log_data,
  717.                (size_t)local_log_data_length);
  718.  
  719. #ifndef NOCPIC
  720.     cmsld (current->conversation_ID,
  721.            local_log_data,
  722.            &(local_log_data_length),
  723.            &(current->return_code));
  724. #endif
  725.  
  726.     if (CM_OK == current->return_code)
  727.         current->log_data_length = local_log_data_length;
  728.  
  729.     free_memory((void *)local_log_data);
  730.  
  731.     return get_new_conversation_state(current);
  732. }
  733.  
  734.  
  735. CM_CONVERSATION_STATE build_cmsmn  (CPIC_CONV_ATTRIB *current)
  736. {
  737.     /*=========================================================================
  738.      * Set Mode Name
  739.      *=======================================================================*/
  740.  
  741.     unsigned char *local_mode_name;
  742.     CM_INT32 local_mode_name_length;
  743.  
  744.     if (TRUE == generate_valid_parm()) {
  745.         CM_INT32 i;
  746.  
  747. #ifndef NOCPIC
  748.         cmemn (current->conversation_ID,
  749.                current->mode_name,
  750.                &(current->mode_name_length),
  751.                &(current->return_code));
  752. #endif
  753.  
  754.         /* current was initialized to all zeros (if CMEMN fails) */
  755.         local_mode_name_length = current->mode_name_length;
  756.         local_mode_name = (unsigned char *)
  757.                              get_memory((size_t)local_mode_name_length);
  758.         for (i = 0; i < local_mode_name_length; i++)
  759.             local_mode_name[i] = current->mode_name[i];
  760.     }
  761.     else {
  762.         local_mode_name_length = get_random_CM_INT32();
  763.         local_mode_name = (unsigned char *)
  764.                              get_memory((size_t)local_mode_name_length);
  765.  
  766.         /* fill the field with random data */
  767.         fill_field((char *)local_mode_name,
  768.                    (size_t)local_mode_name_length);
  769.     }
  770.  
  771.  
  772. #ifndef NOCPIC
  773.     cmsmn (current->conversation_ID,
  774.            (unsigned char CM_PTR)local_mode_name,
  775.            (CM_INT32 CM_PTR)&(local_mode_name_length),
  776.            &(current->return_code));
  777. #endif
  778.  
  779.     free_memory((void *)local_mode_name);
  780.  
  781.     return get_new_conversation_state(current);
  782. }
  783.  
  784.  
  785. CM_CONVERSATION_STATE build_cmspln (CPIC_CONV_ATTRIB *current)
  786. {
  787.     /*=========================================================================
  788.      * Set Partner LU Name
  789.      *=======================================================================*/
  790.  
  791.     unsigned char *local_partner_LU_name;
  792.     CM_INT32 local_partner_LU_name_length;
  793.  
  794.     if (TRUE == generate_valid_parm()) {
  795.         CM_INT32 i;
  796.  
  797. #ifndef NOCPIC
  798.         cmepln(current->conversation_ID,
  799.                current->partner_LU_name,
  800.                &(current->partner_LU_name_length),
  801.                &(current->return_code));
  802. #endif
  803.  
  804.         /* current was initialized to all zeros (if CMEPLN fails) */
  805.         local_partner_LU_name_length = current->partner_LU_name_length;
  806.         local_partner_LU_name = (unsigned char *)
  807.                                get_memory((size_t)local_partner_LU_name_length);
  808.  
  809.         for (i = 0; i < local_partner_LU_name_length; i++)
  810.             local_partner_LU_name[i] = current->partner_LU_name[i];
  811.     }
  812.     else {
  813.         local_partner_LU_name_length = get_random_CM_INT32();
  814.         local_partner_LU_name =
  815.              (unsigned char *)get_memory((size_t)local_partner_LU_name_length);
  816.         /* fill the field with random data */
  817.         fill_field((char *)local_partner_LU_name,
  818.                    (size_t)local_partner_LU_name_length);
  819.     }
  820.  
  821.  
  822. #ifndef NOCPIC
  823.     cmspln(current->conversation_ID,
  824.            (unsigned char CM_PTR)local_partner_LU_name,
  825.            (CM_INT32 CM_PTR)&(local_partner_LU_name_length),
  826.            &(current->return_code));
  827. #endif
  828.  
  829.     free_memory((void *)local_partner_LU_name);
  830.  
  831.     return get_new_conversation_state(current);
  832. }
  833.  
  834.  
  835. CM_CONVERSATION_STATE build_cmsptr (CPIC_CONV_ATTRIB *current)
  836. {
  837.     /*=========================================================================
  838.      * Set Prepare To Receive Type
  839.      *=======================================================================*/
  840.  
  841.     CM_PREPARE_TO_RECEIVE_TYPE local_prepare_to_receive_type;
  842.  
  843.     if (TRUE == generate_valid_parm()) {
  844.         switch (rand() % 3) {
  845.             case 1:
  846.                 local_prepare_to_receive_type = CM_PREP_TO_RECEIVE_FLUSH;
  847.                 break;
  848.             case 2:
  849.                 local_prepare_to_receive_type = CM_PREP_TO_RECEIVE_CONFIRM;
  850.                 break;
  851.             default:
  852.                 local_prepare_to_receive_type = CM_PREP_TO_RECEIVE_SYNC_LEVEL;
  853.                 break;
  854.         }
  855.     }
  856.     else {
  857.         local_prepare_to_receive_type =
  858.                 (CM_PREPARE_TO_RECEIVE_TYPE)get_random_CM_INT32();
  859.     }
  860.  
  861. #ifndef NOCPIC
  862.     cmsptr(current->conversation_ID,
  863.            (CM_INT32 CM_PTR)&(local_prepare_to_receive_type),
  864.            &(current->return_code));
  865. #endif
  866.  
  867.     if (CM_OK == current->return_code)
  868.         current->prepare_to_receive_type = local_prepare_to_receive_type;
  869.  
  870.     return get_new_conversation_state(current);
  871. }
  872.  
  873.  
  874. CM_CONVERSATION_STATE build_cmsrc  (CPIC_CONV_ATTRIB *current)
  875. {
  876.     /*=========================================================================
  877.      * Set Return Control
  878.      *=======================================================================*/
  879.  
  880.     CM_RETURN_CONTROL local_return_control;
  881.  
  882.     if (TRUE == generate_valid_parm()) {
  883.         switch (rand() % 2) {
  884.             case 1:
  885.                 local_return_control = CM_IMMEDIATE;
  886.                 break;
  887.             default:
  888.                 local_return_control = CM_WHEN_SESSION_ALLOCATED;
  889.                 break;
  890.         }
  891.     }
  892.     else {
  893.         local_return_control = (CM_RETURN_CONTROL)get_random_CM_INT32();
  894.     }
  895.  
  896. #ifndef NOCPIC
  897.     cmsrc (current->conversation_ID,
  898.            (CM_INT32 CM_PTR)&(local_return_control),
  899.            &(current->return_code));
  900. #endif
  901.  
  902.     if (CM_OK == current->return_code)
  903.         current->return_control = local_return_control;
  904.  
  905.     return get_new_conversation_state(current);
  906. }
  907.  
  908.  
  909. CM_CONVERSATION_STATE build_cmsrt  (CPIC_CONV_ATTRIB *current)
  910. {
  911.     /*=========================================================================
  912.      * Set Receive Type
  913.      *=======================================================================*/
  914.  
  915.     CM_RECEIVE_TYPE local_receive_type;
  916.  
  917.     if (TRUE == generate_valid_parm()) {
  918.         switch (rand() % 2) {
  919.             case 1:
  920.                 local_receive_type = CM_RECEIVE_IMMEDIATE;
  921.                 break;
  922.             default:
  923.                 local_receive_type = CM_RECEIVE_AND_WAIT;
  924.                 break;
  925.         }
  926.     }
  927.     else {
  928.         local_receive_type = (CM_RECEIVE_TYPE)get_random_CM_INT32();
  929.     }
  930.  
  931. #ifndef NOCPIC
  932.     cmsrt (current->conversation_ID,
  933.            (CM_INT32 CM_PTR)&(local_receive_type),
  934.            &(current->return_code));
  935. #endif
  936.  
  937.     if (CM_OK == current->return_code)
  938.         current->receive_type = local_receive_type;
  939.  
  940.     return get_new_conversation_state(current);
  941. }
  942.  
  943.  
  944. CM_CONVERSATION_STATE build_cmssl  (CPIC_CONV_ATTRIB *current)
  945. {
  946.     /*=========================================================================
  947.      * Set Sync Level
  948.      *=======================================================================*/
  949.  
  950.     CM_SYNC_LEVEL local_sync_level;
  951.  
  952.     if (TRUE == generate_valid_parm()) {
  953.         switch (rand() % 3) {
  954.             case 1:
  955.                 local_sync_level = CM_CONFIRM;
  956.                 break;
  957.             case 2:
  958.                 local_sync_level = CM_SYNC_POINT;
  959.                 break;
  960.             default:
  961.                 local_sync_level = CM_NONE;
  962.                 break;
  963.         }
  964.     }
  965.     else {
  966.         local_sync_level = (CM_SYNC_LEVEL)get_random_CM_INT32();
  967.     }
  968.  
  969. #ifndef NOCPIC
  970.     cmssl (current->conversation_ID,
  971.            (CM_INT32 CM_PTR)&(local_sync_level),
  972.            &(current->return_code));
  973. #endif
  974.  
  975.     if (CM_OK == current->return_code)
  976.         current->sync_level = local_sync_level;
  977.  
  978.     return get_new_conversation_state(current);
  979. }
  980.  
  981.  
  982. CM_CONVERSATION_STATE build_cmsst  (CPIC_CONV_ATTRIB *current)
  983. {
  984.     /*=========================================================================
  985.      * Set Send Type
  986.      *=======================================================================*/
  987.  
  988.     CM_SEND_TYPE local_send_type;
  989.  
  990.     if (TRUE == generate_valid_parm()) {
  991.         switch (rand() % 5) {
  992.             case 1:
  993.                 local_send_type = CM_SEND_AND_FLUSH;
  994.                 break;
  995.             case 2:
  996.                 local_send_type = CM_SEND_AND_CONFIRM;
  997.                 break;
  998.             case 3:
  999.                 local_send_type = CM_SEND_AND_PREP_TO_RECEIVE;
  1000.                 break;
  1001.             case 4:
  1002.                 local_send_type = CM_SEND_AND_DEALLOCATE;
  1003.                 break;
  1004.             default:
  1005.                 local_send_type = CM_BUFFER_DATA;
  1006.                 break;
  1007.         }
  1008.     }
  1009.     else {
  1010.         local_send_type = (CM_SEND_TYPE)get_random_CM_INT32();
  1011.     }
  1012.  
  1013. #ifndef NOCPIC
  1014.     cmsst (current->conversation_ID,
  1015.            (CM_INT32 CM_PTR)&(local_send_type),
  1016.            &(current->return_code));
  1017. #endif
  1018.  
  1019.     if (CM_OK == current->return_code)
  1020.         current->send_type = local_send_type;
  1021.  
  1022.     return get_new_conversation_state(current);
  1023. }
  1024.  
  1025.  
  1026. CM_CONVERSATION_STATE build_cmstpn (CPIC_CONV_ATTRIB *current)
  1027. {
  1028.     /*=========================================================================
  1029.      * Set TP Name
  1030.      *=======================================================================*/
  1031.  
  1032.     void *local_TP_name = (void *)NULL;
  1033.     CM_INT32 local_TP_name_length = 0;
  1034.  
  1035.     if (TRUE == generate_valid_parm()) {
  1036.         local_TP_name = get_memory((size_t)local_TP_name_length);
  1037.     }
  1038.     else {
  1039.         local_TP_name_length = get_random_CM_INT32();
  1040.         local_TP_name = get_memory((size_t)local_TP_name_length);
  1041.         /* fill the field with random data */
  1042.         fill_field((char *)local_TP_name,
  1043.                    (size_t)local_TP_name_length);
  1044.     }
  1045.  
  1046.  
  1047. #ifndef NOCPIC
  1048.     cmstpn(current->conversation_ID,
  1049.            (unsigned char CM_PTR)local_TP_name,
  1050.            (CM_INT32 CM_PTR)&(local_TP_name_length),
  1051.            &(current->return_code));
  1052. #endif
  1053.  
  1054.     free_memory((void *)local_TP_name);
  1055.  
  1056.     return get_new_conversation_state(current);
  1057. }
  1058.  
  1059.  
  1060. CM_CONVERSATION_STATE build_cmtrts (CPIC_CONV_ATTRIB *current)
  1061. {
  1062.     /*=========================================================================
  1063.      * Test Request To Send
  1064.      *=======================================================================*/
  1065.  
  1066. #ifndef NOCPIC
  1067.     cmtrts(current->conversation_ID,
  1068.            &(current->request_to_send_received),
  1069.            &(current->return_code));
  1070. #endif
  1071.  
  1072.     /* validate the returned request_to_send_received value */
  1073.     (void)check_rts(current);
  1074.  
  1075.     return get_new_conversation_state(current);
  1076.  
  1077. }
  1078.  
  1079.  
  1080. void fetch_conversation_state(CPIC_CONV_ATTRIB *current)
  1081. {
  1082.     /*=========================================================================
  1083.      * Determine the current conversation state.
  1084.      *=======================================================================*/
  1085.  
  1086. #ifdef NOCPIC
  1087.     /* Randomly generate the next state */
  1088.     current->conversation_state = (CM_CONVERSATION_STATE)
  1089.                                   (rand() % (NUM_CPIC_STATES));
  1090. #else
  1091.     /* Extract the current conversation state, trusting CPI-C to return
  1092.      * the correct answer.  This call has potential portability
  1093.      * problems, since Extract Conversation State is not implemented on
  1094.      * all platforms.
  1095.      */
  1096.     cmecs (current->conversation_ID,
  1097.            &(current->conversation_state),
  1098.            &(current->return_code));
  1099. #endif
  1100. }
  1101.