Back to index

im-sdk  12.3.91
im-forward-event-with-operations-reply.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_message *
00012 iiimp_forward_event_with_operations_reply_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_operation *       operation)
00017 {
00018     IIIMP_message *  m;
00019     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00020     if (NULL == m) {
00021        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00022        return NULL;
00023     }
00024     m->opcode = IM_FORWARD_EVENT_WITH_OPERATIONS_REPLY;
00025     m->im_id = im_id;
00026     m->ic_id = ic_id;
00027     m->v.forward_event_with_operations_reply.operation = operation;
00028     return m;
00029 }
00030 
00031 
00032 void
00033 iiimp_forward_event_with_operations_reply_delete(
00034     IIIMP_data_s *   data_s,
00035     IIIMP_message *  m)
00036 {
00037     if (NULL == m) return;
00038     iiimp_operation_list_delete(
00039        data_s, m->v.forward_event_with_operations_reply.operation);
00040     free(m);
00041     return;
00042 }
00043 
00044 
00045 uchar_t *
00046 iiimp_forward_event_with_operations_reply_pack(
00047     IIIMP_data_s *   data_s,
00048     IIIMP_card16     im_id,
00049     IIIMP_card16     ic_id,
00050     IIIMP_operation *       operation_list,
00051     size_t *         buf_size)
00052 {
00053     size_t           nbyte;
00054     int                     length;
00055     uchar_t *        buf;
00056     size_t           rest;
00057     uchar_t *        p;
00058     size_t           op_list_nbyte;
00059     IIIMP_operation *       o;
00060 
00061     nbyte = 0;
00062     nbyte += 2;      /* input method id */
00063     nbyte += 2;      /* input contents id */
00064     nbyte += 4;      /* byte length of operation list */
00065     for (op_list_nbyte = 0, o = operation_list; NULL != o; o = o->next) {
00066        op_list_nbyte += o->nbyte;
00067     }
00068     nbyte += op_list_nbyte; /* operation list */
00069 
00070     length = (nbyte >> 2);
00071     *buf_size = (1 + 3 + nbyte);
00072 
00073     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00074     if (NULL == buf) {
00075        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00076        return NULL;
00077     }
00078 
00079     PUT_PACKET_HEADER(buf, IM_FORWARD_EVENT_WITH_OPERATIONS_REPLY, length);
00080 
00081     rest = nbyte;
00082     p = (buf + 4);
00083 
00084     PUTU16(im_id, rest, p, data_s->byte_swap);
00085     PUTU16(ic_id, rest, p, data_s->byte_swap);
00086     PUTU32(op_list_nbyte, rest, p, data_s->byte_swap);
00087     iiimp_operation_list_pack(data_s, operation_list, &rest, &p);
00088 
00089     return buf;
00090 }
00091 
00092 
00093 IIIMP_message *
00094 iiimp_forward_event_with_operations_reply_unpack(
00095     IIIMP_data_s *   data_s,
00096     IIIMP_card7             opcode,
00097     size_t *         nbyte,
00098     const uchar_t ** ptr)
00099 {
00100     IIIMP_message *                              m;
00101     IIIMP_forward_event_with_operations_reply_v *       v;
00102     size_t                                       rest;
00103     const uchar_t *                              p;
00104     int                                                 len;
00105 
00106     rest = *nbyte;
00107     p = *ptr;
00108 
00109     if (rest < (2 + 2 + 4)) {
00110        data_s->status = IIIMP_DATA_INVALID;
00111        return NULL;
00112     }
00113 
00114     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00115     if (NULL == m) {
00116        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00117        return NULL;
00118     }
00119     v = &(m->v.forward_event_with_operations_reply);
00120 
00121     m->opcode = opcode;
00122 
00123     GETU16(m->im_id, rest, p, data_s->byte_swap);
00124     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00125 
00126     GET32(len, rest, p, data_s->byte_swap);
00127     if ((len < 0) || (rest < len)) {
00128        data_s->status = IIIMP_DATA_INVALID;
00129        return NULL;
00130     }
00131 
00132     v->operation = iiimp_operation_list_unpack(data_s, &rest, &p, len);
00133     if (NULL == v->operation) {
00134        free(m);
00135        return NULL;
00136     }
00137 
00138     *nbyte = rest;
00139     *ptr = p;
00140 
00141     return m;
00142 }
00143 
00144 
00145 void
00146 iiimp_forward_event_with_operations_reply_print(
00147     IIIMP_data_s *   data_s,
00148     IIIMP_message *  m)
00149 {
00150     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00151     iiimp_operation_print(data_s,
00152                        m->v.forward_event_with_operations_reply.operation);
00153 }
00154 
00155 
00156 /* Local Variables: */
00157 /* c-file-style: "iiim-project" */
00158 /* End: */