30 bool synchro,
bool SSL,
31 unsigned int timeout) :
32 Socket(server, port, timeout, timeout, SSL),
67 void mcs::Client::writeToFile(
int des)
116 for (i=0; i<rec->
count(); i++)
126 string s=
"",
msg, filename, fn;
130 unsigned int size = 0;
131 static string bl =
" ";
134 Record* newRecordSet = NULL;
135 static bool batch =
false;
143 if (lrecord)
delete lrecord;
156 throw MCS_ERROR(MSG_CANT_OPEN_FILE, filename.csz);
159 for (i=0; i<hc.
optc(); i++)
160 cmd +=
" -" + hc.
opt(i);
167 buf = (
char *)data->getEntireBuffer(size);
169 for (i=0; i<hc.
optc(); i++)
170 cmd +=
" -" + hc.
opt(i);
184 msg = s.substr(4, 100000);
189 if (code == MSG_BYE) {
192 event(MCS_CLIENT_DISCONNECT,
Data((
void*) NULL));
200 for (ui=0; ui<v.size(); ui++)
207 event(MCS_CLIENT_ERROR,
Data(
msg), code);
212 case MSG_SENDFILE_START:
219 event(MCS_CLIENT_FILE,
Data(fn));
222 case MSG_SENDDATA_START:
229 event(MCS_CLIENT_DATA, d);
232 lrecord =
new Record(buf);
238 case MSG_RECVFILE_START:
244 case MSG_RECVDATA_START:
255 case MSG_NEW_RECORDSET:
257 newRecordSet =
new Record(*lrecord);
274 Data d = newRecordSet->pop();
284 lcid =
aux[0].ival();
285 lchunksize =
aux[1].ival();
296 bool mcs::Client::fetch(
unsigned int newpos,
bool random)
298 static string bl =
" ";
300 if (
code[
code.
count()-1].ival() == MSG_ALREADY_AT_END_OF_FILE)
317 void mcs::Client::event(
int op,
Data d,
int code)
string opt(int i)
Return option at i-th position.
#define MCS_RS_INSERT
Flag for RecordSet::init().
Client(const Client &)
Declared to avoid using of default copy constructor.
string itos(int i)
Convert an integer to a string.
int optc()
Return number of options.
Connect to a MCS server as a client.
Serialize memory buffers or files into chunks.
void parseCmd(string c)
Parse a command line into tokens, arguments and options.
bool File_Dir_Exist(string fn, unsigned int &size)
Check if a file or directory exists.
bool isConnected()
Tell if the object is connected to the MCS server.
string Pwd()
Return the current working dir.
string sval(bool addWhiteSpaces=false) const
Convert internal data to a string object.
void setTag(unsigned char tag)
Set a new value to internal tag.
Record out
Record containing all output lines (code: MSG_OUT) sent by the server while executing the last comman...
A dynamic array of Data objects.
void print(string s)
Writes a string in the socket adding a newline.
int chunksize()
Return the server side chunk size used to send data across network.
void clearRecords()
Clear all records.
#define MCS_SEP
This character is used to split a message into "fields".
The base class that implement the data abstraction layer.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
#define MCS_CMD_PUTDATA
Command: Upload Data objects.
#define MCS_CMD_PUT
Command: Upload a file to the work directory.
Record msg
Record containing all reply's messages sent by the server while executing the last command...
unsigned char getTag()
Retrieve the value of the tag.
bool connected
Flag telling if the client is connected or not.
Record code
Record containing all reply's numeric codes sent by the server while executing the last command...
string remTrailing(string &s, const char *p)
Remove any trailing character "p".
Data field(string name)
Returns the Data object in the vector whose name is "name".
#define MCS_CMD_CID
Command: Retrieve the Client identifier.
bool exec(string cmd, Data *data=NULL)
Execute commands on the server.
string lpath
Local path to read/write files.
void startFetch()
Must be called when record fetching is possible.
vector< string > split(string s, string sep=" ")
Split a string into tokens.
#define MCS_PROMPT_ERROR
Prompt sent after a command raised one error.
Main include file for all MCS based applications.
void sendData(Serializable *from)
Send a block of data through the socket.
void addField(Data *d)
Wrapper around Dynamic_Array.push.
int extractCode(const char *msg)
Extract the numeric code from a server reply.
bool cmpCmd(string cmd)
Check if the string in the parameter is the same as the command (case insensitive).
void init(unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0)
Initailize the Record set.
A general purpose data type.
#define MCS_CMD_DBNAME
Command: Provide the application (database) name.
#define MCS_CMD_USERNAME
Command: Provide user name.
Record recv
Record containing all Data objects sent by the server.
#define MCS_PROMPT_OK
Prompt sent after a command has been executed correctly.
void Close()
Close the socket.
virtual ~Client()
Destructor.
int cid()
Return the server side client identificator.
#define MCS_PROMPT_WARN
Prompt sent after a command raised one or more warnings.
#define MCS_PRE
Prefix of a message for the client, this is the first character.
int count()
Wrapper around Dynamic_Array.count.
int ival() const
Convert internal data to a integer value.
unsigned int recvData(char **buffer, unsigned int maxsize)
Receive data and store in a buffer.
Data & arg(int i)
Return argument at i-th position.
#define MCS_CMD_DBCONNECT
Command: Finalize the authentication process and log in.
string getline()
Reads from a socket until a newline is encountered.
#define MCS_CMD_PASSWORD
Command: Provide password.
bool login(string user, string pass, string db="")
Log in to a MCS server.
Record aux
Record containing all auxiliary fields sent by the server.
Namespace for MCS library.