prelude-connection

## prelude-connection prelude-connection |

## Synopsis

    enum                prelude_connection_permission_t;
    enum                prelude_connection_state_t;
    typedef             prelude_connection_t;
    void                prelude_connection_destroy          (prelude_connection_t *conn);
    int                 prelude_connection_send             (prelude_connection_t *cnx,
                                                             prelude_msg_t *msg);
    int                 prelude_connection_recv             (prelude_connection_t *cnx,
                                                             prelude_msg_t **outmsg);
    int                 prelude_connection_recv_idmef       (prelude_connection_t *con,
                                                             idmef_message_t **idmef);
    int                 prelude_connection_connect          (prelude_connection_t *cnx,
                                                             prelude_client_profile_t *profile,
                                                             prelude_connection_permission_t permission);
    ssize_t             prelude_connection_forward          (prelude_connection_t *cnx,
                                                             prelude_io_t *src,
                                                             size_t count);
    const char *        prelude_connection_get_local_addr   (prelude_connection_t *cnx);
    unsigned int        prelude_connection_get_local_port   (prelude_connection_t *cnx);
    const char *        prelude_connection_get_peer_addr    (prelude_connection_t *cnx);
    unsigned int        prelude_connection_get_peer_port    (prelude_connection_t *cnx);
    prelude_bool_t      prelude_connection_is_alive         (prelude_connection_t *cnx);
    prelude_io_t *      prelude_connection_get_fd           (prelude_connection_t *cnx);
    int                 prelude_connection_close            (prelude_connection_t *cnx);
    void                prelude_connection_set_fd_ref       (prelude_connection_t *cnx,
                                                             prelude_io_t *fd);
    void                prelude_connection_set_fd_nodup     (prelude_connection_t *cnx,
                                                             prelude_io_t *fd);
    void                prelude_connection_set_state        (prelude_connection_t *cnx,
                                                             prelude_connection_state_t state);
    prelude_connection_state_t  prelude_connection_get_state
                                                            (prelude_connection_t *cnx);
    void                prelude_connection_set_data         (prelude_connection_t *cnx,
                                                             void *data);
    void *              prelude_connection_get_data         (prelude_connection_t *cnx);
    const char *        prelude_connection_get_default_socket_filename
                                                            (void);
    prelude_connection_permission_t  prelude_connection_get_permission
                                                            (prelude_connection_t *conn);
    uint64_t            prelude_connection_get_peer_analyzerid
                                                            (prelude_connection_t *cnx);
    void                prelude_connection_set_peer_analyzerid
                                                            (prelude_connection_t *cnx,
                                                             uint64_t analyzerid);
    int                 prelude_connection_new              (prelude_connection_t **ret,
                                                             const char *addr);
    prelude_connection_t * prelude_connection_ref           (prelude_connection_t *conn);
    int                 prelude_connection_new_msgbuf       (prelude_connection_t *connection,
                                                             prelude_msgbuf_t **msgbuf);
    int                 prelude_connection_permission_to_string
                                                            (prelude_connection_permission_t perm,
                                                             prelude_string_t *out);
    int                 prelude_connection_permission_new_from_string
                                                            (prelude_connection_permission_t *out,
                                                             const char *buf);

## Description

## Details

### enum prelude_connection_permission_t

    typedef enum {
            PRELUDE_CONNECTION_PERMISSION_IDMEF_READ      = 0x01, /* client might read received IDMEF message */
            PRELUDE_CONNECTION_PERMISSION_ADMIN_READ      = 0x02, /* client might read received ADMIN message */
            PRELUDE_CONNECTION_PERMISSION_IDMEF_WRITE     = 0x04, /* client might send IDMEF message          */
            PRELUDE_CONNECTION_PERMISSION_ADMIN_WRITE     = 0x08  /* client might issue OPTION request        */
    } prelude_connection_permission_t;

### enum prelude_connection_state_t

    typedef enum {
            PRELUDE_CONNECTION_STATE_ESTABLISHED     = 0x01
    } prelude_connection_state_t;

### prelude_connection_t

    typedef struct prelude_connection prelude_connection_t;

### prelude_connection_destroy ()

    void                prelude_connection_destroy          (prelude_connection_t *conn);

Destroy the connection referenced by `conn`.

In case the connection is still alive, it is closed in a blocking manner. Use `prelude_connection_close()` if you want to close the connection in a non blocking manner prior `prelude_connection_destroy()`.

`conn` : | Pointer to a prelude_connection_t object.

### prelude_connection_send ()

    int                 prelude_connection_send             (prelude_connection_t *cnx,
                                                             prelude_msg_t *msg);

`cnx` : |
`msg` : |
Returns : |

### prelude_connection_recv ()

    int                 prelude_connection_recv             (prelude_connection_t *cnx,
                                                             prelude_msg_t **outmsg);

`cnx` : |
`outmsg` : |
Returns : |

