Esempio n. 1
0
void nprintf(usbdevice* kb, usbprofile* profile, usbmode* mode, const char* format, ...){
    if(!kb && !profile)
        return;
    if(!profile)
        profile = &kb->profile;
    va_list va_args;
    int fifo;
    // Write the string to the keyboard's FIFOs (if any)
    for(int i = 0; i < OUTFIFO_MAX; i++){
        va_start(va_args, format);
        if(kb && (fifo = kb->outfifo[i])){
            if(mode)
                dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
            vdprintf(fifo, format, va_args);
        }
        // Write it to the root FIFOs and include the serial number
        va_start(va_args, format);
        if((fifo = keyboard[0].outfifo[i])){
            dprintf(fifo, "device %s ", profile->serial);
            if(mode)
                dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
            vdprintf(fifo, format, va_args);
        }
    }
}
/*!
 * @brief Poll a named pipe for data to recv and block when none available.
 * @param remote Pointer to the remote instance.
 * @param timeout Amount of time to wait before the poll times out (in milliseconds).
 * @return Indication of success or failure.
 */
static DWORD server_pipe_poll(Remote* remote, long timeout)
{
	DWORD bytesAvailable = 0;
	NamedPipeTransportContext* ctx = (NamedPipeTransportContext*)remote->transport->ctx;

	lock_acquire(remote->lock);

	vdprintf("[NP DISPATCH] testing for data on the pipe, making sure there's enough for a packet header");
	BOOL ready = PeekNamedPipe(ctx->pipe, NULL, 0, NULL, &bytesAvailable, NULL) && bytesAvailable >= sizeof(PacketHeader);
	DWORD result = GetLastError();

	lock_release(remote->lock);

	if (ready)
	{
		vdprintf("[NP DISPATCH] pipe data found %u bytes", bytesAvailable);
		result = ERROR_SUCCESS;
	}
	else
	{
		if (result != ERROR_BROKEN_PIPE)
		{
			// simulate a wait so that we don't bash the crap out of the CPU?
			vdprintf("[NP DISPATCH] pipe data not found, sleeping (error %u)", GetLastError());
			Sleep(timeout);
			result = ERROR_NO_DATA;
		}
	}

	return result;
}
Esempio n. 3
0
File: notify.c Progetto: akosipc/ckb
void nprintf(usbdevice* kb, int nodenumber, usbmode* mode, const char* format, ...){
    if(!kb)
        return;
    usbprofile* profile = kb->profile;
    va_list va_args;
    int fifo;
    if(nodenumber >= 0){
        // If node number was given, print to that node (if open)
        if((fifo = kb->outfifo[nodenumber] - 1) != -1){
            va_start(va_args, format);
            if(mode)
                dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
            vdprintf(fifo, format, va_args);
        }
        return;
    }
    // Otherwise, print to all nodes
    for(int i = 0; i < OUTFIFO_MAX; i++){
        if((fifo = kb->outfifo[i] - 1) != -1){
            va_start(va_args, format);
            if(mode)
                dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
            vdprintf(fifo, format, va_args);
        }
    }
}
Esempio n. 4
0
static void coutl2(const char *color, const char *f, ...)
{
	va_list		ap;

	if (output_fd == -1)
		output_fd = open("/dev/tty", O_RDWR);
	
	va_start(ap, f);
	vdprintf(logfile_fd, f, ap);
	va_end(ap);
	va_start(ap, f);
	cout(color);
	vdprintf(output_fd, f, ap);
	cout(C_CLEAR);
	va_end(ap);
}
Esempio n. 5
0
 /**
 *  Log a message to a filedescriptor.
 *  @param fd File descritpor where the log will be written to
 *  @param lf Logging priority (equal to syslog)
 *  @param fmt Format string
 *  @param ap Variable parameter list
 *  @param with_errno Flag if errno should be printed too
 */
