static int s_ustream_read(BIO *b, char *buf, int len) { struct ustream *s; char *sbuf; int slen; if (!buf || len <= 0) return 0; s = (struct ustream *)b->ptr; if (!s) return 0; sbuf = ustream_get_read_buf(s, &slen); BIO_clear_retry_flags(b); if (!slen) { BIO_set_retry_read(b); return -1; } if (slen > len) slen = len; memcpy(buf, sbuf, slen); ustream_consume(s, slen); return slen; }
__unused static void read_cb(struct ustream *s, int bytes) { struct ustream_buf *buf = s->r.head; ___debug("got '%d' bytes which were not picked up by any function: '%s'", bytes, buf->data); ustream_consume(s, bytes); }
static void slog_cb(struct ustream *s, int bytes) { struct ustream_buf *buf = s->r.head; char *str; int len; do { str = ustream_get_read_buf(s, NULL); if (!str) break; len = strlen(buf->data); if (!len) { bytes -= 1; ustream_consume(s, 1); continue; } log_add(buf->data, len + 1, SOURCE_SYSLOG); ustream_consume(s, len); bytes -= len; } while (bytes > 0); }
static void logread_fd_data_cb(struct ustream *s, int bytes) { while (true) { int len; struct blob_attr *a; a = (void*) ustream_get_read_buf(s, &len); if (len < sizeof(*a) || len < blob_len(a) + sizeof(*a)) break; log_notify(a); ustream_consume(s, blob_len(a) + sizeof(*a)); } if (!log_follow) uloop_end(); }
static void klog_cb(struct ustream *s, int bytes) { struct ustream_buf *buf = s->r.head; char *newline, *str; int len; do { str = ustream_get_read_buf(s, NULL); if (!str) break; newline = strchr(buf->data, '\n'); if (!newline) break; *newline = 0; len = newline + 1 - str; log_add(buf->data, len, SOURCE_KLOG); ustream_consume(s, len); } while (1); }
static void netifd_process_log_read_cb(struct ustream *s, int bytes) { struct netifd_process *proc; const char *log_prefix; char *data; int len = 0; proc = container_of(s, struct netifd_process, log.stream); log_prefix = proc->log_prefix; if (!log_prefix) log_prefix = "process"; do { char *newline; data = ustream_get_read_buf(s, &len); if (!len) break; newline = strchr(data, '\n'); if (proc->log_overflow) { if (newline) { len = newline + 1 - data; proc->log_overflow = false; } } else if (newline) { *newline = 0; len = newline + 1 - data; netifd_log_message(L_NOTICE, "%s (%d): %s\n", log_prefix, proc->uloop.pid, data); } else if (len == s->r.buffer_len) { netifd_log_message(L_NOTICE, "%s (%d): %s [...]\n", log_prefix, proc->uloop.pid, data); proc->log_overflow = true; } else break; ustream_consume(s, len); } while (1); }
static void pipe_cb(struct ustream *s, int bytes) { char *newline, *str; int len; do { str = ustream_get_read_buf(s, NULL); if (!str) break; newline = strchr(str, '\n'); if (!newline) break; *newline = 0; len = newline + 1 - str; syslog(LOG_NOTICE, "%s", str); #ifdef SHOW_BOOT_ON_CONSOLE fprintf(stderr, "%s\n", str); #endif ustream_consume(s, len); } while (1); }
static int s_ustream_read(void *ctx, unsigned char *buf, size_t len) { struct ustream *s = ctx; char *sbuf; int slen; if (s->eof) return 0; sbuf = ustream_get_read_buf(s, &slen); if (slen > len) slen = len; if (!slen) return POLARSSL_ERR_NET_WANT_READ; memcpy(buf, sbuf, slen); ustream_consume(s, slen); return slen; }