Back to index

im-sdk  12.3.91
IIIMPClientDispatcher2.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #if !defined(USE_FRAMEMGR_ALWAYS)
00043 #include <stddef.h>
00044 #include <string.h>
00045 #include <stdlib.h>
00046 #else /* USE_FRAMEMGR_ALWAYS */
00047 #include "FrameMgr.h"
00048 #endif /* USE_FRAMEMGR_ALWAYS */
00049 #include "IIIMPClient.hh"
00050 #include "IMProtoHandler.hh"
00051 #include "IIIMPInputContext.hh"
00052 #include "ICAttribute.hh"
00053 #include "IIIMProtocol.hh"
00054 #include "IMProtocolStructP.hh"
00055 
00056 #if !defined(USE_FRAMEMGR_ALWAYS)
00057 int
00058 IIIMPClient::icattr_list_count(char * p) {
00059   char *ptr;
00060   CARD32 icattr_list_size; 
00061   int num;
00062   CARD16 icattr_size;
00063 
00064   num = 0;
00065   ptr = p;
00066   if (False == need_swap) {
00067     req_get16(ptr, icattr_list_size);
00068     if (icattr_list_size & 0x03) {
00069       icattr_list_size = ((icattr_list_size & (~0x03)) + 4);
00070     }
00071 
00072     while (4 <= icattr_list_size) {
00073       ptr += 2;                           /* skip attribute id */
00074       req_get16(ptr, icattr_size);
00075       icattr_list_size -= 4;
00076       if (icattr_size & 0x03) {           /* padding */
00077        icattr_size = ((icattr_size & (~0x03)) + 4);
00078       }
00079       if (icattr_list_size < icattr_size) {
00080        icattr_size = icattr_list_size;
00081       }
00082 
00083       ptr += icattr_size;
00084       icattr_list_size -= icattr_size;
00085       num += 1;
00086     }
00087   } else {
00088     req_get16s(ptr, icattr_list_size);
00089     if (icattr_list_size & 0x03) {
00090       icattr_list_size = ((icattr_list_size & (~0x03)) + 4);
00091     }
00092 
00093     while (4 <= icattr_list_size) {
00094       ptr += 2;                           /* skip attribute id */
00095       req_get16s(ptr, icattr_size);
00096       icattr_list_size -= 4;
00097       if (icattr_size & 0x03) {           /* padding */
00098        icattr_size = ((icattr_size & (~0x03)) + 4);
00099       }
00100       if (icattr_list_size < icattr_size) {
00101        icattr_size = icattr_list_size;
00102       }
00103 
00104       ptr += icattr_size;
00105       icattr_list_size -= icattr_size;
00106       num += 1;
00107     }
00108   }
00109   return num;
00110 }
00111 
00112 int
00113 IIIMPClient::icattr_size(ICAttribute * icattr) {
00114   int size;
00115   size = 2;          /* attribute id */
00116   size += 2;         /* byte length of value */
00117   if (NULL != icattr) {
00118     size += icattr->value_length;
00119   }
00120   if (size & 0x03) { /* padding */
00121     size = ((size & (~0x03)) + 4);
00122   }
00123   return size;
00124 }
00125 
00126 char *
00127 IIIMPClient::req_put_icattr_list(char * ptr, ICAttribute * icattr, int num) {
00128   int i;
00129   for (i = 0; i < num; i++, icattr++) {
00130     req_put16(ptr, icattr->attribute_id);
00131     req_put16(ptr, icattr->value_length);
00132     memcpy(ptr, icattr->value, icattr->value_length);
00133     if (icattr->value_length & 0x03) {
00134       ptr += ((icattr->value_length & (~0x03)) + 4);
00135     } else {
00136       ptr += icattr->value_length;
00137     }
00138   }
00139   return ptr;
00140 }
00141 
00142 char *
00143 IIIMPClient::req_put_icattr_list_s(char * ptr, ICAttribute * icattr, int num) {
00144   int i;
00145   for (i = 0; i < num; i++, icattr++) {
00146     req_put16s(ptr, icattr->attribute_id);
00147     req_put16s(ptr, icattr->value_length);
00148     memcpy(ptr, icattr->value, icattr->value_length);
00149     if (icattr->value_length & 0x03) {
00150       ptr += ((icattr->value_length & (~0x03)) + 4);
00151     } else {
00152       ptr += icattr->value_length;
00153     }
00154   }
00155   return ptr;
00156 }
00157 
00158 #else /* USE_FRAMEMGR_ALWAYS */
00159 #endif /* USE_FRAMEMGR_ALWAYS */
00160 
00161 /* Set IC values */
00162 void
00163 IIIMPClient::set_card(ICAttribute *value_ret, char *p, IMAttr *ic_attr,
00164                     int value_length) {
00165   char *buf, *bufp;
00166 #if !defined(USE_FRAMEMGR_ALWAYS)
00167   char *ptr;
00168   char *ptr_end;
00169   char *data;
00170   int data_length;
00171 #else /* USE_FRAMEMGR_ALWAYS */
00172   FrameMgr fm;
00173   FmStatus status;
00174   extern XimFrameRec string_fr[];
00175   extern XimFrameRec worddata_fr[];
00176   extern XimFrameRec longdata_fr[];
00177 #endif /* USE_FRAMEMGR_ALWAYS */
00178   short value16;
00179   int value32;
00180   int byte_length;
00181   int value_type = ic_attr->type;
00182   ICAttribute temp_value;
00183   IMAttr temp_attr;
00184   int len, left;
00185 
00186   buf = new char[value_length];
00187 
00188   switch (value_type) {
00189   case IIIMProtocol::XimType_LISTOF_UTF16_STRING:
00190 #if !defined(USE_FRAMEMGR_ALWAYS)
00191     ptr = (char *)p;
00192     ptr_end = (ptr + value_length);
00193     bufp = buf;
00194     left = value_length;
00195     if (False == need_swap) {
00196       while ((ptr < ptr_end) && (0 < left)) {
00197        ptr = req_get_ascii_string(ptr, &data, &byte_length, &data_length);
00198        memcpy(bufp, data, data_length);
00199        delete [] data;
00200        bufp += data_length;
00201        left -= data_length;
00202       }
00203     } else {
00204       while ((ptr < ptr_end) && (0 < left)) {
00205        ptr = req_get_ascii_string_s(ptr, &data, &byte_length, &data_length);
00206        memcpy(bufp, data, data_length);
00207        delete [] data;
00208        bufp += data_length;
00209        left -= data_length;
00210       }
00211     }
00212     value_length = (bufp - buf);
00213 #else /* USE_FRAMEMGR_ALWAYS */
00214     bufp = buf;
00215     temp_attr.attribute_id = 0;
00216     temp_attr.length = 0;
00217     temp_attr.name = NULL;
00218     temp_attr.type = IIIMProtocol::XimType_UTF16_STRING;
00219     left = value_length;
00220     while (left > 0) {
00221       set_card(&temp_value, (char*)p, &temp_attr, left);
00222       len = 2 + temp_value.value_length * 2 +
00223        ((2 + temp_value.value_length * 2) % 4); // evil
00224       p += len;
00225       memmove(bufp, temp_value.value, temp_value.value_length);
00226       free(temp_value.value);
00227       bufp += temp_value.value_length;
00228       *bufp++ = (char)0;
00229       left -= len;
00230     }
00231 #endif /* USE_FRAMEMGR_ALWAYS */
00232     break;
00233   case IIIMProtocol::XimType_UTF16_STRING:
00234 #if !defined(USE_FRAMEMGR_ALWAYS)
00235     ptr = (char *)p;
00236     delete [] buf;
00237     if (False == need_swap) {
00238       ptr = req_get_ascii_string(ptr, &buf, NULL, &value_length);
00239     } else {
00240       ptr = req_get_ascii_string_s(ptr, &buf, NULL, &value_length);
00241     }
00242     value_type = IIIMProtocol::XimType_CARD8;
00243 #else /* USE_FRAMEMGR_ALWAYS */
00244     /* create FrameMgr */
00245     fm = FrameMgrInit(string_fr, (char *)p, need_swap);
00246     /* get data */
00247     FrameMgrGetToken(fm, byte_length);
00248     bufp = buf;
00249     value_length = byte_length/2;
00250     // assume that all the 16bit Unicode characters are ASCII characters
00251     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00252       CARD16 str;
00253       CARD8 byte_data;
00254       FrameMgrGetToken(fm, byte_data);
00255       str = (byte_data << 8) & 0xff00;
00256       FrameMgrGetToken(fm, byte_data);
00257       str += byte_data & 0x00ff;
00258       if (str != 0 && str != 0xff && str != 0xfe)
00259        *bufp++ = (char)str;
00260       else
00261        value_length--;
00262     }
00263     *bufp = (char)0;
00264     value_type = IIIMProtocol::XimType_CARD8;
00265     FrameMgrFree(fm);
00266 #endif /* USE_FRAMEMGR_ALWAYS */
00267     break;
00268   case IIIMProtocol::XimType_CARD8:
00269     memmove(buf, p, value_length);
00270     break;
00271   case IIIMProtocol::XimType_CARD16:
00272 #if !defined(USE_FRAMEMGR_ALWAYS)
00273     ptr = (char *)p;
00274     if (False == need_swap) {
00275       req_get16(ptr, value16);
00276     } else {
00277       req_get16s(ptr, value16);
00278     }
00279 #else /* USE_FRAMEMGR_ALWAYS */
00280     /* create FrameMgr */
00281     fm = FrameMgrInit(worddata_fr, (char *)p, need_swap);
00282     /* get data */
00283     FrameMgrGetToken(fm, value16);
00284     /* free FrameMgr */
00285     FrameMgrFree(fm);
00286 #endif /* USE_FRAMEMGR_ALWAYS */
00287     memmove(buf, &value16, value_length);
00288     break;
00289   case IIIMProtocol::XimType_CARD32:
00290 #if !defined(USE_FRAMEMGR_ALWAYS)
00291     ptr = (char *)p;
00292     if (False == need_swap) {
00293       req_get32(ptr, value16);
00294     } else {
00295       req_get32s(ptr, value16);
00296     }
00297 #else /* USE_FRAMEMGR_ALWAYS */
00298     /* create FrameMgr */
00299     fm = FrameMgrInit(longdata_fr, (char *)p, need_swap);
00300     /* get data */
00301     FrameMgrGetToken(fm, value32);
00302     /* free FrameMgr */
00303     FrameMgrFree(fm);
00304 #endif /* USE_FRAMEMGR_ALWAYS */
00305     memmove(buf, &value32, value_length);
00306     break;
00307   }
00308 
00309   value_ret->attribute_id = ic_attr->attribute_id;
00310   value_ret->name = ic_attr->name;
00311   value_ret->name_length = ic_attr->length;
00312   value_ret->value_length = value_length;
00313   value_ret->type = value_type;
00314   value_ret->value = buf;
00315 
00316   return;
00317 }
00318 
00319 int
00320 IIIMPClient::read_icvalue(CARD16 icvalue_id, int value_length, void *p,
00321                        ICAttribute *value_ret) {
00322   IMAttr *ic_attr = iiim_protocol->get_icattr();
00323   for (IMAttr *attrp = ic_attr;
00324        attrp < &ic_attr[iiim_protocol->count_icattr()]; attrp++) {
00325     if (attrp->attribute_id == icvalue_id) {
00326       set_card(value_ret, (char*)p, attrp, value_length);
00327       return(0);
00328     }
00329   }
00330   return(-1);
00331 }
00332 
00333 int
00334 IIIMPClient::read_imvalue(CARD16 imvalue_id, int value_length, void *p,
00335                        ICAttribute *value_ret) {
00336   IMAttr *im_attr = iiim_protocol->get_imattr();
00337   for (IMAttr *attrp = im_attr;
00338        attrp < &im_attr[iiim_protocol->count_imattr()]; attrp++) {
00339     if (attrp->attribute_id == imvalue_id) {
00340       set_card(value_ret, (char*)p, attrp, value_length);
00341       return(0);
00342     }
00343   }
00344   return(-1);
00345 }
00346 
00347 void
00348 IIIMPClient::change_icvalues(
00349 #if !defined(USE_FRAMEMGR_ALWAYS)
00350        char *ptr,
00351 #else /* USE_FRAMEMGR_ALWAYS */
00352        FrameMgr fm,
00353        int byte_length,
00354 #endif /* USE_FRAMEMGR_ALWAYS */
00355        IMProtocolStruct *call_data) {
00356 #if !defined(USE_FRAMEMGR_ALWAYS)
00357   int attrnum;
00358   int byte_length;
00359 #else /* USE_FRAMEMGR_ALWAYS */
00360   FmStatus status;
00361   int max_attrnum = IIIMPClient::MAX_ATTRNUM;
00362 #endif /* USE_FRAMEMGR_ALWAYS */
00363   IMChangeICStruct *changeic = (IMChangeICStruct*)&call_data->changeic;
00364   ICAttribute *icAttribute_list;
00365   int number;
00366   int first_ic_index = 0;
00367 
00368 #if !defined(USE_FRAMEMGR_ALWAYS)
00369   attrnum = icattr_list_count(ptr);
00370   icAttribute_list = new ICAttribute[attrnum];
00371   if (False == need_swap) {
00372     req_get16(ptr, byte_length);
00373   } else {
00374     req_get16s(ptr, byte_length);
00375   }
00376 #else /* USE_FRAMEMGR_ALWAYS */
00377   icAttribute_list = new ICAttribute[max_attrnum];
00378 #endif /* USE_FRAMEMGR_ALWAYS */
00379 
00380   /* Set InputStyle to Callbacks */
00381   number = 0;
00382   if (byte_length != 0) {
00383 #if !defined(USE_FRAMEMGR_ALWAYS)
00384     if (False == need_swap) {
00385       for (number = 0; number < attrnum; number++) {
00386        req_get16(ptr, icAttribute_list[number].attribute_id);
00387        req_get16(ptr, icAttribute_list[number].value_length);
00388        icAttribute_list[number].value =
00389               new char[icAttribute_list[number].value_length];
00390        memcpy(icAttribute_list[number].value, ptr,
00391               icAttribute_list[number].value_length);
00392        if (icAttribute_list[number].value_length & 0x03) {
00393          ptr += ((icAttribute_list[number].value_length & (~0x03)) + 4);
00394        } else {
00395          ptr += icAttribute_list[number].value_length;
00396        }
00397       }
00398     } else {
00399       for (number = 0; number < attrnum; number++) {
00400        req_get16s(ptr, icAttribute_list[number].attribute_id);
00401        req_get16s(ptr, icAttribute_list[number].value_length);
00402        icAttribute_list[number].value =
00403               new char[icAttribute_list[number].value_length];
00404        memcpy(icAttribute_list[number].value, ptr,
00405               icAttribute_list[number].value_length);
00406        if (icAttribute_list[number].value_length & 0x03) {
00407          ptr += ((icAttribute_list[number].value_length & (~0x03)) + 4);
00408        } else {
00409          ptr += icAttribute_list[number].value_length;
00410        }
00411       }
00412     }
00413 #else /* USE_FRAMEMGR_ALWAYS */
00414     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00415       void *value;
00416       int value_length;
00417       if (number == max_attrnum) {
00418        max_attrnum += IIIMPClient::MAX_ATTRNUM;
00419        ICAttribute *temp = icAttribute_list;
00420        icAttribute_list = new ICAttribute[max_attrnum];
00421        memmove(icAttribute_list, temp, sizeof(ICAttribute) * number);
00422        delete [] temp;
00423       }
00424       FrameMgrGetToken(fm, icAttribute_list[number].attribute_id);
00425       FrameMgrGetToken(fm, value_length);
00426       FrameMgrSetSize(fm, value_length);
00427       icAttribute_list[number].value_length = value_length;
00428       FrameMgrGetToken(fm, value);
00429       icAttribute_list[number].value = new char[value_length];
00430       memmove(icAttribute_list[number].value, value, value_length);
00431       number++;
00432     }
00433 #endif /* USE_FRAMEMGR_ALWAYS */
00434   }
00435   /* The value from the protocol may need to be byte-swapped */
00436   for (ICAttribute *icp = &icAttribute_list[first_ic_index];
00437        icp < &icAttribute_list[number]; icp++) {
00438     void *dummy = icp->value;
00439 
00440     if (read_icvalue(icp->attribute_id,
00441                    icp->value_length,
00442                    icp->value,
00443                    icp) == 0) {
00444       delete dummy;
00445     }
00446   }
00447 
00448   changeic->preedit_attr_num = 0;
00449   changeic->status_attr_num = 0;
00450   changeic->preedit_attr = 0;
00451   changeic->status_attr = 0;
00452   changeic->ic_attr_num = (CARD16)number;
00453   changeic->ic_attr = icAttribute_list;
00454 
00455   return;
00456   /* to CreateICMessageProc or SetICValuesProc */
00457 }
00458 
00459 void
00460 IIIMPClient::free_icvalues(IMProtocolStruct *call_data) {
00461   IMChangeICStruct *changeic = (IMChangeICStruct*)&call_data->changeic;
00462 
00463   for (ICAttribute *icp = changeic->ic_attr;
00464        icp < &changeic->ic_attr[changeic->ic_attr_num]; icp++) {
00465     delete icp->value;
00466   }
00467   delete [] changeic->ic_attr;
00468   return;
00469 }
00470 
00471 void
00472 IIIMPClient::create_ic(IMProtocolStruct *call_data, unsigned char *p) {
00473 #if !defined(USE_FRAMEMGR_ALWAYS)
00474   char *ptr;
00475 #else /* USE_FRAMEMGR_ALWAYS */
00476   FrameMgr fm;
00477   extern XimFrameRec im_createic_fr[], im_createic_reply_fr[];
00478   XimFrameRec *input_fr = im_createic_fr;
00479   XimFrameRec *output_fr = im_createic_reply_fr;
00480 #endif /* USE_FRAMEMGR_ALWAYS */
00481   IMChangeICStruct *changeic = (IMChangeICStruct*)&call_data->changeic;
00482   CARD16 input_method_id;
00483   CARD16 byte_length;
00484   const int IM_OUTPUT_REPLY = IM_CREATEIC_REPLY;
00485 
00486 #ifndef IIIMP_KEEP_ALIVE_PROTOCOL
00487   /*
00488     fix for 4108572:
00489     When JavaOS is booted, it creates a new connection for the dummy
00490     user name "nobody@<hostname>". If there were any old connection
00491     done under the same user name, we close it here. It was left unclosed
00492     when the JavaOS was powered off.
00493   */
00494   if (!respond_keepalive) {
00495     char *at_hostname = strstr(username, "@");
00496     if (!strncmp((char*)username, "nobody", 6)) {
00497        IIIMPClient *cl = &(iiim_protocol->iiimp_client_list.getFirstItem());
00498        while (cl) {
00499          if (cl != this) {
00500            CompoundString user = cl->getUser();
00501            if (strstr(user, at_hostname)) {
00502              // to close the client
00503              if (!cl->respond_keepalive) {
00504                // call destory_ic methods for all input contexts
00505                InputContext *ic = &(cl->input_context_list.getFirstItem());
00506                while(ic){
00507                  if (ic && ((IIIMPInputContext*)ic)->is_active()) {
00508                   cl->input_context_list.remove(ic);
00509                   ((IIIMPInputContext*)ic)->unrealize();
00510                   iiim_protocol->proto_handler->DestroyIC((InputContext*)ic);
00511                  }
00512                  ic = &(cl->input_context_list.getNextItem());
00513                }
00514 
00515                // mark it to be killed later
00516                cl->being_deleted = 1;
00517              }
00518            }
00519         }
00520         cl = &(iiim_protocol->iiimp_client_list.getNextItem());
00521        }
00522     }
00523   }
00524 #endif
00525 
00526 #if !defined(USE_FRAMEMGR_ALWAYS)
00527   ptr = (char *)p;
00528   if (False == need_swap) {
00529     req_get16(ptr, input_method_id);
00530     change_icvalues(ptr, call_data);
00531   } else {
00532     req_get16s(ptr, input_method_id);
00533     change_icvalues(ptr, call_data);
00534   }
00535 #else /* USE_FRAMEMGR_ALWAYS */
00536   /* create FrameMgr */
00537   fm = FrameMgrInit(input_fr, (char *)p, need_swap);
00538 
00539   /* get data */
00540   FrameMgrGetToken(fm, input_method_id);
00541   FrameMgrGetToken(fm, byte_length);
00542 
00543   change_icvalues(fm, byte_length, call_data);
00544 
00545   /* free FrameMgr */
00546   FrameMgrFree(fm);
00547 #endif /* USE_FRAMEMGR_ALWAYS */
00548 
00549   IIIMPInputContext *ic = new IIIMPInputContext(this);
00550   input_context_list.addItem(ic);
00551   CARD16 input_context_id = input_context_list.getIndex(ic);
00552 
00553   // set some icattributes to this new ic
00554   for (ICAttribute *icp = changeic->ic_attr;
00555        icp < &changeic->ic_attr[changeic->ic_attr_num]; icp++) {
00556     if (icp->name == iiim_protocol->ICLocaleName) {
00557       ic->setLocaleName((char*)icp->value);
00558     } else if (icp->name == iiim_protocol->ICEngineName) {
00559       ic->setEngineName((char*)icp->value);
00560     }
00561   }
00562 
00563   iiim_protocol->proto_handler->CreateIC((InputContext*)ic);
00564   iiim_protocol->proto_handler->RealizeIC((InputContext*)ic);
00565 
00566   free_icvalues(call_data);
00567 
00568 #if !defined(USE_FRAMEMGR_ALWAYS)
00569   send_message(input_method_id, input_context_id, IM_OUTPUT_REPLY);
00570 #else /* USE_FRAMEMGR_ALWAYS */
00571   send_message(input_method_id, input_context_id,
00572               output_fr, IM_OUTPUT_REPLY);
00573 #endif /* USE_FRAMEMGR_ALWAYS */
00574   ic->realize();
00575   return;
00576 }
00577 
00578 void
00579 IIIMPClient::set_icvalues(IMProtocolStruct *call_data, unsigned char *p) {
00580 #if !defined(USE_FRAMEMGR_ALWAYS)
00581   char *ptr;
00582 #else /* USE_FRAMEMGR_ALWAYS */
00583   FrameMgr fm;
00584   extern XimFrameRec im_seticvalues_fr[], im_seticvalues_reply_fr[];
00585   XimFrameRec *input_fr = im_seticvalues_fr;
00586   XimFrameRec *output_fr = im_seticvalues_reply_fr;
00587 #endif /* USE_FRAMEMGR_ALWAYS */
00588   IMChangeICStruct *changeic =
00589     (IMChangeICStruct*)&call_data->changeic;
00590   CARD16 input_method_id, input_context_id;
00591   CARD16 byte_length;
00592 
00593   const int IM_OUTPUT_REPLY = IM_SETICVALUES_REPLY;
00594 
00595 #if !defined(USE_FRAMEMGR_ALWAYS)
00596   ptr = (char *)p;
00597   if (False == need_swap) {
00598     req_get16(ptr, input_method_id);
00599     req_get16(ptr, input_context_id);
00600     change_icvalues(ptr, call_data);
00601   } else {
00602     req_get16s(ptr, input_method_id);
00603     req_get16s(ptr, input_context_id);
00604     change_icvalues(ptr, call_data);
00605   }
00606 #else /* USE_FRAMEMGR_ALWAYS */
00607   /* create FrameMgr */
00608   fm = FrameMgrInit(input_fr, (char *)p, need_swap);
00609                   
00610   /* get data */
00611   FrameMgrGetToken(fm, input_method_id);
00612   FrameMgrGetToken(fm, input_context_id);
00613   FrameMgrGetToken(fm, byte_length);
00614 
00615   change_icvalues(fm, byte_length, call_data);
00616 
00617   /* free FrameMgr */
00618   FrameMgrFree(fm);
00619 #endif /* USE_FRAMEMGR_ALWAYS */
00620 
00621   InputContext *ic = &(input_context_list.getItem(input_context_id));
00622   if (ic) {
00623     IIIMPInputContext *iiimp_ic = (IIIMPInputContext*)ic;
00624     // set some icattributes to this new ic
00625     for (ICAttribute *icp = changeic->ic_attr;
00626         icp < &changeic->ic_attr[changeic->ic_attr_num]; icp++) {
00627       if (icp->name == iiim_protocol->ICLocaleName) {
00628        iiimp_ic->setLocaleName((char*)icp->value);
00629       } else if (icp->name == iiim_protocol->ICEngineName) {
00630        iiimp_ic->setEngineName((char*)icp->value);
00631       }
00632     }
00633     iiim_protocol->proto_handler->SetICValues((InputContext*)ic, 0, 0);
00634   } else {
00635     // need to treate as an error
00636   }
00637 
00638   free_icvalues(call_data);
00639 
00640 #if !defined(USE_FRAMEMGR_ALWAYS)
00641   send_message(input_method_id, input_context_id, IM_OUTPUT_REPLY);
00642 #else /* USE_FRAMEMGR_ALWAYS */
00643   send_message(input_method_id, input_context_id,
00644               output_fr, IM_OUTPUT_REPLY);
00645 #endif /* USE_FRAMEMGR_ALWAYS */
00646   return;
00647 }
00648 
00649 ICAttribute*
00650 IIIMPClient::get_icattr(CARD16 *attrID_list, int number) {
00651   ICAttribute *attr_list;
00652   IMAttr *ic_attr = iiim_protocol->get_icattr();
00653 
00654   attr_list = new ICAttribute[number];
00655   if (attr_list = NULL)
00656     return NULL;
00657   memset(attr_list, 0, sizeof(ICAttribute) * number);
00658 
00659   ICAttribute *attrp;
00660   CARD16 *idp;
00661   for (attrp = attr_list, idp = attrID_list;
00662        attrp < &attr_list[number] && idp < &attrID_list[number];
00663        attrp++, idp++) {
00664     for (IMAttr *icp = ic_attr;
00665         icp < &ic_attr[iiim_protocol->count_icattr()]; icp++) {
00666       if (icp->attribute_id == *idp) {
00667        attrp->attribute_id = icp->attribute_id;
00668        attrp->name_length = icp->length;
00669        attrp->name = icp->name;
00670        attrp->type = icp->type;
00671       }
00672     }
00673   }
00674   return attr_list;
00675 }
00676 
00677 void
00678 IIIMPClient::get_icvalues(IMProtocolStruct *call_data, unsigned char *p) {
00679 #if !defined(USE_FRAMEMGR_ALWAYS)
00680   char *ptr;
00681   char *data;
00682   int total_size;
00683   int attr_size;
00684   int i;
00685 #else /* USE_FRAMEMGR_ALWAYS */
00686   FrameMgr fm;
00687   FmStatus status;
00688 #endif /* USE_FRAMEMGR_ALWAYS */
00689   IMChangeICStruct *getic = (IMChangeICStruct*)&call_data->changeic;
00690   CARD16 input_method_id, input_context_id;
00691   CARD16 byte_length;
00692   CARD16 *attrID_list = NULL;
00693   int number;
00694   int iter_count;
00695   ICAttribute *ic_attr = NULL;
00696 
00697 #if !defined(USE_FRAMEMGR_ALWAYS)
00698 #else /* USE_FRAMEMGR_ALWAYS */
00699   extern XimFrameRec im_geticvalues_fr[], im_geticvalues_reply_fr[];
00700   XimFrameRec *input_fr = im_geticvalues_fr;
00701   XimFrameRec *output_fr = im_geticvalues_reply_fr;
00702 #endif /* USE_FRAMEMGR_ALWAYS */
00703   const int IM_OUTPUT_REPLY = IM_GETICVALUES_REPLY;
00704 
00705 #if !defined(USE_FRAMEMGR_ALWAYS)
00706   ptr = (char *)p;
00707   if (False == need_swap) {
00708     req_get16(ptr, input_method_id);
00709     req_get16(ptr, input_context_id);
00710     req_get16(ptr, byte_length);
00711     if (byte_length != 0) {
00712       attrID_list = (CARD16*)new char[byte_length];
00713       number = (byte_length / 2);
00714       for (i = 0; i < number; i++) {
00715        req_get16(ptr, *(attrID_list + i));
00716       }
00717       ic_attr = get_icattr(attrID_list, number);
00718       if (ic_attr == NULL) {
00719        delete [] attrID_list;
00720        return;
00721       }
00722     }
00723   } else {
00724     req_get16s(ptr, input_method_id);
00725     req_get16s(ptr, input_context_id);
00726     req_get16s(ptr, byte_length);
00727     if (byte_length != 0) {
00728       attrID_list = (CARD16*)new char[byte_length];
00729       number = (byte_length / 2);
00730       for (i = 0; i < number; i++) {
00731        req_get16s(ptr, *(attrID_list + i));
00732       }
00733       ic_attr = get_icattr(attrID_list, number);
00734       if (ic_attr == NULL) {
00735        delete [] attrID_list;
00736        return;
00737       }
00738     }
00739   }
00740 #else /* USE_FRAMEMGR_ALWAYS */
00741   /* create FrameMgr */
00742   fm = FrameMgrInit(input_fr, (char *)p, need_swap);
00743 
00744   /* get data */
00745   FrameMgrGetToken(fm, input_method_id);
00746   FrameMgrGetToken(fm, input_context_id);
00747   FrameMgrGetToken(fm, byte_length);
00748 
00749   if (byte_length != 0) {
00750     attrID_list = (CARD16*)new char[byte_length];
00751 
00752     number = 0;
00753     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00754       FrameMgrGetToken(fm, attrID_list[number]);
00755       number++;
00756     }
00757     /* free FrameMgr */
00758     FrameMgrFree(fm);
00759 
00760     ic_attr = get_icattr(attrID_list, number);
00761     if (ic_attr == NULL) {
00762       return;
00763     }
00764   }
00765 #endif /* USE_FRAMEMGR_ALWAYS */
00766   getic->preedit_attr_num = 0; /* no preedit attributes */
00767   getic->status_attr_num = 0;      /* no status attributes */
00768   getic->ic_attr_num = (CARD16)number;
00769   getic->preedit_attr = NULL;
00770   getic->status_attr = NULL;
00771   getic->ic_attr = ic_attr;
00772 
00773   InputContext *ic = &(input_context_list.getItem(input_context_id));
00774   if (ic) {
00775     iiim_protocol->proto_handler->GetICValues((InputContext*)ic, 0, 0);
00776   } else {
00777     // need to treate as an error
00778   }
00779 
00780   iter_count = getic->ic_attr_num;
00781 
00782 #if !defined(USE_FRAMEMGR_ALWAYS)
00783   total_size = 4;
00784   total_size += (2 + 2);
00785   total_size += 2;
00786   attr_size = 0;
00787   for (i = 0; i < iter_count; i++) {
00788     attr_size += icattr_size(ic_attr + i);
00789   }
00790   total_size += 2; /* padding */
00791   data = new char[total_size];
00792   ptr = (data + 4);
00793   if (False == need_swap) {
00794     req_put16(ptr, input_method_id);
00795     req_put16(ptr, input_context_id);
00796     ptr = req_put_icattr_list(ptr, ic_attr, number);
00797     req_put16(ptr, 0);
00798   } else {
00799     req_put16s(ptr, input_method_id);
00800     req_put16s(ptr, input_context_id);
00801     ptr = req_put_icattr_list_s(ptr, ic_attr, number);
00802     req_put16s(ptr, 0);
00803   }
00804 
00805   send_message(IM_OUTPUT_REPLY, data, total_size);
00806 
00807   delete [] data;
00808   delete [] ic_attr;
00809 #else /* USE_FRAMEMGR_ALWAYS */
00810   /* create FrameMgr */
00811   fm = FrameMgrInit(output_fr, NULL, need_swap);
00812        
00813   /* set iteration count for list of ic_attribute */
00814   FrameMgrSetIterCount(fm, iter_count);
00815 
00816   /* set length of BARRAY item in xicattribute_fr*/
00817   ICAttribute *attrp;
00818   for (attrp = ic_attr;
00819        attrp < &ic_attr[getic->ic_attr_num]; attrp++) {
00820     FrameMgrSetSize(fm, attrp->value_length);
00821   }
00822 
00823   const int total_size = FrameMgrGetTotalSize(fm);
00824   CompoundString reply = CompoundString(total_size);
00825   memset(reply, 0, total_size);
00826   FrameMgrSetBuffer(fm, reply);
00827 
00828   FrameMgrPutToken(fm, input_method_id);
00829   FrameMgrPutToken(fm, input_context_id);
00830 
00831   for (attrp = ic_attr;
00832        attrp < &ic_attr[getic->ic_attr_num]; attrp++) {
00833     FrameMgrPutToken(fm, attrp->attribute_id);
00834     FrameMgrPutToken(fm, attrp->value_length);
00835     FrameMgrPutToken(fm, attrp->value);
00836   }
00837 
00838   send_message(IM_OUTPUT_REPLY, reply, total_size);
00839 
00840   delete [] ic_attr;
00841 
00842   /* free FrameMgr */
00843   FrameMgrFree(fm);
00844 #endif /* USE_FRAMEMGR_ALWAYS */
00845   return;
00846 }