void
vlog_msgf(int fd, int lf, const char* fmt, va_list ap, int with_errno)
{
    int level = LOG_PRI(lf);
    char buf[1024];

    if (level_ < level)
    {
        return;
    }

    if (fd > -1)
    {
        dprintf(fd, "%s;", flty_[level]);
        vdprintf(fd, fmt, ap);

        if (with_errno)
        {
            dprintf(fd, " (%s)", strerror(errno));
        }

        dprintf(fd, "\n");
    }
    else
    {
        vsnprintf(buf, sizeof(buf), fmt, ap);
        syslog(level | LOG_DAEMON, "%s", buf);
    }
}
Esempio n. 6
0
// POSIX calls this dprintf, but LP32 Android had fdprintf instead.
extern "C" int fdprintf(int fd, const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  int rc = vdprintf(fd, fmt, ap);
  va_end(ap);
  return rc;
}
Esempio n. 7
0
File: http.c Progetto: netdava/tang
int
http_reply(const char *file, int line,
           enum http_status code, const char *fmt, ...)
{
    const char *msg = NULL;
    va_list ap;
    int a;
    int b;

    switch (code) {
#define XX(num, name, string) case num: msg = # string; break;
    HTTP_STATUS_MAP(XX)
#undef XX
    default:
        return http_reply(file, line, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
    }

    fprintf(stderr, " => %d (%s:%d)\n", code, file, line);

    a = dprintf(STDOUT_FILENO, "HTTP/1.1 %d %s\r\n", code, msg);
    if (a < 0)
        return a;

    va_start(ap, fmt);
    b = vdprintf(STDOUT_FILENO, fmt ? fmt : "Content-Length: 0\r\n\r\n", ap);
    va_end(ap);
    return b < 0 ? b : a + b;
}
Esempio n. 8
0
i64 _debug_out_(
        bool info,
        ch_dbg_mode_e mode,
        i64 line_num,
        const char* filename,
        const char* function,
        const char* format, ... ) //Intentionally using char* here as these are passed in as constants
{
    va_list args;
    va_start(args,format);
    char* fn =  (char*)filename;
    char* mode_str = NULL;
    switch(mode){
        case DBGMODE_HEX:   mode_str = "Hexdump"; break;
        case DBGMODE_FAT:   mode_str = "Fatal  "; break;
        case DBGMODE_ERR:   mode_str = "Error  "; break;
        case DBGMODE_DBG:   mode_str = "Debug  "; break;
        case DBGMODE_WARN:  mode_str = "Warning"; break;
    }
    if(info) dprintf(OUTPUT_TO,"[%s - %s:%i:%s()]  ", mode_str, basename(fn), (int)line_num, function);
    i64 result = vdprintf(OUTPUT_TO,format,args);
    va_end(args);

    if(mode == DBGMODE_FAT){
        exit(-1);
    }

    return result;
}
Esempio n. 9
0
static void display_put(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    vdprintf(logFd(), fmt, args);
    va_end(args);
}
Esempio n. 10
0
int send_frame(int fd, char *format, ...)
{
	int r;
#ifdef VERBOSE_COMMS
	{
		va_list debug_args;
		va_start(debug_args, format);
		if(printf("tx:[") == -1) {
			r = -1;
		} else if((r = vprintf(format, debug_args)) == -1) {
			r = -1;
		} else if(printf("]\r\n") == -1) {
			r = -1;
		}
		va_end(debug_args);
	}
#endif
	va_list args;
	va_start(args, format);
	if(dprintf(fd, "[") == -1) {
		r = -1;
	} else if((r = vdprintf(fd, format, args)) == -1) {
		r = -1;
	} else if(dprintf(fd, "]\r") == -1) {
		r = -1;
	}
	va_end(args);
	return r;
}
Esempio n. 11
0
void logLog(enum llevel_t ll, const char *fn, int ln, bool perr, const char *fmt, ...)
{
	if (ll == DEBUG && !log_verbose) {
		return;
	}

	char strerr[512];
	if (perr == true) {
		snprintf(strerr, sizeof(strerr), "%s", strerror(errno));
	}
	struct ll_t {
		char *descr;
		char *prefix;
		bool print_funcline;
	};
	struct ll_t logLevels[] = {
		{"HR", "\033[0m", false},
		{"HB", "\033[1m", false},
		{"D", "\033[0;4m", true},
		{"I", "\033[1m", true},
		{"W", "\033[0;33m", true},
		{"E", "\033[1;31m", true},
		{"F", "\033[7;35m", true},
	};

	time_t ltstamp = time(NULL);
	struct tm utctime;
	localtime_r(&ltstamp, &utctime);
	char timestr[32];
	if (strftime(timestr, sizeof(timestr) - 1, "%FT%T%z", &utctime) == 0) {
		timestr[0] = '\0';
	}

	/* Start printing logs */
	if (log_fd_isatty) {
		dprintf(log_fd, "%s", logLevels[ll].prefix);
	}
	if (logLevels[ll].print_funcline) {
		dprintf(log_fd, "[%s][%s][%ld] %s():%d ", timestr, logLevels[ll].descr,
			syscall(__NR_getpid), fn, ln);
	}

	va_list args;
	va_start(args, fmt);
	vdprintf(log_fd, fmt, args);
	va_end(args);
	if (perr == true) {
		dprintf(log_fd, ": %s", strerr);
	}
	if (log_fd_isatty) {
		dprintf(log_fd, "\033[0m");
	}
	dprintf(log_fd, "\n");
	/* End printing logs */

	if (ll == FATAL) {
		exit(1);
	}
}
Esempio n. 12
0
int dprintf(int fd, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	return vdprintf(fd, fmt, args);
	va_end(args);
}
Esempio n. 13
0
/*
    write to temp file..
*/
static void fdprintf(int fd, const char *ctl, ...)
{
	va_list va;

	va_start(va, ctl);
	vdprintf(fd, ctl, va);
	va_end(va);
}
Esempio n. 14
0
File: dprintf.c Progetto: KGG814/AOS
int dprintf(int fd, const char *fmt, ...)
{
	int ret;
	va_list ap;
	va_start(ap, fmt);
	ret = vdprintf(fd, fmt, ap);
	va_end(ap);
	return ret;
}
Esempio n. 15
0
ocschedStatus
ocsched_printf(ocschedProcessContext * ctx,char * fmtstr,...)
{
  va_list ap;
  va_start(ap,fmtstr);
  vdprintf(ctx->comm.pipe_out,fmtstr,ap);
  va_end(ap);
  return OCSCHED_SUCCESS;
}
Esempio n. 16
0
int
ly_print(struct lyout *out, const char *format, ...)
{
    int count = 0;
    char *msg = NULL, *aux;
    va_list ap;
#ifndef HAVE_VDPRINTF
    FILE *stream;
#endif

    va_start(ap, format);

    switch (out->type) {
    case LYOUT_FD:
#ifdef HAVE_VDPRINTF
        count = vdprintf(out->method.fd, format, ap);
#else
        stream = fdopen(dup(out->method.fd), "a+");
        if (stream) {
            count = vfprintf(stream, format, ap);
            fclose(stream);
        }
#endif
        break;
    case LYOUT_STREAM:
        count = vfprintf(out->method.f, format, ap);
        break;
    case LYOUT_MEMORY:
        count = vasprintf(&msg, format, ap);
        if (out->method.mem.len + count + 1 > out->method.mem.size) {
            aux = ly_realloc(out->method.mem.buf, out->method.mem.len + count + 1);
            if (!aux) {
                out->method.mem.buf = NULL;
                out->method.mem.len = 0;
                out->method.mem.size = 0;
                LOGMEM(NULL);
                va_end(ap);
                return -1;
            }
            out->method.mem.buf = aux;
            out->method.mem.size = out->method.mem.len + count + 1;
        }
        memcpy(&out->method.mem.buf[out->method.mem.len], msg, count);
        out->method.mem.len += count;
        out->method.mem.buf[out->method.mem.len] = '\0';
        free(msg);
        break;
    case LYOUT_CALLBACK:
        count = vasprintf(&msg, format, ap);
        count = out->method.clb.f(out->method.clb.arg, msg, count);
        free(msg);
        break;
    }

    va_end(ap);
    return count;
}
Esempio n. 17
0
/* ========================================================================== *
 * Write line to stream
 * ========================================================================== */
int
say (const saymode_t mode, const saylevel_t level, const char * const str, ...)
{
  va_list arg;
  int out = 0;
  int priority = 0;

  ASSERT_RETURN (str, "str is NULL.\n", -1)

  /* Set how to print */
  switch (level)
    {
      case MSG_E:
        {
          out = STDERR_FILENO;
          priority = LOG_ERR;
          break;
        }
      case MSG_W:
        {
          out = STDOUT_FILENO;
          priority = LOG_WARNING;
          break;
        }
      case MSG_I:
        {
          out  = STDOUT_FILENO;
          priority = LOG_INFO;
          break;
        }
      default:
        {
          return -1;
        }
    }

  va_start (arg, str);

  /* Write line */
  switch (mode)
    {
    case MODE_FILE:
      vsyslog (priority, str, arg);
      break;

    case MODE_OUT:
      vdprintf (out, str, arg);
      break;

    default:
      return -1;
    }

  va_end (arg);

  return 1;
}
/*!
 * @brief Prepare a wininet request with the given context.
 * @param ctx Pointer to the HTTP transport context to prepare the request from.
 * @param isGet Indication of whether this request is a GET request, otherwise POST is used.
 * @param direction String representing the direction of the communications (for debug).
 * @return An Internet request handle.
 */
static HINTERNET get_request_wininet(HttpTransportContext *ctx, BOOL isGet, const char *direction)
{
	HINTERNET hReq = NULL;
	DWORD flags = INTERNET_FLAG_RELOAD
		| INTERNET_FLAG_NO_CACHE_WRITE
		| INTERNET_FLAG_KEEP_CONNECTION
		| INTERNET_FLAG_NO_AUTO_REDIRECT
		| INTERNET_FLAG_NO_UI;

	if (ctx->ssl)
	{
		flags |= INTERNET_FLAG_SECURE
			| INTERNET_FLAG_IGNORE_CERT_CN_INVALID
			| INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
		dprintf("[%s] Setting secure request flag..", direction);
	}

	do
	{
		vdprintf("[%s] opening request on connection %x to %S", direction, ctx->connection, ctx->uri);
		hReq = HttpOpenRequestW(ctx->connection, isGet ? L"GET" : L"POST", ctx->uri, NULL, NULL, NULL, flags, 0);

		if (hReq == NULL)
		{
			dprintf("[%s] Failed HttpOpenRequestW: %d", direction, GetLastError());
			SetLastError(ERROR_NOT_FOUND);
			break;
		}

		if (ctx->ssl)
		{
			DWORD secureFlags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID
				| SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
				| SECURITY_FLAG_IGNORE_WRONG_USAGE
				| SECURITY_FLAG_IGNORE_UNKNOWN_CA
				| SECURITY_FLAG_IGNORE_REVOCATION;

			dprintf("[%s] Setting secure option flags", direction);
			if (!InternetSetOptionW(hReq, INTERNET_OPTION_SECURITY_FLAGS, &secureFlags, sizeof(secureFlags)))
			{
				dprintf("[%s] Failed InternetSetOptionW: %d", direction, GetLastError());
				SetLastError(ERROR_NOT_FOUND);
				break;
			}
		}

		return hReq;
	} while (0);

	if (hReq != NULL)
	{
		InternetCloseHandle(hReq);
	}

	return NULL;
}
Esempio n. 19
0
static int log_stderr(const char *format, ...)
{
	int result;
	va_list args;

	va_start(args, format);
	result = vdprintf(STDERR_FILENO, format, args);
	va_end(args);
	return result;
}
Esempio n. 20
0
void log_print(int priority, const char *format, ...)
{
    if (priority < log_priority || log_fd < 0)
        return;

    va_list va_arg;
    va_start(va_arg, format);
    vdprintf(log_fd, format, va_arg);
    va_end(va_arg);
}
/*!
 * @brief Wrapper around WinINET-specific request response validation.
 * @param hReq HTTP request handle.
 * @param ctx The HTTP transport context.
 * @return An indication of the result of getting a response.
 */
static DWORD validate_response_wininet(HANDLE hReq, HttpTransportContext* ctx)
{
	DWORD statusCode;
	DWORD statusCodeSize = sizeof(statusCode);
	vdprintf("[PACKET RECEIVE WININET] Getting the result code...");
	if (HttpQueryInfoW(hReq, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &statusCode, &statusCodeSize, 0))
	{
		vdprintf("[PACKET RECEIVE WININET] Returned status code is %d", statusCode);

		// did the request succeed?
		if (statusCode != 200)
		{
			// bomb out
			return ERROR_BAD_CONFIGURATION;
		}
	}

	return ERROR_SUCCESS;
}
Esempio n. 22
0
void logFormat(char* text,...) {
	int fd = open(LOGFILE, O_CREAT| O_WRONLY | O_APPEND,0644);
	if (fd>=0) {
		va_list arglist;
		va_start(arglist, text);
		vdprintf(fd,text, arglist);
		close(fd);
	} 
	
}
Esempio n. 23
0
int printf(const char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);

