Back to index

im-sdk  12.3.91
im-createic.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_createic_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_icattribute *     attr_list)
00016 {
00017     IIIMP_message *  m;
00018     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00019     if (NULL == m) {
00020        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00021        return NULL;
00022     }
00023     m->opcode = IM_CREATEIC;
00024     m->im_id = im_id;
00025     m->ic_id = -1;
00026     m->v.createic.attr_list = attr_list;
00027     return m;
00028 }
00029 
00030 
00031 void
00032 iiimp_createic_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00033 {
00034     if (NULL == m) return;
00035     iiimp_icattribute_list_delete(data_s, m->v.createic.attr_list);
00036     free(m);
00037     return;
00038 }
00039 
00040 
00041 uchar_t *
00042 iiimp_createic_pack(
00043     IIIMP_data_s *   data_s,
00044     IIIMP_card16     im_id,
00045     IIIMP_icattribute *     attr_list,
00046     size_t *         buf_size)
00047 {
00048     size_t           nbyte;
00049     int                     length;
00050     uchar_t *        buf;
00051     size_t           rest;
00052     uchar_t *        p;
00053     size_t           attr_list_nbyte;
00054     IIIMP_icattribute *     a;
00055 
00056     nbyte = 0;
00057     nbyte += 2;      /* input method id */
00058     nbyte += 2;      /* byte length of ic-attribute */
00059     for (attr_list_nbyte = 0, a = attr_list; NULL != a; a = a->next) {
00060        attr_list_nbyte += a->nbyte;
00061     }
00062     nbyte += attr_list_nbyte;      /* ic-attributes */
00063 
00064     length = (nbyte >> 2);
00065     *buf_size = (1 + 3 + nbyte);
00066 
00067     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00068     if (NULL == buf) {
00069        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00070        return NULL;
00071     }
00072 
00073     PUT_PACKET_HEADER(buf, IM_CREATEIC, length);
00074 
00075     rest = nbyte;
00076     p = (buf + 4);
00077 
00078     PUTU16(im_id, rest, p, data_s->byte_swap);
00079     PUTU16(attr_list_nbyte, rest, p, data_s->byte_swap);
00080     iiimp_icattribute_list_pack(data_s, attr_list, &rest, &p);
00081 
00082     return buf;
00083 }
00084 
00085 
00086 IIIMP_message *
00087 iiimp_createic_unpack(
00088     IIIMP_data_s *   data_s,
00089     IIIMP_card7             opcode,
00090     size_t *         nbyte,
00091     const uchar_t ** ptr)
00092 {
00093     IIIMP_message *  m;
00094     IIIMP_createic_v *      v;
00095     size_t           rest;
00096     const uchar_t *  p;
00097     int                     len;
00098 
00099     rest = *nbyte;
00100     p = *ptr;
00101 
00102     if (rest < (2 + 2)) {
00103        data_s->status = IIIMP_DATA_INVALID;
00104        return NULL;
00105     }
00106 
00107     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00108     if (NULL == m) {
00109        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00110        return NULL;
00111     }
00112     v = &(m->v.createic);
00113 
00114     m->opcode = opcode;
00115 
00116     GETU16(m->im_id, rest, p, data_s->byte_swap);
00117     m->ic_id = -1;
00118     GETU16(len, rest, p, data_s->byte_swap);
00119 
00120     if ((len < 0) || (rest < len) || (0 != (len & 0x03))) {
00121        free(m);
00122        data_s->status = IIIMP_DATA_INVALID;
00123        return NULL;
00124     }
00125 
00126     if (0 < len) {
00127        v->attr_list = iiimp_icattribute_list_unpack(data_s, &rest, &p, len);
00128        if (NULL == v->attr_list) {
00129            iiimp_createic_delete(data_s, m);
00130            return NULL;
00131        }
00132     } else {
00133        v->attr_list = NULL;
00134     }
00135 
00136     *nbyte = rest;
00137     *ptr = p;
00138 
00139     return m;
00140 }
00141 
00142 
00143 void
00144 iiimp_createic_print(
00145     IIIMP_data_s *   data_s,
00146     IIIMP_message *  m)
00147 {
00148     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00149     iiimp_icattribute_list_print(data_s, m->v.createic.attr_list);
00150 }
00151 
00152 
00153 /* Local Variables: */
00154 /* c-file-style: "iiim-project" */
00155 /* End: */