Dillo v3.1.1-119-g140d9ebd
|
Library for dealing with dpip tags (dillo plugin protocol tags). More...
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include "dpip.h"
#include "d_size.h"
Go to the source code of this file.
Macros | |
#define | RBUF_SZ 16*1024 |
#define | DPIP_TAG_END " '>" |
#define | DPIP_MODE_SWITCH_TAG "cmd='start_send_page' " |
#define | MSG_ERR(...) fprintf(stderr, "[dpip]: " __VA_ARGS__) |
Enumerations | |
enum | DpipTagParsingState { SEEK_NAME , MATCH_NAME , SKIP_VALUE , SKIP_QUOTE , FOUND } |
Functions | |
char * | a_Dpip_build_cmd (const char *format,...) |
Printf like function for building dpip commands. | |
char * | a_Dpip_get_attr_l (const char *tag, size_t tagsize, const char *attrname) |
Task: given a tag, its size and an attribute name, return the attribute value (stuffing of ' is removed here). | |
char * | a_Dpip_get_attr (const char *tag, const char *attrname) |
Task: given a tag and an attribute name, return its value. | |
int | a_Dpip_check_auth (const char *auth_tag) |
Check whether the given 'auth' string equals what dpid saved. | |
Dsh * | a_Dpip_dsh_new (int fd_in, int fd_out, int flush_sz) |
Create and initialize a dpip socket handler. | |
static int | Dpip_dsh_write (Dsh *dsh, int nb, const char *Data, int DataSize) |
int | a_Dpip_dsh_write (Dsh *dsh, int flush, const char *Data, int DataSize) |
Streamed write to socket. | |
int | a_Dpip_dsh_tryflush (Dsh *dsh) |
int | a_Dpip_dsh_trywrite (Dsh *dsh, const char *Data, int DataSize) |
int | a_Dpip_dsh_write_str (Dsh *dsh, int flush, const char *str) |
Convenience function. | |
static void | Dpip_dsh_read (Dsh *dsh, int blocking) |
Read raw data from the socket into our buffer in either BLOCKING or NONBLOCKING mode. | |
char * | a_Dpip_dsh_read_token2 (Dsh *dsh, int blocking, int *DataSize) |
Return a newlly allocated string with the next dpip token in the socket. | |
char * | a_Dpip_dsh_read_token (Dsh *dsh, int blocking) |
Return a newlly allocated string with the next dpip token in the socket. | |
void | a_Dpip_dsh_close (Dsh *dsh) |
Close this socket for reading and writing. | |
void | a_Dpip_dsh_free (Dsh *dsh) |
Free the SockHandler structure. | |
Variables | |
static const char | Quote = '\'' |
Library for dealing with dpip tags (dillo plugin protocol tags).
Basically the syntax of a dpip tag is:
e.g. (with ' as Quote):
Notes:
Definition in file dpip.c.
#define MSG_ERR | ( | ... | ) | fprintf(stderr, "[dpip]: " __VA_ARGS__) |
enum DpipTagParsingState |
char * a_Dpip_build_cmd | ( | const char * | format, |
... | |||
) |
Printf like function for building dpip commands.
It takes care of dpip escaping of its arguments. NOTE : It ONLY accepts string parameters, and only one s per parameter.
Definition at line 83 of file dpip.c.
References dStr_append(), dStr_append_c(), dStr_free(), dStr_sized_new(), FALSE, Quote, and Dstr::str.
Referenced by a_Bookmarks_add(), a_Bookmarks_chat_add(), a_Cookies_get_query(), a_Cookies_get_query(), a_Cookies_set(), a_Cookies_set(), Bmsrv_dpi_send_status_msg(), Bmsrv_parse_token(), Bmsrv_send_modify_answer(), Bmsrv_send_reload_request(), Capi_dpi_build_cmd(), Capi_dpi_send_source(), Dpi_connect_socket(), Dpi_connect_socket(), Dpi_get_server_port(), Dpi_get_server_port(), Dpiapi_dialog_answer_cb(), File_send_dir(), File_send_error_page(), File_send_file(), File_toggle_html_style(), get_command(), get_message(), main(), main(), send_decoded_data(), send_failure_message(), send_sockport(), srv_parse_tok(), stop_active_dpis(), and try_ftp_transfer().
int a_Dpip_check_auth | ( | const char * | auth_tag | ) |
Check whether the given 'auth' string equals what dpid saved.
Return value: 1 if equal, -1 otherwise
Definition at line 201 of file dpip.c.
References a_Dpip_get_attr(), dFree(), dGethomedir(), dGetline(), dStrconcat(), dStrerror, and MSG_ERR.
Referenced by File_serve_client(), main(), main(), read_req_cb(), and srv_parse_tok().
void a_Dpip_dsh_close | ( | Dsh * | dsh | ) |
Close this socket for reading and writing.
(flush pending data)
Definition at line 504 of file dpip.c.
References a_Dpip_dsh_write(), dClose(), dStrerror, Dsh::fd_in, Dsh::fd_out, and MSG_ERR.
Referenced by File_remove_client(), main(), main(), and read_req_cb().
void a_Dpip_dsh_free | ( | Dsh * | dsh | ) |
Free the SockHandler structure.
Definition at line 525 of file dpip.c.
References dFree(), dReturn_if, dStr_free(), Dsh::rdbuf, and Dsh::wrbuf.
Referenced by File_remove_client(), main(), main(), and read_req_cb().
Dsh * a_Dpip_dsh_new | ( | int | fd_in, |
int | fd_out, | ||
int | flush_sz | ||
) |
Create and initialize a dpip socket handler.
Definition at line 247 of file dpip.c.
References dNew, DPIP_NONBLOCK, DPIP_TAG, dStr_sized_new(), Dsh::fd_in, Dsh::fd_out, Dsh::flush_sz, Dsh::mode, Dsh::rdbuf, Dsh::status, and Dsh::wrbuf.
Referenced by File_add_client(), main(), main(), and read_req_cb().
char * a_Dpip_dsh_read_token | ( | Dsh * | dsh, |
int | blocking | ||
) |
Return a newlly allocated string with the next dpip token in the socket.
Return value: token string on success, NULL otherwise
Definition at line 493 of file dpip.c.
References a_Dpip_dsh_read_token2().
Referenced by File_serve_client(), get_request(), main(), main(), and read_req_cb().
char * a_Dpip_dsh_read_token2 | ( | Dsh * | dsh, |
int | blocking, | ||
int * | DataSize | ||
) |
Return a newlly allocated string with the next dpip token in the socket.
Return value: token string and length on success, NULL otherwise. (useful for handling null characters in the data stream)
Definition at line 438 of file dpip.c.
References Dpip_dsh_read(), DPIP_EOF, DPIP_ERROR, DPIP_LAST_TAG, DPIP_MODE_SWITCH_TAG, DPIP_RAW, DPIP_TAG, DPIP_TAG_END, dStr_erase(), dStr_truncate(), dStrndup(), Dstr::len, Dsh::mode, Dsh::rdbuf, Dsh::status, and Dstr::str.
Referenced by a_Dpip_dsh_read_token(), send_html_text(), send_numbered_text(), and send_plain_text().
int a_Dpip_dsh_tryflush | ( | Dsh * | dsh | ) |
Definition at line 340 of file dpip.c.
References Dpip_dsh_write(), dStr_erase(), Dstr::len, Dstr::str, and Dsh::wrbuf.
Referenced by File_send_file().
int a_Dpip_dsh_trywrite | ( | Dsh * | dsh, |
const char * | Data, | ||
int | DataSize | ||
) |
Definition at line 359 of file dpip.c.
References Dpip_dsh_write(), dStr_append_l(), and Dsh::wrbuf.
Referenced by File_send_file().
int a_Dpip_dsh_write | ( | Dsh * | dsh, |
int | flush, | ||
const char * | Data, | ||
int | DataSize | ||
) |
Streamed write to socket.
Return: 0 on success, 1 on error.
Definition at line 317 of file dpip.c.
References Dpip_dsh_write(), dStr_append_l(), dStr_truncate(), Dstr::len, Dstr::str, and Dsh::wrbuf.
Referenced by a_Dpip_dsh_close(), a_Dpip_dsh_write_str(), main(), send_decoded_data(), send_html_text(), send_numbered_text(), send_plain_text(), and try_ftp_transfer().
int a_Dpip_dsh_write_str | ( | Dsh * | dsh, |
int | flush, | ||
const char * | str | ||
) |
Convenience function.
Definition at line 374 of file dpip.c.
References a_Dpip_dsh_write().
Referenced by Bmsrv_dpi_send_status_msg(), Bmsrv_parse_token(), Bmsrv_send_modify_answer(), Bmsrv_send_modify_page(), Bmsrv_send_modify_page_add_section(), Bmsrv_send_modify_page_add_url(), Bmsrv_send_modify_update(), Bmsrv_send_reload_request(), File_info2html(), File_send_dir(), File_send_error_page(), File_send_file(), File_toggle_html_style(), get_command(), main(), main(), send_bm_page(), send_decoded_data(), send_dpip_tag(), send_failure_message(), send_html_text(), send_numbered_text(), send_plain_text(), srv_parse_tok(), and try_ftp_transfer().
char * a_Dpip_get_attr | ( | const char * | tag, |
const char * | attrname | ||
) |
Task: given a tag and an attribute name, return its value.
Return value: the attribute value, or NULL if not present or malformed.
Definition at line 192 of file dpip.c.
References a_Dpip_get_attr_l().
Referenced by a_Cookies_get_query(), a_Cookies_get_query(), a_Dpip_check_auth(), Dpi_get_server_port(), Dpi_get_server_port(), File_serve_client(), get_command(), get_message(), main(), main(), and read_req_cb().
char * a_Dpip_get_attr_l | ( | const char * | tag, |
size_t | tagsize, | ||
const char * | attrname | ||
) |
Task: given a tag, its size and an attribute name, return the attribute value (stuffing of ' is removed here).
Return value: the attribute value, or NULL if not present or malformed.
Definition at line 134 of file dpip.c.
References dStrndup(), FOUND, MATCH_NAME, Quote, SEEK_NAME, SKIP_QUOTE, and SKIP_VALUE.
Referenced by a_Dpiapi_dialog(), a_Dpip_get_attr(), Bmsrv_parse_token(), Dpi_parse_token(), and srv_parse_tok().
|
static |
Read raw data from the socket into our buffer in either BLOCKING or NONBLOCKING mode.
Definition at line 383 of file dpip.c.
References Dpip_dsh_read(), DPIP_EAGAIN, DPIP_EOF, DPIP_ERROR, DPIP_NONBLOCK, dReturn_if, dStr_append_l(), dStrerror, Dsh::fd_in, Dsh::fd_out, Dsh::mode, MSG_ERR, RBUF_SZ, Dsh::rdbuf, and Dsh::status.
Referenced by a_Dpip_dsh_read_token2(), and Dpip_dsh_read().
|
static |
Definition at line 270 of file dpip.c.
References DPIP_EAGAIN, DPIP_ERROR, DPIP_NONBLOCK, dStrerror, Dsh::fd_out, Dsh::mode, MSG_ERR, and Dsh::status.
Referenced by a_Dpip_dsh_tryflush(), a_Dpip_dsh_trywrite(), and a_Dpip_dsh_write().
|
static |
Definition at line 35 of file dpip.c.
Referenced by a_Dpip_build_cmd(), and a_Dpip_get_attr_l().