Back to index

im-sdk  12.3.91
im-forward-event-with-operations.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_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_contents * contents,
00017     IIIMP_operation *       operation)
00018 {
00019     IIIMP_message *  m;
00020     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00021     if (NULL == m) {
00022        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00023        return NULL;
00024     }
00025     m->opcode = IM_FORWARD_EVENT_WITH_OPERATIONS;
00026     m->im_id = im_id;
00027     m->ic_id = ic_id;
00028     m->v.forward_event_with_operations.contents = contents;
00029     m->v.forward_event_with_operations.operation = operation;
00030     return m;
00031 }
00032 
00033 
00034 void
00035 iiimp_forward_event_with_operations_delete(
00036     IIIMP_data_s *   data_s,
00037     IIIMP_message *  m)
00038 {
00039     if (NULL == m) return;
00040     iiimp_contents_delete(data_s, m->v.forward_event_with_operations.contents);
00041     iiimp_operation_list_delete(data_s,
00042                             m->v.forward_event_with_operations.operation);
00043     free(m);
00044     return;
00045 }
00046 
00047 
00048 uchar_t *
00049 iiimp_forward_event_with_operations_pack(
00050     IIIMP_data_s *   data_s,
00051     IIIMP_card16     im_id,
00052     IIIMP_card16     ic_id,
00053     IIIMP_contents * contents,
00054     IIIMP_operation *       operation_list,
00055     size_t *         buf_size)
00056 {
00057     size_t           nbyte;
00058     int                     length;
00059     uchar_t *        buf;
00060     size_t           rest;
00061     uchar_t *        p;
00062     size_t           op_list_nbyte;
00063     IIIMP_operation *       o;
00064 
00065     nbyte = 0;
00066     nbyte += 2;                    /* input method id */
00067     nbyte += 2;                    /* input contents id */
00068     nbyte += contents->nbyte;      /* forwarded string of text */
00069     nbyte += 4;                    /* byte length of operation list */
00070     for (op_list_nbyte = 0, o = operation_list; NULL != o; o = o->next) {
00071        op_list_nbyte += o->nbyte;
00072     }
00073     nbyte += op_list_nbyte; /* operation list */
00074 
00075     length = (nbyte >> 2);
00076     *buf_size = (1 + 3 + nbyte);
00077 
00078     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00079     if (NULL == buf) {
00080        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00081        return NULL;
00082     }
00083 
00084     PUT_PACKET_HEADER(buf, IM_FORWARD_EVENT_WITH_OPERATIONS, length);
00085 
00086     rest = nbyte;
00087     p = (buf + 4);
00088 
00089     PUTU16(im_id, rest, p, data_s->byte_swap);
00090     PUTU16(ic_id, rest, p, data_s->byte_swap);
00091     iiimp_contents_pack(data_s, contents, &rest, &p);
00092     PUTU32(op_list_nbyte, rest, p, data_s->byte_swap);
00093     iiimp_operation_list_pack(data_s, operation_list, &rest, &p);
00094 
00095     return buf;
00096 }
00097 
00098 
00099 IIIMP_message *
00100 iiimp_forward_event_with_operations_unpack(
00101     IIIMP_data_s *   data_s,
00102     IIIMP_card7             opcode,
00103     size_t *         nbyte,
00104     const uchar_t ** ptr)
00105 {
00106     IIIMP_message *                       m;
00107     IIIMP_forward_event_with_operations_v *      v;
00108     size_t                                rest;
00109     const uchar_t *                       p;
00110     int                                          len;
00111 
00112     rest = *nbyte;
00113     p = *ptr;
00114 
00115     if (rest < (2 + 2 + 4)) {
00116        data_s->status = IIIMP_DATA_INVALID;
00117        return NULL;
00118     }
00119 
00120     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00121     if (NULL == m) {
00122        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00123        return NULL;
00124     }
00125     v = &(m->v.forward_event_with_operations);
00126 
00127     m->opcode = opcode;
00128 
00129     GETU16(m->im_id, rest, p, data_s->byte_swap);
00130     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00131 
00132     v->contents = iiimp_contents_unpack(data_s, &rest, &p, rest);
00133     if (NULL == v->contents) {
00134        free(m);
00135        return NULL;
00136     }
00137 
00138     GET32(len, rest, p, data_s->byte_swap);
00139     if ((len < 0) || (rest < len)) {
00140        data_s->status = IIIMP_DATA_INVALID;
00141        return NULL;
00142     }
00143 
00144     v->operation = iiimp_operation_list_unpack(data_s, &rest, &p, len);
00145     if (NULL == v->operation) {
00146        iiimp_contents_delete(data_s, v->contents);
00147        free(m);
00148        return NULL;
00149     }
00150 
00151     *nbyte = rest;
00152     *ptr = p;
00153 
00154     return m;
00155 }
00156 
00157 
00158 void
00159 iiimp_forward_event_with_operations_print(
00160     IIIMP_data_s *   data_s,
00161     IIIMP_message *  m)
00162 {
00163     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00164     iiimp_contents_print(data_s, m->v.forward_event_with_operations.contents);
00165     iiimp_operation_print(data_s, m->v.forward_event_with_operations.operation);
00166 }
00167 
00168 
00169 /* Local Variables: */
00170 /* c-file-style: "iiim-project" */
00171 /* End: */