Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dpip.c File Reference

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"
Include dependency graph for dpip.c:

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.
 
Dsha_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 = '\''
 

Detailed Description

Library for dealing with dpip tags (dillo plugin protocol tags).

Basically the syntax of a dpip tag is:

"<"[*alpha] *(<name>"="Quote<escaped_value>Quote) " "Quote">"
static const char Quote
Definition dpip.c:35
  1. No space is allowed around the "=" sign between a name and its value.
  2. The Quote character is not allowed in <name>.
  3. Attribute values stuff Quote as QuoteQuote.

e.g. (with ' as Quote):

<a='b' b='c' '> OK
<dpi a='b i' b='12' '> OK
<a='>' '> OK
<a='ain''t no doubt' '> OK
<a='ain''t b=''no'' b='' doubt' '> OK
<a = '>' '> Wrong

Notes:

  • Restriction #1 is for easy finding of end of tag (EOT=Space+Quote+>).
  • Restriction #2 can be removed, but what for? ;)
  • The functions here provide for this functionality.

Definition in file dpip.c.

Macro Definition Documentation

◆ DPIP_MODE_SWITCH_TAG

#define DPIP_MODE_SWITCH_TAG   "cmd='start_send_page' "

Definition at line 29 of file dpip.c.

◆ DPIP_TAG_END

#define DPIP_TAG_END   " '>"

Definition at line 28 of file dpip.c.

◆ MSG_ERR

#define MSG_ERR (   ...)    fprintf(stderr, "[dpip]: " __VA_ARGS__)

Definition at line 30 of file dpip.c.

◆ RBUF_SZ

#define RBUF_SZ   16*1024

Definition at line 25 of file dpip.c.

Enumeration Type Documentation

◆ DpipTagParsingState

Enumerator
SEEK_NAME 
MATCH_NAME 
SKIP_VALUE 
SKIP_QUOTE 
FOUND 

Definition at line 67 of file dpip.c.

Function Documentation

◆ a_Dpip_build_cmd()

◆ a_Dpip_check_auth()

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().

◆ a_Dpip_dsh_close()

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().

◆ a_Dpip_dsh_free()

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().

◆ a_Dpip_dsh_new()

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().

◆ a_Dpip_dsh_read_token()

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().

◆ a_Dpip_dsh_read_token2()

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().

◆ a_Dpip_dsh_tryflush()

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().

◆ a_Dpip_dsh_trywrite()

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().

◆ a_Dpip_dsh_write()

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().

◆ a_Dpip_dsh_write_str()

◆ a_Dpip_get_attr()

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().

◆ a_Dpip_get_attr_l()

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().

◆ Dpip_dsh_read()

static void Dpip_dsh_read ( Dsh dsh,
int  blocking 
)
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().

◆ Dpip_dsh_write()

static int Dpip_dsh_write ( Dsh dsh,
int  nb,
const char *  Data,
int  DataSize 
)
static

Variable Documentation

◆ Quote

const char Quote = '\''
static

Definition at line 35 of file dpip.c.

Referenced by a_Dpip_build_cmd(), and a_Dpip_get_attr_l().