46 int snprintf(
char *str,
size_t size,
const char *format, ...);
52 PROCESS(shell_dec64_process,
"dec64");
55 "dec64: decode base64 input",
56 &shell_dec64_process);
58 #define BASE64_MAX_LINELEN 76
60 struct base64_decoder_state {
61 uint8_t data[3 * BASE64_MAX_LINELEN / 4];
63 unsigned long tmpdata;
69 base64_decode_char(
char c)
71 if(c >=
'A' && c <=
'Z') {
73 }
else if(c >=
'a' && c <=
'z') {
75 }
else if(c >=
'0' && c <=
'9') {
87 base64_add_char(
struct base64_decoder_state *s,
char c)
93 if(s->dataptr >=
sizeof(s->data)) {
100 s->tmpdata = (s->tmpdata << 6) | base64_decode_char(c);
102 if(s->sextets == 4) {
104 s->data[s->dataptr] = (uint8_t)(s->tmpdata >> 16);
105 s->data[s->dataptr + 1] = (uint8_t)(s->tmpdata >> 8);
106 s->data[s->dataptr + 2] = (uint8_t)(s->tmpdata);
108 if(s->dataptr ==
sizeof(s->data)) {
120 struct base64_decoder_state s;
129 if(input->len1 + input->len2 == 0) {
133 s.sextets = s.dataptr = s.padding = 0;
135 for(i = 0; i < input->len1; ++i) {
136 base64_add_char(&s, input->data1[i]);
138 for(i = 0; i < input->len2; ++i) {
139 base64_add_char(&s, input->data2[i]);
141 shell_output(&dec64_command, s.data, s.dataptr - s.padding,
"", 0);
147 shell_base64_init(
void)
#define PROCESS_EXIT()
Exit the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
Main header file for the Contiki shell
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
Structure for shell input data.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.