Tor  0.4.7.0-alpha-dev
Functions
control_proto.c File Reference

Formatting functions for controller data. More...

#include "core/or/or.h"
#include "core/mainloop/connection.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/connection_edge.h"
#include "feature/control/control_proto.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/cpath_build_state_st.h"
#include "core/or/entry_connection_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/socks_request_st.h"
#include "feature/control/control_connection_st.h"
#include "lib/container/smartlist.h"
#include "lib/encoding/kvline.h"

Go to the source code of this file.

Functions

void connection_write_str_to_buf (const char *s, control_connection_t *conn)
 
void connection_printf_to_buf (control_connection_t *conn, const char *format,...)
 
size_t write_escaped_data (const char *data, size_t len, char **out)
 
size_t read_escaped_data (const char *data, size_t len, char **out)
 
void send_control_done (control_connection_t *conn)
 
void control_write_reply (control_connection_t *conn, int code, int c, const char *s)
 
void control_vprintf_reply (control_connection_t *conn, int code, int c, const char *fmt, va_list ap)
 
void control_write_endreply (control_connection_t *conn, int code, const char *s)
 
void control_printf_endreply (control_connection_t *conn, int code, const char *fmt,...)
 
void control_write_midreply (control_connection_t *conn, int code, const char *s)
 
void control_printf_midreply (control_connection_t *conn, int code, const char *fmt,...)
 
void control_write_datareply (control_connection_t *conn, int code, const char *s)
 
void control_printf_datareply (control_connection_t *conn, int code, const char *fmt,...)
 
void control_write_data (control_connection_t *conn, const char *data)
 
void control_write_reply_line (control_connection_t *conn, const control_reply_line_t *line, bool lastone)
 
void control_write_reply_lines (control_connection_t *conn, smartlist_t *lines)
 
void control_reply_add_one_kv (smartlist_t *reply, int code, int flags, const char *key, const char *val)
 
void control_reply_append_kv (smartlist_t *reply, const char *key, const char *val)
 
void control_reply_add_str (smartlist_t *reply, int code, const char *s)
 
void control_reply_add_printf (smartlist_t *reply, int code, const char *fmt,...)
 
void control_reply_add_done (smartlist_t *reply)
 
void control_reply_line_free_ (control_reply_line_t *line)
 
void control_reply_clear (smartlist_t *reply)
 
void control_reply_free_ (smartlist_t *reply)
 

Detailed Description

Formatting functions for controller data.

Definition in file control_proto.c.

Function Documentation

◆ connection_printf_to_buf()

void connection_printf_to_buf ( control_connection_t conn,
const char *  format,
  ... 
)

Acts like sprintf, but writes its formatted string to the end of conn->outbuf.

Definition at line 41 of file control_proto.c.

Referenced by control_write_reply().

◆ connection_write_str_to_buf()

void connection_write_str_to_buf ( const char *  s,
control_connection_t conn 
)

Append a NUL-terminated string s to the end of conn->outbuf.

Definition at line 32 of file control_proto.c.

Referenced by control_send_http_reject().

◆ control_printf_datareply()

void control_printf_datareply ( control_connection_t conn,
int  code,
const char *  fmt,
  ... 
)

Write a formatted DataReplyLine

Definition at line 259 of file control_proto.c.

Referenced by control_write_reply_line().

◆ control_printf_endreply()

void control_printf_endreply ( control_connection_t conn,
int  code,
const char *  fmt,
  ... 
)

◆ control_printf_midreply()

void control_printf_midreply ( control_connection_t conn,
int  code,
const char *  fmt,
  ... 
)

Write a formatted MidReplyLine

Definition at line 240 of file control_proto.c.

◆ control_vprintf_reply()

void control_vprintf_reply ( control_connection_t conn,
int  code,
int  c,
const char *  fmt,
va_list  ap 
)

Write a formatted reply to the control channel.

Parameters
conncontrol connection
codenumeric result code
cseparator character, usually ' ', '-', or '+'
fmtformat string
apva_list from caller

Definition at line 197 of file control_proto.c.

Referenced by control_printf_datareply(), control_printf_endreply(), and control_printf_midreply().

◆ control_write_data()

void control_write_data ( control_connection_t conn,
const char *  data 
)

Write a CmdData

Definition at line 271 of file control_proto.c.

Referenced by control_write_reply_line().

◆ control_write_datareply()

void control_write_datareply ( control_connection_t conn,
int  code,
const char *  s 
)

Write a DataReplyLine

Definition at line 252 of file control_proto.c.

◆ control_write_endreply()

void control_write_endreply ( control_connection_t conn,
int  code,
const char *  s 
)

◆ control_write_midreply()

void control_write_midreply ( control_connection_t conn,
int  code,
const char *  s 
)

Write a MidReplyLine

Definition at line 233 of file control_proto.c.

Referenced by control_write_reply_line().

◆ control_write_reply()

void control_write_reply ( control_connection_t conn,
int  code,
int  c,
const char *  s 
)

Write a reply to the control channel.

Parameters
conncontrol connection
codenumeric result code
cseparator character, usually ' ', '-', or '+'
sstring reply content

Definition at line 183 of file control_proto.c.

Referenced by control_write_datareply(), control_write_endreply(), and control_write_midreply().

◆ read_escaped_data()

size_t read_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, removing any period that appears at the start of a line, and replacing all CRLF sequences with LF. Return the number of bytes in *out.

This corresponds to CmdData in control-spec.txt.

Definition at line 130 of file control_proto.c.

◆ send_control_done()

void send_control_done ( control_connection_t conn)

Send a "DONE" message down the control connection conn.

Definition at line 169 of file control_proto.c.

Referenced by handle_control_hspost(), handle_control_postdescriptor(), and handle_control_saveconf().

◆ write_escaped_data()

size_t write_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, adding a period before any period that appears at the start of a line, and adding a period-CRLF line at the end. Replace all LF characters sequences with CRLF. Return the number of bytes in *out.

This corresponds to CmdData in control-spec.txt.

Definition at line 71 of file control_proto.c.

Referenced by control_write_data().