/* -*- mode: C; coding: euc-japan -*- */ /* $OpenXM: OpenXM/src/ox_toolkit/oxf.c,v 1.1 2000/10/10 05:23:21 ohara Exp $ */ /* This module includes functions for sending/receiveng CMO's. Some commnets is written in Japanese by the EUC-JP coded character set. */ #include #include #include #include #include #include #include #include #include #include "mysocket.h" #include "ox_toolkit.h" OXFILE *oxf_open(int fd) { OXFILE *oxfp = (OXFILE *)malloc(sizeof(OXFILE)); oxfp->fd = fd; oxfp->send_int32 = send_int32_nbo; oxfp->receive_int32 = receive_int32_nbo; oxfp->control = NULL; return oxfp; /* oxfp->fp = fdopen(fd, "a+"); */ /* return (oxfp->fp != NULL)? oxfp: NULL; */ } OXFILE *oxf_control(OXFILE *oxfp) { return oxfp->control; } /* The function determines a byte order of integer on the OpenXM connection `oxfp'. */ /* REMARKS: we request the byte order of macine integer on a local machine by (*(char *)&offer). The fact depends on OX_BYTE_LITTLE_ENDIAN==1. */ void oxf_determine_byteorder_client(OXFILE *oxfp) { int offer = OX_BYTE_LITTLE_ENDIAN; char receiv; int mode; oxf_read(&receiv, 1, 1, oxfp); oxf_write(&offer, 1, 1, oxfp); mode = (receiv == *(char *)&offer); oxf_setopt(oxfp, mode); } /* Server 側ではこちらを用いる */ /* いまの実装は dup されていることが前提になっている */ void oxf_determine_byteorder_server(OXFILE *oxfp) { int offer = OX_BYTE_LITTLE_ENDIAN; char receiv; int mode; oxf_write(&offer, 1, 1, oxfp); oxf_read(&receiv, 1, 1, oxfp); mode = (receiv == *(char *)&offer); oxf_setopt(oxfp, mode); } void oxf_flush(OXFILE *oxfp) { /* fflush(oxfp->fp); */ } void oxf_close(OXFILE *oxfp) { close(oxfp->fd); /* fclose(oxfp->fp); */ } #define OXF_SETOPT_NBO 0 #define OXF_SETOPT_LBO 1 void oxf_setopt(OXFILE *oxfp, int mode) { if (mode == OXF_SETOPT_LBO) { oxfp->send_int32 = send_int32_lbo; oxfp->receive_int32 = receive_int32_lbo; }else if (mode == OXF_SETOPT_NBO) { oxfp->send_int32 = send_int32_nbo; oxfp->receive_int32 = receive_int32_nbo; } } OXFILE *oxf_connect_active(char *hostname, short port) { int fd = mysocketOpen(hostname, port); return oxf_open(fd); } OXFILE *oxf_connect_passive(int listened) { int fd = mysocketAccept(listened); return oxf_open(fd); } #define LENGTH_OF_ONETIME_PASSWORD 64 /* a password generator. */ char *generate_otp() { static char crypto[] = "%.,^_+-=/@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static char otp[LENGTH_OF_ONETIME_PASSWORD+1] = {0}; int i; srandom(time(NULL)); for(i=0; i