Back to index

im-sdk  12.3.91
im-aux-value.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_aux_value_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card7             opcode,
00015     IIIMP_card16     im_id,
00016     IIIMP_card16     ic_id,
00017     IIIMP_card32     class_index,
00018     IIIMP_string *   input_method_name,
00019     IIIMP_card32_list *     integer_value,
00020     IIIMP_string *   string_value)
00021 {
00022     IIIMP_message *  m;
00023     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00024     if (NULL == m) {
00025        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00026        return NULL;
00027     }
00028     m->opcode = opcode;
00029     m->im_id = im_id;
00030     m->ic_id = ic_id;
00031     m->v.aux_value.class_index = class_index;
00032     m->v.aux_value.input_method_name = input_method_name;
00033     m->v.aux_value.integer_value = integer_value;
00034     m->v.aux_value.string_value = string_value;
00035     return m;
00036 }
00037 
00038 
00039 void
00040 iiimp_aux_value_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00041 {
00042     if (NULL == m) return;
00043     iiimp_string_delete(data_s, m->v.aux_value.input_method_name);
00044     iiimp_card32_list_delete(data_s, m->v.aux_value.integer_value);
00045     iiimp_string_list_delete(data_s, m->v.aux_value.string_value);
00046     free(m);
00047     return;
00048 }
00049 
00050 
00051 uchar_t *
00052 iiimp_aux_value_pack(
00053     IIIMP_data_s *   data_s,
00054     IIIMP_card7             opcode,
00055     IIIMP_card16     im_id,
00056     IIIMP_card16     ic_id,
00057     IIIMP_card32     class_index,
00058     IIIMP_string *   input_method_name,
00059     IIIMP_card32_list *     integer_value,
00060     IIIMP_string *   string_value,
00061     size_t *         buf_size)
00062 {
00063     size_t           nbyte;
00064     int                     length;
00065     uchar_t *        buf;
00066     size_t           rest;
00067     uchar_t *        p;
00068     size_t           integer_value_nbyte;
00069     size_t           string_value_nbyte;
00070     IIIMP_string *   s;
00071 
00072     nbyte = 0;
00073     nbyte += 2;      /* input method id */
00074     nbyte += 2;      /* input context id */
00075     nbyte += 4;      /* auxiliary window class index */
00076     nbyte += input_method_name->nbyte;    /* input method name */
00077     nbyte += 4;      /* byte length of integer value list */
00078     integer_value_nbyte = ((NULL != integer_value) ? integer_value->nbyte : 0);
00079     nbyte += integer_value_nbyte;  /* integer value list */
00080     nbyte += 4;      /* byte length of string value list */
00081     string_value_nbyte = 0;
00082     for (s = string_value; NULL != s; s = s->next) {
00083        string_value_nbyte += s->nbyte;
00084     }
00085     nbyte += string_value_nbyte;   /* string value list */
00086 
00087     length = (nbyte >> 2);
00088     *buf_size = (1 + 3 + nbyte);
00089 
00090     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00091     if (NULL == buf) {
00092        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00093        return NULL;
00094     }
00095 
00096     PUT_PACKET_HEADER(buf, opcode, length);
00097 
00098     rest = nbyte;
00099     p = (buf + 4);
00100 
00101     PUTU16(im_id, rest, p, data_s->byte_swap);
00102     PUTU16(ic_id, rest, p, data_s->byte_swap);
00103     PUTU32(class_index, rest, p, data_s->byte_swap);
00104     iiimp_string_pack(data_s, input_method_name, &rest, &p);
00105     PUTU32(integer_value_nbyte, rest, p, data_s->byte_swap);
00106     iiimp_card32_list_pack(data_s, integer_value, &rest, &p);
00107     PUTU32(string_value_nbyte, rest, p, data_s->byte_swap);
00108     iiimp_string_list_pack(data_s, string_value, &rest, &p);
00109 
00110     return buf;
00111 }
00112 
00113 
00114 IIIMP_message *
00115 iiimp_aux_value_unpack(
00116     IIIMP_data_s *   data_s,
00117     IIIMP_card7             opcode,
00118     size_t *         nbyte,
00119     const uchar_t ** ptr)
00120 {
00121     IIIMP_message *  m;
00122     IIIMP_aux_value_v *     v;
00123     size_t           rest;
00124     const uchar_t *  p;
00125     int                     len;
00126 
00127     rest = *nbyte;
00128     p = *ptr;
00129 
00130     if (rest < (2 + 2 + 4 + 4)) {
00131        data_s->status = IIIMP_DATA_INVALID;
00132        return NULL;
00133     }
00134 
00135     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00136     if (NULL == m) {
00137        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00138        return NULL;
00139     }
00140     v = &(m->v.aux_value);
00141 
00142     m->opcode = opcode;
00143     v->input_method_name = NULL;
00144     v->integer_value = NULL;
00145     v->string_value = NULL;
00146 
00147     GETU16(m->im_id, rest, p, data_s->byte_swap);
00148     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00149     GETU32(v->class_index, rest, p, data_s->byte_swap);
00150 
00151     m->opcode = opcode;
00152 
00153     v->input_method_name = iiimp_string_unpack(data_s, &rest, &p, rest);
00154     if (NULL == v->input_method_name) {
00155        free(m);
00156        return NULL;
00157     }
00158 
00159     GET32(len, rest, p, data_s->byte_swap);
00160     if ((len < 0) || (rest < len)) {
00161        iiimp_aux_value_delete(data_s, m);
00162        data_s->status = IIIMP_DATA_INVALID;
00163        return NULL;
00164     }
00165 
00166     if (0 < len) {
00167        v->integer_value = iiimp_card32_list_unpack(data_s, &rest, &p, len);
00168        if (NULL == v->integer_value) {
00169            iiimp_aux_value_delete(data_s, m);
00170            return NULL;
00171        }
00172     }
00173 
00174     GET32(len, rest, p, data_s->byte_swap);
00175     if ((len < 0) || (rest < len)) {
00176        iiimp_aux_value_delete(data_s, m);
00177        data_s->status = IIIMP_DATA_INVALID;
00178        return NULL;
00179     }
00180 
00181     if (0 < len) {
00182        v->string_value = iiimp_string_list_unpack(data_s, &rest, &p, len);
00183        if (NULL == v->string_value) {
00184            iiimp_aux_value_delete(data_s, m);
00185            return NULL;
00186        }
00187     }
00188 
00189     *nbyte = rest;
00190     *ptr = p;
00191 
00192     return m;
00193 }
00194 
00195 
00196 void
00197 iiimp_aux_value_print(
00198     IIIMP_data_s *   data_s,
00199     IIIMP_message *  m)
00200 {
00201     IIIMP_aux_value_v *     v;
00202     IIIMP_string *   s;
00203 
00204     v = &(m->v.aux_value);
00205     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00206     (void)fprintf(data_s->print_fp, "\tindex=%d name=", v->class_index);
00207     iiimp_string_print(data_s, v->input_method_name);
00208     (void)fputc('\n', data_s->print_fp);
00209     iiimp_card32_list_print(data_s, v->integer_value);
00210     for (s = v->string_value; NULL != s; s = s->next) {
00211        (void)fprintf(data_s->print_fp, "       *");
00212        iiimp_string_print(data_s, s);
00213        (void)fputc('\n', data_s->print_fp);
00214     }
00215 }
00216 
00217 
00218 /* Local Variables: */
00219 /* c-file-style: "iiim-project" */
00220 /* End: */