1 /* Copyright 1992 NEC Corporation, Tokyo, Japan.
2  *
3  * Permission to use, copy, modify, distribute and sell this software
4  * and its documentation for any purpose is hereby granted without
5  * fee, provided that the above copyright notice appear in all copies
6  * and that both that copyright notice and this permission notice
7  * appear in supporting documentation, and that the name of NEC
8  * Corporation not be used in advertising or publicity pertaining to
9  * distribution of the software without specific, written prior
10  * permission.  NEC Corporation makes no representations about the
11  * suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16  * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #if !defined(lint) && !defined(__CODECENTER__)
24 static char rcs_id[] = "@(#) 102.1 $Id: convert.c,v 1.10.2.1 2003/12/27 17:15:24 aida_s Exp $";
25 #endif
26 
27 /* LINTLIBRARY */
28 
29 #include "server.h"
30 #include <patchlevel.h>
31 
32 #if CANNA_LIGHT
33 #ifdef EXTENSION
34 #undef EXTENSION
35 #endif
36 #endif
37 
38 #define SIZEOFSHORT 2 /* for protocol */
39 #define SIZEOFLONG  4 /* for protocol */
40 
41 #define SENDBUFSIZE 1024
42 
43 #define ACK0 0
44 #define ACK1 1
45 #define ACK2 2
46 #define ACK3 3
47 #define CHECK_ACK_BUF_SIZE	(ACK_BUFSIZE + (SIZEOFLONG * 2) )
48 #define IR_INT_MAX 32767
49 #define IR_INT_INVAL(x) ((unsigned int)x > IR_INT_MAX)
50 
51 #ifdef MIN
52 # undef MIN
53 #endif
54 #define MIN RKI_MIN
55 static int ProcReq0 pro((char *buf, int size));
56 extern const char *ProtoName[];
57 
58 #ifdef DEBUGPROTO
59 static void
printproto(p,n)60 printproto(p, n)
61 char *p;
62 int n;
63 {
64   int i;
65 
66   for (i = 0 ; i < n ; i++) {
67     if (i) {
68       if ((i %  4) == 0) printf(" ");
69       if ((i % 32) == 0) printf("\n");
70     }
71     printf("%02x", (unsigned)((*p++) & 0xff));
72   }
73   printf("\n");
74 }
75 
76 static void
probe(format,n,p)77 probe(format, n, p)
78 char *format, *p;
79 int n;
80 {
81   printf(format, n);
82   printproto(p, n);
83 }
84 #else /* !DEBUGPROTO */
85 #define probe(a, b, c)
86 #endif /* !DEBUGPROTO */
87 
88 typedef struct {
89   int (*func) pro((ClientPtr *));
90   int (*extdat) pro((char *, int));
91 } oreqproc;
92 
93 extern oreqproc Vector[];
94 #ifdef EXTENSION
95 extern oreqproc ExtensionVector[];
96 #endif /* EXTENSION */
97 #ifdef USE_EUC_PROTOCOL
98 extern const char *ExtensionName[][2] ;
99 #endif /* USE_EUC_PROTOCOL */
100 
101 static IRReq	Request ;
102 #ifdef USE_EUC_PROTOCOL
103 static IRAck	Acknowledge ;
104 static char
105 local_buffer[ LOCAL_BUFSIZE ],
106 local_buffer2[ LOCAL_BUFSIZE ] ;
107 #endif /* USE_EUC_PROTOCOL */
108 
109 unsigned int
110 TotalRequestTypeCount[ MAXREQUESTNO ] ;
111 int canna_server_hi = 0 ;
112 int canna_server_lo = 0 ;
113 
114 void
getserver_version()115 getserver_version()
116 {
117     char version[ 32 ], *buf ;
118 
119     strcpy( version, W_VERSION ) ;
120     if( version[0] ) {
121 	if( !(buf = (char *)strtok(version, ".")) ) {
122 	    return ;
123 	}
124 	canna_server_hi = atoi( buf ) ;
125 	if( !(buf = (char *)strtok((char *)NULL, ".")) ) {
126 	    return ;
127 	}
128 	canna_server_lo = atoi( buf ) ;
129     }
130 }
131 
132 #ifdef USE_EUC_PROTOCOL
133 static int
getFirstKouho(cxnum,start,end,status,datap)134 getFirstKouho( cxnum, start, end, status, datap )
135 int cxnum, start, end, *status;
136 BYTE **datap;
137 {
138     char *src = local_buffer2 ;
139     register char *dst = (char *)*datap;
140     BYTE *data_buffer = *datap;
141     register int i, len, size = 0, maxsz = SENDBUFSIZE;
142     Ushort cbuf[CBUFSIZE];
143 
144    ir_debug( Dmsg(5,"��ͥ�����ꥹ��\n" ); )
145     for( i = start; i < end; i++){
146 	len = RkwGetKanji( cxnum, (Ushort *)cbuf, CBUFSIZE  );
147 	len = ushort2euc( cbuf, len, src, LOCAL_BUFSIZE ) + 1;
148 	size += len;
149 	if( size > maxsz ) {
150 	    BYTE *local_bufptr;
151 	    int bufcnt = size - len;
152 
153 	    maxsz = maxsz * 2;
154 	    local_bufptr = (BYTE *)malloc(maxsz);
155 	    if (local_bufptr) {
156 		ir_debug( Dmsg(8, "malloc size is %d.\n", maxsz) );
157 
158 		bcopy(*datap, (char *)local_bufptr, bufcnt);
159 		if( *datap != data_buffer )
160 		    free( (char *)*datap );
161 		*datap = local_bufptr;
162 		dst = (char *)local_bufptr + bufcnt;
163 	    } else {
164 		*status = -1;
165 		PrintMsg( "First Kouho Buffer allocate failed!!\n" );
166 		return 0;
167 	    }
168 	}
169 	strcpy(dst, src);
170        ir_debug( Dmsg(5,"%d:[%s]", i, dst ); )
171 	dst += len ;
172 	RkwRight( cxnum ) ;
173     }
174    ir_debug( Dmsg(5,"\n" ); )
175     *status = i;
176     RkwGoTo( cxnum, start ) ;/* ��Ƭʸ�������ʸ����ᤷ�Ƥ��� */
177     return size;
178 }
179 
180 static int
listsize(src,cnt)181 listsize(src, cnt)
182 char *src;
183 int cnt;
184 {
185     register int i, size = 0, len = 0;
186 
187     for( i = 0; i < cnt; i++ ){
188 	len = strlen(src) + 1;
189 	size += len;
190        ir_debug( Dmsg(5,"%d:[%s] ", i, src ); )
191 	src += len;
192     }
193    ir_debug( Dmsg(5,"\n" ); )
194     return size;
195 }
196 
197 #endif /* USE_EUC_PROTOCOL */
198 
199 int
ir_error(clientp)200 ir_error(clientp)
201 ClientPtr *clientp ; /* ARGSUSED */
202 {
203     ir_debug(Dmsg(5, "ir_error() invoked\n"));
204     return( -1 ) ;
205 }
206 
207 #ifdef USE_EUC_PROTOCOL
208 #ifdef DEBUG
209 static int
WriteClient(client,buf,size)210 WriteClient(client, buf, size)
211 ClientPtr client;
212 const BYTE *buf;
213 size_t size;
214 {
215     ir_debug( Dmsg(10, "WriteClient:") );
216     ir_debug( DebugDump( 10, buf, size ) );
217     return ClientBuf_store_reply(client->client_buf, buf, size);
218 }
219 #else
220 # define WriteClient(c, b, s) ClientBuf_store_reply((c)->client_buf, b, s)
221 #endif
222 #endif /* USE_EUC_PROTOCOL */
223 
224 static int
SendTypeE1Reply2(client_buf,stat)225 SendTypeE1Reply2(client_buf, stat)
226 ClientBuf *client_buf;
227 int stat;
228 {
229     BYTE buf[4], *p = buf;
230 
231     LTOL4(stat, p);
232 
233     return ClientBuf_store_reply(client_buf, buf, sizeof buf);
234 }
235 
236 #ifdef USE_EUC_PROTOCOL
237 
238 #define SendType0Reply SendTypeE1Reply
239 
240 static int
SendTypeE1Reply(client,stat)241 SendTypeE1Reply(client, stat)
242 register ClientPtr client;
243 int stat;
244 {
245     BYTE buf[4], *p = buf;
246 
247     LTOL4(stat, p);
248 
249     return WriteClient(client, buf, sizeof(buf));
250 }
251 
252 static int
SendTypeE2Reply(client,stat,cnt,str,slen)253 SendTypeE2Reply(client, stat, cnt, str, slen)
254 register ClientPtr client;
255 char *str;
256 int stat, cnt, slen;
257 {
258     BYTE lbuf[SENDBUFSIZE], *bufp = lbuf, *p;
259     char *wp;
260     int res, dlen = cnt * SIZEOFLONG + slen, sz = 2 * SIZEOFLONG + dlen;
261     int nlen, i;
262 
263     if (sz <= SENDBUFSIZE || (bufp = (BYTE *)malloc(sz))) {
264 	p = bufp;
265 	LTOL4(stat, p); p += SIZEOFLONG;
266 	LTOL4(dlen, p); p += SIZEOFLONG;
267 
268 	for (wp = str, i = 0 ; i < cnt ; wp += nlen, i++) {
269 	    nlen = strlen(wp) + 1;
270 	    LTOL4(nlen, p);  p += SIZEOFLONG;
271 	    strcpy((char *)p, wp); p += nlen;
272 	}
273 
274 	res = WriteClient(client, bufp, sz);
275 	if (bufp != lbuf) free((char *)bufp);
276 	return res;
277     }
278     return -1;
279 }
280 
281 static int
SendTypeE3Reply(client,stat,storefunc,extdata,slen)282 SendTypeE3Reply(client, stat, storefunc, extdata, slen)
283 register ClientPtr client;
284 int stat, slen, (*storefunc)();
285 BYTE *extdata;
286 {
287     BYTE lbuf[SENDBUFSIZE], *bufp = lbuf, *p;
288     int sz = 2 * SIZEOFLONG + slen;
289     int res;
290 
291     if (sz <= SENDBUFSIZE || (bufp = (BYTE *)malloc(sz))) {
292 	p = bufp;
293 	LTOL4(stat, p); p += SIZEOFLONG;
294 	LTOL4(slen, p); p += SIZEOFLONG;
295 
296 	if (storefunc)
297 	    (*storefunc)(client, stat, extdata, p);
298 
299 	res = WriteClient(client, bufp, sz);
300 	if (bufp != lbuf) free((char *)bufp);
301 	return res;
302     }
303     return -1;
304 }
305 
306 /* #define SendTypeE4Reply SendTypeE3Reply */
307 /* IR_GET_LEX�� TypeE4Reply�Ǥʤ� TypeE3Reply�ʤΤ� TypeE4�Ϥ���ʤ� */
308 /* IR_GET_WORD_DIC�� TypeE2�ǤϤʤ�������� TypeE4�ˤ��� */
309 
310 static int
SendTypeE4Reply(client,stat,cnt,infoptr,slen)311 SendTypeE4Reply(client, stat, cnt, infoptr, slen)
312 register ClientPtr client;
313 BYTE *infoptr;
314 int stat, cnt, slen;
315 {
316     BYTE lbuf[SENDBUFSIZE], *bufp = lbuf, *p;
317     int res, sz = 2 * SIZEOFLONG + slen;
318 
319     if (sz <= SENDBUFSIZE || (bufp = (BYTE *)malloc(sz))) {
320 	p = bufp;
321 	LTOL4(stat, p); p += SIZEOFLONG;
322 	LTOL4(slen, p); p += SIZEOFLONG;
323 
324 	LTOL4( cnt, p ) ; p += SIZEOFLONG;
325 	bcopy( infoptr, p, cnt ) ;
326 
327 	res = WriteClient(client, bufp, sz);
328 	if (bufp != lbuf) free((char *)bufp);
329 	return res;
330     }
331     return -1;
332 }
333 
334 /* IR_SER_STAT�� TypeE5Reply���Τ�ΤǤ��� */
335 
336 #define SendTypeE5Reply(client_buf, size) \
337     ClientBuf_store_reply(client_buf, Acknowledge.SendAckBuffer, size)
338 
339 /* IR_SER_STAT2�� TypeE6Reply���Τ�ΤǤ��� */
340 
341 #define SendTypeE6Reply SendTypeE5Reply
342 
343 /* IR_HOST�����Τˤ� TypeE2Reply�ǤϤʤ��Τ� TypeE7Reply���� */
344 
345 #define SendTypeE7Reply(client, size) \
346     WriteClient(client, Acknowledge.SendAckBuffer, size)
347 
348 static const char *
irerrhdr(client)349 irerrhdr(client)
350 ClientPtr client;
351 {
352     static char buf[50];
353     int proto = Request.Request2.Type;
354     sprintf(buf, "[%.25s](%.20s)", client->username, ProtoName[proto - 1]);
355     return buf;
356 }
357 
358 static void
print_context_error(client)359 print_context_error(client)
360 ClientPtr client;
361 {
362     PrintMsg( "%s Context Err\n", irerrhdr(client));
363 }
364 
365 #endif /* USE_EUC_PROTOCOL */
366 
367 static int
ir_initialize(clientp,client_buf)368 ir_initialize(clientp, client_buf)
369 ClientPtr *clientp;
370 ClientBuf *client_buf;
371 {
372     Req2 *req = &Request.Request2 ;
373     int stat;
374 
375     stat = open_session(clientp, req->name, client_buf);
376     if (SendTypeE1Reply2(client_buf, stat) < 0)
377 	return -1;
378     if (stat == -1)
379 	EventMgr_finalize_notify(global_event_mgr, client_buf);
380     return 0;
381 }
382 
383 #ifdef USE_EUC_PROTOCOL
384 
ir_finalize(clientp)385 ir_finalize(clientp)
386 register ClientPtr *clientp ;
387 {
388     ClientPtr client = *clientp ;
389 
390     if( SendTypeE1Reply(client, 0) < 0 )
391 	return( -1 ) ;
392 
393     /* close������������ʥ���ƥ����Ȥγ������� */
394     close_session(clientp, 1);
395     return( 0 ) ;
396 }
397 
ir_killserver(clientp)398 ir_killserver(clientp)
399 register ClientPtr *clientp;
400 {
401     ClientPtr client = *clientp;
402 
403     if( SendTypeE1Reply(client, 0) < 0 )
404 	return -1;
405     return 0;
406 }
407 
ir_create_context(clientp)408 ir_create_context(clientp)
409 ClientPtr *clientp ;
410 {
411     ClientPtr client = *clientp ;
412     int cxnum, stat = -1;
413 
414     cxnum = RkwCreateContext() ;
415     if( SetDicHome( client, cxnum ) > 0 ) {
416       set_cxt(client, cxnum);
417       stat = cxnum;
418     } else {
419 	Req0 *req0 = &Request.Request0 ;
420 
421 	RkwCloseContext(cxnum);
422 	PrintMsg("%s Can't set dictionary home\n",
423 		irerrhdr(client, req0->Type));
424     }
425     return SendTypeE1Reply(client, stat);
426 }
427 
ir_duplicate_context(clientp)428 ir_duplicate_context(clientp)
429 ClientPtr *clientp ;
430 {
431     Req1 *req = &Request.Request1 ;
432     ClientPtr client = *clientp ;
433     int cxnum, stat = -1;
434 
435     cxnum = req->context;
436     if (chk_cxt(client, cxnum)) {
437 	stat = cxnum = RkwDuplicateContext( cxnum );
438 	if (cxnum >= 0) {
439 	  if (!set_cxt(client, cxnum)) {
440 	    RkwCloseContext(cxnum);
441 	    stat = -1;
442 	  }
443 	}
444     } else {
445 	PrintMsg("%s Context Err[%d]\n", irerrhdr(client), cxnum ) ;
446     }
447 
448     return SendTypeE1Reply(client, stat);
449 }
450 
ir_close_context(clientp)451 ir_close_context(clientp)
452 ClientPtr *clientp ;
453 {
454     Req1 *req = &Request.Request1 ;
455     ClientPtr client = *clientp ;
456     int cxnum, stat = -1;
457 
458     cxnum = req->context;
459     if (chk_cxt(client, cxnum)) {
460 	stat = RkwCloseContext(cxnum);
461 	off_cxt(client, cxnum);
462     } else {
463 	print_context_error(client);
464     }
465 
466     return SendTypeE1Reply(client, stat);
467 }
468 
ir_dictionary_list(clientp)469 ir_dictionary_list(clientp)
470 ClientPtr *clientp ;
471 {
472     Req3 *req = &Request.Request3 ;
473     ClientPtr client = *clientp ;
474     char *dicnames = local_buffer ;
475     int cxnum, size = 0 ;
476     int ret = -1, max;
477 
478     cxnum = req->context;
479     if (chk_cxt(client, cxnum)) {
480 	max = MIN( req->number, LOCAL_BUFSIZE ) ;
481 	if( (ret = (int)RkwGetDicList(cxnum, (char *)dicnames, max)) < 0) {
482 	    ret = 0;
483 	} else {
484 	   ir_debug( Dmsg(5,"����ꥹ��\n" ); )
485 	    size = listsize(dicnames, ret);
486 	}
487     } else {
488 	PrintMsg("%s Context Err[%d]\n", irerrhdr(client), cxnum );
489     }
490 
491     return SendTypeE2Reply(client, ret, (ret < 0)? 0: ret, dicnames, size);
492 }
493 
ir_get_yomi(clientp)494 ir_get_yomi( clientp )
495 ClientPtr *clientp ;
496 {
497     Req5 *req = &Request.Request5 ;
498     ClientPtr client = *clientp ;
499     char *yomi = local_buffer ;
500     int ret = -1, cxnum ;
501     int size = 0 ;
502     Ushort cbuf[CBUFSIZE];
503 
504     cxnum = req->context;
505     if (chk_cxt(client, cxnum)) {
506 	int bunsetuno = req->number ;
507 	int maxyomi = MIN( req->datalen, LOCAL_BUFSIZE ) ;
508 
509        ir_debug( Dmsg(5,"maxyomi [ %d ]\n", maxyomi ); )
510 	if( RkwGoTo(cxnum, bunsetuno) == bunsetuno ) {
511 	    ret = RkwGetYomi( cxnum, (Ushort *)cbuf, CBUFSIZE );
512 	    /* ushort2euc�� -1���֤����ȤϤʤ��Τ� */
513 	    ret = ushort2euc(cbuf, ret, yomi, maxyomi);
514 	    if (ret) {
515 		size = ret + 1;
516 	    }
517 	} else {
518 	    PrintMsg("%s bunsetu move failed\n", irerrhdr(client));
519        }
520     } else {
521 	print_context_error(client);
522     }
523     return SendTypeE2Reply(client, ret, (ret > 0)? 1: 0, yomi, size);
524 }
525 
ir_set_dic_path(clientp)526 ir_set_dic_path( clientp )
527 ClientPtr *clientp ;
528 /* ARGSUSED */
529 {
530     return( 0 ) ;
531 }
532 
ir_define_dic(clientp)533 ir_define_dic(clientp)
534 ClientPtr *clientp ;
535 {
536     Req7 *req = &Request.Request7 ;
537     ClientPtr client = *clientp ;
538     char *dicname, *data ;
539     int cxnum, ret = -1;
540     Ushort cbuf[CBUFSIZE];
541 
542     cxnum = req->context;
543     if (chk_cxt(client, cxnum)) {
544 	dicname = req->dicname ;
545 	data = req->datainfo ;
546        ir_debug( Dmsg(5,"����̾=%s\n", dicname ); )
547        ir_debug( Dmsg(5,"��Ͽ����ǡ���[%s]\n", data );)
548 	euc2ushort( data, strlen( (char *)data ), cbuf, CBUFSIZE );
549 	ret = RkwDefineDic( cxnum, (char *)dicname, (Ushort *)cbuf );
550     } else {
551 	print_context_error(client);
552     }
553 
554     return SendTypeE1Reply(client, ret);
555 }
556 
ir_delete_dic(clientp)557 ir_delete_dic(clientp)
558 ClientPtr *clientp ;
559 {
560     Req7 *req = &Request.Request7 ;
561     ClientPtr client = *clientp ;
562     char *dicname, *data ;
563     int cxnum, ret = -1;
564     Ushort cbuf[CBUFSIZE];
565 
566     cxnum = req->context;
567     if (chk_cxt(client, cxnum)) {
568 	dicname = req->dicname ;
569 	data = req->datainfo ;
570        ir_debug( Dmsg(5,"����̾=%s\n", dicname ); )
571        ir_debug( Dmsg(5,"�������ǡ���[%s]\n", data ); )
572 	euc2ushort( data, strlen( (char *)data ), cbuf, CBUFSIZE );
573 	ret = RkwDeleteDic( cxnum, (char *)dicname, (Ushort *)cbuf );
574     } else {
575 	print_context_error(client);
576     }
577 
578     return SendTypeE1Reply(client, ret);
579 }
580 
ir_get_dir_list(clientp)581 ir_get_dir_list(clientp)
582 ClientPtr *clientp ;
583 {
584     Req3 *req = &Request.Request3 ;
585     ClientPtr client = *clientp ;
586     char *dicnames = local_buffer ;
587     int cxnum, ret = -1, max;
588     int size = 0 ;
589 
590     cxnum = req->context;
591     if (chk_cxt(client, cxnum)) {
592 	max = MIN( req->number, LOCAL_BUFSIZE ) ;
593 
594 	ret = RkwGetDirList( cxnum, (char *)dicnames, max) ;
595 	if( ret >= 0 ) {
596 	   ir_debug( Dmsg(5,"����ꥹ��\n" ); )
597 	    size = listsize(dicnames, ret);
598 	}
599     } else {
600 	print_context_error(client);
601     }
602     return SendTypeE2Reply(client, ret, (ret < 0)? 0: ret, dicnames, size);
603 }
604 
ir_mount_dictionary(clientp)605 ir_mount_dictionary(clientp)
606 ClientPtr *clientp ;
607 {
608     Req8 *req = &Request.Request8 ;
609     ClientPtr client = *clientp ;
610     char *dicname ;
611     int cxnum, mode, ret = -1;
612     extern MMountFlag;
613 
614     cxnum = req->context;
615     if (chk_cxt(client, cxnum)) {
616 	mode = req->mode ;
617        ir_debug( Dmsg(5,"dicname = %s\n", req->data ); )
618 	dicname = req->data ;
619 	ret = RkwMountDic( cxnum, (char *)dicname, mode | MMountFlag) ;
620     } else {
621 	print_context_error(client);
622     }
623 
624     return SendTypeE1Reply(client, ret);
625 }
626 
ir_umount_dictionary(clientp)627 ir_umount_dictionary(clientp)
628 ClientPtr *clientp ;
629 {
630     Req8 *req = &Request.Request8 ;
631     ClientPtr client = *clientp ;
632     int cxnum, ret = -1;
633 
634     cxnum = req->context;
635     if (chk_cxt(client, cxnum)) {
636        ir_debug( Dmsg(5,"dicname = %s\n", req->data ); )
637 	ret = RkwUnmountDic( cxnum, (char *)req->data ) ;
638     } else {
639 	print_context_error(client);
640     }
641 
642     return SendTypeE1Reply(client, ret);
643 }
644 
ir_rmount_dictionary(clientp)645 ir_rmount_dictionary(clientp)
646 ClientPtr *clientp ;
647 {
648     Req9 *req = &Request.Request9  ;
649     ClientPtr client = *clientp ;
650     int cxnum, where ;
651     int ret = -1 ;
652 
653     cxnum = req->context;
654     if (chk_cxt(client, cxnum)) {
655 	where = req->number ;
656        ir_debug( Dmsg(5,"dicname = %s\n", req->data ); )
657 	ret = RkwRemountDic( cxnum, (char *)req->data, where ) ;
658     } else {
659 	print_context_error(client);
660     }
661 
662     return SendTypeE1Reply(client, ret);
663 }
664 
ir_mount_list(clientp)665 ir_mount_list( clientp )
666 ClientPtr *clientp ;
667 {
668     Req3 *req = &Request.Request3 ;
669     ClientPtr client = *clientp ;
670     char *dicnames = local_buffer ;
671     int cxnum, ret = -1, size = 0;
672 
673     cxnum = req->context;
674     if (chk_cxt(client, cxnum)) {
675 	ret = RkwGetMountList( cxnum, (char *)dicnames,
676 			      MIN( req->number, LOCAL_BUFSIZE ) ) ;
677 	if( ret < 0 ) {
678 	    ret = 0;
679 	} else {
680 	   ir_debug( Dmsg(5,"����ꥹ��\n" ); )
681 	    size = listsize(dicnames, ret);
682 	}
683     } else {
684 	print_context_error(client);
685     }
686 
687     return SendTypeE2Reply(client, ret, (ret < 0)? 0: ret, dicnames, size);
688 }
689 
ir_convert(clientp)690 ir_convert( clientp )
691 ClientPtr *clientp ;
692 {
693     Req8 *req = &Request.Request8 ;
694     ClientPtr client = *clientp ;
695     int cxnum, yomilen, ret, mode ;
696     int size = 0 ;
697     char *data, lbuf[SENDBUFSIZE], *datap = lbuf;
698     Ushort cbuf[CBUFSIZE];
699     int stat = -1, len;
700 
701     cxnum = req->context;
702     if (chk_cxt(client, cxnum)) {
703 	mode = req->mode ;
704 	yomilen = req->datalen ;
705 	data = req->data ;
706 	if( yomilen + 1 <= CHECK_ACK_BUF_SIZE )
707 	    data[ yomilen + 1 ] = '\0' ;
708        ir_debug( Dmsg(5,"�ɤ� = %s\n",data ); )
709 	len = euc2ushort( data, yomilen, cbuf, CBUFSIZE );
710 	if ((ret = RkwBgnBun( cxnum, (Ushort *)cbuf, len, mode )) >= 0) {
711 	    /* ��ͥ�����ꥹ�Ȥ�������� */
712 	    size = getFirstKouho(cxnum, 0, ret, &stat, (BYTE **)&datap);
713 	} else {
714 	    PrintMsg( "%s kana-kanji convert failed\n",
715 		    irerrhdr(client));
716 	    *datap = '\0' ;
717 	}
718     } else {
719 	print_context_error(client);
720 	*datap = (char)0 ;
721     }
722     ret = SendTypeE2Reply(client, stat, (stat < 0)? 0: stat, datap, size);
723     if (datap != lbuf) free((char *)datap);
724     return ret;
725 }
726 
ir_convert_end(clientp)727 ir_convert_end( clientp )
728 ClientPtr *clientp ;
729 {
730     Req4 *req = &Request.Request4 ;
731     ClientPtr client = *clientp ;
732     int cxnum, len, i, mode, ret = -1;
733 
734     cxnum = req->context;
735     if (chk_cxt(client, cxnum)) {
736 	len = req->number ;
737 	if( len ) {
738 	    mode = 1 ;
739 	    if( RkwGoTo( cxnum, 0 ) != 0 ) {
740 		PrintMsg("%s ir_convert_end: RkwGoTo failed\n",
741 			irerrhdr(client));
742 	    }
743 	   ir_debug( Dmsg( 5,"�ؽ����������\n" ); )
744 	    /* �����ȸ������Ƭ�˰�ư���饤����Ȥ����������� */
745 	    /* �ңˤ��Τ餻�� */
746 	    for( i = 0; i < len; i++ ){
747 		if( req->kouho[ i ] != RkwXfer( cxnum, req->kouho [ i ] ) ) {
748 		    PrintMsg("%s ir_convert_end: RkwXfer failed\n",
749 			    irerrhdr(client));
750 		}
751 	       ir_debug( DebugDispKanji( cxnum, i ); )
752 		if( RkwRight( cxnum ) == 0 && i != (len - 1) ) {
753 		    PrintMsg("%s ir_convert_end: RkwRight failed\n",
754 			    irerrhdr(client));
755 		}
756 	    }
757 	   ir_debug( Dmsg( 5,"\n" ); )
758 	} else {
759 	    mode = 0 ;
760 	}
761 	ret = RkwEndBun( cxnum, mode ) ;
762     } else {
763 	print_context_error(client);
764     }
765 
766     return SendTypeE1Reply(client, ret);
767 }
768 
ir_get_kanjilist(clientp)769 ir_get_kanjilist( clientp )
770 ClientPtr *clientp ;
771 {
772     Req5 *req = &Request.Request5 ;
773     ClientPtr client = *clientp ;
774     char *kouho = local_buffer ;
775     char *yomi, *data ;
776     int ret = -1, size = 0, cxnum, len	;
777     int bunsetuno, maxkanji ;
778     Ushort cbuf[CBIGBUFSIZE], *cbufp;
779     register int clen, i;
780     char workbuf[CBUFSIZE];
781 
782     cxnum = req->context;
783     if (chk_cxt(client, cxnum)) {
784 	bunsetuno = req->number ;
785 	maxkanji = MIN( req->datalen, LOCAL_BUFSIZE ) ;
786        ir_debug( Dmsg(5,"maxkanji [ %d ]\n", maxkanji ); )
787 	if( RkwGoTo(cxnum, bunsetuno) == bunsetuno ) {
788 	    ret = RkwGetKanjiList( cxnum, (Ushort *)cbuf, CBIGBUFSIZE );
789 	    cbufp = cbuf;
790 	    for( i = 0; i < ret; i++ )
791 		cbufp += ushortstrlen( cbufp ) + 1;
792 	    len = ushort2euc( cbuf, cbufp - cbuf, kouho, maxkanji );
793 	    clen = RkwGetYomi( cxnum, (Ushort *)cbuf, CBIGBUFSIZE );
794 	    clen = ushort2euc( cbuf, clen, workbuf, CBUFSIZE ) + 1;
795 	    maxkanji = MIN(len, (maxkanji - clen));
796 	    data = kouho;
797 	    for( i = ret = 0; i < maxkanji; i++ ){
798 		if( !(*data++) ){
799 		    ret++;
800 		}
801 	    }
802 	    yomi = kouho;
803 	    if( ret ) {
804 	       ir_debug( Dmsg(5,"����ꥹ��\n" ); )
805 		size = listsize( kouho, ret );
806 		yomi += size;
807 	    } else {
808 		*yomi = '\0'; yomi++;
809 	    }
810 	    /* �ɤߤ�Ǹ�ˤĤ���*/
811 	    strcpy( (char *)yomi, (char *)workbuf );
812 	    size += clen;
813 	} else {
814 	    PrintMsg("%s bunsetu move failed\n", irerrhdr(client));
815        }
816     } else {
817 	print_context_error(client);
818     }
819     return SendTypeE2Reply(client, ret, (ret < 0)? 0: (ret + 1), kouho, size);
820 }
821 
ir_resize(clientp)822 ir_resize(clientp)
823 ClientPtr *clientp ;
824 {
825 #define ENLARGE -1
826 #define SHORTEN -2
827     Req5 *req = &Request.Request5 ;
828     ClientPtr client = *clientp ;
829     int ret, cxnum, yomilen, bunsetu ;
830     int size = 0 ;
831     BYTE lbuf[SENDBUFSIZE], *lbufp = lbuf;
832     int stat = 0;
833 
834     cxnum = req->context;
835     if (chk_cxt(client, cxnum)) {
836 	bunsetu = req->number ;
837 	yomilen = req->datalen ;
838 
839 	RkwGoTo(cxnum, bunsetu) ;
840        ir_debug( Dmsg(5,"yomilen = %d\n",yomilen ); )
841        ir_debug( Dmsg(5,"bunsetu = %d\n",bunsetu ); )
842 	switch( yomilen ) {
843 	    case ENLARGE :
844 		ret = RkwEnlarge( cxnum ) ;
845 		break ;
846 	    case SHORTEN :
847 		ret = RkwShorten( cxnum ) ;
848 		break ;
849 	    default :
850 		ret = RkeResize( cxnum, yomilen );
851 		break ;
852 	    }
853 	/* ��ͥ�����ꥹ�Ȥ�������� */
854 	size = getFirstKouho(cxnum, bunsetu, ret, &stat, &lbufp);
855     } else {
856 	print_context_error(client);
857     }
858     ret = SendTypeE2Reply(client, stat, (stat < 0)? 0: stat - bunsetu,
859 			  (char *)lbufp, size);
860     if (lbufp != lbuf) free((char *)lbufp);
861     return ret;
862 }
863 
ir_store_yomi(clientp)864 ir_store_yomi( clientp )
865 ClientPtr *clientp ;
866 {
867     Req9 *req = &Request.Request9 ;
868     ClientPtr client = *clientp ;
869     int cxnum, bunsetu, len, ret ;
870     int size = 0 ;
871     char *data ;
872     Ushort cbuf[CBUFSIZE];
873     BYTE lbuf[SENDBUFSIZE], *lbufp = lbuf;
874     int stat = 0;
875 
876     cxnum = req->context;
877     if (chk_cxt(client, cxnum)) {
878 	bunsetu = req->number ;
879 	len = req->datalen ;
880 
881 	RkwGoTo( cxnum, bunsetu ) ;
882 
883 	data = req->data ;
884 	data[ len + 1 ] = '\0' ;
885        ir_debug( Dmsg(5,"�ɤ� = %s\n",data ); )
886 	ret = euc2ushort( data, len, cbuf, CBUFSIZE );
887 	if ((ret = RkwStoreYomi( cxnum, (Ushort *)cbuf, ret )) >= 0) {
888 	    size = getFirstKouho(cxnum, bunsetu, ret, &stat, &lbufp);
889 	} else {
890 	    PrintMsg("%s RkwStoreYomi faild\n", irerrhdr(client));
891 	}
892     } else {
893 	print_context_error(client);
894     }
895     ret = SendTypeE2Reply(client, stat, (stat < 0)? 0: stat,
896 			  (char *)lbufp, size);
897     if (lbufp != lbuf) free((char *)lbufp);
898     return ret;
899 }
900 
ir_query_extension(clientp)901 ir_query_extension( clientp )
902 ClientPtr *clientp ;
903 {
904     Req12 *req = &Request.Request12 ;
905     ClientPtr client = *clientp ;
906     int i = 0 ;
907     int status = -1 ;
908 
909     while( strlen( ExtensionName[ i ][ 0 ] ) ) {
910 	if( !strcmp( ExtensionName[ i ][ 0 ], (char *)req->data ) ) {
911 	    status = atoi( ExtensionName[ i ][ 1 ] ) ;
912 	    break ;
913 	}
914 	i++ ;
915     }
916 
917     return SendTypeE1Reply(client, status);
918 }
919 
920 static void iroha2canna pro((char *));
921 
922 #ifdef EXTENSION
ir_list_dictionary(clientp)923 ir_list_dictionary( clientp )
924 ClientPtr *clientp ;
925 {
926     Req9 *req = &Request.Request9 ;
927     ClientPtr client = *clientp ;
928     char *dicnames = local_buffer ;
929     char *dirname, *dirnamelong;
930     int cxnum, size = 0, ret = -1;
931 
932     cxnum = req->context;
933     if (chk_cxt(client, cxnum)) {
934 	size = MIN( req->number, LOCAL_BUFSIZE ) ;
935 	dirname = (char *)req->data;
936 	iroha2canna( dirname );
937 	dirnamelong = insertUserSla(dirname, strlen(dirname));
938 	if (dirnamelong) {
939 	  if (checkPermissionToRead(client, dirnamelong, (char *)0) >= 0) {
940 	    ret = RkwListDic(cxnum, (unsigned char *)dirnamelong,
941 			     (unsigned char *)dicnames, size);
942 	  }
943 	  free(dirnamelong);
944 	}
945 	/* else ERROR because ret == -1 */
946 	if( ret < 0 ) {
947 	    size = 0;
948 	} else {
949 	   ir_debug( Dmsg(5,"����ꥹ��\n" ); )
950 	    size = listsize(dicnames, ret);
951 	}
952     } else {
953 	PrintMsg( "[%s@%s](%s) Context Err\n", client->username, client->hostname, ProtoName[ req->Type - 1 ]	) ;
954     }
955 
956     return SendTypeE2Reply(client, ret, (ret < 0)? 0: ret, dicnames, size);
957 }
958 
959 
ir_create_dictionary(clientp)960 ir_create_dictionary( clientp )
961 ClientPtr *clientp ;
962 {
963     Req8 *req = &Request.Request8 ;
964     ClientPtr client = *clientp ;
965     int cxnum, ret = -1;
966 
967     cxnum = req->context;
968     if (chk_cxt(client, cxnum)) {
969        ir_debug( Dmsg(5,"dicname = %s\n", req->data ); )
970 	ret = RkwCreateDic(cxnum, (unsigned char *)req->data, req->mode);
971     } else {
972 	print_context_error(client);
973     }
974 
975     return SendTypeE1Reply(client, ret);
976 }
977 
978 
ir_remove_dictionary(clientp)979 ir_remove_dictionary( clientp )
980 ClientPtr *clientp ;
981 {
982     Req8 *req = &Request.Request8 ;
983     ClientPtr client = *clientp ;
984     int cxnum, ret = -1;
985 
986     cxnum = req->context;
987     if (chk_cxt(client, cxnum)) {
988        ir_debug( Dmsg(5,"dicname = %s\n", req->data ); )
989 	ret = RkwRemoveDic(cxnum, (unsigned char *)req->data, 0);
990     } else {
991 	print_context_error(client);
992     }
993 
994     return SendTypeE1Reply(client, ret);
995 }
996 
ir_rename_dictionary(clientp)997 ir_rename_dictionary( clientp )
998 ClientPtr *clientp ;
999 {
1000     Req10 *req = &Request.Request10 ;
1001     ClientPtr client = *clientp ;
1002     int cxnum ;
1003     int ret = -1 ;
1004 
1005     cxnum = req->context;
1006     if (chk_cxt(client, cxnum)) {
1007       ret = RkwRenameDic(cxnum, (unsigned char *)req->dicname,
1008 			 (unsigned char *)req->textdicname, req->mode);
1009     } else {
1010 	print_context_error(client);
1011     }
1012 
1013     return SendTypeE1Reply(client, ret);
1014 }
1015 
ir_get_word_text_dic(clientp)1016 ir_get_word_text_dic( clientp )
1017 ClientPtr *clientp ;
1018 {
1019     Req10 *req = &Request.Request10 ;
1020     ClientPtr client = *clientp ;
1021     BYTE *infobuf = (BYTE *)local_buffer ;
1022     char *dicname, *dirname, *dirnamelong;
1023     int cxnum, infosize, ret = -1, cnt = 0, size = SIZEOFLONG;
1024     Ushort cbuf[CBUFSIZE];
1025 
1026     cxnum = req->context;
1027     if (chk_cxt(client, cxnum)) {
1028 	dirname = (req->diclen ? (char *)req->dicname : (char *)NULL);
1029 	iroha2canna( dirname );
1030 	infosize = MIN( req->mode, MAXDATA ) ;
1031 	dicname = (char *)req->textdicname;
1032 	if (dirname && dirname[0]) {
1033 	  dirnamelong = insertUserSla(dirname, strlen(dirname));
1034 	  if (dirnamelong) {
1035 	    if (checkPermissionToRead(client, dirnamelong, dicname) >= 0) {
1036 	      ret = RkwGetWordTextDic(cxnum, (unsigned char *)dirnamelong,
1037 				      (unsigned char *)dicname,
1038 				      (Ushort *)cbuf, CBIGBUFSIZE);
1039 	    }
1040 	    free(dirnamelong);
1041 	  }
1042 	}
1043 	else {
1044 	  ret = RkwGetWordTextDic(cxnum, (unsigned char *)dirname,
1045 				  (unsigned char *)dicname,
1046 				  (Ushort *)cbuf, CBIGBUFSIZE);
1047 	}
1048 	if (ret > 0) {
1049 	  ret = ushort2euc( cbuf, ret, (char *)infobuf, infosize );
1050 	}
1051 	if( ret > 0 ) {
1052 	    cnt = ret + 1 ;
1053 	    size = cnt + SIZEOFLONG;
1054 	}
1055     } else {
1056 	print_context_error(client);
1057     }
1058     return SendTypeE4Reply(client, ret, cnt, infobuf, size);
1059 }
1060 #endif /* EXTENSION */
1061 
1062 static int
storeStat(client,ret,src,dest)1063 storeStat(client, ret, src, dest)
1064 ClientPtr client;
1065 int ret;
1066 BYTE *src, *dest;
1067 {
1068     if( ret >= 0 ) {
1069 	RkStat *stat = (RkStat *)src;
1070 	BYTE *bufp = dest;
1071 
1072 	LTOL4(stat->bunnum, dest);	/* bunsetsu bangou */
1073 	dest += SIZEOFLONG;
1074 	LTOL4(stat->candnum, dest);	/* kouho bangou */
1075 	dest += SIZEOFLONG;
1076 	LTOL4(stat->maxcand, dest);	/* sou kouho suu */
1077 	dest += SIZEOFLONG;
1078 	LTOL4(stat->diccand, dest);	/* jisho ni aru kouho suu */
1079 	dest += SIZEOFLONG;
1080 	LTOL4(stat->ylen, dest);	/* yomigana no nagasa (in byte) */
1081 	dest += SIZEOFLONG;
1082 	LTOL4(stat->klen, dest);	/* kanji no nagasa (in byte) */
1083 	dest += SIZEOFLONG;
1084 	LTOL4(stat->tlen, dest);	/* tango no kosuu */
1085 
1086 	if( !client->version_lo ) {	      /* client version �� �� �Τ� */
1087 	    register int *p = (int *)bufp;
1088 	    register int tmp1 = p[ 2 ];
1089 	    register int tmp2 = p[ 3 ] ;
1090 	    int i ;
1091 
1092 	    for( i = 2; i < 5; i++ )
1093 		p[ i ] = p[ i + 2 ] ;
1094 	    p[ 5 ] = tmp1 ;
1095 	    p[ 6 ] = tmp2 ;
1096 	}
1097     }
1098     return ret;
1099 }
1100 
ir_get_stat(clientp)1101 ir_get_stat( clientp )
1102 ClientPtr *clientp ;
1103 {
1104     Req5 *req = &Request.Request5 ;
1105     ClientPtr client = *clientp ;
1106     int cxnum, kouho, bunsetu, ret = -1;
1107     int size = 0 ;
1108     RkStat stat ;
1109 
1110     cxnum = req->context;
1111     if (chk_cxt(client, cxnum)) {
1112 	bunsetu = req->number ;
1113 	kouho = req->datalen ;
1114 
1115 	RkwGoTo( cxnum, bunsetu ) ;
1116 	RkwXfer( cxnum, kouho ) ;
1117 
1118 	ret = RkeGetStat( cxnum, &stat );
1119 	size = SIZEOFLONG * 7;
1120 
1121     } else {
1122 	print_context_error(client);
1123     }
1124     return SendTypeE3Reply(client, ret, storeStat, (BYTE *)&stat, size);
1125 }
1126 
1127 static int
storeLex(client,tangosu,src,dest)1128 storeLex(client, tangosu, src, dest)
1129 ClientPtr client; /* ARGSUSED */
1130 int tangosu;
1131 BYTE *src, *dest;
1132 {
1133     if( tangosu >= 0 ) {
1134 	register int i;
1135 	RkLex *lex = (RkLex *)src;
1136 
1137 	for (i = 0; i < tangosu; i++, lex++) {
1138 	    LTOL4(lex->ylen, dest);	/* yomigana no nagasa (in byte) */
1139 	    dest += SIZEOFLONG;
1140 	    LTOL4(lex->klen, dest);	/* kanji no nagasa (in byte) */
1141 	    dest += SIZEOFLONG;
1142 	    LTOL4(lex->rownum, dest);	/* row number */
1143 	    dest += SIZEOFLONG;
1144 	    LTOL4(lex->colnum, dest);	/* column number */
1145 	    dest += SIZEOFLONG;
1146 	    LTOL4(lex->dicnum, dest);	/* dic number */
1147 	    dest += SIZEOFLONG;
1148 	}
1149     }
1150     return tangosu;
1151 }
1152 
ir_get_lex(clientp)1153 ir_get_lex( clientp )
1154 ClientPtr *clientp ;
1155 {
1156     Req11 *req = &Request.Request11 ;
1157     ClientPtr client = *clientp ;
1158     RkLex *lex = (RkLex *)local_buffer ;
1159     int     cxnum ;
1160     int     size = 0 ;
1161     int tangosu = -1;
1162 
1163     cxnum = req->context;
1164     if (chk_cxt(client, cxnum)) {
1165 
1166 	RkwGoTo( cxnum, req->number ) ;
1167 	RkwXfer( cxnum, req->kouho ) ;
1168 
1169 	tangosu = RkeGetLex( cxnum, lex, MIN( req->max, LOCAL_BUFSIZE/sizeof( RkLex ) )	);
1170 	size = tangosu * SIZEOFLONG * 5;
1171 
1172     } else {
1173 	print_context_error(client);
1174     }
1175 
1176     return SendTypeE3Reply(client, tangosu, storeLex, (BYTE *)lex, size);
1177 }
1178 
1179 #ifdef DEBUG
1180 void
DispDebug(client)1181 DispDebug( client )
1182 ClientPtr client ;
1183 {
1184     char    return_date[DATE_LENGH] ;
1185     long    wtime = (long)client->used_time ;
1186     char    buf[10] ;
1187 
1188     (void)ClientStat( client, GETDATE, 0, return_date ) ;
1189     Dmsg(5,"�桼��̾         :%s\n", client->username ) ;
1190     Dmsg(5,"���ͥ��Ȥ������� :%s\n", return_date ) ;
1191     Dmsg(5,"�ۥ���̾         :%s\n", client->hostname ) ;
1192     sprintf( buf,"%02ld:%02ld:%02ld", wtime/3600, (wtime%3600)/60, (wtime%3600)%60 ) ;
1193     Dmsg(5,"�桼���������   :%s\n\n", buf ) ;
1194 }
1195 #endif
1196 
1197 static int
SetServerVersion(buf)1198 SetServerVersion( buf )
1199 char *buf ;
1200 {
1201   char tmpstr[14]; /* 14 is enough */
1202   int SendSize;
1203 
1204   sprintf(tmpstr, "%d.%d", CANNA_MAJOR_MINOR / 1000, CANNA_MAJOR_MINOR % 1000);
1205   SendSize = strlen(tmpstr) + 1;
1206 
1207   LTOL4(SendSize, buf) ; buf += SIZEOFLONG;
1208   /* �����ФΥС��������åȤ��� */
1209   bcopy(tmpstr, buf, SendSize);
1210   return SendSize + SIZEOFLONG;
1211 }
1212 
1213 int
ir_server_stat2(client_buf)1214 ir_server_stat2( client_buf )
1215 ClientBuf *client_buf ;
1216 {
1217     char *sendp = Acknowledge.SendAckBuffer ;
1218     char *savep ;
1219     register ClientPtr	    who ;
1220     ClientPtr *OutPut;
1221     int     RequestCount[ MAXREQUESTNO ] ;
1222     int     i, j, len, retval, max_cx, n;
1223     size_t count;
1224 
1225     OutPut = get_all_other_clients(NULL, &count);
1226 
1227     /* �ץ�ȥ���С�������å� */
1228     sendp += SetServerVersion( sendp ) ;
1229 
1230     /* ���߻��糧�å� */
1231     LTOL4( time( NULL ), sendp ) ; sendp += SIZEOFLONG ;
1232 
1233     /* �ץ�ȥ�������å� */
1234     LTOL4( REALREQUEST, sendp ) ; sendp += SIZEOFLONG ;
1235 
1236     /* �ץ�ȥ���̾�ꥹ�Ⱥ��� */
1237     savep = sendp ; sendp += SIZEOFLONG ;
1238     for( i = 1; i < MAXREQUESTNO; i++ ) {
1239 	RequestCount[ i - 1 ] = htonl( TotalRequestTypeCount[ i ] ) ;
1240 	strcpy( (char *)sendp, ProtoName[ i - 1 ] ) ;
1241 	sendp += (strlen( ProtoName[ i - 1 ] ) + 1 ) ;
1242     }
1243 
1244     /* �ץ�ȥ���̾�ꥹ��Ĺ���å� */
1245     LTOL4( sendp - ( savep + SIZEOFLONG ), savep ) ;
1246 
1247     /* �ץ�ȥ���������٥��å� */
1248     bcopy( RequestCount, sendp, REALREQUEST * SIZEOFLONG ) ;
1249     sendp += ( REALREQUEST * SIZEOFLONG ) ;
1250 
1251     /* ��³���Ƥ��륯�饤����ȿ����å� */
1252     LTOL4( count, sendp ) ; sendp += SIZEOFLONG ;
1253 
1254     /* ����ƥ����ȿ����å� */
1255     max_cx = 0;
1256     for (i = 0 ; i < count ; i++) {
1257       int *contexts;
1258 
1259       who = OutPut[i];
1260       contexts = who->context_flag;
1261       for (j = 0, n = who->ncon ; j < n ; j++) {
1262 	if (max_cx < contexts[j]) {
1263 	  max_cx = contexts[j];
1264 	}
1265       }
1266     }
1267     max_cx += (max_cx % SIZEOFSHORT); /* ????? */
1268 
1269     LTOL4(max_cx, sendp ) ; sendp += SIZEOFLONG ;
1270 
1271     if( SendTypeE6Reply(client_buf, sendp - Acknowledge.SendAckBuffer) < 0 ) {
1272       retval = -1;
1273       goto stat2done;
1274     }
1275 
1276     /* �ƥ��饤����Ⱦ�����å� */
1277     for( i = 0; i < count; i ++ ) {
1278 	int id;
1279 	savep = sendp = Acknowledge.SendAckBuffer ;
1280 	who = OutPut[ i ] ;
1281 	sendp += SIZEOFLONG ;
1282 
1283 	id = ClientBuf_getfd(who->client_buf);
1284 	LTOL4( id, sendp ) ; sendp += SIZEOFLONG ;
1285 	LTOL4( who->usr_no, sendp ) ; sendp += SIZEOFLONG ;
1286 	LTOL4( who->used_time, sendp ) ; sendp += SIZEOFLONG ;
1287 	LTOL4( who->idle_date, sendp ) ; sendp += SIZEOFLONG ;
1288 	LTOL4( who->connect_date, sendp ) ; sendp += SIZEOFLONG ;
1289 
1290 	/* �ץ�ȥ���������پ����å� */
1291 	for( j = 1; j < MAXREQUESTNO; j++ ) {
1292 	    LTOL4( who->pcount[ j ], sendp ) ; sendp += SIZEOFLONG ;
1293 	}
1294 
1295 	/* �桼��̾���å� */
1296 	if (!who->username) {
1297 	    len = 1;
1298 	    LTOL4( len, sendp ) ; sendp += SIZEOFLONG ;
1299 	    bzero( sendp, len ) ; sendp += len ;
1300 	} else {
1301 	    len = strlen( who->username ) + 1 ;
1302 	    LTOL4( len, sendp ) ; sendp += SIZEOFLONG ;
1303 	    bcopy( who->username, sendp, len ) ; sendp += len ;
1304 	};
1305 
1306 	/* �ۥ���̾���å� */
1307 	if (!who->hostname) {
1308 	    len = 1 ;
1309 	    LTOL4( len, sendp ) ; sendp += SIZEOFLONG ;
1310 	    bzero( sendp, len ) ; sendp += len ;
1311 	} else {
1312 	    len = strlen( who->hostname ) + 1 ;
1313 	    LTOL4( len, sendp ) ; sendp += SIZEOFLONG ;
1314 	    bcopy( who->hostname, sendp, len ) ; sendp += len ;
1315 	};
1316 
1317 	/* ����ƥ����ȴ����ե饰���å� */
1318 	bzero(sendp, max_cx);
1319 	for (j = 0 ; j < who->ncon ; j++) {
1320 	  sendp[who->context_flag[j]] = 1;
1321 	}
1322 	sendp += max_cx;
1323 
1324 	/* ���饤����ȴ�������ꥹ��Ĺ���å� */
1325 	LTOL4( sendp - (savep + SIZEOFLONG), savep ) ;
1326 
1327 	if( SendTypeE6Reply(client_buf, sendp - savep) < 0 ) {
1328 	  retval = -1;
1329 	  goto stat2done;
1330 	}
1331 
1332 	who ++ ;
1333     }
1334 
1335     EventMgr_finalize_notify(global_event_mgr, client_buf);
1336     retval = 1;
1337   stat2done:
1338     if (OutPut) {
1339       free((char *)OutPut);
1340     }
1341     return retval;
1342 }
1343 
1344 int
ir_server_stat(client_buf)1345 ir_server_stat( client_buf )
1346 ClientBuf *client_buf ;
1347 {
1348     char *sendp = Acknowledge.SendAckBuffer ;
1349     register ClientPtr	    who ;
1350     register ClientStatPtr  Wp ;
1351     ClientPtr		    *OutPut;
1352     ClientStatRec	    *Sstat;
1353     int 		    i, j, InfoSize, SendSize, retval;
1354     int 		    RequestCount[ OLD_MAXREQUESTNO ] ;
1355     size_t		    count;
1356 
1357     OutPut = get_all_other_clients(NULL, &count);
1358     Sstat = (ClientStatRec *)malloc(count * sizeof(ClientStatRec));
1359 
1360     if (!OutPut || !Sstat)
1361 	count = 0; /* ñ�˥��顼�ˤ��٤��Ǥ�? */
1362 
1363     InfoSize = sizeof( ClientStatRec )*count ;
1364 
1365     Wp = Sstat ;
1366     for( i = 0 ; i < count; i++ ) {
1367         int id;
1368 	who = OutPut[ i ] ;
1369        ir_debug( DispDebug( who ); )
1370         id = ClientBuf_getfd(who->client_buf);
1371 	Wp->id = htonl( id ) ;
1372 	Wp->usr_no = htonl( who->usr_no ) ;
1373 	Wp->used_time = htonl( who->used_time ) ;
1374 	Wp->idle_date = htonl( who->idle_date ) ;
1375 	Wp->connect_date = htonl( who->connect_date ) ;
1376 	for( j = 0; j < OLD_MAXREQUESTNO; j++ )
1377 	    Wp->pcount[ j ] = htonl( who->pcount[ j ] ) ;
1378 	strncpy( Wp->username, who->username, 10 ) ;
1379 	strncpy( Wp->hostname, who->hostname, 15 ) ;
1380 	bzero(Wp->context_flag, OLD_MAX_CX);
1381 	for (j = 0 ; j < who->ncon ; j++) {
1382 	  int inde = who->context_flag[j];
1383 	  if (inde < OLD_MAX_CX) {
1384 	    Wp->context_flag[inde] = 1;
1385 	  }
1386 	}
1387 	Wp ++ ;
1388     }
1389 
1390     /* �����ФΥС����������Τ��� */
1391     sendp += SetServerVersion( sendp ) ;
1392 
1393     /* �����Ф�Ω���夬�äƤ������ץ�ȥ��� */
1394     for( i = 0; i < OLD_MAXREQUESTNO; i++ )
1395 	RequestCount[ i ] = htonl( TotalRequestTypeCount[ i ] ) ;
1396 
1397     SendSize = SIZEOFLONG * OLD_MAXREQUESTNO ;
1398     LTOL4( SendSize, sendp ) ; sendp += SIZEOFLONG ;
1399     bcopy( RequestCount, sendp, SendSize ) ; sendp += SendSize ;
1400 
1401     /* ��������륯�饤����ȿ������Τ��� */
1402     LTOL4( count, sendp ) ; sendp += SIZEOFLONG ;
1403 
1404     /* �����Фθ��ߤλ�������Τ��� */
1405     LTOL4( time( NULL ), sendp ) ; sendp += SIZEOFLONG ;
1406 
1407     /* �ºݤ˥��饤����Ⱦ�������Τ��� */
1408     if (Sstat) { /* ���� */
1409       bcopy( Sstat, sendp, InfoSize ) ; sendp += InfoSize ;
1410     }
1411 
1412     if( SendTypeE5Reply(client_buf, sendp - Acknowledge.SendAckBuffer) < 0 ) {
1413       retval = -1;
1414       goto statdone;
1415     }
1416 
1417     EventMgr_finalize_notify(global_event_mgr, client_buf);
1418     retval = 1;
1419   statdone:
1420     if (OutPut) {
1421       free((char *)OutPut);
1422     }
1423     if (Sstat) {
1424       free((char *)Sstat);
1425     }
1426     return retval;
1427 }
1428 
ir_host_ctl(clientp)1429 ir_host_ctl( clientp )
1430 ClientPtr *clientp ;
1431 {
1432     ClientPtr client = *clientp ;
1433     char *sendp = Acknowledge.SendAckBuffer ;
1434     char *savep = Acknowledge.SendAckBuffer + SIZEOFLONG ;
1435     char *namep ;
1436     ACLPtr wp ;
1437     int cnt, i ;
1438 
1439     LTOL4( NumberAccessControlList(), sendp ) ; sendp += (SIZEOFLONG * 2) ;
1440 
1441     for( wp = ACLHead; wp != (ACLPtr)NULL; wp = wp->next ) {
1442 	cnt = strlen( (char *)wp->hostname ) + 1 ;
1443 	LTOL4( cnt, sendp ) ; sendp += SIZEOFLONG ;
1444 	strcpy( (char *)sendp, (char *)wp->hostname ) ;
1445 	sendp += cnt ;
1446 	LTOL4( wp->usercnt, sendp ) ; sendp += SIZEOFLONG ;
1447 	for( i = 0, namep = wp->usernames; i < wp->usercnt; i++ ) {
1448 	    cnt = strlen( (char *)namep ) + 1 ;
1449 	    LTOL4( cnt, sendp ) ; sendp += SIZEOFLONG ;
1450 	    strcpy( (char *)sendp, (char *)namep ) ;
1451 	    sendp += cnt ;
1452 	    namep += cnt ;
1453 	}
1454     }
1455     LTOL4( sendp - (savep + SIZEOFLONG), savep ) ;
1456     if( SendTypeE7Reply(client, sendp - Acknowledge.SendAckBuffer) < 0 )
1457 	return( -1 ) ;
1458 
1459     close_session(clientp, 1);
1460     return( 1 ) ;
1461 }
1462 
1463 #endif /* USE_EUC_PROTOCOL */
1464 
1465 int
ir_nosession(clientp,client_buf)1466 ir_nosession(clientp, client_buf)
1467 ClientPtr *clientp;
1468 ClientBuf *client_buf;
1469 {
1470     int proto = Request.Request2.Type, r;
1471 
1472     switch (proto) {
1473 	case IR_INIT:
1474 	    r = ir_initialize(clientp, client_buf);
1475 	    break;
1476 #ifdef USE_EUC_PROTOCOL
1477 	case IR_SER_STAT:
1478 	     r = ir_server_stat(client_buf);
1479 	    break;
1480 	case IR_SER_STAT2:
1481 	     r = ir_server_stat2(client_buf);
1482 	    break;
1483 #endif
1484 	default:
1485 	    r = ir_error(clientp);
1486 	    break;
1487     };
1488     return r;
1489 }
1490 
1491 /*
1492  * ��Ȥ��io.c�����줤�Ƥ�����Τ������鲼���֤�
1493  */
1494 
1495 #define SIZE4	4
1496 #define SIZE8	8
1497 #define SIZE12	12
1498 #define SIZE16	16
1499 #define SIZE20	20
1500 
1501 int
parse_euc_request(request,data,len,username,hostname)1502 parse_euc_request(request, data, len, username, hostname)
1503 int *request;
1504 BYTE *data;
1505 size_t len;
1506 const char *username;
1507 const char *hostname;
1508 {
1509     int (*ReqCallFunc) pro((char *, int)) ;
1510     register Req0 *req0 = &Request.Request0 ;
1511     const char *username0 = username ? username : "";
1512     const char *hostname0 = hostname ? hostname : "";
1513     int needsize;
1514 
1515     ir_debug(Dmsg(5, "EUC�ץ�ȥ���Υꥯ�����Ȥ����, Ĺ��=%d\n", len));
1516     if (len < 4)
1517 	return 4 - len;
1518 
1519     req0->Type = (int)L4TOL(data);
1520     ir_debug( Dmsg(10, "NewReadRequest:") );
1521     ir_debug( DebugDump( 10, (char *)data, len ) );
1522     ir_debug(Dmsg(5,"Client: <%s@%s> [%d]\n",
1523 		   username0, hostname0, req0->Type ));
1524 
1525     if( (0 > req0->Type) ||
1526 #ifdef EXTENSION
1527        ( (req0->Type > REALREQUEST) && (req0->Type < EXTBASEPROTONO) ) ||
1528 	    (req0->Type > (MAXEXTREQUESTNO+EXTBASEPROTONO))
1529 #else
1530        (req0->Type > REALREQUEST)
1531 #endif
1532 	    ) {
1533 	if (username) {
1534 	    PrintMsg( "[%s] ", username  ) ;
1535 	}
1536 	PrintMsg( "Request error[ %d ]\n", req0->Type ) ;
1537 	return -1;
1538     }
1539 
1540 #ifdef EXTENSION
1541     /* �ץ�ȥ���Υ�������˥ǡ�����Ƥ�Ǥ���ؿ���Ƥ� */
1542     if( req0->Type >= EXTBASEPROTONO ) {
1543 	int xrequest = req0->Type - EXTBASEPROTONO ;
1544 	ReqCallFunc = ExtensionVector[ xrequest ].extdat;
1545 	CallFunc = ExtensionVector[ xrequest ].func;
1546     }
1547     else
1548 #endif /* EXTENSION */
1549     {
1550        ir_debug( Dmsg( 8,"Now Call %s\n", DebugProc[ req0->Type ][ 1 ] ); )
1551 	ReqCallFunc = Vector[ req0->Type ].extdat;
1552 	CallFunc = Vector[ req0->Type ].func;
1553     }
1554     if( (needsize = (* ReqCallFunc)( data, len ))  < 0 ) {
1555 	if (username) {
1556 	    PrintMsg( "[%s] ", username  ) ;
1557 	}
1558 	PrintMsg( "Read Data failed\n") ;
1559 	return -1;
1560     } else if (needsize > 0) {
1561 	return needsize;
1562     }
1563 
1564     /* �ץ�ȥ���μ���������פ��� */
1565 #ifdef EXTENSION
1566     if( req0->Type < MAXREQUESTNO )
1567 #endif
1568 	TotalRequestTypeCount[ req0->Type ] ++ ;
1569 
1570     *request = req0->Type;
1571 #ifdef DEBUG
1572 # ifdef EXTENSION
1573     if (req0->Type >= EXTBASEPROTONO)
1574 	CallFuncName = "(extension)";
1575     else
1576 # endif
1577 	CallFuncName = DebugProc[req0->Type][0];
1578 #endif
1579     return 0;
1580 }
1581 
1582 static int
ProcReq0(buf,size)1583 ProcReq0( buf, size )
1584 char *buf ;
1585 int size ;
1586 /* ARGSUSED */
1587 {
1588     return( 0 ) ;
1589 }
1590 
1591 #ifdef USE_EUC_PROTOCOL
1592 
ProcReq1(buf,size)1593 ProcReq1( buf, size )
1594 char *buf ;
1595 int size ;
1596 {
1597     register Req1 *req = &Request.Request1  ;
1598 
1599     if( size < SIZE8 )
1600 	return( SIZE8 - size ) ;
1601 
1602     req->context = (int)L4TOL(buf + SIZE4);
1603    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1604     return( 0 ) ;
1605 }
1606 
1607 #endif /* USE_EUC_PROTOCOL */
1608 
ProcReq2(buf,size)1609 ProcReq2( buf, size )
1610 char *buf ;
1611 int size ;
1612 {
1613     register Req2 *req = &Request.Request2 ;
1614     int needsize ;
1615 
1616    ir_debug( Dmsg(10,"ProcReq start!!\n" ); )
1617     if( (needsize = SIZE8 - size) > 0 )
1618 	return( needsize ) ;
1619 
1620     req->namelen = (int)L4TOL(buf + SIZE4);
1621     if( IR_INT_INVAL(req->namelen) )
1622 	return( -1 );
1623    ir_debug( Dmsg(10,"req->namelen =%d\n", req->namelen ); )
1624 
1625     if( (needsize = SIZE8 + req->namelen - size) > 0 )
1626 	return( needsize ) ;
1627 
1628     if( req->namelen > 0 ){
1629 	req->name = buf + SIZE8 ;
1630 	if( req->name[req->namelen - 1] != 0 )
1631 	    return( -1 );
1632     }
1633    ir_debug( Dmsg(10,"req->namelen =%d\n", req->namelen ); )
1634    ir_debug( Dmsg(10,"req->name =%s\n", req->name ); )
1635     return( 0 ) ;
1636 }
1637 
1638 #ifdef USE_EUC_PROTOCOL
1639 
ProcReq3(buf,size)1640 ProcReq3( buf, size )
1641 char *buf ;
1642 int size ;
1643 {
1644     register Req3 *req = &Request.Request3 ;
1645     int needsize ;
1646 
1647     if( (needsize = SIZE12 - size ) > 0 )
1648 	return( needsize ) ;
1649 
1650     req->context = (int)L4TOL(buf + SIZE4);
1651     req->number = (int)L4TOL(buf + SIZE8);
1652    ir_debug( Dmsg(10,"req->contest =%d\n", req->context ); )
1653    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1654     return( 0 ) ;
1655 }
1656 
ProcReq4(buf,size)1657 ProcReq4( buf, size )
1658 char *buf ;
1659 int size ;
1660 {
1661     register Req4 *req = &Request.Request4 ;
1662     register int i ;
1663     int needsize ;
1664 
1665     if( (needsize = SIZE12 - size ) > 0 )
1666 	return( needsize ) ;
1667 
1668     req->context = (int)L4TOL(buf + SIZE4);
1669     req->number = (int)L4TOL(buf + SIZE8);
1670 
1671    ir_debug( Dmsg(5,"req->number=%d\n", req->number ); )
1672 
1673     if( (needsize = SIZE12 + (req->number)*SIZE4 - size ) > 0 )
1674 	return( needsize ) ;
1675 
1676     buf += SIZE12 ;
1677     req->kouho = (int *)buf ;
1678     for( i = 0; i < req->number; i++, buf+= SIZE4 )
1679 	req->kouho[ i ] = (int)L4TOL(buf);
1680 
1681    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1682    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1683 #ifdef DEBUG
1684     for( i = 0; i < req->number; i++ )
1685        Dmsg(10,"req->kouho =%d\n", req->kouho[ i ] ) ;
1686 #endif
1687     return( 0 ) ;
1688 }
1689 
ProcReq5(buf,size)1690 ProcReq5( buf, size )
1691 char *buf ;
1692 int size ;
1693 {
1694     register Req5 *req = &Request.Request5 ;
1695     int needsize ;
1696 
1697     if( (needsize = SIZE16 - size ) > 0 )
1698 	return( needsize ) ;
1699 
1700     req->context = (int)L4TOL(buf + SIZE4);
1701     req->number = (int)L4TOL(buf + SIZE8);
1702     req->datalen = (int)L4TOL(buf + SIZE12);
1703    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1704    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1705    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1706     return( 0 ) ;
1707 }
1708 
ProcReq6(buf,size)1709 ProcReq6( buf, size )
1710 char *buf ;
1711 int size ;
1712 {
1713     register Req6 *req = &Request.Request6 ;
1714     int needsize ;
1715 
1716     if( (needsize = SIZE16 - size ) > 0 )
1717 	return( needsize ) ;
1718 
1719     req->context =(int)L4TOL(buf + SIZE4);
1720     req->mode = (int)L4TOL(buf + SIZE8);
1721     req->datalen = (int)L4TOL(buf + SIZE12);
1722 
1723     if( (needsize = SIZE16 + req->datalen - size ) > 0 )
1724 	return( needsize ) ;
1725 
1726     req->data = buf + SIZE16 ;
1727    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1728    ir_debug( Dmsg(10,"req->mode =%d\n", req->mode ); )
1729    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1730    ir_debug( Dmsg(10,"req->data =%s\n", req->data ); )
1731 
1732     return( 0 ) ;
1733 }
1734 
ProcReq7(buf,size)1735 ProcReq7( buf, size )
1736 char *buf ;
1737 int size ;
1738 {
1739     register Req7 *req = &Request.Request7 ;
1740     int needsize ;
1741 
1742     if( (needsize = SIZE12 - size ) > 0 )
1743 	return( needsize ) ;
1744 
1745     req->context = (int)L4TOL(buf + SIZE4);
1746     req->diclen = (int)L4TOL(buf + SIZE8);
1747 
1748     if( (needsize = SIZE12 + req->diclen - size ) > 0 )
1749 	return( needsize ) ;
1750 
1751     req->dicname = buf + SIZE12 ;
1752 
1753     if( (needsize = SIZE12 + req->diclen - size ) > 0 )
1754 	return( needsize ) ;
1755 
1756     req->datalen = (int)L4TOL(buf + SIZE12 + req->diclen);
1757 
1758     if( (needsize = SIZE16 + req->diclen + req->datalen - size ) > 0 )
1759 	return( needsize ) ;
1760 
1761     req->datainfo = buf + SIZE16 + req->diclen ;
1762    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1763    ir_debug( Dmsg(10,"req->diclen =%d\n", req->diclen ); )
1764    ir_debug( Dmsg(10,"req->dicname =%s\n", req->dicname ); )
1765    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1766    ir_debug( Dmsg(10,"req->datainfo =%s\n", req->datainfo ); )
1767     return( 0 ) ;
1768 }
1769 
ProcReq8(buf,size)1770 ProcReq8( buf, size )
1771 char *buf ;
1772 int size ;
1773 {
1774     register Req8 *req = &Request.Request8 ;
1775     int needsize ;
1776 
1777     if( (needsize = SIZE12 - size ) > 0 )
1778 	return( needsize ) ;
1779 
1780     req->context = (int)L4TOL(buf + SIZE4);
1781     req->datalen = (int)L4TOL(buf + SIZE8);
1782 
1783     if( (needsize = SIZE12 + req->datalen - size ) > 0 )
1784 	return( needsize ) ;
1785 
1786     req->data = buf + SIZE12 ;
1787 
1788     if( (needsize = SIZE16 + req->datalen - size ) > 0 )
1789 	return( needsize ) ;
1790 
1791     req->mode = (int)L4TOL(buf + SIZE12 + req->datalen);
1792 
1793    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1794    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1795    ir_debug( Dmsg(10,"req->data =%s\n", req->data ); )
1796    ir_debug( Dmsg(10,"req->mode =%d\n", req->mode ); )
1797     return( 0 ) ;
1798 }
1799 
ProcReq9(buf,size)1800 ProcReq9( buf, size )
1801 char *buf ;
1802 int size ;
1803 {
1804     register Req9 *req = &Request.Request9 ;
1805     int needsize ;
1806 
1807     if( (needsize = SIZE16 - size) > 0 )
1808 	return( needsize ) ;
1809 
1810     req->context = (int)L4TOL(buf + SIZE4);
1811     req->number = (int)L4TOL(buf + SIZE8);
1812     req->datalen = (int)L4TOL(buf + SIZE12);
1813 
1814     if( (needsize = SIZE16 + req->datalen - size) > 0 )
1815 	return( needsize ) ;
1816 
1817     req->data = buf + SIZE16 ;
1818 
1819    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1820    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1821    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1822    ir_debug( Dmsg(10,"req->data =%s\n", req->data ); )
1823     return( 0 ) ;
1824 }
1825 
ProcReq10(buf,size)1826 ProcReq10( buf, size )
1827 char *buf ;
1828 int size ;
1829 {
1830     register Req10 *req = &Request.Request10 ;
1831     int needsize ;
1832 
1833     if( (needsize = SIZE12 - size) > 0 )
1834 	return( needsize ) ;
1835 
1836     req->context = (int)L4TOL(buf + SIZE4);
1837     req->diclen = (int)L4TOL(buf + SIZE8);
1838 
1839     if( (needsize = SIZE12 + req->diclen - size) > 0 )
1840 	return( needsize ) ;
1841 
1842     req->dicname = buf + SIZE12 ;
1843 
1844     if( (needsize = SIZE16 + req->diclen - size) > 0 )
1845 	return( needsize ) ;
1846 
1847     req->textdiclen = (int)L4TOL(buf + SIZE12 + req->diclen);
1848 
1849     if( (needsize = SIZE16 + req->diclen + req->textdiclen - size) > 0 )
1850 	return( needsize ) ;
1851 
1852     if( req->textdiclen )
1853 	req->textdicname = buf + SIZE16 + req->diclen ;
1854     else
1855 	req->textdicname = (char *)NULL ;
1856 
1857     if( (needsize = SIZE20 + req->diclen + req->textdiclen - size) > 0 )
1858 	return( needsize ) ;
1859 
1860     req->mode = (int)L4TOL(buf + SIZE16 + req->diclen + req->textdiclen);
1861 
1862    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1863    ir_debug( Dmsg(10,"req->diclen =%d\n", req->diclen ); )
1864    ir_debug( Dmsg(10,"req->dicname =%s\n", req->dicname ); )
1865    ir_debug( Dmsg(10,"req->textdiclen =%d\n", req->textdiclen ); )
1866    ir_debug( Dmsg(10,"req->textdicname =%s\n", req->textdicname ); )
1867    ir_debug( Dmsg(10,"req->mode =%d\n", req->mode ); )
1868 
1869     return( 0 ) ;
1870 }
1871 
ProcReq11(buf,size)1872 ProcReq11( buf, size )
1873 char *buf ;
1874 int size ;
1875 {
1876     register Req11 *req = &Request.Request11 ;
1877     int needsize ;
1878 
1879     if( (needsize = SIZE20 - size) > 0 )
1880 	return( needsize ) ;
1881 
1882     req->context = (int)L4TOL(buf + SIZE4);
1883     req->number = (int)L4TOL(buf + SIZE8);
1884     req->kouho = (int)L4TOL(buf + SIZE12);
1885     req->max = (int)L4TOL(buf + SIZE16);
1886    ir_debug( Dmsg(10,"req->context =%d\n", req->context ); )
1887    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1888    ir_debug( Dmsg(10,"req->kouho =%d\n", req->kouho ); )
1889    ir_debug( Dmsg(10,"req->max =%d\n", req->max ); )
1890     return( 0 ) ;
1891 }
1892 
ProcReq12(buf,size)1893 ProcReq12( buf, size )
1894 char *buf ;
1895 int size ;
1896 {
1897     register Req12 *req = &Request.Request12 ;
1898     int needsize ;
1899 
1900     if( (needsize = SIZE8 - size) > 0 )
1901 	return( needsize ) ;
1902 
1903     req->datalen = (int)L4TOL(buf + SIZE4);
1904 
1905     if( (needsize = SIZE8 + req->datalen - size) > 0 )
1906 	return( needsize ) ;
1907 
1908     if( req->datalen > 0 ){
1909 	req->data = buf + SIZE8 ;
1910     }
1911 
1912     if( (needsize = SIZE8 + req->datalen - size) > 0 )
1913 	return( needsize ) ;
1914 
1915     req->number = (int)L4TOL(buf + SIZE8 + req->datalen);
1916 
1917    ir_debug( Dmsg(10,"req->datalen =%d\n", req->datalen ); )
1918    ir_debug( Dmsg(10,"req->data =%s\n", req->data ); )
1919    ir_debug( Dmsg(10,"req->number =%d\n", req->number ); )
1920     return( 0 ) ;
1921 }
1922 
1923 static void
iroha2canna(dirnames)1924 iroha2canna( dirnames )
1925 char *dirnames;
1926 {
1927   if (dirnames) {
1928     char *buf, *wp;
1929 
1930     buf = dirnames;
1931 
1932     while( *buf ){
1933       wp = buf + 5;
1934       if( !strncmp( (char *)buf, "iroha", 5 ) && (( *wp=='\0' ) || ( *wp==':' )) ){
1935 	bcopy( "canna", buf, 5 );
1936 	buf += 5;
1937       }
1938       while( (*buf != ':') && (*buf != '\0') )
1939 	buf++;
1940       buf++;
1941     }
1942   }
1943 }
1944 
1945 #endif /* USE_EUC_PROTOCOL */
1946 
1947 #ifdef DEBUG
1948 void
DebugDump(level,buf,size)1949 DebugDump( level, buf, size )
1950 int level, size ;
1951 const char *buf ;
1952 {
1953     char buf1[80] ;
1954     char buf2[17] ;
1955     char c ;
1956     int     i, j;
1957     int     count = 0 ;
1958 
1959     Dmsg( level, " SIZE = %d\n", size ) ;
1960     Dmsg( level, " COUNT  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f      0123456789abcdef\n" ) ;
1961     for (i = 0; i < size; i += 16) {
1962 	    bzero( buf1, 50 ) ;
1963 	    bzero( buf2, 17 ) ;
1964 	    for (j = 0; j < 16; j++) {
1965 		    if( i+j >= size ) {
1966 			strcat( (char *)buf1, "   " ) ;
1967 			strcat( (char *)buf2, " " ) ;
1968 		    } else {
1969 			sprintf( (char *)buf1,
1970 				"%s%02x ", buf1, (c = buf[i + j]) & 0xFF);
1971 			if((unsigned)(c & 0xff) >= (unsigned)' ' &&
1972 			   (unsigned)(c & 0xff) < (unsigned)0x7f )
1973 			    sprintf( (char *)buf2,"%s%c", buf2, c ) ;
1974 			else
1975 			    sprintf( (char *)buf2,"%s.", buf2 ) ;
1976 		    }
1977 	    }
1978 	    Dmsg( level," %05x %s     %s\n", count++,  buf1, buf2 );
1979     }
1980 
1981 }
1982 
1983 void
DebugDispKanji(cxnum,num)1984 DebugDispKanji( cxnum, num )
1985 int cxnum, num ;
1986 {
1987     char buf[1024] ;
1988     Ushort cbuf[1024];
1989     int len;
1990 
1991     len = RkwGetKanji( cxnum, (Ushort *)cbuf, 1024 );
1992     ushort2euc( cbuf, len, buf, 1024 );
1993     Dmsg( 5,"%d:[%s] ", num, buf ) ;
1994 }
1995 #endif /* DEBUG */
1996 
1997 #ifdef PROTO
RkwListDic(cxnum,dirname,mbuf,size)1998 RkwListDic( cxnum, dirname, mbuf, size )
1999 int cxnum, size ;
2000 char *dirname, *mbuf ;
2001 {
2002     if( RkwSetDicPath( cxnum, dirname ) < 0 )
2003 	return( -1 ) ;
2004 
2005     return( RkwGetDicList( cxnum, mbuf, size ) ) ;
2006 }
2007 
RkwCreateDic(cxnum,dicname,mode)2008 RkwCreateDic( cxnum, dicname, mode )
2009 int cxnum, mode ;
2010 char *dicname ;
2011 {
2012     return( 0 ) ;
2013 }
2014 
RkwRemoveDic(cxnum,dicname)2015 RkwRemoveDic( cxnum, dicname )
2016 int cxnum ;
2017 char *dicname ;
2018 {
2019     return( 0 ) ;
2020 }
2021 
RkwRenameDic(cxnum,dicname,newdicname,mode)2022 RkwRenameDic( cxnum, dicname, newdicname, mode )
2023 int cxnum, mode ;
2024 char *dicname, *newdicname ;
2025 {
2026     return( 0 ) ;
2027 }
2028 
2029 /* CopyDic �����  */
2030 
RkwCopyDic(cxnum,dirname,dicname,newdicname,mode)2031 RkwCopyDic(cxnum, dirname, dicname, newdicname, mode)
2032 int cxnum, mode ;
2033 char *dirname, *dicname, *newdicname ;
2034 {
2035     return( 0 ) ;
2036 }
2037 /* �����ޤ� */
RkwGetWordTextDic(cxnum,dirname,dicname,info,infolen)2038 RkwGetWordTextDic( cxnum, dirname, dicname, info, infolen )
2039 int cxnum, infolen ;
2040 char *dirname, *dicname, *info ;
2041 {
2042    ir_debug( Dmsg( 5,"RkwGetWordTextDic( %d, %s, %s, info, infolen )\n", cxnum, dirname, dicname ) );
2043     strncpy( info, "�Ƥ��� #T35 �ƥ���", infolen ) ;
2044 
2045     return( strlen( info ) ) ;
2046 }
2047 
2048 #endif /* PROTO */
2049 
2050 oreqproc Vector[] =
2051 {
2052 #ifdef USE_EUC_PROTOCOL
2053 /* 0x00 */	{ ir_error,		   ProcReq0 },
2054 /* 0x01 */	{ ir_error /* hack */,	   ProcReq2 },
2055 /* 0x02 */	{ ir_finalize,		   ProcReq0 },
2056 /* 0x03 */	{ ir_create_context,	   ProcReq0 },
2057 /* 0x04 */	{ ir_duplicate_context,    ProcReq1 },
2058 /* 0x05 */	{ ir_close_context,	   ProcReq1 },
2059 /* 0x06 */	{ ir_dictionary_list,	   ProcReq3 },
2060 /* 0x07 */	{ ir_get_yomi,		   ProcReq5 },
2061 /* 0x08 */	{ ir_define_dic,	   ProcReq7 },
2062 /* 0x09 */	{ ir_delete_dic,	   ProcReq7 },
2063 /* 0x0a */	{ ir_set_dic_path,	   ProcReq8 },
2064 /* 0x0b */	{ ir_get_dir_list,	   ProcReq3 },
2065 /* 0x0c */	{ ir_mount_dictionary,	   ProcReq8 },
2066 /* 0x0d */	{ ir_umount_dictionary,    ProcReq8 },
2067 /* 0x0e */	{ ir_rmount_dictionary,    ProcReq9 },
2068 /* 0x0f */	{ ir_mount_list,	   ProcReq3 },
2069 /* 0x10 */	{ ir_convert,		   ProcReq8 },
2070 /* 0x11 */	{ ir_convert_end,	   ProcReq4 },
2071 /* 0x12 */	{ ir_get_kanjilist,	   ProcReq5 },
2072 /* 0x13 */	{ ir_resize,		   ProcReq5 },
2073 /* 0x14 */	{ ir_store_yomi,	   ProcReq9 },
2074 /* 0x15 */	{ ir_get_lex,		   ProcReq11 },
2075 /* 0x16 */	{ ir_get_stat,		   ProcReq5 },
2076 /* 0x17 */	{ ir_error /* hack */,	   ProcReq0 },
2077 /* 0x18 */	{ ir_error /* hack */,	   ProcReq0 },
2078 /* 0x19 */	{ ir_host_ctl,		   ProcReq0 },
2079 /* 0x1a */	{ ir_query_extension,	   ProcReq12 }
2080 #else /* !USE_EUC_PROTOCOL */
2081 /* 0x00 */	{ ir_error,		   ProcReq0 },
2082 /* 0x01 */	{ ir_error /* hack */,	   ProcReq2 },
2083 #if 0
2084 /* 0x02 */	{ ir_error,		   ProcReq0 },
2085 /* 0x03 */	{ ir_error,		   ProcReq0 },
2086 /* 0x04 */	{ ir_error,		   ProcReq0 },
2087 /* 0x05 */	{ ir_error,		   ProcReq0 },
2088 /* 0x06 */	{ ir_error,		   ProcReq0 },
2089 /* 0x07 */	{ ir_error,		   ProcReq0 },
2090 /* 0x08 */	{ ir_error,		   ProcReq0 },
2091 /* 0x09 */	{ ir_error,		   ProcReq0 },
2092 /* 0x0a */	{ ir_error,		   ProcReq0 },
2093 /* 0x0b */	{ ir_error,		   ProcReq0 },
2094 /* 0x0c */	{ ir_error,		   ProcReq0 },
2095 /* 0x0d */	{ ir_error,		   ProcReq0 },
2096 /* 0x0e */	{ ir_error,		   ProcReq0 },
2097 /* 0x0f */	{ ir_error,		   ProcReq0 },
2098 /* 0x10 */	{ ir_error,		   ProcReq0 },
2099 /* 0x11 */	{ ir_error,		   ProcReq0 },
2100 /* 0x12 */	{ ir_error,		   ProcReq0 },
2101 /* 0x13 */	{ ir_error,		   ProcReq0 },
2102 /* 0x14 */	{ ir_error,		   ProcReq0 },
2103 /* 0x15 */	{ ir_error,		   ProcReq0 },
2104 /* 0x16 */	{ ir_error,		   ProcReq0 },
2105 /* 0x17 */	{ ir_error,		   ProcReq0 },
2106 /* 0x18 */	{ ir_error,		   ProcReq0 },
2107 /* 0x19 */	{ ir_error,		   ProcReq0 },
2108 /* 0x1a */	{ ir_error,	   	   ProcReq0 }
2109 #endif
2110 #endif /* !USE_EUC_PROTOCOL */
2111 } ;
2112 
2113 #ifdef EXTENSION
2114 static oreqproc ExtensionVector[] =
2115 {
2116 #ifdef USE_EUC_PROTOCOL
2117 /* 0x00 */	{ ir_list_dictionary,	   ProcReq9 },
2118 /* 0x01 */	{ ir_create_dictionary,    ProcReq8 },
2119 /* 0x02 */	{ ir_remove_dictionary,    ProcReq8 },
2120 /* 0x03 */	{ ir_rename_dictionary,    ProcReq10 },
2121 /* 0x04 */	{ ir_get_word_text_dic,    ProcReq10 },
2122 #else /* !USE_EUC_PROTOCOL */
2123 /* 0x00 */	{ ir_error,	   ProcReq0 },
2124 /* 0x01 */	{ ir_error,	   ProcReq0 },
2125 /* 0x02 */	{ ir_error, 	   ProcReq0 },
2126 /* 0x03 */	{ ir_error,    	   ProcReq0 },
2127 /* 0x04 */	{ ir_error,	   ProcReq0 },
2128 #endif /* !USE_EUC_PROTOCOL */
2129 } ;
2130 #endif /* EXTENSION */
2131 
2132 const char *ProtoName[] = {
2133     "IR_INIT",
2134     "IR_FIN",
2135     "IR_CRE_CON",
2136     "IR_DUP_CON",
2137     "IR_CLO_CON",
2138     "IR_DIC_LIST",
2139     "IR_GET_YOMI",
2140     "IR_DEF_DIC",
2141     "IR_UNDEF_DIC",
2142     "IR_DIC_PATH",
2143     "IR_DIR_LIST",
2144     "IR_MNT_DIC",
2145     "IR_UMNT_DIC",
2146     "IR_RMNT_DIC",
2147     "IR_MNT_LIST",
2148     "IR_CONVERT",
2149     "IR_CONV_END",
2150     "IR_KAN_LST",
2151     "IR_RESIZE",
2152     "IR_STO_YOMI",
2153     "IR_GET_LEX",
2154     "IR_GET_STA",
2155     "IR_SER_STAT",
2156     "IR_SER_STAT2",
2157     "IR_HOST_CTL",
2158     "IR_QUERY_EXT",
2159 } ;
2160 
2161 #ifdef DEBUG
2162 const char *DebugProc[][2] = {
2163     { "ir_null",		      "ProcReq0" } ,
2164     { "ir_initialize",		      "ProcReq2" } ,
2165     { "ir_finalize",		      "ProcReq0" } ,
2166     { "ir_create_context",	      "ProcReq0" } ,
2167     { "ir_duplicate_context",	      "ProcReq1" } ,
2168     { "ir_close_context",	      "ProcReq1" } ,
2169     { "ir_dictionary_list",	      "ProcReq3" } ,
2170     { "ir_get_yomi",		      "ProcReq5" } ,
2171     { "ir_define_dic",		      "ProcReq7" } ,
2172     { "ir_delete_dic",		      "ProcReq7" } ,
2173     { "ir_set_dic_path",	      "ProcReq8" } ,
2174     { "ir_get_dir_list",	      "ProcReq3" } ,
2175     { "ir_mount_dictionary",	      "ProcReq8" } ,
2176     { "ir_umount_dictionary",	      "ProcReq8" } ,
2177     { "ir_rmount_dictionary",	      "ProcReq9" } ,
2178     { "ir_mount_list",		      "ProcReq3" } ,
2179     { "ir_convert",		      "ProcReq8" } ,
2180     { "ir_convert_end", 	      "ProcReq4" } ,
2181     { "ir_get_kanjilist",	      "ProcReq5" } ,
2182     { "ir_resize",		      "ProcReq5" } ,
2183     { "ir_store_yomi",		      "ProcReq9" } ,
2184     { "ir_get_lex",		      "ProcReq11"} ,
2185     { "ir_get_stat",		      "ProcReq5" } ,
2186     { "ir_server_stat", 	      "ProcReq0" } ,
2187     { "ir_server_stat2",	      "ProcReq0" } ,
2188     { "ir_host_ctl",		      "ProcReq0" } ,
2189     { "ir_query_extension",	      "ProcReq12" }
2190 } ;
2191 #endif
2192 
2193 const char *ExtensionName[][2] = {
2194     /* Request Name		Start Protocol Number */
2195 #ifdef EXTENSION
2196     { REMOTE_DIC_UTIL,		"65536" }, /* 0x10000 */
2197 #endif /* EXTENSION */
2198     { "",		      "" }
2199 } ;
2200