c-hglib
 All Data Structures Files Functions Variables Typedefs Macros
client.h File Reference
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  hg_header
 This structure contains the variables for the header. More...
struct  hg_handle
 This structure will be use to handle the connection with the server. More...

Typedefs

typedef struct hg_header hg_header
 This structure contains the variables for the header.
typedef struct hg_handle hg_handle
 This structure will be use to handle the connection with the server.

Functions

hg_handlehg_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.
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 sizebuff)
 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.

Typedef Documentation

This structure contains the variables for the header.

Parameters
channelThe channel will stock a letter that will indicate the type of channel.
lengthThe length will stock the size of data that will be send or the maxim data that can be received by the server.

This structure will be use to handle the connection with the server.

Parameters
p_read p_writeContains 2 fd for parent for the bidirectional connection.
childpidThe pid of the process that will open the connection.
headerThe header that will contain the current header-action (channel, length).

Function Documentation

hg_handle* hg_open ( const char *  path,
char *  encoding 
)

Open the connection with the mercurial command server.

The handle structure will be allocated.

Parameters
pathThe path to the repository wherewith I want to create a connection NULL argument means the repository in which I am.
encodingWill set HGENCODING to the given encoding NULL argument means the default encoding. (UTF-8)
Return values
handle- A handle for this connection.
NULLIndicate 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.

int hg_close ( hg_handle **  handle)

Close the connection for the given handle.

Erase the handle and free the memory

Parameters
handleThe handle of the connection that I want to close
Return values
0if successful
-1to 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.

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
handleThe handle of the connection, wherewith I want to communicate
commandAn array of pointers to null-terminated strings that represent the argument list available to the new command.
cmd_sizeThe length of command array.
Return values
0if successful
-1to 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
handleThe handle of the connection, wherewith I want to communicate
bufferA character array where the read content will be stored.
sizebuffThe number of bytes to read.
Return values
Numberthe number of bytes that were read.
-1to 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
handleThe handle of the connection, wherewith I want to communicate
bufferA null terminated character string of the content to write.
sizebuffThe number of bytes to write
Return values
Numberthe number of bytes that were written
-1to 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.

char hg_channel ( hg_handle handle)

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
handleThe handle of the connection, wherewith I want to communicate
Return values
0if successful
-1to 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.

hg_header hg_head ( hg_handle handle)

Return the current header.

Sometimes, the user needs the entire header. This is a way to do that.

Parameters
handleThe handle of the connection, wherewith I want to communicate
Return values
hg_headerthe header stucture for the given handle.
NULLto 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.

int hg_exitcode ( hg_handle handle)

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
handleThe handle of the connection, wherewith I want to communicate
Return values
exitcodeif successful
-1to 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.