[BACK]Return to zclient.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/zclient.c, Revision 1.6

1.1       ohara       1: /* -*- mode: C -*- */
1.6     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.5 2003/02/04 20:43:55 ohara Exp $ */
1.1       ohara       3:
                      4: /* A sample implementation of an OpenXM client with OpenXM C library */
                      5:
                      6: #include <stdio.h>
                      7: #include <stdlib.h>
                      8: #include <unistd.h>
                      9: #include <string.h>
                     10: #include "ox_toolkit.h"
                     11:
1.6     ! ohara      12: int oxc_start(char *remote_host, int port, char *passwd);
        !            13:
1.2       ohara      14: static OXFILE *connection(int listened, char *passwd)
1.1       ohara      15: {
                     16:     OXFILE *oxfp = oxf_connect_passive(listened);
                     17:     if(oxf_confirm_client(oxfp, passwd)) {
                     18:         oxf_determine_byteorder_client(oxfp);
                     19:         return oxfp;
                     20:     }
                     21:     oxf_close(oxfp);
                     22:     return NULL;
                     23: }
                     24:
                     25: OXFILE *open_server(char *remote_host)
                     26: {
1.6     ! ohara      27:     int port;
1.1       ohara      28:     int listen;
                     29:     char *passwd = generate_otp();
                     30:
1.2       ohara      31:     if ((listen = oxf_listen(&port)) != -1) {
1.1       ohara      32:         if (oxc_start(remote_host, port, passwd) != 0) {
1.4       ohara      33:             ox_printf("zclient:: remotehost = %s.\n", remote_host);
1.2       ohara      34:             return connection(listen, passwd);
1.1       ohara      35:         }
                     36:     }
                     37:     return NULL;
                     38: }
                     39:
                     40: int main(int argc, char* argv[])
                     41: {
1.2       ohara      42:     OXFILE *oxfp;
                     43:        char *remote, *cmd;
1.1       ohara      44:
1.5       ohara      45:     ox_stderr_init(stderr);
1.2       ohara      46:        if (argc < 3) {
1.4       ohara      47:         ox_printf("we have a few argument.\n");
                     48:         ox_printf("Usage:\n  %s [remotehost] [command]\n", argv[0]);
1.2       ohara      49:                return 0;
                     50:        }
1.1       ohara      51:
1.2       ohara      52:        remote = argv[1];
                     53:        cmd    = argv[2];
1.1       ohara      54:
1.2       ohara      55:     if ((oxfp = open_server(remote)) == NULL) {
1.4       ohara      56:         ox_printf("zclient:: I cannot open a server.\n");
1.1       ohara      57:         exit(1);
                     58:     }
1.4       ohara      59:     ox_printf("zclient:: I succeed to open an OX server.\n");
1.2       ohara      60:
                     61:        if(oxf_execute_cmd(oxfp, cmd) != NULL) {
1.4       ohara      62:         ox_printf("zclient:: I succeed to connect a calc server!!\n");
1.2       ohara      63:        }
                     64:
1.4       ohara      65:     oxf_close(oxfp);
                     66:     ox_printf("zclient:: closed.\n");
1.1       ohara      67:     return 0;
                     68: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>