Back to index

im-sdk  12.3.91
im-register-hotkeys.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_register_hotkeys_new(
00013     IIIMP_data_s *          data_s,
00014     IIIMP_card16            im_id,
00015     IIIMP_card16            scope_and_profile_id,
00016     HOTKEY_LIST *           hotkeys)
00017 {
00018     IIIMP_message *  m;
00019     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00020     if (NULL == m) {
00021        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00022        return NULL;
00023     }
00024     m->opcode = IM_REGISTER_HOTKEYS;
00025     m->im_id = im_id;
00026     m->ic_id = -1;
00027     m->v.register_hotkeys.scope_and_profile_id = scope_and_profile_id; 
00028     m->v.register_hotkeys.scope = -1;
00029     m->v.register_hotkeys.profile_id = -1;
00030     m->v.register_hotkeys.hotkeys = hotkeys;
00031     return m;
00032 }
00033 
00034 void
00035 iiimp_register_hotkeys_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00036 {
00037     if (NULL == m) return;
00038     iiimp_hotkey_list_delete(data_s, m->v.register_hotkeys.hotkeys);
00039     free(m);
00040 }
00041 
00042 
00043 uchar_t *
00044 iiimp_register_hotkeys_pack(
00045     IIIMP_data_s *          data_s,
00046     IIIMP_card16            im_id,
00047     IIIMP_card16            scope_and_profile_id,
00048     HOTKEY_LIST *           hotkeys,
00049     size_t *                buf_size)
00050 {
00051     size_t                  nbyte;
00052     int                            length;
00053     uchar_t *               buf;
00054     size_t                  rest;
00055     uchar_t *               p;
00056 
00057     nbyte = 0
00058        + 2     /* input method id */
00059        + 2     /* PAD(2) */
00060        + 2     /* SCOPE and PROFILE_ID */
00061        + 2;     /* byte length of list of HOTKEYS */
00062 
00063     if (NULL != hotkeys) {
00064        nbyte += hotkeys->nbyte; /* hotkey keys list */
00065     }
00066 
00067     length = (nbyte >> 2);
00068     *buf_size = (1 + 3 + nbyte);
00069 
00070     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00071     if (NULL == buf) {
00072        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00073        return NULL;
00074     }
00075 
00076     PUT_PACKET_HEADER(buf, IM_REGISTER_HOTKEYS, length);
00077 
00078     rest = nbyte;
00079     p = (buf + 4);
00080 
00081     PUTU16(im_id, rest, p, data_s->byte_swap);
00082     PUTU16(0, rest, p, data_s->byte_swap);
00083     PUTU16(scope_and_profile_id, rest, p, data_s->byte_swap);
00084     if (NULL == hotkeys) {
00085        PUTU16(0, rest, p, data_s->byte_swap);
00086     } else {
00087        PUTU16(hotkeys->nbyte, rest, p, data_s->byte_swap);
00088        iiimp_hotkey_list_pack(data_s, hotkeys, &rest, &p);
00089     }
00090     return buf;
00091 }
00092 
00093 IIIMP_message *
00094 iiimp_register_hotkeys_unpack(
00095     IIIMP_data_s *   data_s,
00096     IIIMP_card7             opcode,
00097     size_t *         nbyte,
00098     const uchar_t ** ptr)
00099 {
00100     IIIMP_message *                m;
00101     IIIMP_register_hotkeys_v *             v;
00102     size_t                         rest;
00103     const uchar_t *                p;
00104     int                                   len;
00105 
00106     rest = *nbyte;
00107     p = *ptr;
00108 
00109     if (rest < (2 + 2 + 2 + 2 + 0)) {
00110        data_s->status = IIIMP_DATA_INVALID;
00111        return NULL;
00112     }
00113 
00114     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00115     if (NULL == m) {
00116        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00117        return NULL;
00118     }
00119     v = &(m->v.register_hotkeys);
00120 
00121     m->opcode = opcode;
00122     v->hotkeys = NULL;
00123 
00124     GETU16(m->im_id, rest, p, data_s->byte_swap);
00125     m->ic_id = -1;
00126     SKIP16(rest, p);
00127     GET_SCOPE_FOR_HOTKEY(v->scope, p, data_s->byte_swap);
00128     GETU15(v->profile_id, p, data_s->byte_swap);
00129     GETU16(v->scope_and_profile_id, rest, p, data_s->byte_swap);
00130 
00131     GETU16(len, rest, p, data_s->byte_swap);
00132     if ((len < 0) || (rest < len)) {
00133        iiimp_register_hotkeys_delete(data_s, m);
00134        data_s->status = IIIMP_DATA_INVALID;
00135        return NULL;
00136     }
00137 
00138     v->hotkeys = iiimp_hotkey_list_unpack(data_s, &rest, &p, len);
00139     if (NULL == v->hotkeys) {
00140        iiimp_register_hotkeys_delete(data_s, m);
00141        return NULL;
00142     }
00143 
00144     *nbyte = rest;
00145     *ptr = p;
00146 
00147     return (IIIMP_message *)m;
00148 }
00149 
00150 
00151 void
00152 iiimp_register_hotkeys_print(
00153     IIIMP_data_s *   data_s,
00154     IIIMP_message *  m)
00155 {
00156     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00157     iiimp_hotkey_list_print(data_s, m->v.register_hotkeys.hotkeys);
00158 }
00159 
00160 
00161 /* Local Variables: */
00162 /* c-file-style: "iiim-project" */
00163 /* End: */