Exemple #1
0
static void NET_Ban_f (void)
{
	char	addrStr [32];
	char	maskStr [32];
	void	(*print_fn)(const char *fmt, ...) FUNCP_PRINTF(1,2);

	if (cmd_source == src_command)
	{
		if (!sv.active)
		{
			Cmd_ForwardToServer ();
			return;
		}
		print_fn = Con_Printf;
	}
	else
	{
		if (pr_global_struct->deathmatch)
			return;
		print_fn = SV_ClientPrintf;
	}

	switch (Cmd_Argc ())
	{
	case 1:
		if (banAddr.s_addr != INADDR_ANY)
		{
			Q_strcpy(addrStr, inet_ntoa(banAddr));
			Q_strcpy(maskStr, inet_ntoa(banMask));
			print_fn("Banning %s [%s]\n", addrStr, maskStr);
		}
		else
			print_fn("Banning not active\n");
		break;

	case 2:
		if (q_strcasecmp(Cmd_Argv(1), "off") == 0)
			banAddr.s_addr = INADDR_ANY;
		else
			banAddr.s_addr = inet_addr(Cmd_Argv(1));
		banMask.s_addr = INADDR_NONE;
		break;

	case 3:
		banAddr.s_addr = inet_addr(Cmd_Argv(1));
		banMask.s_addr = inet_addr(Cmd_Argv(2));
		break;

	default:
		print_fn("BAN ip_address [mask]\n");
		break;
	}
}
void queue_lex_debug_print(queue_lex* q, void(*print_fn)(void*))
{
	while(q->count > 0) {
		lexical_pair curr;
		queue_deque_lex(q, &curr);
		print_fn(&curr);
	}
}
Exemple #3
0
/*
==================
Host_Status_f
==================
*/
static void Host_Status_f (void)
{
	void	(*print_fn) (unsigned int, const char *, ...)
						FUNCP_PRINTF(2,3);
	client_t	*client;
	int			seconds;
	int			minutes;
	int			hours = 0;
	int			j;

	if (cmd_source == src_command)
	{
		if (!sv.active)
		{
			Cmd_ForwardToServer ();
			return;
		}
		print_fn = CON_Printf;
	}
	else
		print_fn = SV_ClientPrintf;

	print_fn (_PRINT_NORMAL, "host:    %s\n", Cvar_VariableString ("hostname"));
	print_fn (_PRINT_NORMAL, "version: %4.2f\n", ENGINE_VERSION);
	if (tcpipAvailable)
		print_fn (_PRINT_NORMAL, "tcp/ip:  %s\n", my_tcpip_address);
	if (ipxAvailable)
		print_fn (_PRINT_NORMAL, "ipx:     %s\n", my_ipx_address);
	print_fn (_PRINT_NORMAL, "map:     %s\n", sv.name);
	print_fn (_PRINT_NORMAL, "players: %i active (%i max)\n\n",
					net_activeconnections, svs.maxclients);
	for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
	{
		if (!client->active)
			continue;
		seconds = (int)(net_time - NET_QSocketGetTime(client->netconnection));
		minutes = seconds / 60;
		if (minutes)
		{
			seconds -= (minutes * 60);
			hours = minutes / 60;
			if (hours)
				minutes -= (hours * 60);
		}
		else
			hours = 0;
		print_fn (_PRINT_NORMAL, "#%-2u %-16.16s  %3i  %2i:%02i:%02i\n",
					j + 1, client->name, (int)client->edict->v.frags,
					hours, minutes, seconds);
		print_fn (_PRINT_NORMAL, "   %s\n", NET_QSocketGetAddressString(client->netconnection));
	}
}
Exemple #4
0
void zl_printf(const char* format, ...) {
    char* buffer = safe_malloc(BUFSIZE);
    va_list arguments;
    va_start(arguments, format);

    vsnprintf(buffer, BUFSIZE, format, arguments);
    print_fn(buffer);

    va_end(arguments);
    free(buffer);
}
Exemple #5
0
Fichier : print.c Projet : 8l/awl
void awl_printf(const char* format, ...) {
    /* TODO: Make it similar to stringbuilder_t? */
    char* buffer = safe_malloc(BUFSIZE);
    va_list arguments;
    va_start(arguments, format);

    vsnprintf(buffer, BUFSIZE, format, arguments);
    print_fn(buffer);

    va_end(arguments);
    free(buffer);
}
Exemple #6
0
/*
==================
Host_Status_f
==================
*/
void Host_Status_f (void)
{
	client_t	*client;
	int			seconds;
	int			minutes;
	int			hours = 0;
	int			j;
	void		(*print_fn) (const char *fmt, ...) __fp_attribute__((__format__(__printf__,1,2)));

	if (cmd_source == src_command)
	{
		if (!sv.active)
		{
			Cmd_ForwardToServer ();
			return;
		}
		print_fn = Con_Printf;
	}
	else
		print_fn = SV_ClientPrintf;

	print_fn ("host:    %s\n", Cvar_VariableString ("hostname"));
	print_fn ("version: %4.2f\n", VERSION);
	if (tcpipAvailable)
		print_fn ("tcp/ip:  %s\n", my_tcpip_address);
	if (ipxAvailable)
		print_fn ("ipx:     %s\n", my_ipx_address);
	print_fn ("map:     %s\n", sv.name);
	print_fn ("players: %i active (%i max)\n\n", net_activeconnections, svs.maxclients);
	for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
	{
		if (!client->active)
			continue;
		seconds = (int)(net_time - NET_QSocketGetTime(client->netconnection));
		minutes = seconds / 60;
		if (minutes)
		{
			seconds -= (minutes * 60);
			hours = minutes / 60;
			if (hours)
				minutes -= (hours * 60);
		}
		else
			hours = 0;
		print_fn ("#%-2u %-16.16s  %3i  %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
		print_fn ("   %s\n", NET_QSocketGetAddressString(client->netconnection));
	}
}
Exemple #7
0
int sechk_lib_print_modules_report(sechk_lib_t * lib)
{
	int retv, num_selected = 0, rc = 0;
	size_t i;
	sechk_module_t *mod = NULL;
	sechk_mod_fn_t print_fn = NULL;

	if (!lib) {
		fprintf(stderr, "Error: invalid library\n");
		errno = EINVAL;
		return -1;
	}
	for (i = 0; i < apol_vector_get_size(lib->modules); i++) {
		mod = apol_vector_get_element(lib->modules, i);
		if (mod->selected)
			num_selected++;
	}
	for (i = 0; i < apol_vector_get_size(lib->modules); i++) {
		mod = apol_vector_get_element(lib->modules, i);
		/* if module is "off" or its output format is quiet continue */
		if (!mod->selected || mod->outputformat & SECHK_OUT_QUIET)
			continue;
		/* if module is below the minsev do not print unless exactly one module is selected */
		if (lib->minsev && sechk_lib_compare_sev(mod->severity, lib->minsev) < 0 && num_selected != 1)
			continue;
		/* if module is the only selected one make sure output is generated */
		if (mod->outputformat == SECHK_OUT_NONE && num_selected == 1)
			mod->outputformat = SECHK_OUT_SHORT;
		assert(mod->name);
		printf("\nModule name: %s\tSeverity: %s\n%s\n", mod->name, mod->severity, mod->detailed_description);
		print_fn = sechk_lib_get_module_function(mod->name, SECHK_MOD_FN_PRINT, lib);
		if (!print_fn) {
			ERR(lib->policy, "Could not get print function for module %s.", mod->name);
			errno = ENOTSUP;
			return -1;
		}
		retv = print_fn(mod, lib->policy, NULL);
		if (retv) {
			fprintf(stderr, "Error: unable to print results for module %s \n", mod->name);
			rc = -1;
		}
	}

	return rc;
}
Exemple #8
0
/* ////////////////////////////////////////////////////////////////////////// */
int
mmu_list_dump(const char *prefix,
              mmu_list_t *list,
              void (*print_fn)(const char *oprefix,
                               const void *item))
{
    size_t item = 0;

    if (NULL == list) return MMU_FAILURE_INVALID_ARG;

    if (NULL == print_fn) return MMU_SUCCESS;
    /* print from head to tail */
    for (item = 0; item < list->size; ++item) {
        print_fn(prefix, list->item_ptrs[item]->datap);
    }

    return MMU_SUCCESS;
}
/* Print out the given instruction, using the given instruction print function,
 * and return the printed text as a (malloc allocated) string.
 */
static char* InstToStringConvert(const NCDecoderInst* dinst,
                                 inst_print_fn print_fn) {
  /* Print to a memory buffer, and then duplicate. */
  struct GioMemoryFile filemem;
  struct Gio *file = (struct Gio*) &filemem;
  char buffer[MAX_INST_TEXT_SIZE];
  char* result;

  /* Note: Be sure to leave an extra byte to add the null character to
   * the end of the string.
   */
  GioMemoryFileCtor(&filemem, buffer, MAX_INST_TEXT_SIZE - 1);
  print_fn(dinst, file);
  buffer[filemem.curpos < MAX_INST_TEXT_SIZE
         ? filemem.curpos : MAX_INST_TEXT_SIZE] ='\0';
  result = strdup(buffer);
  GioMemoryFileDtor(file);
  return result;
}
Exemple #10
0
static void parse_direntry (const char *root, const char *burl, const char *path, const char *name, 
    time_t mtime, int opt,
    char **m, size_t *o, size_t *s, int *num,
    void (*print_fn)(const int what, const char*, const char*, const char*, time_t, char**, size_t*, size_t*, int *) ) {
  const int l3 = strlen(name) - 3;
  const int l4 = l3 - 1;
  const int l5 = l4 - 1;
  const int l6 = l5 - 1;
  const int l9 = l6 - 3;
  if ((l4 > 0 && ( !strcmp(&name[l4], ".avi")
                || !strcmp(&name[l4], ".mov")
                || !strcmp(&name[l4], ".ogg")
                || !strcmp(&name[l4], ".ogv")
                || !strcmp(&name[l4], ".mpg")
                || !strcmp(&name[l4], ".mov")
                || !strcmp(&name[l4], ".mp4")
                || !strcmp(&name[l4], ".mkv")
                || !strcmp(&name[l4], ".vob")
                || !strcmp(&name[l4], ".asf")
                || !strcmp(&name[l4], ".avs")
                || !strcmp(&name[l4], ".dts")
                || !strcmp(&name[l4], ".flv")
                || !strcmp(&name[l4], ".m4v")
        )) ||
      (l5 > 0 && ( !strcmp(&name[l5], ".h264")
                || !strcmp(&name[l5], ".webm")
        )) ||
      (l6 > 0 && ( !strcmp(&name[l6], ".dirac")
        )) ||
      (l9 > 0 && ( !strcmp(&name[l9], ".matroska")
        )) ||
      (l3 > 0 && ( !strcmp(&name[l3], ".dv")
        ))
     ) {
    char *url = strdup(burl);
    char *vurl = strstr(url, "/index"); // TODO - do once per dir.
    if (vurl) *++vurl = 0;
    print_fn(1, url, path, name, mtime, m, o, s, num);
    free(url);
  }
}
Exemple #11
0
void
logpage(int argc, char *argv[])
{
	int				fd, nsid;
	int				log_page = 0, pageflag = false;
	int				hexflag = false, ns_specified;
	char				ch, *p;
	char				cname[64];
	uint32_t			size;
	void				*buf;
	const char			*vendor = NULL;
	struct logpage_function		*f;
	struct nvme_controller_data	cdata;
	print_fn_t			print_fn;

	while ((ch = getopt(argc, argv, "p:xv:")) != -1) {
		switch (ch) {
		case 'p':
			/* TODO: Add human-readable ASCII page IDs */
			log_page = strtol(optarg, &p, 0);
			if (p != NULL && *p != '\0') {
				fprintf(stderr,
				    "\"%s\" not valid log page id.\n",
				    optarg);
				logpage_usage();
			}
			pageflag = true;
			break;
		case 'x':
			hexflag = true;
			break;
		case 'v':
			vendor = optarg;
			break;
		}
	}

	if (!pageflag) {
		printf("Missing page_id (-p).\n");
		logpage_usage();
	}

	/* Check that a controller and/or namespace was specified. */
	if (optind >= argc)
		logpage_usage();

	if (strstr(argv[optind], NVME_NS_PREFIX) != NULL) {
		ns_specified = true;
		parse_ns_str(argv[optind], cname, &nsid);
		open_dev(cname, &fd, 1, 1);
	} else {
		ns_specified = false;
		nsid = NVME_GLOBAL_NAMESPACE_TAG;
		open_dev(argv[optind], &fd, 1, 1);
	}

	read_controller_data(fd, &cdata);

	/*
	 * The log page attribtues indicate whether or not the controller
	 * supports the SMART/Health information log page on a per
	 * namespace basis.
	 */
	if (ns_specified) {
		if (log_page != NVME_LOG_HEALTH_INFORMATION)
			errx(1, "log page %d valid only at controller level",
			    log_page);
		if (cdata.lpa.ns_smart == 0)
			errx(1,
			    "controller does not support per namespace "
			    "smart/health information");
	}

	print_fn = print_hex;
	size = DEFAULT_SIZE;
	if (!hexflag) {
		/*
		 * See if there is a pretty print function for the specified log
		 * page.  If one isn't found, we just revert to the default
		 * (print_hex). If there was a vendor specified bt the user, and
		 * the page is vendor specific, don't match the print function
		 * unless the vendors match.
		 */
		for (f = logfuncs; f->log_page > 0; f++) {
			if (f->vendor != NULL && vendor != NULL &&
			    strcmp(f->vendor, vendor) != 0)
				continue;
			if (log_page != f->log_page)
				continue;
			print_fn = f->print_fn;
			size = f->size;
			break;
		}
	}

	if (log_page == NVME_LOG_ERROR) {
		size = sizeof(struct nvme_error_information_entry);
		size *= (cdata.elpe + 1);
	}

	/* Read the log page */
	buf = get_log_buffer(size);
	read_logpage(fd, log_page, nsid, buf, size);
	print_fn(buf, size);

	close(fd);
	exit(0);
}
Exemple #12
0
void
logpage(int argc, char *argv[])
{
	int				fd, nsid;
	int				log_page = 0, pageflag = false;
	int				hexflag = false, ns_specified;
	int				ch;
	char				*p;
	char				cname[64];
	uint32_t			size;
	void				*buf;
	struct logpage_function		*f;
	struct nvm_identify_controller	cdata;
	print_fn_t			print_fn;

	while ((ch = getopt(argc, argv, "p:x")) != -1) {
		switch (ch) {
		case 'p':
			/* TODO: Add human-readable ASCII page IDs */
			log_page = strtol(optarg, &p, 0);
			if (p != NULL && *p != '\0') {
				fprintf(stderr,
				    "\"%s\" not valid log page id.\n",
				    optarg);
				logpage_usage();
			/* TODO: Define valid log page id ranges in nvme.h? */
			} else if (log_page == 0 ||
				   (log_page >= 0x04 && log_page <= 0x7F) ||
				   (log_page >= 0x80 && log_page <= 0xBF)) {
				fprintf(stderr,
				    "\"%s\" not valid log page id.\n",
				    optarg);
				logpage_usage();
			}
			pageflag = true;
			break;
		case 'x':
			hexflag = true;
			break;
		}
	}

	if (!pageflag) {
		printf("Missing page_id (-p).\n");
		logpage_usage();
	}

	/* Check that a controller and/or namespace was specified. */
	if (optind >= argc)
		logpage_usage();

	if (strstr(argv[optind], NVME_NS_PREFIX) != NULL) {
		ns_specified = true;
		parse_ns_str(argv[optind], cname, &nsid);
		open_dev(cname, &fd, 1, 1);
	} else {
		ns_specified = false;
		nsid = 0xffffffff;
		open_dev(argv[optind], &fd, 1, 1);
	}

	read_controller_data(fd, &cdata);

	/*
	 * The log page attribtues indicate whether or not the controller
	 * supports the SMART/Health information log page on a per
	 * namespace basis.
	 */
	if (ns_specified) {
		if (log_page != NVME_LOG_HEALTH_INFORMATION)
			errx(1, "log page %d valid only at controller level",
			    log_page);
		if (!(cdata.lpa & NVME_ID_CTRLR_LPA_NS_SMART))
			errx(1,
			    "controller does not support per namespace "
			    "smart/health information");
	}

	print_fn = print_hex;
	if (!hexflag) {
		/*
		 * See if there is a pretty print function for the
		 *  specified log page.  If one isn't found, we
		 *  just revert to the default (print_hex).
		 */
		f = logfuncs;
		while (f->log_page > 0) {
			if (log_page == f->log_page) {
				print_fn = f->fn;
				break;
			}
			f++;
		}
	}

	/* Read the log page */
	switch (log_page) {
	case NVME_LOG_ERROR:
		size = sizeof(struct nvme_error_information_entry);
		size *= (cdata.elpe + 1);
		break;
	case NVME_LOG_HEALTH_INFORMATION:
		size = sizeof(struct nvme_health_information_page);
		break;
	case NVME_LOG_FIRMWARE_SLOT:
		size = sizeof(struct nvme_firmware_page);
		break;
	default:
		size = DEFAULT_SIZE;
		break;
	}

	buf = get_log_buffer(size);
	read_logpage(fd, log_page, nsid, buf, size);
	print_fn(buf, size);

	close(fd);
	exit(0);
}
Exemple #13
0
void
logpage(int argc, char *argv[])
{
	int				fd, nsid, len;
	int				log_page = 0, pageflag = false;
	int				hexflag = false;
	int				allow_ns = false;
	char				ch, *p, *nsloc = NULL;
	char				*cname = NULL;
	size_t				size;
	void				*buf;
	struct logpage_function		*f;
	struct nvme_controller_data	cdata;
	print_fn_t			print_fn;

	while ((ch = getopt(argc, argv, "p:x")) != -1) {
		switch (ch) {
		case 'p':
			/* TODO: Add human-readable ASCII page IDs */
			log_page = strtol(optarg, &p, 0);
			if (p != NULL && *p != '\0') {
				fprintf(stderr,
				    "\"%s\" not valid log page id.\n",
				    optarg);
				logpage_usage();
			/* TODO: Define valid log page id ranges in nvme.h? */
			} else if (log_page == 0 ||
				   (log_page >= 0x04 && log_page <= 0x7F) ||
				   (log_page >= 0x80 && log_page <= 0xBF)) {
				fprintf(stderr,
				    "\"%s\" not valid log page id.\n",
				    optarg);
				logpage_usage();
			}
			pageflag = true;
			break;
		case 'x':
			hexflag = true;
			break;
		}
	}

	if (!pageflag) {
		printf("Missing page_id (-p).\n");
		logpage_usage();
	}

	/* Check that a controller and/or namespace was specified. */
	if (optind >= argc)
		logpage_usage();

	/*
	 * The log page attribtues indicate whether or not the controller
	 * supports the SMART/Health information log page on a per
	 * namespace basis.
	 */
	cname = malloc(strlen(NVME_CTRLR_PREFIX) + 2);
	len = strlen(NVME_CTRLR_PREFIX) + 1;
	cname = strncpy(cname, argv[optind], len);
	open_dev(cname, &fd, 1, 1);
	read_controller_data(fd, &cdata);

	if (log_page == NVME_LOG_HEALTH_INFORMATION && cdata.lpa.ns_smart != 0)
		allow_ns = true;

	/* If a namespace id was specified, validate it's use */
	if (strstr(argv[optind], NVME_NS_PREFIX) != NULL) {
		if (!allow_ns) {
			if (log_page != NVME_LOG_HEALTH_INFORMATION) {
				fprintf(stderr,
				    "Namespace ID not valid for log page %d.\n",
				    log_page);
			} else if (cdata.lpa.ns_smart == 0) {
				fprintf(stderr,
				    "Controller does not support per "
				    "namespace SMART/Health information.\n");
			}
			close(fd);
			exit(EX_IOERR);
		}
		nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10);
		if (nsloc != NULL)
			nsid = strtol(nsloc + 2, NULL, 10);
		if (nsloc == NULL || (nsid == 0 && errno != 0)) {
			fprintf(stderr,
			    "Invalid namespace ID %s.\n",
			    argv[optind]);
			close(fd);
			exit(EX_IOERR);
		}

		/*
		 * User is asking for per namespace log page information
		 * so close the controller and open up the namespace.
		 */
		close(fd);
		open_dev(argv[optind], &fd, 1, 1);
	} else
		nsid = NVME_GLOBAL_NAMESPACE_TAG;

	print_fn = print_hex;
	if (!hexflag) {
		/*
		 * See if there is a pretty print function for the
		 *  specified log page.  If one isn't found, we
		 *  just revert to the default (print_hex).
		 */
		f = logfuncs;
		while (f->log_page > 0) {
			if (log_page == f->log_page) {
				print_fn = f->fn;
				break;
			}
			f++;
		}
	}

	/* Read the log page */
	switch (log_page) {
	case NVME_LOG_ERROR:
		size = sizeof(struct nvme_error_information_entry);
		size *= (cdata.elpe + 1);
		break;
	case NVME_LOG_HEALTH_INFORMATION:
		size = sizeof(struct nvme_health_information_page);
		break;
	case NVME_LOG_FIRMWARE_SLOT:
		size = sizeof(struct nvme_firmware_page);
		break;
	default:
		size = DEFAULT_SIZE;
		break;
	}

	buf = get_log_buffer(size);
	read_logpage(fd, log_page, nsid, buf, size);
	print_fn(buf, size);

	close(fd);
	exit(EX_OK);
}
Exemple #14
0
Fichier : print.c Projet : 8l/awl
void awlval_println(const awlval* v) {
    awlval_print(v);
    print_fn("\n");
}
Exemple #15
0
Fichier : print.c Projet : 8l/awl
void awlval_print(const awlval* v) {
    char* str = awlval_to_str(v);
    print_fn(str);
    free(str);
}
Exemple #16
0
void zlval_print(const zlval* v) {
    char* str = zlval_to_str(v);
    print_fn(str);
    free(str);
}
Exemple #17
0
void zlval_println(const zlval* v) {
    zlval_print(v);
    print_fn("\n");
}
Exemple #18
0
static int parse_dir (const int fd, const char *root, const char *burl, const char *path, int opt,
    char **m, size_t *o, size_t *s, int *num,
    void (*print_fn)(const int what, const char*, const char*, const char*, time_t, char**, size_t*, size_t*, int *) ) {
  DIR  *D;
  struct dirent *dd;
  char dn[MAX_PATH];
  int rv = 0;
  snprintf(dn, MAX_PATH, "%s%s%s", root, SL_SEP(root), path);

  debugmsg(DEBUG_ICS, "IndexDir: indexing '%s'\n", dn);
  if (!(D = opendir (dn)))  {
    dlog(LOG_WARNING, "IndexDir: could not open dir '%s'\n", dn);
    return -1;
  }

  while ((dd = readdir (D))) {
    struct stat fs;
    char rn[MAX_PATH]; // absolute, starting at local root /
    if (dd->d_name[0] == '.') continue; // make optional
#if 0
    int delen = strlen(d->d_name);
    if (delen == 1 && dd->d_name[0] == '.') continue; // '.'
    if (delen == 2 && dd->d_name[0] == '.' && dd->d_name[1] == '.') continue; // '..'
#endif

    snprintf(rn, MAX_PATH, "%s/%s", dn, dd->d_name);
    if(stat(rn, &fs) == 0) { // XXX lstat vs stat
      char fn[MAX_PATH]; // relative to this *root.
      snprintf(fn, MAX_PATH, "%s%s%s", path, SL_SEP(path), dd->d_name);
      if (S_ISDIR(fs.st_mode)) {
        if ((opt&OPT_FLAT) == OPT_FLAT) {
          char pn[MAX_PATH];
          snprintf(pn, MAX_PATH, "%s%s%s/", path, SL_SEP(path), dd->d_name);
          if ((rv = parse_dir(fd, root, burl, pn, opt, m, o, s, num, print_fn))) {
            if (rv == -1) rv = 0; // opendir failed -- continue
            else break;
          }
          if (strlen(*m) > 0) {
            int tx = CSEND(fd, (*m));
            if (tx > 0) {
              (*o) = 0;
              (*m)[0] = '\0';
            } else if (tx < 0) {
              debugmsg(DEBUG_ICS, "abort indexing\n");
              rv = -2;
              break;
            }
          }
        } else {
          print_fn(0, burl, path, dd->d_name, fs.st_mtime, m, o, s, num);
        }
      }
      else if (
#ifndef HAVE_WINDOWS
          S_ISLNK(fs.st_mode) ||
#endif
          S_ISREG(fs.st_mode)) {
        parse_direntry(root, burl, path, dd->d_name, fs.st_mtime, opt, m, o, s, num, print_fn);
      }
    }
  }
  closedir(D);
  return rv;
}
Exemple #19
0
int     attr_vprint_plain(VSTREAM *fp, int flags, va_list ap)
{
    const char *myname = "attr_print_plain";
    int     attr_type;
    char   *attr_name;
    unsigned int_val;
    unsigned long long_val;
    char   *str_val;
    HTABLE_INFO **ht_info_list;
    HTABLE_INFO **ht;
    static VSTRING *base64_buf;
    ssize_t len_val;
    ATTR_PRINT_SLAVE_FN print_fn;
    void   *print_arg;

    /*
     * Sanity check.
     */
    if (flags & ~ATTR_FLAG_ALL)
	msg_panic("%s: bad flags: 0x%x", myname, flags);

    /*
     * Iterate over all (type, name, value) triples, and produce output on
     * the fly.
     */
    while ((attr_type = va_arg(ap, int)) != ATTR_TYPE_END) {
	switch (attr_type) {
	case ATTR_TYPE_INT:
	    attr_name = va_arg(ap, char *);
	    int_val = va_arg(ap, int);
	    vstream_fprintf(fp, "%s=%u\n", attr_name, (unsigned) int_val);
	    if (msg_verbose)
		msg_info("send attr %s = %u", attr_name, (unsigned) int_val);
	    break;
	case ATTR_TYPE_LONG:
	    attr_name = va_arg(ap, char *);
	    long_val = va_arg(ap, long);
	    vstream_fprintf(fp, "%s=%lu\n", attr_name, long_val);
	    if (msg_verbose)
		msg_info("send attr %s = %lu", attr_name, long_val);
	    break;
	case ATTR_TYPE_STR:
	    attr_name = va_arg(ap, char *);
	    str_val = va_arg(ap, char *);
	    vstream_fprintf(fp, "%s=%s\n", attr_name, str_val);
	    if (msg_verbose)
		msg_info("send attr %s = %s", attr_name, str_val);
	    break;
	case ATTR_TYPE_DATA:
	    attr_name = va_arg(ap, char *);
	    len_val = va_arg(ap, ssize_t);
	    str_val = va_arg(ap, char *);
	    if (base64_buf == 0)
		base64_buf = vstring_alloc(10);
	    base64_encode(base64_buf, str_val, len_val);
	    vstream_fprintf(fp, "%s=%s\n", attr_name, STR(base64_buf));
	    if (msg_verbose)
		msg_info("send attr %s = [data %ld bytes]",
			 attr_name, (long) len_val);
	    break;
	case ATTR_TYPE_FUNC:
	    print_fn = va_arg(ap, ATTR_PRINT_SLAVE_FN);
	    print_arg = va_arg(ap, void *);
	    print_fn(attr_print_plain, fp, flags | ATTR_FLAG_MORE, print_arg);
	    break;
	case ATTR_TYPE_HASH:
	    ht_info_list = htable_list(va_arg(ap, HTABLE *));
	    for (ht = ht_info_list; *ht; ht++) {
		vstream_fprintf(fp, "%s=%s\n", ht[0]->key, ht[0]->value);
		if (msg_verbose)
		    msg_info("send attr name %s value %s",
			     ht[0]->key, ht[0]->value);
	    }
	    myfree((char *) ht_info_list);
	    break;
	default:
	    msg_panic("%s: unknown type code: %d", myname, attr_type);
	}
    }
    if ((flags & ATTR_FLAG_MORE) == 0)
	VSTREAM_PUTC('\n', fp);
    return (vstream_ferror(fp));
}
Exemple #20
0
int     attr_vprint64(VSTREAM *fp, int flags, va_list ap)
{
    const char *myname = "attr_print64";
    int     attr_type;
    char   *attr_name;
    unsigned int_val;
    unsigned long long_val;
    char   *str_val;
    HTABLE_INFO **ht_info_list;
    HTABLE_INFO **ht;
    ssize_t len_val;
    ATTR_PRINT_SLAVE_FN print_fn;
    void   *print_arg;

    /*
     * Sanity check.
     */
    if (flags & ~ATTR_FLAG_ALL)
	msg_panic("%s: bad flags: 0x%x", myname, flags);

    /*
     * Iterate over all (type, name, value) triples, and produce output on
     * the fly.
     */
    while ((attr_type = va_arg(ap, int)) != ATTR_TYPE_END) {
	switch (attr_type) {
	case ATTR_TYPE_INT:
	    attr_name = va_arg(ap, char *);
	    attr_print64_str(fp, attr_name, strlen(attr_name));
	    int_val = va_arg(ap, int);
	    VSTREAM_PUTC(':', fp);
	    attr_print64_num(fp, (unsigned) int_val);
	    VSTREAM_PUTC('\n', fp);
	    if (msg_verbose)
		msg_info("send attr %s = %u", attr_name, int_val);
	    break;
	case ATTR_TYPE_LONG:
	    attr_name = va_arg(ap, char *);
	    attr_print64_str(fp, attr_name, strlen(attr_name));
	    long_val = va_arg(ap, long);
	    VSTREAM_PUTC(':', fp);
	    attr_print64_long_num(fp, (unsigned long) long_val);
	    VSTREAM_PUTC('\n', fp);
	    if (msg_verbose)
		msg_info("send attr %s = %lu", attr_name, long_val);
	    break;
	case ATTR_TYPE_STR:
	    attr_name = va_arg(ap, char *);
	    attr_print64_str(fp, attr_name, strlen(attr_name));
	    str_val = va_arg(ap, char *);
	    VSTREAM_PUTC(':', fp);
	    attr_print64_str(fp, str_val, strlen(str_val));
	    VSTREAM_PUTC('\n', fp);
	    if (msg_verbose)
		msg_info("send attr %s = %s", attr_name, str_val);
	    break;
	case ATTR_TYPE_DATA:
	    attr_name = va_arg(ap, char *);
	    attr_print64_str(fp, attr_name, strlen(attr_name));
	    len_val = va_arg(ap, ssize_t);
	    str_val = va_arg(ap, char *);
	    VSTREAM_PUTC(':', fp);
	    attr_print64_str(fp, str_val, len_val);
	    VSTREAM_PUTC('\n', fp);
	    if (msg_verbose)
		msg_info("send attr %s = [data %ld bytes]",
			 attr_name, (long) len_val);
	    break;
	case ATTR_TYPE_FUNC:
	    print_fn = va_arg(ap, ATTR_PRINT_SLAVE_FN);
	    print_arg = va_arg(ap, void *);
	    print_fn(attr_print64, fp, flags | ATTR_FLAG_MORE, print_arg);
	    break;
	case ATTR_TYPE_HASH:
	    attr_print64_str(fp, ATTR_NAME_OPEN, sizeof(ATTR_NAME_OPEN) - 1);
	    VSTREAM_PUTC('\n', fp);
	    ht_info_list = htable_list(va_arg(ap, HTABLE *));
	    for (ht = ht_info_list; *ht; ht++) {
		attr_print64_str(fp, ht[0]->key, strlen(ht[0]->key));
		VSTREAM_PUTC(':', fp);
		attr_print64_str(fp, ht[0]->value, strlen(ht[0]->value));
		VSTREAM_PUTC('\n', fp);
		if (msg_verbose)
		    msg_info("send attr name %s value %s",
			     ht[0]->key, (char *) ht[0]->value);
	    }
	    myfree((void *) ht_info_list);
	    attr_print64_str(fp, ATTR_NAME_CLOSE, sizeof(ATTR_NAME_CLOSE) - 1);
	    VSTREAM_PUTC('\n', fp);
	    break;
	default:
	    msg_panic("%s: unknown type code: %d", myname, attr_type);
	}
    }
    if ((flags & ATTR_FLAG_MORE) == 0)
	VSTREAM_PUTC('\n', fp);
    return (vstream_ferror(fp));
}