ELinks 0.16.1.1
bencoding.c File Reference
#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include "elinks.h"
#include "protocol/bittorrent/bencoding.h"
#include "protocol/bittorrent/common.h"
#include "util/error.h"
#include "util/sha1.h"
#include "util/scanner.h"
#include "util/string.h"
#include "util/time.h"
Include dependency graph for bencoding.c:

Data Structures

struct  bencoding_dictionary_info

Macros

#define is_bencoding_integer(c)
#define is_bencoding_list(c)
#define is_bencoding_dictionary(c)
#define is_bencoding_end(c)
#define is_bencoding_string(c)
#define scan_bencoding_integer(scanner, s)
#define DICT(key, keytype, valuetype)

Enumerations

enum  bencoding_token {
  BENCODING_TOKEN_INTEGER = 'i' , BENCODING_TOKEN_LIST = 'l' , BENCODING_TOKEN_DICTIONARY = 'd' , BENCODING_TOKEN_END = 'e' ,
  BENCODING_TOKEN_STRING = 256 , BENCODING_TOKEN_FILES , BENCODING_TOKEN_NAME , BENCODING_TOKEN_ANNOUNCE ,
  BENCODING_TOKEN_ANNOUNCE_LIST , BENCODING_TOKEN_COMMENT , BENCODING_TOKEN_CREATED_BY , BENCODING_TOKEN_CREATION_DATE ,
  BENCODING_TOKEN_INFO , BENCODING_TOKEN_LENGTH , BENCODING_TOKEN_MD5SUM , BENCODING_TOKEN_PATH ,
  BENCODING_TOKEN_PIECES , BENCODING_TOKEN_PIECE_LENGTH , BENCODING_TOKEN_FAILURE_REASON , BENCODING_TOKEN_INTERVAL ,
  BENCODING_TOKEN_IP , BENCODING_TOKEN_PEERS , BENCODING_TOKEN_PEER_ID , BENCODING_TOKEN_PORT ,
  BENCODING_TOKEN_COMPLETE , BENCODING_TOKEN_DOWNLOADED , BENCODING_TOKEN_INCOMPLETE , BENCODING_TOKEN_NONE = 0 ,
  BENCODING_TOKEN_ERROR = 1
}

Functions

static void scan_bencoding_token (struct scanner *scanner, struct scanner_token *token)
static void skip_bencoding_tokens (struct scanner *scanner)
static struct scanner_tokenscan_bencoding_tokens (struct scanner *scanner)
enum bencoding_token check_bencoding_dictionary_entry (struct scanner *scanner, struct scanner_token **value_ptr)
static off_t parse_bencoding_integer (struct scanner_token *token)
static char * normalize_bencoding_path (const char *path, int pathlen, int *malicious)
static enum bittorrent_state add_bittorrent_file (struct bittorrent_meta *meta, char *path, struct bittorrent_file *template_)
static enum bittorrent_state parse_bencoding_file_path (struct scanner *scanner, struct string *path)
static enum bittorrent_state parse_bencoding_file_dictionary (struct bittorrent_meta *meta, struct scanner *scanner, struct string *path)
static enum bittorrent_state parse_bencoding_files_list (struct bittorrent_meta *meta, struct scanner *scanner)
static enum bittorrent_state parse_bencoding_info_dictionary (struct bittorrent_meta *meta, struct scanner *scanner)
static enum bittorrent_state check_bittorrent_metafile (struct bittorrent_meta *meta)
enum bittorrent_state parse_bittorrent_metafile (struct bittorrent_meta *meta, struct bittorrent_const_string *metafile)
static enum bittorrent_state parse_bencoding_peer_dictionary (struct bittorrent_connection *bittorrent, struct scanner *scanner)
static enum bittorrent_state parse_bencoding_peers_list (struct bittorrent_connection *bittorrent, struct scanner *scanner)
static enum bittorrent_state parse_bencoding_peers_string (struct bittorrent_connection *bittorrent, struct scanner *scanner)
enum bittorrent_state parse_bittorrent_tracker_response (struct bittorrent_connection *bittorrent, struct bittorrent_const_string *response)

Variables

struct scanner_info bencoding_scanner_info
static const struct bencoding_dictionary_info bencoding_dictionary_entries []

Macro Definition Documentation

◆ DICT

#define DICT ( key,
keytype,
valuetype )
Value:
{ key, BENCODING_TOKEN_##keytype, BENCODING_TOKEN_##valuetype }

◆ is_bencoding_dictionary

#define is_bencoding_dictionary ( c)
Value:
@ BENCODING_TOKEN_DICTIONARY
Definition bencoding.c:42

◆ is_bencoding_end

#define is_bencoding_end ( c)
Value:
@ BENCODING_TOKEN_END
Definition bencoding.c:43

◆ is_bencoding_integer

#define is_bencoding_integer ( c)
Value:
@ BENCODING_TOKEN_INTEGER
Definition bencoding.c:40

◆ is_bencoding_list

#define is_bencoding_list ( c)
Value:
@ BENCODING_TOKEN_LIST
Definition bencoding.c:41

◆ is_bencoding_string

#define is_bencoding_string ( c)
Value:
(isdigit(c))
#define isdigit(a)
strchr()
Definition stub.h:60

◆ scan_bencoding_integer

#define scan_bencoding_integer ( scanner,
s )
Value:
while ((s) < (scanner)->end && isdigit(*(s))) (s)++;
const char * s
Definition general.c:826
The struct scanner describes the current state of the scanner.
Definition scanner.h:107

Enumeration Type Documentation

◆ bencoding_token

