libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
client.c File Reference
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "coap.h"

Go to the source code of this file.

Data Structures

struct  content_type_t
 

Macros

#define FLAGS_BLOCK   0x01
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define HANDLE_BLOCK1(Pdu)
 
#define BUFSIZE   40
 

Typedefs

typedef unsigned char method_t
 

Functions

static void set_timeout (coap_tick_t *timer, const unsigned int seconds)
 
int append_to_output (const unsigned char *data, size_t len)
 
void close_output ()
 
coap_pdu_tnew_ack (coap_context_t *ctx, coap_queue_t *node)
 
coap_pdu_tnew_response (coap_context_t *ctx, coap_queue_t *node, unsigned int code)
 
coap_pdu_tcoap_new_request (coap_context_t *ctx, method_t m, coap_list_t *options)
 
coap_tid_t clear_obs (coap_context_t *ctx, const coap_address_t *remote)
 
int resolve_address (const str *server, struct sockaddr *dst)
 
static coap_opt_tget_block (coap_pdu_t *pdu, coap_opt_iterator_t *opt_iter)
 
int check_token (coap_pdu_t *received)
 
void message_handler (struct coap_context_t *ctx, const coap_address_t *remote, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id)
 
void usage (const char *program, const char *version)
 
int join (coap_context_t *ctx, char *group_name)
 
int order_opts (void *a, void *b)
 
coap_list_tnew_option_node (unsigned short key, unsigned int length, unsigned char *data)
 
void cmdline_content_type (char *arg, unsigned short key)
 
void cmdline_uri (char *arg)
 
int cmdline_blocksize (char *arg)
 
void set_blocksize ()
 
void cmdline_subscribe (char *arg)
 
int cmdline_proxy (char *arg)
 
void cmdline_token (char *arg)
 
void cmdline_option (char *arg)
 
int check_segment (const unsigned char *s, size_t length)
 Runs through the given path (or query) segment and checks if percent-encodings are correct. More...
 
void decode_segment (const unsigned char *seg, size_t length, unsigned char *buf)
 Decodes percent-encoded characters while copying the string seg of size length to buf. More...
 
int cmdline_input (char *text, str *buf)
 
int cmdline_input_from_file (char *filename, str *buf)
 
method_t cmdline_method (char *arg)
 
coap_context_tget_context (const char *node, const char *port)
 
int main (int argc, char **argv)
 

Variables

int flags = 0
 
static unsigned char _token_data [8]
 
str the_token = { 0, _token_data }
 
static coap_list_toptlist = NULL
 
static coap_uri_t uri
 
static str proxy = { 0, NULL }
 
static unsigned short proxy_port = COAP_DEFAULT_PORT
 
static int ready = 0
 
static str output_file = { 0, NULL }
 
static FILE * file = NULL
 
static str payload = { 0, NULL }
 
unsigned char msgtype = COAP_MESSAGE_CON
 
method_t method = 1
 
coap_block_t block = { .num = 0, .m = 0, .szx = 6 }
 
unsigned int wait_seconds = 90
 
coap_tick_t max_wait
 
unsigned int obs_seconds = 30
 
coap_tick_t obs_wait = 0
 

Macro Definition Documentation

#define BUFSIZE   40
#define FLAGS_BLOCK   0x01

Definition at line 31 of file client.c.

#define HANDLE_BLOCK1 (   Pdu)
Value:
((flags & FLAGS_BLOCK) == 0) && \
((Pdu)->hdr->code == COAP_RESPONSE_CODE(201) || \
(Pdu)->hdr->code == COAP_RESPONSE_CODE(204)))
#define COAP_REQUEST_POST
Definition: pdu.h:51
#define FLAGS_BLOCK
Definition: client.c:31
#define COAP_RESPONSE_CODE(N)
Definition: pdu.h:92
method_t method
Definition: client.c:51
int flags
Definition: client.c:26
#define COAP_REQUEST_PUT
Definition: pdu.h:52

Definition at line 262 of file client.c.

#define min (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 61 of file client.c.

Typedef Documentation

typedef unsigned char method_t

Definition at line 50 of file client.c.

Function Documentation

int append_to_output ( const unsigned char *  data,
size_t  len 
)

Definition at line 70 of file client.c.

int check_segment ( const unsigned char *  s,
size_t  length 
)

Runs through the given path (or query) segment and checks if percent-encodings are correct.

This function returns -1 on error or the length of s when decoded.

Definition at line 219 of file uri.c.

int check_token ( coap_pdu_t received)
inline

Definition at line 269 of file client.c.

coap_tid_t clear_obs ( coap_context_t ctx,
const coap_address_t *  remote 
)

