コード例 #1
0
ファイル: wproc.c プロジェクト: rlugojr/nagioscore
static int send_command(int sd, int events, void *discard)
{
	char buf[8192];
	int ret;
	simple_worker *wp;
	struct kvvec *kvv;

	ret = read(sd, buf, sizeof(buf));
	if (ret == 0) {
		iobroker_close(iobs, sd);
		return 0;
	}
	if (ret < 0) {
		printf("main: Failed to read() from fd %d: %s",
			   sd, strerror(errno));
	}

	/* this happens when we're reading from stdin */
	buf[--ret] = 0;

	kvv = kvvec_create(5);
	wp = wps[wp_index++ % NWPS];
	kvvec_addkv(kvv, "job_id", (char *)mkstr("%d", wp->job_index++));
	kvvec_addkv_wlen(kvv, "command", sizeof("command") - 1, buf, ret);
	kvvec_addkv(kvv, "timeout", (char *)mkstr("%d", 10));
	printf("Sending kvvec with %d pairs to worker %d\n", kvv->kv_pairs, wp->pid);
	worker_send_kvvec(wp->sd, kvv);
	kvvec_destroy(kvv, 0);
	return 0;
}
コード例 #2
0
void TestSerialization::testDeSerializeWideString()
{
	// Test deserialize
	{
		std::istringstream is(serializeWideString(teststring2_w), std::ios::binary);
		UASSERT(deSerializeWideString(is) == teststring2_w);
		UASSERT(!is.eof());
		is.get();
		UASSERT(is.eof());
	}

	// Test deserialize an incomplete length specifier
	{
		std::istringstream is(mkstr("\x53"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeWideString(is));
	}

	// Test deserialize a string with an incomplete character
	{
		std::istringstream is(mkstr("\x00\x07\0a\0b\0c\0d\0e\0f\0"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeWideString(is));
	}

	// Test deserialize a string with incomplete data
	{
		std::istringstream is(mkstr("\x00\x08\0a\0b\0c\0d\0e\0f"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeWideString(is));
	}
}
コード例 #3
0
void TestSerialization::testDeSerializeLongString()
{
	// Test deserialize
	{
		std::istringstream is(serializeLongString(teststring2), std::ios::binary);
		UASSERT(deSerializeLongString(is) == teststring2);
		UASSERT(!is.eof());
		is.get();
		UASSERT(is.eof());
	}

	// Test deserialize an incomplete length specifier
	{
		std::istringstream is(mkstr("\x53"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeLongString(is));
	}

	// Test deserialize a string with incomplete data
	{
		std::istringstream is(mkstr("\x00\x00\x00\x05 abc"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeLongString(is));
	}

	// Test deserialize a string with a length too large
	{
		std::istringstream is(mkstr("\xFF\xFF\xFF\xFF blah"), std::ios::binary);
		EXCEPTION_CHECK(SerializationError, deSerializeLongString(is));
	}
}
コード例 #4
0
ファイル: adplib.c プロジェクト: u-u-h/adpc
tsequence *readseq_next_line(treadseq *rs){

  tsequence *ts;
  int pos;

  ts = sequence_new();
  ts->success    = 0;
  if (adplib_debug>1) printf("rs: success = 0\n");

  if (adplib_debug>1) printf("rs: %d\n", rs->start[rs->current]);

  rs->temp[0] = 0; pos = 0;
  if (rs->start[rs->current] != 0) {
    while ((rs->start[rs->current] != '\n') && (rs->start[rs->current] != 0)) 
       rs->temp[pos++] = rs->start[rs->current++];
    if (rs->start[rs->current]=='\n') rs->current++;

    rs->temp[pos] = 0;
    ts->seq          = mkstr(rs->temp);
    ts->original_seq = mkstr(rs->temp);

    // remove additional #13 for DOS input files:
    if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0;
  
    // remove additional #13 for DOS input files:
    if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0;

    ts->length = ts->original_length = strlen(ts->seq);
    ts->success    = 1;
    if (adplib_debug>1) printf("rs: success = 1\n");
  }
  
  return ts; 
}
コード例 #5
0
/* bbcall - build tree to set _callsite at call site *cp, emit call site data */
static void bbcall(Symbol yycounts, Coordinate* cp, Tree* e) {
    static Symbol caller;
    Value v;
    union coordinate u;
    Symbol p = genident(STATIC, array(voidptype, 0, 0), GLOBAL);
    Tree t = *e;

    defglobal(p, LIT);
    defpointer(cp->file ? mkstr(cp->file)->u.c.loc : (Symbol)0);
    defpointer(mkstr(cfunc->name)->u.c.loc);
    if (IR->little_endian) {
        u.le.x = cp->x;
        u.le.y = cp->y;
    } else {
        u.be.x = cp->x;
        u.be.y = cp->y;
    }
    (*IR->defconst)(U, unsignedtype->size, (v.u = u.coord, v));
    if (caller == 0) {
        caller = mksymbol(EXTERN, "_caller", ptr(voidptype));
        caller->defined = 0;
    }
    if (generic((*e)->op) != CALL)
        t = (*e)->kids[0];
    assert(generic(t->op) == CALL);
    t = tree(t->op, t->type,
             tree(RIGHT, t->kids[0]->type,
                  t->kids[0],
                  tree(RIGHT, t->kids[0]->type, asgn(caller, idtree(p)), t->kids[0])),
             t->kids[1]);
    if (generic((*e)->op) != CALL)
        t = tree((*e)->op, (*e)->type, t, (*e)->kids[1]);
    *e = t;
}
コード例 #6
0
ファイル: adplib.c プロジェクト: u-u-h/adpc
void tokenizer_exec(ttokenizer *t, char *name, char *s)
{
  int i;
  char in_quotes;
  char *ttoken;
  char  septoken[]  = {1,0};

  // free old token strings:
  for (i=0; i < t->count; i++) free(t->token[i]);

  // build new token array: 
  t->count = 1;

  // replace whitespaces:
  in_quotes = 0;
  for (i=0; i<strlen(s); i++) {
    if (!in_quotes && (s[i] == ' ')) s[i] = 1;
    if (s[i] == 39) {
      in_quotes = 1-in_quotes;
      s[i] = 1;
    }
  }
  // build token list:
  t->token[0]     = mkstr(name);
  while((ttoken = strtok(s,septoken))) {
    t->token[t->count++] = mkstr(ttoken);
    s = NULL;
  }
  // debug output:
  /*   if (debug) { */
  /*        printf("#token: %d\n", t->count-1);  */
  /*        for (i=1;i<t->count;i++) printf("%s\n", t->token[i]);  */
}
コード例 #7
0
ファイル: workers.c プロジェクト: atj/nagios
/*
 * Handles adding the command and macros to the kvvec,
 * as well as shipping the command off to a designated
 * worker
 */
static int wproc_run_job(worker_job *job, nagios_macros *mac)
{
	static struct kvvec kvv = KVVEC_INITIALIZER;
	worker_process *wp;

	/*
	 * get_worker() also adds job to the workers list
	 * and sets job_id
	 */
	wp = get_worker(job);
	if (!wp || job->id < 0)
		return ERROR;

	/*
	 * XXX FIXME: add environment macros as
	 *  kvvec_addkv(kvv, "env", "NAGIOS_LALAMACRO=VALUE");
	 *  kvvec_addkv(kvv, "env", "NAGIOS_LALAMACRO2=VALUE");
	 * so workers know to add them to environment. For now,
	 * we don't support that though.
	 */
	if (!kvvec_init(&kvv, 4))	/* job_id, type, command and timeout */
		return ERROR;

	kvvec_addkv(&kvv, "job_id", (char *)mkstr("%d", job->id));
	kvvec_addkv(&kvv, "type", (char *)mkstr("%d", job->type));
	kvvec_addkv(&kvv, "command", job->command);
	kvvec_addkv(&kvv, "timeout", (char *)mkstr("%u", job->timeout));
	send_kvvec(wp->sd, &kvv);
	wp->jobs_running++;
	wp->jobs_started++;

	return 0;
}
コード例 #8
0
ファイル: mpirun_ckpt.c プロジェクト: hpc/mvapich2-cce
char *create_mpispawn_vars(char *mpispawn_env)
{

    char *tmp = NULL;
#ifdef CR_FTB
    /* Keep mpispawn happy. Pass some junk value */
    tmp = mkstr("%s MPISPAWN_MPIRUN_CR_PORT=%d", mpispawn_env, 0);
#else
    tmp = mkstr("%s MPISPAWN_MPIRUN_CR_PORT=%d", mpispawn_env, mpirun_port);
#endif
    if (tmp) {
        free(mpispawn_env);
        mpispawn_env = tmp;
    } else {
        PRINT_ERROR("[1] mkstr() failed\n");
        goto allocation_error;
    }

    // TODO Should be useless, MPISPAWN_CR_CKPT_CNT should be enough
    // Remove this in the future
    int restart_context = 0;
    if ( restart_version >= 0 ) restart_context = 1;
    tmp = mkstr("%s MPISPAWN_CR_CONTEXT=%d", mpispawn_env, restart_context);
    if (tmp) {
        free(mpispawn_env);
        mpispawn_env = tmp;
    } else {
        PRINT_ERROR("[2] mkstr() failed\n");
        goto allocation_error;
    }

    tmp = mkstr("%s MPISPAWN_CR_SESSIONID=%s", mpispawn_env, sessionid);
    if (tmp) {
        free(mpispawn_env);
        mpispawn_env = tmp;
    } else {
        PRINT_ERROR("[3] mkstr() failed\n");
        goto allocation_error;
    }

    tmp = mkstr("%s MPISPAWN_CR_CKPT_CNT=%d", mpispawn_env, restart_version);
    if (tmp) {
        free(mpispawn_env);
        mpispawn_env = tmp;
    } else {
        PRINT_ERROR("[4] mkstr() failed\n");
        goto allocation_error;
    }

    return tmp;

  allocation_error:
    if (mpispawn_env) {
        PRINT_ERROR("Error: current mpispawn_env = '%s'\n", mpispawn_env);
        free(mpispawn_env);
    }
    exit(EXIT_FAILURE);

}
コード例 #9
0
ファイル: sftp.c プロジェクト: lalbornoz/FySTY
struct fxp_names *fxp_readdir_recv(struct sftp_packet *pktin,
				   struct sftp_request *req)
{
    sfree(req);
    if (pktin->type == SSH_FXP_NAME) {
	struct fxp_names *ret;
	unsigned long i;

        i = get_uint32(pktin);

	/*
	 * Sanity-check the number of names. Minimum is obviously
	 * zero. Maximum is the remaining space in the packet
	 * divided by the very minimum length of a name, which is
	 * 12 bytes (4 for an empty filename, 4 for an empty
	 * longname, 4 for a set of attribute flags indicating that
	 * no other attributes are supplied).
	 */
	if (get_err(pktin) || i > get_avail(pktin) / 12) {
	    fxp_internal_error("malformed FXP_NAME packet");
	    sftp_pkt_free(pktin);
	    return NULL;
	}

	/*
	 * Ensure the implicit multiplication in the snewn() call
	 * doesn't suffer integer overflow and cause us to malloc
	 * too little space.
	 */
	if (i > INT_MAX / sizeof(struct fxp_name)) {
	    fxp_internal_error("unreasonably large FXP_NAME packet");
	    sftp_pkt_free(pktin);
	    return NULL;
	}

	ret = snew(struct fxp_names);
	ret->nnames = i;
	ret->names = snewn(ret->nnames, struct fxp_name);
	for (i = 0; i < (unsigned long)ret->nnames; i++) {
	    ret->names[i].filename = mkstr(get_string(pktin));
	    ret->names[i].longname = mkstr(get_string(pktin));
            get_fxp_attrs(pktin, &ret->names[i].attrs);
        }

	if (get_err(pktin)) {
            fxp_internal_error("malformed FXP_NAME packet");
            for (i = 0; i < (unsigned long)ret->nnames; i++) {
                sfree(ret->names[i].filename);
                sfree(ret->names[i].longname);
            }
            sfree(ret->names);
            sfree(ret);
            sfree(pktin);
            return NULL;
	}
        sftp_pkt_free(pktin);
	return ret;
    } else {
コード例 #10
0
ファイル: workers.c プロジェクト: caidui/nagios4-cn
/*
 * Handles adding the command and macros to the kvvec,
 * as well as shipping the command off to a designated
 * worker
 */
static int wproc_run_job(struct wproc_job *job, nagios_macros *mac)
{
	static struct kvvec kvv = KVVEC_INITIALIZER;
	struct kvvec_buf *kvvb;
	struct kvvec *env_kvvp = NULL;
	struct kvvec_buf *env_kvvb = NULL;
	struct wproc_worker *wp;
	int ret, result = OK;

	if (!job || !job->wp)
		return ERROR;

	wp = job->wp;

	if (!kvvec_init(&kvv, 4))	/* job_id, type, command and timeout */
		return ERROR;

	kvvec_addkv(&kvv, "job_id", (char *)mkstr("%d", job->id));
	kvvec_addkv(&kvv, "type", (char *)mkstr("%d", job->type));
	kvvec_addkv(&kvv, "command", job->command);
	kvvec_addkv(&kvv, "timeout", (char *)mkstr("%u", job->timeout));

	/* Add the macro environment variables */
	if(mac) {
		env_kvvp = macros_to_kvv(mac);
		if(NULL != env_kvvp) {
			env_kvvb = kvvec2buf(env_kvvp, '=', '\n', 0);
			if(NULL == env_kvvb) {
				kvvec_destroy(env_kvvp, KVVEC_FREE_KEYS);
			}
			else {
				kvvec_addkv_wlen(&kvv, "env", strlen("env"), env_kvvb->buf,
						env_kvvb->buflen);
			}
		}
	}
	kvvb = build_kvvec_buf(&kvv);
	ret = write(wp->sd, kvvb->buf, kvvb->bufsize);
	if (ret != (int)kvvb->bufsize) {
		logit(NSLOG_RUNTIME_ERROR, TRUE, "wproc: '%s' seems to be choked. ret = %d; bufsize = %lu: errno = %d (%s)\n",
			  wp->name, ret, kvvb->bufsize, errno, strerror(errno));
		destroy_job(job);
		result = ERROR;
	} else {
		wp->jobs_running++;
		wp->jobs_started++;
		loadctl.jobs_running++;
	}
	if(NULL != env_kvvp) kvvec_destroy(env_kvvp, KVVEC_FREE_KEYS);
	if(NULL != env_kvvb) {
		free(env_kvvb->buf);
		free(env_kvvb);
	}
	free(kvvb->buf);
	free(kvvb);

	return result;
}
コード例 #11
0
std::string CInitializer::GetDefaultsXmlFile()
{
    std::string fzdatadir = mkstr(getenv("FZ_DATADIR"));
    std::string file = CheckPathForDefaults(fzdatadir, 0, "fzdefaults.xml");
    if (!file.empty())
        return file;
    file = CheckPathForDefaults(fzdatadir, 1, "fzdefaults.xml");
    if (!file.empty())
        return file;

    std::string home = mkstr(getenv("HOME"));
    if (!home.empty())
    {
        if (home[home.size() - 1] != '/')
            home += '/';
        home += ".filezilla/fzdefaults.xml";

        struct stat buf;
        if (!stat(home.c_str(), &buf))
            return home;
    }

    file = "/etc/filezilla/fzdefaults.xml";

    struct stat buf;
    if (!stat(file.c_str(), &buf))
        return file;


    file = CheckPathForDefaults(mkstr(SELFPATH), 2, "share/filezilla/fzdefaults.xml");
    if (!file.empty())
        return file;
    file = CheckPathForDefaults(mkstr(DATADIR), 0, "filezilla/fzdefaults.xml");
    if (!file.empty())
        return file;

    std::string path = mkstr(getenv("PATH"));
    while (!path.empty())
    {
        std::string segment;
        int pos = path.find(':');
        if (pos == -1)
            segment.swap(path);
        else
        {
            segment = path.substr(0, pos);
            path = path.substr(pos + 1);
        }

        file = CheckPathForDefaults(segment, 1, "share/filezilla/fzdefaults.xml");
        if (!file.empty())
            return file;
    }

    return "";
}
コード例 #12
0
ファイル: nsock_proxy.c プロジェクト: 4nY0n0m0u5/nmap
static int parse_uri(const char *proxystr, struct uri *uri) {
  const char *p, *q;

  /* Scheme, section 3.1. */
  p = proxystr;
  if (!isalpha(*p))
    goto fail;

  q = p;
  while (isalpha(*q) || isdigit(*q) || *q == '+' || *q == '-' || *q == '.')
    q++;

  if (*q != ':')
      goto fail;

  uri->scheme = mkstr(p, q);

  /* "An implementation should accept uppercase letters as equivalent to
   * lowercase in scheme names (e.g., allow "HTTP" as well as "http") for the
   * sake of robustness..." */
  lowercase(uri->scheme);

  /* Authority, section 3.2. */
  p = q + 1;
  if (*p == '/' && *(p + 1) == '/') {
    char *authority = NULL;

    p += 2;
    q = p;
    while (!(*q == '/' || *q == '?' || *q == '#' || *q == '\0'))
      q++;
          ;
    authority = mkstr(p, q);
    if (uri_parse_authority(authority, uri) < 0) {
      free(authority);
      goto fail;
    }
    free(authority);

    p = q;
  }

  /* Path, section 3.3. We include the query and fragment in the path. The
   * path is also not percent-decoded because we just pass it on to the origin
   * server. */

  q = strchr(p, '\0');
  uri->path = mkstr(p, q);

  return 1;

fail:
  uri_free(uri);
  return -1;
}
コード例 #13
0
void TestSerialization::testSerializeString()
{
	// Test blank string
	UASSERT(serializeString("") == mkstr("\0\0"));

	// Test basic string
	UASSERT(serializeString("Hello world!") == mkstr("\0\14Hello world!"));

	// Test character range
	UASSERT(serializeString(teststring2) == mkstr("\1\0") + teststring2);
}
コード例 #14
0
ファイル: utils.c プロジェクト: tfb-bull/lcap
int uri_parse(const char *uri_s, struct uri *uri)
{
    const char *p, *q;

    uri_init(uri);

    /* Scheme, section 3.1. */
    p = uri_s;
    if (!is_alpha_char(*p))
        goto fail;

    q = p;
    while (is_alpha_char(*q)
           || is_digit_char(*q)
           || *q == '+'
           || *q == '-'
           || *q == '.')
        q++;

    if (*q != ':')
        goto fail;

    uri->scheme = mkstr(p, q);
    lowercase(uri->scheme);

    /* Authority, section 3.2. */
    p = q + 1;
    if (*p == '/' && *(p + 1) == '/') {
        char *authority = NULL;

        p += 2;
        q = p;
        while (!(*q == '/' || *q == '?' || *q == '#' || *q == '\0'))
            q++;

        authority = mkstr(p, q);
        if (uri_parse_authority(uri, authority)) {
            free(authority);
            goto fail;
        }
        free(authority);
        p = q;
    }

    q = strchr(p, '\0');
    uri->path = mkstr(p, q);

    return 0;

fail:
    uri_free(uri);
    return -EINVAL;
}
コード例 #15
0
ファイル: http.c プロジェクト: mogi57/nmap-5.61TEST4-android
/* Parse a URI string into a struct URI. Any parts of the URI that are absent
   will become NULL entries in the structure, except for the port which will be
   -1. Returns NULL on error. See RFC 3986, section 3 for syntax. */
struct uri *uri_parse(struct uri *uri, const char *uri_s)
{
    const char *p, *q;

    uri_init(uri);

    /* Scheme, section 3.1. */
    p = uri_s;
    if (!is_alpha_char(*p))
        goto fail;
    for (q = p; is_alpha_char(*q) || is_digit_char(*q) || *q == '+' || *q == '-' || *q == '.'; q++)
        ;
    if (*q != ':')
        goto fail;
    uri->scheme = mkstr(p, q);
    /* "An implementation should accept uppercase letters as equivalent to
       lowercase in scheme names (e.g., allow "HTTP" as well as "http") for the
       sake of robustness..." */
    lowercase(uri->scheme);

    /* Authority, section 3.2. */
    p = q + 1;
    if (*p == '/' && *(p + 1) == '/') {
        char *authority = NULL;

        p += 2;
        for (q = p; !(*q == '/' || *q == '?' || *q == '#' || *q == '\0'); q++)
            ;
        authority = mkstr(p, q);
        if (uri_parse_authority(uri, authority) == NULL) {
            free(authority);
            goto fail;
        }
        free(authority);

        p = q;
    }
    if (uri->port == -1)
        uri->port = scheme_default_port(uri->scheme);

    /* Path, section 3.3. We include the query and fragment in the path. The
       path is also not percent-decoded because we just pass it on to the origin
       server. */
    q = strchr(p, '\0');
    uri->path = mkstr(p, q);

    return uri;

fail:
    uri_free(uri);
    return NULL;
}
コード例 #16
0
void TestSerialization::testSerializeWideString()
{
	// Test blank string
	UASSERT(serializeWideString(L"") == mkstr("\0\0"));

	// Test basic string
	UASSERT(serializeWideString(utf8_to_wide("Hello world!")) ==
		mkstr("\0\14\0H\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0!"));

	// Test character range
	UASSERT(serializeWideString(teststring2_w) ==
		mkstr("\1\0") + teststring2_w_encoded);
}
コード例 #17
0
ファイル: t_exhaust.c プロジェクト: SylvestreG/bitrig
static char *
ps(const char *m, const char *s, size_t len)
{
	char *d, *s1, *s2, *s3;
	s1 = mkstr(m, len);
	s2 = mkstr(s, len);
	s3 = concat(s1, s2);
	free(s2);
	free(s1);
	d = concat("(.?)", s3);
	free(s3);
	return d;
}
コード例 #18
0
ファイル: t_exhaust.c プロジェクト: SylvestreG/bitrig
static char *
p6(size_t len)
{
	char *d, *s1, *s2;
	s1 = mkstr("(?:(.*)|", len);
	s2 = concat(s1, "(.*)");
	free(s1);
	s1 = mkstr(")", len);
	d = concat(s2, s1);
	free(s1);
	free(s2);
	return d;
}
コード例 #19
0
ファイル: match.c プロジェクト: Dioxylin/es-shell
static List *extractsinglematch(const char *subject, const char *pattern,
				const char *quoting, List *result) {
	int i;
	const char *s;

	if (!haswild(pattern, quoting) /* no wildcards, so no matches */
	    || !match(subject, pattern, quoting))
		return NULL;

	for (s = subject, i = 0; pattern[i] != '\0'; s++) {
		if (ISQUOTED(quoting, i))
			i++;
		else {
			int c = pattern[i++];
			switch (c) {
			    case '*': {
				const char *begin;
				if (pattern[i] == '\0')
					return mklist(mkstr(gcdup(s)), result);
				for (begin = s;; s++) {
					const char *q = TAILQUOTE(quoting, i);
					assert(*s != '\0');
					if (match(s, pattern + i, q)) {
						result = mklist(mkstr(gcndup(begin, s - begin)), result);
						return haswild(pattern + i, q)
							? extractsinglematch(s, pattern + i, q, result)
							: result;
					}
				}
			    }
			    case '[': {
				int j = rangematch(pattern + i, TAILQUOTE(quoting, i), *s);
				assert(j != RANGE_FAIL);
				if (j == RANGE_ERROR) {
					assert(*s == '[');
					break;
				}
				i += j;
			    }
			    /* FALLTHROUGH */
			    case '?':
				result = mklist(mkstr(str("%c", *s)), result);
				break;
			    default:
				break;
			}
		}
	}

	return result;
}
コード例 #20
0
ファイル: t_exhaust.c プロジェクト: SylvestreG/bitrig
static char *
p1(size_t len)
{
	char *d, *s1, *s2, *s3;
	s1 = mkstr("\\(", 60);
	s2 = mkstr("(.*)", len);
	s3 = concat(s1, s2);
	free(s2);
	free(s1);
	s1 = concat(s3, ")");
	free(s3);
	d = concat("(", s1);
	free(s1);
	return d;
}
コード例 #21
0
ファイル: debug.cpp プロジェクト: Lnd-stoL/glGraphics
    /*static*/ void gl::printGLError (GLenum errorCode)
    {
        if (errorCode == GL_NO_ERROR) return;

        std::string errorString = "";
        if (errorCode == GL_INVALID_ENUM)
            errorString = "GL_INVALID_ENUM: An unacceptable value is specified for an enumerated argument.";

        else if (errorCode == GL_INVALID_VALUE)
            errorString = "GL_INVALID_VALUE: A numeric argument is out of range.";

        else if (errorCode == GL_INVALID_OPERATION)
            errorString = "GL_INVALID_OPERATION: The specified operation is not allowed in the current state.";

        else if (errorCode == GL_INVALID_FRAMEBUFFER_OPERATION)
            errorString = "GL_INVALID_FRAMEBUFFER_OPERATION: The framebuffer object is not complete.";

        else if (errorCode == GL_OUT_OF_MEMORY)
            errorString = "GL_OUT_OF_MEMORY: There is not enough memory left to execute the command.";

        else errorString = "Unknown internal error.";


        log::println_err (mkstr ("OpenGL reported an error: (", (unsigned) errorCode, ") ", errorString));
    }
コード例 #22
0
std::string CInitializer::GetSettingFromFile(std::string file, const std::string& name)
{
    TiXmlDocument xmldoc;
    if (!xmldoc.LoadFile(file.c_str()))
        return "";

    TiXmlElement* main = xmldoc.FirstChildElement("FileZilla3");
    if (!main)
        return "";

    TiXmlElement* settings = main->FirstChildElement("Settings");
    if (!settings)
        return "";

    for (TiXmlElement* setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting"))
    {
        const char* nodeVal = setting->Attribute("name");
        if (!nodeVal || strcmp(nodeVal, name.c_str()))
            continue;

        TiXmlNode* textNode = setting->FirstChild();
        if (!textNode || !textNode->ToText())
            continue;

        return mkstr(textNode->Value());
    }

    return "";
}
コード例 #23
0
void YouBotOODLWrapper::initializeBase() {

	try {
		youBotBase = new youbot::YouBotBase("youbot-base", mkstr(YOUBOT_CONFIGURATIONS_DIR));
		youBotBase->doJointCommutation();
//	} catch (youbot::FileNotFoundException& e) {
	} catch (std::exception& e) {
		std::string errorMessage = e.what();
		ROS_FATAL("Cannot open youBot driver: \n %s ", errorMessage.c_str());
		ROS_ERROR("Base could not be initialized!");
		hasBase = false;
		return;
	}

	/* setup input/output communication */
	baseCommandSubscriber = node.subscribe("cmd_vel", 1000, &YouBotOODLWrapper::baseCommandCallback, this);
	baseOdometryPublisher = node.advertise<nav_msgs::Odometry>("odom", 1);
	baseJointStatePublisher = node.advertise<sensor_msgs::JointState>("base_joint_states", 1);

	/* setup frame_ids */
	youBotOdometryFrameID = "odom";
	youBotOdometryChildFrameID = "base_footprint";

	ROS_INFO("Base is initialized.");
	hasBase = true;
}
コード例 #24
0
ファイル: sftp.c プロジェクト: lalbornoz/FySTY
char *fxp_realpath_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
    sfree(req);

    if (pktin->type == SSH_FXP_NAME) {
	unsigned long count;
        char *path;
        ptrlen name;

        count = get_uint32(pktin);
	if (get_err(pktin) || count != 1) {
	    fxp_internal_error("REALPATH did not return name count of 1\n");
            sftp_pkt_free(pktin);
	    return NULL;
	}
        name = get_string(pktin);
	if (get_err(pktin)) {
	    fxp_internal_error("REALPATH returned malformed FXP_NAME\n");
            sftp_pkt_free(pktin);
	    return NULL;
	}
        path = mkstr(name);
	sftp_pkt_free(pktin);
        return path;
    } else {
	fxp_got_status(pktin);
        sftp_pkt_free(pktin);
	return NULL;
    }
}
コード例 #25
0
ファイル: glob.c プロジェクト: Dioxylin/es-shell
/* glob -- globbing prepass (glob if we need to, and dispatch for tilde expansion) */
extern List *glob(List *list, StrList *quote) {
	List *lp;
	StrList *qp;
	Boolean doglobbing = FALSE;

	for (lp = list, qp = quote; lp != NULL; lp = lp->next, qp = qp->next)
		if (qp->str != QUOTED) {
			assert(lp->term != NULL);
			assert(!isclosure(lp->term));
			Ref(char *, str, getstr(lp->term));
			assert(qp->str == UNQUOTED || strlen(qp->str) == strlen(str));
			if (hastilde(str, qp->str)) {
				Ref(List *, l0, list);
				Ref(List *, lr, lp);
				Ref(StrList *, q0, quote);
				Ref(StrList *, qr, qp);
				str = expandhome(str, qp);
				lr->term = mkstr(str);
				lp = lr;
				qp = qr;
				list = l0;
				quote = q0;
				RefEnd4(qr, q0, lr, l0);
			}
			if (haswild(str, qp->str))
				doglobbing = TRUE;
			RefEnd(str);
		}
コード例 #26
0
ファイル: ssh2connection-server.c プロジェクト: gdh1995/putty
static ChanopenResult chan_open_direct_tcpip(
    struct ssh2_connection_state *s, SshChannel *sc,
    ptrlen dstaddr, int dstport, ptrlen peeraddr, int peerport)
{
    PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
    Channel *ch;
    char *dstaddr_str, *err;

    dstaddr_str = mkstr(dstaddr);

    ppl_logevent("Received request to connect to port %s:%d (from %.*s:%d)",
                 dstaddr_str, dstport, PTRLEN_PRINTF(peeraddr), peerport);
    err = portfwdmgr_connect(
        s->portfwdmgr, &ch, dstaddr_str, dstport, sc, ADDRTYPE_UNSPEC);

    sfree(dstaddr_str);

    if (err != NULL) {
        ppl_logevent("Port open failed: %s", err);
        sfree(err);
        CHANOPEN_RETURN_FAILURE(
            SSH2_OPEN_CONNECT_FAILED, ("Connection failed"));
    }

    ppl_logevent("Port opened successfully");
    CHANOPEN_RETURN_SUCCESS(ch);
}
コード例 #27
0
ファイル: misccmds.c プロジェクト: GnoConsortium/gno
bool_t
delchar(bool_t fixpos, bool_t undo)
/*    bool_t          fixpos;	/* if TRUE fix the cursor position when done */
/*    bool_t          undo;	/* if TRUE put char deleted into Undo buffer */
{
    int             i;

    /* Check for degenerate case; there's nothing in the file. */
    if (bufempty())
	return FALSE;

    if (lineempty(Curschar))	/* can't do anything */
	return FALSE;

    if (undo)
	AppendToUndobuff(mkstr(gchar(Curschar)));

    /* Delete the char. at Curschar by shifting everything in the line down. */
    for (i = Curschar->index + 1; i < Curschar->linep->size; i++)
	Curschar->linep->s[i - 1] = Curschar->linep->s[i];

    /*
     * If we just took off the last character of a non-blank line, we don't
     * want to end up positioned at the newline. 
     */
    if (fixpos) {
	if (gchar(Curschar) == NUL && Curschar->index > 0 && State != INSERT)
	    Curschar->index--;
    }
    CHANGED;
    return TRUE;
}
コード例 #28
0
ファイル: http.c プロジェクト: mogi57/nmap-5.61TEST4-android
/* Returns 0 on success and nonzero on failure. */
int http_parse_status_line(const char *line, struct http_response *response)
{
    const char *p, *q;

    http_response_init(response);

    /* Version. */
    p = parse_http_version(line, &response->version);
    if (p == line)
        return -1;
    while (*p == ' ')
        p++;

    /* Status code. */
    errno = 0;
    response->code = parse_long(p, (char **) &q);
    if (errno != 0 || q == p)
        return -1;
    p = q;

    /* Reason phrase. */
    while (*p == ' ')
        p++;
    q = p;
    while (!is_crlf(q))
        q++;
    /* We expect that the CRLF ends the string. */
    if (*skip_crlf(q) != '\0')
        return -1;
    response->phrase = mkstr(p, q);

    return 0;
}
コード例 #29
0
ファイル: adplib.c プロジェクト: u-u-h/adpc
/* create a new format string entry */
static tformat_string *format_string_newentry(char type, char *string){
  tformat_string *f;
  f = (tformat_string *) mcalloc(1, sizeof(tformat_string));
  f->type   = type;
  f->string = mkstr(string);
  f->next   = NULL;
  return f;
}
コード例 #30
0
ファイル: adplib.c プロジェクト: u-u-h/adpc
tsequence *readseq_next_fasta(treadseq *rs){

  tsequence *ts;
  int pos;
  char inpc,fil;

  ts = sequence_new();

  rs->temp[0] = 0; pos = 0;
  if ((rs->start[rs->current] == '>')  && (rs->start[rs->current] != 0)) {
    if (!rs->first_descr_read && rs->first_input_read) {
      fprintf(stderr, "error in input file: missing description for first sequence\n");
      exit(1);
    }
    rs->first_descr_read = 1;
    rs->current++;
    while ((rs->start[rs->current] != '\n') && (rs->start[rs->current] != 0)) rs->temp[pos++] = rs->start[rs->current++];
    if (rs->start[rs->current]) rs->current++;
  }
  rs->temp[pos] = 0;
  ts->descr = mkstr(rs->temp);

  // remove additional #13 for DOS input files:
  if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0;

  rs->temp[0] = 0; pos = 0;
  fil = 1;
  while ((fil || (rs->start[rs->current] != '>')) && (rs->start[rs->current] != 0)) {
    while (((inpc = rs->start[rs->current]) != '\n') && (rs->start[rs->current] != 0)) 
       if (((inpc >= 65) && (inpc <= 90)) ||
           ((inpc >= 97) && (inpc <= 122))) rs->temp[pos++] = rs->start[rs->current++];
       else                                 rs->current++;
    fil = 0;
    if (rs->start[rs->current]) rs->current++;
    rs->first_input_read = 1;
  }
  rs->temp[pos] = 0;
  ts->seq           = mkstr(rs->temp);
  ts->original_seq  = mkstr(rs->temp);
  ts->length = ts->original_length = strlen(ts->seq);
  if (ts->seq[0]) ts->success    = 1;
  else            ts->success    = 0;

  return ts; 
}