### prelude_connection_recv_idmef ()

    int                 prelude_connection_recv_idmef       (prelude_connection_t *con,
                                                             idmef_message_t **idmef);

`con` : |
`idmef` : |
Returns : |

### prelude_connection_connect ()

    int                 prelude_connection_connect          (prelude_connection_t *cnx,
                                                             prelude_client_profile_t *profile,
                                                             prelude_connection_permission_t permission);

`cnx` : |
`profile` : |
`permission` : |
Returns : |

### prelude_connection_forward ()

    ssize_t             prelude_connection_forward          (prelude_connection_t *cnx,
                                                             prelude_io_t *src,
                                                             size_t count);

`cnx` : |
`src` : |
`count` : |
Returns : |

### prelude_connection_get_local_addr ()

    const char *        prelude_connection_get_local_addr   (prelude_connection_t *cnx);

`cnx` : | Pointer to a prelude_connection_t object.
Returns : | the local address used to connect.

### prelude_connection_get_local_port ()

    unsigned int        prelude_connection_get_local_port   (prelude_connection_t *cnx);

`cnx` : | Pointer to a prelude_connection_t object.
Returns : | the local port used to connect.

### prelude_connection_get_peer_addr ()

    const char *        prelude_connection_get_peer_addr    (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_get_peer_port ()

    unsigned int        prelude_connection_get_peer_port    (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_is_alive ()

    prelude_bool_t      prelude_connection_is_alive         (prelude_connection_t *cnx);

`cnx` : | Pointer to a prelude_connection_t object.
Returns : | 0 if the connection associated with `cnx` is alive, -1 otherwise.

### prelude_connection_get_fd ()

    prelude_io_t *      prelude_connection_get_fd           (prelude_connection_t *cnx);

`cnx` : | Pointer to a prelude_connection_t object.
Returns : | A pointer to the prelude_io_t object used for communicating with the peer.

### prelude_connection_close ()

    int                 prelude_connection_close            (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_set_fd_ref ()

    void                prelude_connection_set_fd_ref       (prelude_connection_t *cnx,
                                                             prelude_io_t *fd);

`cnx` : |
`fd` : |

### prelude_connection_set_fd_nodup ()

    void                prelude_connection_set_fd_nodup     (prelude_connection_t *cnx,
                                                             prelude_io_t *fd);

`cnx` : |
`fd` : |

### prelude_connection_set_state ()

    void                prelude_connection_set_state        (prelude_connection_t *cnx,
                                                             prelude_connection_state_t state);

`cnx` : |
`state` : |

### prelude_connection_get_state ()

    prelude_connection_state_t  prelude_connection_get_state
                                                            (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_set_data ()

    void                prelude_connection_set_data         (prelude_connection_t *cnx,
                                                             void *data);

`cnx` : |
`data` : |

### prelude_connection_get_data ()

    void *              prelude_connection_get_data         (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_get_default_socket_filename ()

    const char *        prelude_connection_get_default_socket_filename
                                                            (void);

Returns : |

### prelude_connection_get_permission ()

    prelude_connection_permission_t  prelude_connection_get_permission
                                                            (prelude_connection_t *conn);

`conn` : |
Returns : |

### prelude_connection_get_peer_analyzerid ()

    uint64_t            prelude_connection_get_peer_analyzerid
                                                            (prelude_connection_t *cnx);

`cnx` : |
Returns : |

### prelude_connection_set_peer_analyzerid ()

    void                prelude_connection_set_peer_analyzerid
                                                            (prelude_connection_t *cnx,
                                                             uint64_t analyzerid);

`cnx` : |
`analyzerid` : |

### prelude_connection_new ()

    int                 prelude_connection_new              (prelude_connection_t **ret,
                                                             const char *addr);

`ret` : |
`addr` : |
Returns : |

### prelude_connection_ref ()

    prelude_connection_t * prelude_connection_ref           (prelude_connection_t *conn);

Increases `conn` reference count.

`prelude_connection_destroy()` will decrease the refcount until it reaches 0, at which point `conn` will be destroyed.

`conn` : | Pointer to a prelude_connection_t object to reference.
Returns : | `conn`.

### prelude_connection_new_msgbuf ()

    int                 prelude_connection_new_msgbuf       (prelude_connection_t *connection,
                                                             prelude_msgbuf_t **msgbuf);

`connection` : |
`msgbuf` : |
Returns : |

### prelude_connection_permission_to_string ()

    int                 prelude_connection_permission_to_string
                                                            (prelude_connection_permission_t perm,
                                                             prelude_string_t *out);

`perm` : |
`out` : |
Returns : |

### prelude_connection_permission_new_from_string ()

    int                 prelude_connection_permission_new_from_string
                                                            (prelude_connection_permission_t *out,
                                                             const char *buf);

`out` : |
`buf` : |
Returns : |