Definition at line 166 of file client.c.

void close_output ( )

Definition at line 95 of file client.c.

int cmdline_blocksize ( char *  arg)

Definition at line 690 of file client.c.

void cmdline_content_type ( char *  arg,
unsigned short  key 
)

Definition at line 566 of file client.c.

int cmdline_input ( char *  text,
str buf 
)

Definition at line 793 of file client.c.

int cmdline_input_from_file ( char *  filename,
str buf 
)

Definition at line 810 of file client.c.

method_t cmdline_method ( char *  arg)

Definition at line 867 of file client.c.

void cmdline_option ( char *  arg)

Definition at line 774 of file client.c.

int cmdline_proxy ( char *  arg)

Definition at line 735 of file client.c.

void cmdline_subscribe ( char *  arg)

Definition at line 728 of file client.c.

void cmdline_token ( char *  arg)
inline

Definition at line 768 of file client.c.

void cmdline_uri ( char *  arg)

Definition at line 624 of file client.c.

coap_pdu_t* coap_new_request ( coap_context_t ctx,
method_t  m,
coap_list_t options 
)

Definition at line 131 of file client.c.

void decode_segment ( const unsigned char *  seg,
size_t  length,
unsigned char *  buf 
)

Decodes percent-encoded characters while copying the string seg of size length to buf.

The caller of this function must ensure that the percent-encodings are correct (i.e. the character '' is always followed by two hex digits. and that buf provides sufficient space to hold the result. This function is supposed to be called by make_decoded_option() only.

Parameters
segThe segment to decode and copy.
lengthLength of seg.
bufThe result buffer.

Definition at line 197 of file uri.c.

static coap_opt_t* get_block ( coap_pdu_t pdu,
coap_opt_iterator_t opt_iter 
)
inlinestatic

Definition at line 249 of file client.c.

coap_context_t* get_context ( const char *  node,
const char *  port 
)

Definition at line 879 of file client.c.

int join ( coap_context_t ctx,
char *  group_name 
)

Definition at line 464 of file client.c.

int main ( int  argc,
char **  argv 
)

Definition at line 921 of file client.c.

void message_handler ( struct coap_context_t ctx,
const coap_address_t *  remote,
coap_pdu_t sent,
coap_pdu_t received,
const coap_tid_t  id 
)

Definition at line 275 of file client.c.

coap_pdu_t* new_ack ( coap_context_t ctx,
coap_queue_t node 
)

Definition at line 108 of file client.c.

coap_list_t* new_option_node ( unsigned short  key,
unsigned int  length,
unsigned char *  data 
)

Definition at line 536 of file client.c.

coap_pdu_t* new_response ( coap_context_t ctx,
coap_queue_t node,
unsigned int  code 
)

Definition at line 121 of file client.c.

int order_opts ( void *  a,
void *  b 
)

Definition at line 524 of file client.c.

int resolve_address ( const str server,
struct sockaddr *  dst 
)

Definition at line 207 of file client.c.

void set_blocksize ( )

Definition at line 714 of file client.c.

static void set_timeout ( coap_tick_t *  timer,
const unsigned int  seconds 
)
inlinestatic

Definition at line 64 of file client.c.

void usage ( const char *  program,
const char *  version 
)

Definition at line 418 of file client.c.

Variable Documentation

unsigned char _token_data[8]
static

Definition at line 28 of file client.c.

coap_block_t block = { .num = 0, .m = 0, .szx = 6 }

Definition at line 53 of file client.c.

FILE* file = NULL
static

Definition at line 44 of file client.c.

int flags = 0

Definition at line 26 of file client.c.

coap_tick_t max_wait

Definition at line 56 of file client.c.

method_t method = 1

Definition at line 51 of file client.c.

unsigned char msgtype = COAP_MESSAGE_CON

Definition at line 48 of file client.c.

unsigned int obs_seconds = 30

Definition at line 58 of file client.c.

coap_tick_t obs_wait = 0

Definition at line 59 of file client.c.

coap_list_t* optlist = NULL
static

Definition at line 33 of file client.c.

str output_file = { 0, NULL }
static

Definition at line 43 of file client.c.

str payload = { 0, NULL }
static

Definition at line 46 of file client.c.

str proxy = { 0, NULL }
static

Definition at line 37 of file client.c.

unsigned short proxy_port = COAP_DEFAULT_PORT
static

Definition at line 38 of file client.c.

int ready = 0
static

Definition at line 41 of file client.c.

str the_token = { 0, _token_data }

Definition at line 29 of file client.c.

coap_uri_t uri
static

Definition at line 36 of file client.c.

unsigned int wait_seconds = 90

Definition at line 55 of file client.c.