rasdaman complete source
rasmgr_utils_comm.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
36 #ifndef RASMGR_UTILS_COMM_HH
37 #define RASMGR_UTILS_COMM_HH
38 
39 
40 #include <stdio.h>
41 #include <errno.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <sys/types.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <netdb.h>
48 #include <iostream>
49 #include <string.h>
50 
51 #include "../rasmgr/ras_crypto.hh"
52 
53 // now defined vid -D as compile flag -- PB 2003-sep-03
54 // const int RMANVERSION = 5100;
55 
56 extern const char* RASMGRPORTS;
57 extern const char* RASMGRHOST;
58 
59 
60 const int MAXMSG = 2048;
61 const int MAXCOMMAND = 100;
62 const int MAXMSGRASCONTROL = 20000;
63 
64 const int MAXUSERNAME = 100;
65 const int MAXENCRPASS = 35;
66 const int MAXHOSTNAME = 100;
67 
68 const int COMM_CONT = 0;
69 const int COMM_SEND = 1;
70 const int COMM_EXIT = 2;
71 const int COMM_ERR = 3;
72 const int COMM_ACDN = 4;
73 
74 class RasMgrClientComm
75 {
76 public:
77  RasMgrClientComm();
78  ~RasMgrClientComm();
79 
80  void setRasMgrHost(const char *rasmgrHost, int rasmgrPort);
81  const char* getRasMgrHost();
82  void setUserIdentification(const char *userName, const char *encrPass);
83 
84  int openSocket();
85  void closeSocket();
86 
87  int sendMessage(const char *message);
88  int sendMessageGetAnswer(const char *message, const char **responsePtr);
89  const char* readMessage();
90  const char* getHeader();
91  const char* getBody();
92 
93 private:
94  int writeWholeMessage(int socket,char *destBuffer,int buffSize);
95  int readWholeMessage(int socket,char *destBuffer,int buffSize);
96  const char *stripBlanks(const char*);
97 
98  char answerMessage[MAXMSGRASCONTROL];
99  char *answerBody;
100 
101  char userName[MAXUSERNAME];
102  char encrPass[MAXENCRPASS];
103 
104  int rasmgrSocket;
105  char rasmgrHost[MAXHOSTNAME];
106  int rasmgrPort;
107 };
108 
109 //#####################################################################
110 class UserLogin
111 {
112 public:
113  UserLogin();
114  ~UserLogin();
115  int interactiveLogin();
116  int environmentLogin();
117  int quickLogin();
118  const char *getUserName();
119  const char *getEncrPass();
120 private:
121 
122  char userName[MAXUSERNAME];
123  char encrPass[MAXENCRPASS];
124 };
125 
126 #endif