Back to index

im-sdk  12.3.91
IIIMPClientDispatcher3.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 #include "FrameMgr.h"
00043 #include "IIIMPClient.hh"
00044 #include "IMProtoHandler.hh"
00045 #include "IIIMPInputContext.hh"
00046 #include "ICAttribute.hh"
00047 #include "IIIMProtocol.hh"
00048 #include "IMProtocolStructP.hh"
00049 
00050 #include <sys/types.h>
00051 #include <sys/stat.h>
00052 #include <fcntl.h>
00053 
00054 #ifndef       WIN32
00055 #include <unistd.h>
00056 #endif
00057 
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <string.h>
00061 
00062 char *read_object(char *, int *);
00063 char *read_ccdef(char *, char *, int*);
00064 
00065 char *
00066 read_object(
00067            char *path,             /* path */
00068            int *length             /* return length */
00069            )
00070 {
00071   FILE *fd;
00072   int ret;
00073   struct stat s_buf;
00074   char *contents;
00075   *length = 0;
00076 
00077   if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD)) {
00078     perror("");
00079     return 0;
00080   }
00081   contents = new char[s_buf.st_size + 1];
00082 
00083   if ((fd = fopen(path, "rb")) == NULL) {
00084     perror("");
00085     return 0;
00086   }
00087   ret = fread(contents, s_buf.st_size, 1, fd);
00088 
00089   /*
00090    * if (ret != s_buf.st_size) { printf("size error %d != %d\n",
00091    * ret, s_buf.st_size); return 0; }
00092    */
00093   *length = s_buf.st_size;
00094 
00095 #ifdef DEBUG
00096   for (int i = 0; i < *length; i++) {
00097     printf("%x\n", contents[i]);
00098   }
00099 #endif
00100 
00101   fclose(fd);
00102 
00103   return contents;
00104 }
00105 
00106 static int get_path(char *, char *);
00107 static FILE *openfile(char *, char *);
00108 
00109 #define       TMPUNIT 1024
00110 #define       BUFSIZE 1024
00111 
00112 #ifdef _POSIX_PATH_MAX
00113 #define PATHNAME_MAX _POSIX_PATH_MAX
00114 #else
00115 #define PATHNAME_MAX 1024
00116 #endif
00117 
00118 char *
00119 read_ccdef(
00120           char *path,
00121           char *basepath,
00122           int *length
00123           )
00124 {
00125   FILE *fp;
00126   int ret;
00127   struct stat s_buf;
00128   char *tmp;
00129   char line[PATHNAME_MAX];
00130   char incfile[PATHNAME_MAX];
00131   int m = 1;
00132 
00133   if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD)) {
00134     return 0;
00135   }
00136 
00137   tmp = (char *) malloc(sizeof(char) * TMPUNIT);
00138   strcpy(tmp, "");
00139 
00140   if ((fp = fopen(path, "rb")) == NULL) {
00141     return 0;
00142   }
00143   while (fgets((char *) line, 256, fp) != NULL) {
00144     if (strlen(line) <= 1) {
00145       continue;
00146     }
00147     if (strncmp(line, "#", 1) == 0) {
00148       continue;
00149     }
00150     if (strstr(line, "include")) {
00151       if (get_path(line, &incfile[0])) {
00152        FILE *fp2 = openfile(basepath, incfile);
00153        if (fp2 == NULL) {
00154 #ifdef DEBUG
00155          printf("can't open incfile=%s\n", incfile);
00156 #endif
00157          continue;
00158        } else {
00159          while (fgets((char *) line, 256, fp2) != NULL) {
00160            if (strlen(line) <= 1) {
00161              continue;
00162            }
00163            if (strncmp(line, "#", 1) == 0) {
00164              continue;
00165            }
00166            if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
00167              tmp = (char *) realloc((void *) tmp,
00168                                  sizeof(char) * TMPUNIT * (++m));
00169            }
00170            strcat(tmp, line);
00171 #ifdef DEBUG
00172            printf("line=[%s]\n", line);
00173 #endif
00174          }
00175          fclose(fp2);
00176        }
00177       } else {
00178        if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
00179          tmp = (char *) realloc((void *) tmp,
00180                              sizeof(char) * TMPUNIT * (++m));
00181        }
00182        strcat(tmp, line);
00183 #ifdef DEBUG
00184        printf("line=[%s]\n", line);
00185 #endif
00186       }
00187     } else {
00188       if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
00189        tmp = (char *) realloc((void *) tmp,
00190                             sizeof(char) * TMPUNIT * (++m));
00191       }
00192       strcat(tmp, line);
00193 #ifdef DEBUG
00194       printf("line=[%s]\n", line);
00195 #endif
00196     }
00197   }
00198   fclose(fp);
00199 
00200   *length = strlen(tmp);
00201   return tmp;
00202 }
00203 
00204 #define       Token " \n\r\t,\"'"
00205 
00206 static int
00207 get_path(
00208         char *p,
00209         char *path
00210         )
00211 {
00212   char tmp[BUFSIZE];
00213   char *k;
00214 
00215   strcpy(tmp, p);
00216   k = strtok(tmp, Token);
00217   if (k != NULL) {
00218     if (strncmp(k, "include", 7) == 0) {
00219       k = strtok(NULL, Token);
00220       if (k != NULL) {
00221        strcpy(path, k);
00222       }
00223       k = strtok(NULL, Token);
00224       if (k != NULL) {
00225        return 0;
00226       } else {
00227        return 1;
00228       }
00229     }
00230   }
00231   return 0;
00232 }
00233 
00234 static FILE *
00235 openfile(
00236         char *basepath,
00237         char *incfile
00238         )
00239 {
00240   char path[PATHNAME_MAX];
00241 #ifdef WIN32
00242   if (incfile[0] == '\\') {
00243 #else
00244     if (incfile[0] == '/') {
00245 #endif
00246       sprintf(path, "%s", incfile);
00247     } else {
00248 #ifdef WIN32
00249       sprintf(path, "%s\\%s", basepath, incfile);
00250 #else
00251       sprintf(path, "%s/%s", basepath, incfile);
00252 #endif
00253     }
00254     return fopen(path, "r");
00255 }
00256 
00257 void
00258 IIIMPClient::SetStringToFrame(FrameMgr fm, UTFCHAR* utf_str,
00259                            int char_length) {
00260   CARD8 *str = (CARD8*)utf_str;
00261   const int one_unit = sizeof(UTFCHAR)/sizeof(char);
00262   for (CARD8 *strp = str; strp < &str[char_length * one_unit];) {
00263     CARD8 first_byte, second_byte;
00264     if (need_swap) {
00265       second_byte = *strp++;
00266       first_byte  = *strp++;
00267     } else {
00268       first_byte  = *strp++;
00269       second_byte = *strp++;
00270     }
00271     FrameMgrPutToken(fm, first_byte);
00272     FrameMgrPutToken(fm, second_byte);
00273   }
00274 }
00275 
00276 void
00277 IIIMPClient::SetStringToFrame(FrameMgr fm, char* str,
00278                            int length) {
00279   CARD8 first_byte, second_byte;
00280   if (need_swap) {
00281     for (char *strp = str; strp < &str[length];) {
00282       CARD16 c = (CARD16)(*(strp++));
00283       first_byte = *((CARD8 *)(&c) + 1);
00284       second_byte = *((CARD8 *)(&c) + 0);
00285       FrameMgrPutToken(fm, first_byte);
00286       FrameMgrPutToken(fm, second_byte);
00287     }
00288   } else {
00289     for (char *strp = str; strp < &str[length];) {
00290       CARD16 c = (CARD16)(*(strp++));
00291       first_byte = *((CARD8 *)(&c) + 0);
00292       second_byte = *((CARD8 *)(&c) + 1);
00293       FrameMgrPutToken(fm, first_byte);
00294       FrameMgrPutToken(fm, second_byte);
00295     }
00296   }
00297 }
00298 
00299 unsigned char *
00300 IIIMPClient::create_jarfile_object_frame(IMObjectDescriptorStruct *od,
00301                                     char *contents, int ob_size,
00302                                     unsigned int *buf_size) {
00303   extern XimFrameRec jarfileobject_fr[];
00304   FrameMgr fm;
00305 
00306   /* create FrameMgr */
00307   fm = FrameMgrInit(jarfileobject_fr, (char *)NULL, need_swap);
00308 
00309   /* set iteration count for list of ic_attribute */
00310   FrameMgrSetIterCount(fm, od->count_names);
00311 
00312   /* set byte length of BIT16 item in STRING list */
00313   int i;
00314   for (i = 0; i < od->count_names; i++) {
00315     CompoundString name = od->class_names[i];
00316     int len = strlen((char*)name);
00317     FrameMgrSetIterCount(fm, len);
00318   }
00319 
00320   FrameMgrSetSize(fm, ob_size);    // byte length of jar file
00321 
00322   const int total_size = FrameMgrGetTotalSize(fm);
00323   unsigned char *buffer  = new unsigned char[total_size];
00324   memset(buffer, 0, total_size);
00325   FrameMgrSetBuffer(fm, buffer);
00326 
00327   for (i = 0; i < od->count_names; i++) {
00328     CompoundString name = od->class_names[i];
00329     int len = strlen((char*)name);
00330     for (char *strp = name; strp < &(name)[len]; strp++) {
00331       CARD16 str = (CARD16)*strp;
00332       CARD8 byte_data;
00333       byte_data = (str << 8) & 0xff00;
00334       FrameMgrPutToken(fm, byte_data);
00335       byte_data = str & 0x00ff;
00336       FrameMgrPutToken(fm, byte_data);
00337     }
00338   }
00339   FrameMgrPutToken(fm, ob_size);
00340   FrameMgrPutToken(fm, contents);
00341 
00342   FrameMgrFree(fm);
00343 
00344   *buf_size = total_size;
00345   return buffer;
00346 }
00347 
00348 unsigned char *
00349 IIIMPClient::create_ccdef_object_frame(IMObjectDescriptorStruct *od,
00350                                    char *contents, int ob_size,
00351                                    unsigned int *buf_size) {
00352   extern XimFrameRec ccdef_fr[];
00353   FrameMgr fm;
00354 
00355   /* create FrameMgr */
00356   fm = FrameMgrInit(ccdef_fr, (char *)NULL, need_swap);
00357 
00358   FrameMgrSetIterCount(fm, ob_size);
00359 
00360   const int total_size = FrameMgrGetTotalSize(fm);
00361   unsigned char *buffer  = new unsigned char[total_size];
00362   memset(buffer, 0, total_size);
00363   FrameMgrSetBuffer(fm, buffer);
00364 
00365   SetStringToFrame(fm, contents, ob_size);
00366 
00367   FrameMgrFree(fm);
00368 
00369   *buf_size = total_size;
00370   return buffer;
00371 }
00372 
00373 unsigned char *
00374 IIIMPClient::create_binfile_object_frame(IMObjectDescriptorStruct *od,
00375                                     unsigned int *buf_size) {
00376   extern XimFrameRec binfileobject_fr[];
00377   FrameMgr fm;
00378   int i;
00379 
00380   /* create FrameMgr */
00381   fm = FrameMgrInit(binfileobject_fr, (char *)NULL, need_swap);
00382 
00383   FrameMgrSetIterCount(fm, strlen(od->path));
00384 
00385   const int total_size = FrameMgrGetTotalSize(fm);
00386   unsigned char *buffer  = new unsigned char[total_size];
00387   memset(buffer, 0, total_size);
00388   FrameMgrSetBuffer(fm, buffer);
00389 
00390 #ifdef notdef
00391   for (i = 0; i < od->count_names; i++) {
00392     CompoundString name = od->class_names[i];
00393     int len = strlen((char*)name);
00394     for (char *strp = name; strp < &(name)[len]; strp++) {
00395       CARD16 str = (CARD16)*strp;
00396       CARD8 byte_data;
00397       byte_data = (str << 8) & 0xff00;
00398       FrameMgrPutToken(fm, byte_data);
00399       byte_data = str & 0x00ff;
00400       FrameMgrPutToken(fm, byte_data);
00401     }
00402   }
00403 #endif
00404   SetStringToFrame(fm, od->path, strlen(od->path));
00405 
00406   FrameMgrFree(fm);
00407 
00408   *buf_size = total_size;
00409   return buffer;
00410 }
00411 
00412 void
00413 IIIMPClient::set_imvalues(IMProtocolStruct *call_data, unsigned char *p) {
00414   CARD16 input_method_id;
00415   CARD16 byte_length;
00416   FrameMgr fm;
00417   FmStatus status;
00418 
00419   extern XimFrameRec im_setimvalues_fr[], im_setimvalues_reply_fr[];
00420   XimFrameRec *input_fr = im_setimvalues_fr;
00421   XimFrameRec *output_fr = im_setimvalues_reply_fr;
00422   const int IM_OUTPUT_REPLY = IM_SETIMVALUES_REPLY;
00423 
00424   /* create FrameMgr */
00425   fm = FrameMgrInit(input_fr, (char *)p, need_swap);
00426 
00427   /* get data */
00428   FrameMgrGetToken(fm, input_method_id);
00429   FrameMgrGetToken(fm, byte_length);
00430 
00431   if (byte_length != 0) {
00432     if (alloc_attr == 0) {
00433       alloc_attr = IIIMPClient::MAX_ATTRNUM;
00434       imAttribute_list = new ICAttribute[alloc_attr];
00435       memset(imAttribute_list, 0, sizeof(ICAttribute) * alloc_attr);
00436       active_attr = 0;
00437     }
00438     int first_im_index = active_attr;
00439     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00440       void *value;
00441       int value_length;
00442       if (active_attr == alloc_attr) {
00443        alloc_attr += IIIMPClient::MAX_ATTRNUM;
00444        ICAttribute *temp = imAttribute_list;
00445        imAttribute_list = new ICAttribute[alloc_attr];
00446        memset(imAttribute_list, 0, sizeof(ICAttribute) * alloc_attr);
00447        memmove(imAttribute_list, temp, sizeof(ICAttribute) * active_attr);
00448        delete [] temp;
00449       }
00450       FrameMgrGetToken(fm, imAttribute_list[active_attr].attribute_id);
00451       FrameMgrGetToken(fm, value_length);
00452       FrameMgrSetSize(fm, value_length);
00453       imAttribute_list[active_attr].value_length = value_length;
00454       FrameMgrGetToken(fm, value);
00455       imAttribute_list[active_attr].value = new char[value_length];
00456       memmove(imAttribute_list[active_attr].value, value, value_length);
00457       active_attr++;
00458     }
00459     /* The value from the protocol may need to be byte-swapped */
00460     for (ICAttribute *imp = &imAttribute_list[first_im_index];
00461         imp < &imAttribute_list[active_attr]; imp++) {
00462       char *tmp_imp_value = (char*) imp->value;
00463       if (read_imvalue(imp->attribute_id,
00464                      imp->value_length,
00465                      imp->value,
00466                      imp) == 0) {
00467        if (imp->name == iiim_protocol->IMListName) {
00468          ;
00469        }
00470        else if (imp->name == iiim_protocol->IMClientName) {
00471 #if !defined(USE_FRAMEMGR_ALWAYS)
00472          int left = imp->value_length;
00473 #else /* USE_FRAMEMGR_ALWAYS */
00474          int left = imp->value_length/2 - 1; // evil
00475 #endif /* USE_FRAMEMGR_ALWAYS */
00476          // LISTofSTRING(applicationName, osName, osArck, osVersion)
00477          char *p = (char*)imp->value;
00478          size_t len;
00479          if (left == 0) continue;
00480          application_name = (char*)p;
00481          len = strlen(p) + 1; p += len; left -= len;
00482          if (left == 0) continue;
00483 
00484          os_name = (char*)p;
00485          len = strlen(p) + 1; p += len; left -= len;
00486          if (left == 0) continue;
00487 
00488          os_arch = (char*)p;
00489          len = strlen(p) + 1; p += len; left -= len;
00490          if (left == 0) continue;
00491 
00492          os_version = (char*)p;
00493          // LISTofSTRING(display_name, server_vendor) may follow
00494          len = strlen(p) + 1; p += len; left -= len;
00495          if (left <= 0) continue;
00496 
00497          xDisplayName = (char*)p;
00498          len = strlen(p) + 1; p += len; left -= len;
00499          if (left <= 0) continue;
00500 
00501          xServerVendor = (char*)p;
00502        }
00503        else if (imp->name == iiim_protocol->IMObjectListName) {
00504          ;
00505        }
00506        else if (imp->name == iiim_protocol->IMCCDEFName) {
00507          ;
00508        }
00509        else if (imp->name == iiim_protocol->IMGUIObjectName) {
00510          ;
00511        }
00512        else if (imp->name == iiim_protocol->IMLWEObjectName) {
00513          ;
00514        }
00515       }
00516       delete [] tmp_imp_value;
00517       delete [] imp->value;
00518     }
00519   }
00520 
00521   /* free FrameMgr */
00522   FrameMgrFree(fm);
00523 
00524   // IF this IM_SETIMVALUES is sent before the 1st input context is
00525   // created, send OBJECTDESCRIPTOR to the client
00526 
00527   if (input_context_list.getSize() == 0) {
00528 
00529     // return INPUTMETHODLIST to the client if any
00530     int count = iiim_protocol->countIME();
00531     int i;
00532     extern XimFrameRec inputmethod_fr[];
00533     int iter_count;
00534     unsigned char *imelist_buf = (unsigned char*)0;
00535     unsigned int imelist_size = 0;
00536     IMEditorStruct ime;
00537     for (i = 0; i < count; i++) {
00538       ime = iiim_protocol->getIME(i+1);
00539       fm = FrameMgrInit(inputmethod_fr, NULL, need_swap);
00540 
00541       iter_count = strlen(ime.domain); // object User
00542       FrameMgrSetIterCount(fm, iter_count);
00543       iter_count = ime.name_length;
00544       FrameMgrSetIterCount(fm, iter_count);
00545 
00546       int lang_count = ime.count_locales;
00547 
00548       /* set iteration count of lang names */
00549       FrameMgrSetIterCount(fm, lang_count);
00550 
00551       // set byte length of BIT16 item in STRING list
00552       int j;
00553       for (j = 0; j < lang_count; j++) {
00554        CompoundString langp(ime.locales[i]);
00555        int len = strlen((char*)langp);
00556        FrameMgrSetIterCount(fm, len);
00557       }
00558 
00559       const int ime_size = FrameMgrGetTotalSize(fm);
00560       CompoundString ime_buf = CompoundString(ime_size);
00561       memset(ime_buf, 0, ime_size);
00562       FrameMgrSetBuffer(fm, ime_buf);
00563 
00564       FrameMgrPutToken(fm, ime.id);
00565       SetStringToFrame(fm, ime.domain, strlen(ime.domain));
00566       SetStringToFrame(fm, ime.name, ime.name_length);
00567 
00568       for (j = 0; j < lang_count; j++) {
00569        CompoundString langp(ime.locales[i]);
00570        SetStringToFrame(fm, langp, strlen(langp));
00571       }
00572 
00573       if (!imelist_buf) {
00574        imelist_buf = new unsigned char[ime_size];
00575        imelist_size = ime_size;
00576        memmove(imelist_buf, ime_buf, ime_size);
00577       } else {
00578        unsigned char *temp = new unsigned char[imelist_size + ime_size];
00579        unsigned char *pTemp = temp;
00580        memmove(pTemp, imelist_buf, imelist_size);
00581        pTemp += imelist_size;
00582        memmove(pTemp, ime_buf, ime_size);
00583        imelist_size += ime_size;
00584        delete [] imelist_buf;
00585        imelist_buf = temp;
00586       }
00587       /* free FrameMgr */
00588       FrameMgrFree(fm);
00589     }
00590 
00591     // return OBJECTDESCRIPTORLIST to the client
00592     count = iiim_protocol->countObjectDescriptors();
00593     extern XimFrameRec objectdescriptor_fr[];
00594     unsigned char *odlist_buf = (unsigned char*)0;
00595     unsigned int odlist_size = 0;
00596     IMObjectDescriptorStruct od;
00597 
00598     CompoundString client_type = getApplicationName();
00599 
00600     for (i = 0; i < count; i++) {
00601       od = iiim_protocol->getObjectDescriptor(i+1);
00602 
00603       if(strstr((char*)client_type, "JDK")){ /* JAVA */
00604         if(od.type == IM_DOWNLOADINGOBJECT_BINGUI_TYPE ||
00605            od.type == IM_DOWNLOADINGOBJECT_BINLWE_TYPE) {
00606           continue;
00607         }
00608       } else { /* from xiiimp.so.2 */
00609         if(od.type == IM_DOWNLOADINGOBJECT_JARGUI_TYPE ||
00610            od.type == IM_DOWNLOADINGOBJECT_JARLWE_TYPE) {
00611           continue;
00612         }
00613       }
00614 
00615       fm = FrameMgrInit(objectdescriptor_fr, NULL, need_swap);
00616       iter_count = strlen(od.domain); // reversed unique domain name
00617       FrameMgrSetIterCount(fm, iter_count);
00618       iter_count = od.name_length;
00619       FrameMgrSetIterCount(fm, iter_count);
00620       iter_count = 0;              // signature
00621       FrameMgrSetIterCount(fm, iter_count);
00622       iter_count = strlen(od.scope); // object User
00623       FrameMgrSetIterCount(fm, iter_count);
00624 
00625       const int od_size = FrameMgrGetTotalSize(fm);
00626       CompoundString od_buf = CompoundString(od_size);
00627       memset(od_buf, 0, od_size);
00628       FrameMgrSetBuffer(fm, od_buf);
00629 
00630       IMObjectCategory category = IM_GUI_OBJECT;
00631       FrameMgrPutToken(fm, category);
00632       FrameMgrPutToken(fm, od.size);
00633       FrameMgrPutToken(fm, od.type);
00634       FrameMgrPutToken(fm, od.id);
00635       SetStringToFrame(fm, od.domain, strlen(od.domain));
00636       SetStringToFrame(fm, od.name, od.name_length);
00637       SetStringToFrame(fm, od.signature, strlen(od.signature));
00638       SetStringToFrame(fm, od.scope, strlen(od.scope));
00639 
00640       if (!odlist_buf) {
00641        odlist_buf = new unsigned char[od_size];
00642        odlist_size = od_size;
00643        memmove(odlist_buf, od_buf, od_size);
00644       } else {
00645        unsigned char *temp = new unsigned char[odlist_size + od_size];
00646        unsigned char *pTemp = temp;
00647        memmove(pTemp, odlist_buf, odlist_size);
00648        pTemp += odlist_size;
00649        memmove(pTemp, od_buf, od_size);
00650        odlist_size += od_size;
00651        delete [] odlist_buf;
00652        odlist_buf = temp;
00653       }
00654       /* free FrameMgr */
00655       FrameMgrFree(fm);
00656     }
00657 
00658     ICAttribute im_attr[2];
00659     int n = 0;
00660     if (imelist_size > 0) {
00661       im_attr[n].attribute_id = INPUT_METHOD_LIST;
00662       im_attr[n].value_length = imelist_size;
00663       im_attr[n].value = (void*)imelist_buf;
00664       n++;
00665     }
00666     if (odlist_size > 0) {
00667       im_attr[n].attribute_id = OBJECT_DESCRIPTOR_LIST;
00668       im_attr[n].value_length = odlist_size;
00669       im_attr[n].value = (void*)odlist_buf;
00670       n++;
00671     }
00672     if (n > 0) {
00673       send_imvalues_message(input_method_id, IM_SETIMVALUES,
00674                          im_attr, n);
00675     }
00676 
00677     delete [] imelist_buf;
00678     delete [] odlist_buf;
00679   }
00680 
00681   // Send IM_SETIMVALUES_REPLY to the previous
00682   // IM_SETIMVALUES from the client.
00683 #if !defined(USE_FRAMEMGR_ALWAYS)
00684   send_message(input_method_id, 0, IM_OUTPUT_REPLY);
00685 #else /* USE_FRAMEMGR_ALWAYS */
00686   send_message(input_method_id, 0, output_fr, IM_OUTPUT_REPLY);
00687 #endif /* USE_FRAMEMGR_ALWAYS */
00688 
00689   respond_keepalive = True;
00690   return;
00691 }
00692 
00693 void
00694 IIIMPClient::get_imvalues(IMProtocolStruct *call_data, unsigned char *p) {
00695   CARD16 input_method_id;
00696   CARD16 byte_length;
00697   FrameMgr fm;
00698   FmStatus status;
00699 
00700   extern XimFrameRec im_getimvalues_fr[], im_getimvalues_reply_fr[];
00701   XimFrameRec *input_fr = im_getimvalues_fr;
00702   XimFrameRec *output_fr = im_getimvalues_reply_fr;
00703   const int IM_OUTPUT_REPLY = IM_GETIMVALUES_REPLY;
00704 
00705   /* create FrameMgr */
00706   fm = FrameMgrInit(input_fr, (char *)p, need_swap);
00707 
00708   /* get data */
00709   FrameMgrGetToken(fm, input_method_id);
00710   FrameMgrGetToken(fm, byte_length);
00711 
00712   CARD16 *attrID_list = NULL;
00713   int number = 0;
00714   if (byte_length != 0) {
00715     attrID_list = (CARD16*)new char[byte_length];
00716     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00717       FrameMgrGetToken(fm, attrID_list[number]);
00718       number++;
00719     }
00720   }
00721   /* free FrameMgr */
00722   FrameMgrFree(fm);
00723 
00724 
00725   ICAttribute *im_attr = new ICAttribute[number];
00726   int i;
00727   IMObjectDescriptorStruct *od = &(iiim_protocol->getFirstObjectDescriptor());
00728   memset(im_attr, 0, sizeof(ICAttribute) * number);
00729   while (od) {
00730     for (i = 0; i < number; i++) {
00731       if (im_attr[i].attribute_id) break;
00732       if (attrID_list[i] == od->id) {
00733        im_attr[i].attribute_id = od->id;
00734        char *contents = 0;
00735        int ob_size = 0;
00736        unsigned int buf_size;
00737        unsigned char *buffer;
00738 
00739        switch (od->type) {
00740        case IM_DOWNLOADINGOBJECT_JARGUI_TYPE:
00741        case IM_DOWNLOADINGOBJECT_JARLWE_TYPE:
00742          contents = read_object(od->path, &ob_size);
00743          buffer = create_jarfile_object_frame(od, contents, ob_size,
00744                                           &buf_size);
00745          im_attr[i].value_length = buf_size;
00746          im_attr[i].value = (void*)buffer;
00747          delete [] contents;
00748          break;
00749        case IM_DOWNLOADINGOBJECT_CCDEF_TYPE:
00750          contents = read_ccdef(od->path, od->basepath, &ob_size);
00751          buffer = create_ccdef_object_frame(od, contents, ob_size,
00752                                         &buf_size);
00753          im_attr[i].value_length = buf_size;
00754          im_attr[i].value = (void*)buffer;
00755          delete [] contents;
00756          break;
00757        case IM_DOWNLOADINGOBJECT_BINGUI_TYPE:
00758        case IM_DOWNLOADINGOBJECT_BINLWE_TYPE:
00759          buffer = create_binfile_object_frame(od, &buf_size);
00760          im_attr[i].value_length = buf_size;
00761          im_attr[i].value = (void*)buffer;
00762          delete [] contents;
00763          break;
00764        case IM_DOWNLOADINGOBJECT_SGUI_TYPE:
00765        case IM_DOWNLOADINGOBJECT_SLWE_TYPE:
00766        default:
00767          break;
00768        }
00769        break;
00770       }
00771       
00772     }
00773     od = &(iiim_protocol->getNextObjectDescriptor());
00774   }
00775   send_imvalues_message(input_method_id, IM_GETIMVALUES_REPLY,
00776                      im_attr, number);
00777   ICAttribute *attrp;
00778   for (attrp = im_attr; attrp < &im_attr[number]; attrp++) {
00779     delete attrp->value;
00780   }
00781   delete [] attrID_list;
00782   delete [] im_attr;
00783   return;
00784 }
00785 
00786 void
00787 IIIMPClient::send_imvalues_message(int input_method_id,
00788                                int message_type,
00789                                ICAttribute *im_attr, int n) {
00790   extern XimFrameRec im_setimvalues_fr[], im_setimvalues_reply_fr[];
00791   XimFrameRec *input_fr = im_setimvalues_fr;
00792   XimFrameRec *output_fr = im_setimvalues_reply_fr;
00793   FrameMgr fm;
00794 
00795   /* create FrameMgr */
00796   fm = FrameMgrInit(input_fr, (char *)NULL, need_swap);
00797 
00798   /* set iteration count for list of im_attribute */
00799   FrameMgrSetIterCount(fm, n);
00800 
00801   /* set length of BARRAY item in imattribute_fr*/
00802   ICAttribute *attrp;
00803   for (attrp = im_attr; attrp < &im_attr[n]; attrp++) {
00804     FrameMgrSetSize(fm, attrp->value_length);
00805   }
00806 
00807   const int total_size = FrameMgrGetTotalSize(fm);
00808   CompoundString reply = CompoundString(total_size);
00809   memset(reply, 0, total_size);
00810   FrameMgrSetBuffer(fm, reply);
00811 
00812   unsigned char *replyp = reply.toUchar();
00813 
00814   FrameMgrPutToken(fm, input_method_id);
00815   replyp += 2 + 2 + 4;             // imid + pad(2) + byte_length
00816 
00817   for (attrp = im_attr; attrp < &im_attr[n]; attrp++) {
00818     FrameMgrPutToken(fm, attrp->attribute_id); replyp += 2;
00819     FrameMgrPutToken(fm, attrp->value_length); replyp += 2 + 4; // padding + len
00820     memmove(replyp, attrp->value, attrp->value_length);
00821     replyp += attrp->value_length;
00822     replyp += ((attrp->value_length) % 4);
00823     FrameMgrSkipToken(fm, 2);      // value, padding
00824   }
00825   send_message(message_type, reply, total_size);
00826 
00827   /* free FrameMgr */
00828   FrameMgrFree(fm);
00829 
00830   if (message_type == IM_SETIMVALUES) {
00831     // wait IM_SETIMVALUES_REPLY
00832     get_amessage();
00833   }
00834 
00835   return;
00836 }