Enumerator
BENCODING_TOKEN_INTEGER 
BENCODING_TOKEN_LIST 
BENCODING_TOKEN_DICTIONARY 
BENCODING_TOKEN_END 
BENCODING_TOKEN_STRING 
BENCODING_TOKEN_FILES 
BENCODING_TOKEN_NAME 
BENCODING_TOKEN_ANNOUNCE 
BENCODING_TOKEN_ANNOUNCE_LIST 
BENCODING_TOKEN_COMMENT 
BENCODING_TOKEN_CREATED_BY 
BENCODING_TOKEN_CREATION_DATE 
BENCODING_TOKEN_INFO 
BENCODING_TOKEN_LENGTH 
BENCODING_TOKEN_MD5SUM 
BENCODING_TOKEN_PATH 
BENCODING_TOKEN_PIECES 
BENCODING_TOKEN_PIECE_LENGTH 
BENCODING_TOKEN_FAILURE_REASON 
BENCODING_TOKEN_INTERVAL 
BENCODING_TOKEN_IP 
BENCODING_TOKEN_PEERS 
BENCODING_TOKEN_PEER_ID 
BENCODING_TOKEN_PORT 
BENCODING_TOKEN_COMPLETE 
BENCODING_TOKEN_DOWNLOADED 
BENCODING_TOKEN_INCOMPLETE 
BENCODING_TOKEN_NONE 
BENCODING_TOKEN_ERROR 

Function Documentation

◆ add_bittorrent_file()

enum bittorrent_state add_bittorrent_file ( struct bittorrent_meta * meta,
char * path,
struct bittorrent_file * template_ )
static

◆ check_bencoding_dictionary_entry()

enum bencoding_token check_bencoding_dictionary_entry ( struct scanner * scanner,
struct scanner_token ** value_ptr )

◆ check_bittorrent_metafile()

enum bittorrent_state check_bittorrent_metafile ( struct bittorrent_meta * meta)
static

◆ normalize_bencoding_path()

char * normalize_bencoding_path ( const char * path,
int pathlen,
int * malicious )
static

◆ parse_bencoding_file_dictionary()

enum bittorrent_state parse_bencoding_file_dictionary ( struct bittorrent_meta * meta,
struct scanner * scanner,
struct string * path )
static

◆ parse_bencoding_file_path()

enum bittorrent_state parse_bencoding_file_path ( struct scanner * scanner,
struct string * path )
static

◆ parse_bencoding_files_list()

enum bittorrent_state parse_bencoding_files_list ( struct bittorrent_meta * meta,
struct scanner * scanner )
static

◆ parse_bencoding_info_dictionary()

enum bittorrent_state parse_bencoding_info_dictionary ( struct bittorrent_meta * meta,
struct scanner * scanner )
static

◆ parse_bencoding_integer()

off_t parse_bencoding_integer ( struct scanner_token * token)
static

◆ parse_bencoding_peer_dictionary()

enum bittorrent_state parse_bencoding_peer_dictionary ( struct bittorrent_connection * bittorrent,
struct scanner * scanner )
static

◆ parse_bencoding_peers_list()

enum bittorrent_state parse_bencoding_peers_list ( struct bittorrent_connection * bittorrent,
struct scanner * scanner )
static

◆ parse_bencoding_peers_string()

enum bittorrent_state parse_bencoding_peers_string ( struct bittorrent_connection * bittorrent,
struct scanner * scanner )
static

◆ parse_bittorrent_metafile()

enum bittorrent_state parse_bittorrent_metafile ( struct bittorrent_meta * meta,
struct bittorrent_const_string * metafile )

◆ parse_bittorrent_tracker_response()

enum bittorrent_state parse_bittorrent_tracker_response ( struct bittorrent_connection * bittorrent,
struct bittorrent_const_string * response )

◆ scan_bencoding_token()

void scan_bencoding_token ( struct scanner * scanner,
struct scanner_token * token )
inlinestatic

◆ scan_bencoding_tokens()

struct scanner_token * scan_bencoding_tokens ( struct scanner * scanner)
static

◆ skip_bencoding_tokens()

void skip_bencoding_tokens ( struct scanner * scanner)
static

Variable Documentation

◆ bencoding_dictionary_entries

const struct bencoding_dictionary_info bencoding_dictionary_entries[]
static
Initial value:
= {
DICT("announce list", ANNOUNCE_LIST, LIST),
DICT("announce", ANNOUNCE, STRING),
DICT("comment", COMMENT, STRING),
DICT("complete", COMPLETE, INTEGER),
DICT("created by", CREATED_BY, STRING),
DICT("creation date", CREATION_DATE, INTEGER),
DICT("downloaded", DOWNLOADED, INTEGER),
DICT("failure reason", FAILURE_REASON, STRING),
DICT("files", FILES, LIST),
DICT("incomplete", INCOMPLETE, INTEGER),
DICT("info", INFO, DICTIONARY),
DICT("interval", INTERVAL, INTEGER),
DICT("ip", IP, STRING),
DICT("length", LENGTH, INTEGER),
DICT("md5sum", MD5SUM, STRING),
DICT("name", NAME, STRING),
DICT("path", PATH, LIST),
DICT("peer id", PEER_ID, STRING),
DICT("peers", PEERS, LIST),
DICT("peers", PEERS, STRING),
DICT("piece length", PIECE_LENGTH, INTEGER),
DICT("pieces", PIECES, STRING),
DICT("port", PORT, INTEGER),
DICT(NULL, NONE, NONE),
}
#define DICT(key, keytype, valuetype)
Definition bencoding.c:249
#define NULL
Definition explodename.c:35

◆ bencoding_scanner_info

struct scanner_info bencoding_scanner_info
Initial value:
= {
}
static struct scanner_token * scan_bencoding_tokens(struct scanner *scanner)
Definition bencoding.c:204