Back to index

im-sdk  12.3.91
im-setimvalues.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_setimvalues_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_imattribute *     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_SETIMVALUES;
00024     m->im_id = im_id;
00025     m->ic_id = -1;
00026     m->v.setimvalues.attr_list = attr_list;
00027     return m;
00028 }
00029 
00030 
00031 
00032 void
00033 iiimp_setimvalues_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_imattribute_list_delete(data_s, m->v.setimvalues.attr_list);
00037     free(m);
00038 }
00039 
00040 
00041 uchar_t *
00042 iiimp_setimvalues_pack(
00043     IIIMP_data_s *   data_s,
00044     IIIMP_card16     im_id,
00045     IIIMP_imattribute *     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_imattribute *     a;
00055 
00056     nbyte = 0;
00057     nbyte += 2;                    /* input method id */
00058     nbyte += 2;                    /* PAD(2) */
00059     nbyte += 4;                    /* byte length of data_s-attribute */
00060     for (attr_list_nbyte = 0, a = attr_list; NULL != a; a = a->next) {
00061        attr_list_nbyte += a->nbyte;
00062     }
00063     nbyte += attr_list_nbyte;      /* data_s-attributes */
00064 
00065     length = (nbyte >> 2);
00066     *buf_size = (1 + 3 + nbyte);
00067 
00068     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00069     if (NULL == buf) {
00070        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00071        return NULL;
00072     }
00073 
00074     PUT_PACKET_HEADER(buf, IM_SETIMVALUES, length);
00075 
00076     rest = nbyte;
00077     p = (buf + 4);
00078 
00079     PUTU16(im_id, rest, p, data_s->byte_swap);
00080     PUTU16(0, rest, p, data_s->byte_swap);
00081     PUTU32(attr_list_nbyte, rest, p, data_s->byte_swap);
00082     iiimp_imattribute_list_pack(data_s, attr_list, &rest, &p);
00083 
00084     return buf;
00085 }
00086 
00087 
00088 IIIMP_message *
00089 iiimp_setimvalues_unpack(
00090     IIIMP_data_s *   data_s,
00091     IIIMP_card7             opcode,
00092     size_t *         nbyte,
00093     const uchar_t ** ptr)
00094 {
00095     IIIMP_message *         m;
00096     IIIMP_setimvalues_v *   v;
00097     size_t                  rest;
00098     const uchar_t *         p;
00099     int                            len;
00100 
00101     rest = *nbyte;
00102     p = *ptr;
00103 
00104     if (rest < (2 + 2 + 4)) {
00105        data_s->status = IIIMP_DATA_INVALID;
00106        return NULL;
00107     }
00108 
00109     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00110     if (NULL == m) {
00111        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00112        return NULL;
00113     }
00114     v = &(m->v.setimvalues);
00115 
00116     m->opcode = opcode;
00117     v->attr_list = NULL;
00118 
00119     GETU16(m->im_id, rest, p, data_s->byte_swap);
00120     m->ic_id = -1;
00121     SKIP16(rest, p);
00122 
00123     GET32(len, rest, p, data_s->byte_swap);
00124     if ((len < 0) || (rest < len) || (0 != (len & 0x03))) {
00125        iiimp_setimvalues_delete(data_s, m);
00126        data_s->status = IIIMP_DATA_INVALID;
00127        return NULL;
00128     }
00129 
00130     v->attr_list = iiimp_imattribute_list_unpack(data_s, &rest, &p, len);
00131     if (NULL == v->attr_list) {
00132        iiimp_setimvalues_delete(data_s, m);
00133        return NULL;
00134     }
00135 
00136     *nbyte = rest;
00137     *ptr = p;
00138 
00139     return m;
00140 }
00141 
00142 
00143 void
00144 iiimp_setimvalues_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_imattribute_list_print(data_s, m->v.setimvalues.attr_list);
00150 }
00151 
00152 
00153 /* Local Variables: */
00154 /* c-file-style: "iiim-project" */
00155 /* End: */