#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include "client.h"
#include "utils.h"
Go to the source code of this file.
Functions |
int | read_header (hg_handle *handle) |
| Reading the header from cmdsrv.
|
int | read_hello (hg_handle *handle) |
| Reading the hello msg from cmd server.
|
hg_handle * | hg_open (const char *path, char *encoding) |
| Open the connection with the mercurial command server.
|
int | hg_close (hg_handle **handle) |
| Close the connection for the given handle.
|
char * | cmd_prepare (char *const command[], size_t *cmd_size) |
| Prepare the command for sending process.
|
int | hg_rawcommand (hg_handle *handle, char *const command[], size_t cmd_size) |
| Sending a command to the mercurial command server, through the given handle.
|
int | hg_rawread (hg_handle *handle, char *buffer, size_t sizebuff) |
| Reading some unparse data from the server.
|
int | hg_rawwrite (hg_handle *handle, const char *buffer, size_t buff_size) |
| Will write the buffer to server for the connection establish by the handle.
|
char | hg_channel (hg_handle *handle) |
| Reading the current channel.
|
hg_header | hg_head (hg_handle *handle) |
| Return the current header.
|
int | hg_exitcode (hg_handle *handle) |
| The exitcode for the current command.
|
Macro Definition Documentation
Function Documentation
Reading the header from cmdsrv.
The function will read the header from the command server and will save it to the header parameter of the handle structure.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
- Return values
-
0 | if succesfull |
-1 | to indicate an error, with errno set appropriately |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
- read(2) command errors
Definition at line 31 of file client.c.
Reading the hello msg from cmd server.
After the connection, the command server sends a hello message. The message contains the command server capabilities and the messages encoding.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
- Return values
-
0 | if succesfull |
-1 | to indicate an error, with errno set appropriately |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
- read(2) command errors
Definition at line 67 of file client.c.
hg_handle* hg_open |
( |
const char * |
path, |
|
|
char * |
encoding |
|
) |
| |
Open the connection with the mercurial command server.
The handle structure will be allocated.
- Parameters
-
path | The path to the repository wherewith I want to create a connection NULL argument means the repository in which I am. |
encoding | Will set HGENCODING to the given encoding NULL argument means the default encoding. (UTF-8) |
- Return values
-
handle | - A handle for this connection. |
NULL | Indicate an error, with errno set appropriately. |
errno can be :
- execl(2) command errors
- dup2(2) command errors
- fork(2) command errors
- pipe(2) command errors
- EFAULT - for a bad path address
- EINVAL - for a bad encoding
Definition at line 103 of file client.c.
Close the connection for the given handle.
Erase the handle and free the memory
- Parameters
-
handle | The handle of the connection that I want to close |
- Return values
-
0 | if successful |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument ( handle it's set to a null pointer)
- kill(2) command errors
Definition at line 159 of file client.c.
char* cmd_prepare |
( |
char *const |
command[], |
|
|
size_t * |
cmd_size |
|
) |
| |
Prepare the command for sending process.
Replace all the blank space with the '\0' character.
- Parameters
-
command | an array that will contain the mercurial command |
cmd_size | - array size |
- Return values
-
string | representing the command that will be send to cmdsrv |
*cmd_size | will be set on string size |
char *command[] = {"tip", "-p"};
prinf("==%s==", cmd_str);
---> ==tip\0-p==
Definition at line 195 of file client.c.
int hg_rawcommand |
( |
hg_handle * |
handle, |
|
|
char *const |
command[], |
|
|
size_t |
cmd_size |
|
) |
| |
Sending a command to the mercurial command server, through the given handle.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
command | An array of pointers to null-terminated strings that represent the argument list available to the new command. |
cmd_size | The length of command array. |
- Return values
-
0 | if successful |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument ( handle it's set to a null pointer)
- write(2) command errors
Definition at line 224 of file client.c.
int hg_rawread |
( |
hg_handle * |
handle, |
|
|
char * |
buffer, |
|
|
size_t |
sizebuff |
|
) |
| |
Reading some unparse data from the server.
Will read just a 'line', the header that is received from server and the data that comes after the header
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
buffer | A character array where the read content will be stored. |
sizebuff | The number of bytes to read. |
- Return values
-
Number | the number of bytes that were read. |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
- read(2) command errors
Definition at line 259 of file client.c.
int hg_rawwrite |
( |
hg_handle * |
handle, |
|
|
const char * |
buffer, |
|
|
size_t |
sizebuff |
|
) |
| |
Will write the buffer to server for the connection establish by the handle.
This function will be used when one of the input channels will be received from the command server. ('I' or 'L' channels)
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
buffer | A null terminated character string of the content to write. |
sizebuff | The number of bytes to write |
- Return values
-
Number | the number of bytes that were written |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
- write(2) command errors
Definition at line 292 of file client.c.
Reading the current channel.
Before you read or write data, you will want to know for what kind of data is server waiting, an input data or an output data. This function will return the current channel for the connection established by the handle.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
- Return values
-
0 | if successful |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
Definition at line 319 of file client.c.
Return the current header.
Sometimes, the user needs the entire header. This is a way to do that.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
- Return values
-
hg_header | the header stucture for the given handle. |
NULL | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
Definition at line 332 of file client.c.
The exitcode for the current command.
The server tell use that he finished his action when the 'r' channel is send. This function will get the exitcode from the server, in as a measure to tell that the command was finished.
- Parameters
-
handle | The handle of the connection, wherewith I want to communicate |
- Return values
-
exitcode | if successful |
-1 | to indicate an error, with errno set appropriately. |
errno can be:
- EINVAL - Invalid argument (handle it's set to a null pointer)
- read(2) command errors
Definition at line 340 of file client.c.