Back to index

im-sdk  12.3.91
im-lookup-choice-draw.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_lookup_choice_draw_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     int                     first,
00017     int                     last,
00018     int                     current,
00019     IIIMP_text *     choice,
00020     IIIMP_text *     index_label,
00021     IIIMP_text *     title)
00022 {
00023     IIIMP_message *  m;
00024     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00025     if (NULL == m) {
00026        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00027        return NULL;
00028     }
00029     m->opcode = IM_LOOKUP_CHOICE_DRAW;
00030     m->im_id = im_id;
00031     m->ic_id = ic_id;
00032     m->v.lookup_choice_draw.first = first;
00033     m->v.lookup_choice_draw.last = last;
00034     m->v.lookup_choice_draw.current = current;
00035     m->v.lookup_choice_draw.choice = choice;
00036     m->v.lookup_choice_draw.index_label = index_label;
00037     m->v.lookup_choice_draw.title = title;
00038     return m;
00039 }
00040 
00041 
00042 void
00043 iiimp_lookup_choice_draw_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00044 {
00045     if (NULL == m) return;
00046     iiimp_text_list_delete(data_s, m->v.lookup_choice_draw.choice);
00047     iiimp_text_list_delete(data_s, m->v.lookup_choice_draw.index_label);
00048     iiimp_text_delete(data_s, m->v.lookup_choice_draw.title);
00049     free(m);
00050     return;
00051 }
00052 
00053 
00054 uchar_t *
00055 iiimp_lookup_choice_draw_pack(
00056     IIIMP_data_s *   data_s,
00057     IIIMP_card16     im_id,
00058     IIIMP_card16     ic_id,
00059     int                     first,
00060     int                     last,
00061     int                     current,
00062     IIIMP_text *     choice,
00063     IIIMP_text *     index_label,
00064     IIIMP_text *     title,
00065     size_t *         buf_size)
00066 {
00067     size_t           nbyte;
00068     int                     length;
00069     uchar_t *        buf;
00070     size_t           rest;
00071     uchar_t *        p;
00072     size_t           choice_list_nbyte;
00073     size_t           index_label_list_nbyte;
00074     IIIMP_text *     text;
00075 
00076     nbyte = 0;
00077     nbyte += 2;                           /* input method id */
00078     nbyte += 2;                           /* input context id */
00079     nbyte += 4;                           /* index of first candidate */
00080     nbyte += 4;                           /* index of last candidate */
00081     nbyte += 4;                           /* index of current candidate */
00082     nbyte += 4;                           /* byte length of choice list */
00083     choice_list_nbyte = 0;
00084     for (text = choice; NULL != text; text = text->next) {
00085        choice_list_nbyte += text->nbyte;
00086     }
00087     nbyte += choice_list_nbyte;           /* choice list */
00088     nbyte += 4;      /* byte length of index label list */
00089     index_label_list_nbyte = 0;
00090     for (text = index_label; NULL != text; text = text->next) {
00091        index_label_list_nbyte += text->nbyte;
00092     }
00093     nbyte += index_label_list_nbyte;      /* index label list */
00094     if (NULL == title) {
00095        nbyte += (4 + 4);
00096     } else {
00097        nbyte += title->nbyte;
00098     }
00099 
00100     length = (nbyte >> 2);
00101     *buf_size = (1 + 3 + nbyte);
00102 
00103     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00104     if (NULL == buf) {
00105        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00106        return NULL;
00107     }
00108 
00109     PUT_PACKET_HEADER(buf, IM_LOOKUP_CHOICE_DRAW, length);
00110 
00111     rest = nbyte;
00112     p = (buf + 4);
00113 
00114     PUTU16(im_id, rest, p, data_s->byte_swap);
00115     PUTU16(ic_id, rest, p, data_s->byte_swap);
00116     PUTU32(first, rest, p, data_s->byte_swap);
00117     PUTU32(last, rest, p, data_s->byte_swap);
00118     PUTU32(current, rest, p, data_s->byte_swap);
00119     PUTU32(choice_list_nbyte, rest, p, data_s->byte_swap);
00120     iiimp_text_list_pack(data_s, choice, &rest, &p);
00121     PUTU32(index_label_list_nbyte, rest, p, data_s->byte_swap);
00122     iiimp_text_list_pack(data_s, index_label, &rest, &p);
00123     iiimp_text_pack(data_s, title, &rest, &p);
00124 
00125     return buf;
00126 }
00127 
00128 
00129 IIIMP_message *
00130 iiimp_lookup_choice_draw_unpack(
00131     IIIMP_data_s *   data_s,
00132     IIIMP_card7             opcode,
00133     size_t *         nbyte,
00134     const uchar_t ** ptr)
00135 {
00136     IIIMP_message *                m;
00137     IIIMP_lookup_choice_draw_v *   v;
00138     size_t                         rest;
00139     const uchar_t *                p;
00140     int                                   len;
00141 
00142     rest = *nbyte;
00143     p = *ptr;
00144 
00145     if (rest < (2 + 2 + 4 + 4 + 4 + 4)) {
00146        data_s->status = IIIMP_DATA_INVALID;
00147        return NULL;
00148     }
00149 
00150     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00151     if (NULL == m) {
00152        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00153        return NULL;
00154     }
00155     v = &(m->v.lookup_choice_draw);
00156 
00157     m->opcode = opcode;
00158     v->choice = NULL;
00159     v->index_label = NULL;
00160     v->title = NULL;
00161 
00162     GETU16(m->im_id, rest, p, data_s->byte_swap);
00163     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00164 
00165     GET32(v->first, rest, p, data_s->byte_swap);
00166     GET32(v->last, rest, p, data_s->byte_swap);
00167     GET32(v->current, rest, p, data_s->byte_swap);
00168 
00169     GET32(len, rest, p, data_s->byte_swap);
00170     if ((len < 0) || (rest < len)) {
00171        free(m);
00172        data_s->status = IIIMP_DATA_INVALID;
00173        return NULL;
00174     }
00175 
00176     if (0 < len) {
00177        v->choice = iiimp_text_list_unpack(data_s, &rest, &p, len);
00178        if ((NULL == v->choice) || (rest < 4)) {
00179            iiimp_lookup_choice_draw_delete(data_s, m);
00180            return NULL;
00181        }
00182     }
00183 
00184     GET32(len, rest, p, data_s->byte_swap);
00185     if ((len < 0) || (rest < len)) {
00186        iiimp_lookup_choice_draw_delete(data_s, m);
00187        data_s->status = IIIMP_DATA_INVALID;
00188        return NULL;
00189     }
00190 
00191     if (0 < len) {
00192        v->index_label = iiimp_text_list_unpack(data_s, &rest, &p, len);
00193        if ((NULL == v->index_label) || (rest < 4)) {
00194            iiimp_lookup_choice_draw_delete(data_s, m);
00195            return NULL;
00196        }
00197     }
00198 
00199     if (0 < len) {
00200        v->title = iiimp_text_unpack(data_s, &rest, &p, rest);
00201        if (NULL == v->title) {
00202            iiimp_lookup_choice_draw_delete(data_s, m);
00203            return NULL;
00204        }
00205     }
00206 
00207     *nbyte = rest;
00208     *ptr = p;
00209 
00210     return m;
00211 }
00212 
00213 
00214 void
00215 iiimp_lookup_choice_draw_print(
00216     IIIMP_data_s *   data_s,
00217     IIIMP_message *  m)
00218 {
00219     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00220 
00221     (void)fputc('\t', data_s->print_fp);
00222     (void)fprintf(data_s->print_fp, "first=%d ", m->v.lookup_choice_draw.first);
00223     (void)fprintf(data_s->print_fp, "last=%d ", m->v.lookup_choice_draw.last);
00224     (void)fprintf(data_s->print_fp, "current=%d ",
00225                 m->v.lookup_choice_draw.current);
00226     (void)fprintf(data_s->print_fp, "\n\tchoice=\n");
00227     iiimp_text_list_print(data_s, m->v.lookup_choice_draw.choice);
00228     (void)fprintf(data_s->print_fp, "\tlabel=\n");
00229     iiimp_text_list_print(data_s, m->v.lookup_choice_draw.index_label);
00230     (void)fprintf(data_s->print_fp, "\ttitle=\n");
00231     iiimp_text_print(data_s, m->v.lookup_choice_draw.title);
00232 }
00233 
00234 
00235 /* Local Variables: */
00236 /* c-file-style: "iiim-project" */
00237 /* End: */