	int ret = vdprintf(STDOUT_FILENO, fmt, args);

	va_end(args);
	return ret;
}
Esempio n. 24
0
/* From glibc */
int dprintf(int d, const char *format, ...)
{
  va_list arg;
  int done;

  va_start (arg, format);
  done = vdprintf (d, format, arg);
  va_end (arg);

  return done;
}
Esempio n. 25
0
void		print_log(char *str, ...)
{
	va_list			ap;

	if (VERBOSE)
	{
		va_start(ap, str);
		vdprintf(2, str, ap);
		va_end(ap);
	}
}
Esempio n. 26
0
void nrprintf(const char* format, ...){
    va_list va_args;
    char line = '\n';
    int fifo;
    for(int i = 0; i < OUTFIFO_MAX; i++){
        va_start(va_args, format);
        if((fifo = keyboard[0].outfifo[i])){
            vdprintf(fifo, format, va_args);
        }
    }
}
Esempio n. 27
0
static void	cout(const char *f, ...)
{
	va_list		ap;

	if (output_fd == -1)
		output_fd = open("/dev/tty", O_RDWR);

	va_start(ap, f);
	vdprintf(output_fd, f, ap);
	va_end(ap);
}
Esempio n. 28
0
static int
conn_send(const conn_t *conn, const char *fmt, ...)
{
    va_list ap;
    int r;

    va_start(ap, fmt);
    r = vdprintf(conn->sock, fmt, ap);
    va_end(ap);
    return r;
}
Esempio n. 29
0
int dprintf(int fd, FAR const IPTR char *fmt, ...)
{
  va_list ap;
  int ret;

  va_start(ap, fmt);
  ret = vdprintf(fd, fmt, ap);
  va_end(ap);

  return ret;
}
Esempio n. 30
0
void nrprintf(int nodenumber, const char* format, ...){
    if(nodenumber >= OUTFIFO_MAX)
        return;
    va_list va_args;
    int fifo;
    if(nodenumber >= 0){
        // If node number was given, print to that node (if open)
        if((fifo = keyboard[0].outfifo[nodenumber])){
            va_start(va_args, format);
            vdprintf(fifo, format, va_args);
        }
        return;
    }
    // Otherwise, print to all nodes
    for(int i = 0; i < OUTFIFO_MAX; i++){
        if((fifo = keyboard[0].outfifo[i])){
            va_start(va_args, format);
            vdprintf(fifo, format, va_args);
        }
    }
}