示例#1
0
void Test__cstring_new(CuTest* tc)
{
  CSTRING* cptr = NULL;

  // check creation with a 0
  cptr = cstring_new(0);
  CuAssertPtrNotNull(tc, cptr);
  CuAssertStrEquals(tc, "", cptr->string);
  CuAssertIntEquals(tc, 0, cptr->length);
  CuAssertIntEquals(tc, CSTRING_BUFSIZE, cptr->memsize);
  CuAssertIntEquals(tc, 1, cptr->canfree);
  cstring_free(&cptr);

  // check creation with a higher value
  cptr = cstring_new(128);
  CuAssertPtrNotNull(tc, cptr);
  CuAssertStrEquals(tc, "", cptr->string);
  CuAssertIntEquals(tc, 0, cptr->length);
  CuAssertIntEquals(tc, 129, cptr->memsize);
  CuAssertIntEquals(tc, 1, cptr->canfree);
  cstring_free(&cptr);
}
示例#2
0
void entity_header_free(entity_header p)
{
	if(p != NULL) {
		cstring_free(p->allow);
		cstring_free(p->content_encoding);
		cstring_free(p->content_language);
		cstring_free(p->content_location);
		cstring_free(p->content_md5);
		cstring_free(p->content_type);
		cstring_free(p->content_range);
		cstring_free(p->cache_control);

		free(p);
	}
}
示例#3
0
cstring cstring_dup(const char* src)
{
	cstring dest = NULL;

	assert(src != NULL);
	if( (dest = cstring_new()) != NULL) {
		if(!cstring_copy(dest, src)) {
			cstring_free(dest);
			dest = NULL;
		}
	}

	return dest;
}
示例#4
0
int
uentryList_lookupRealName (uentryList s, cstring name)
{
  if (uentryList_isDefined (s))
    {
      int i;
      
      for (i = 0; i < uentryList_size (s); i++)
	{
	  cstring uname = uentry_getName (s->elements[i]);

	  if (cstring_equal (name, uname))
	    {
	      cstring_free (uname);
	      return i;
	    }      

	  cstring_free (uname);
	}
    }

   return -1;
}
示例#5
0
static int parse_new_cookie_secure(cookie c, const char* value, meta_error e)
{
	int secure;
	cstring str;
	
	if( (str = cstring_new()) == NULL) 
		return set_os_error(e, errno);

	if(!get_cookie_attribute(value, "$Secure", str, e)) {
		cstring_free(str);
		return 0;
	}

	secure = atoi(c_str(str));
	if(secure != 1 && secure != 0) {
		cstring_free(str);
		return set_http_error(e, HTTP_400_BAD_REQUEST);
	}

	cookie_set_secure(c, secure);
	cstring_free(str);
	return 1;
}
示例#6
0
文件: demo_hsrfs.c 项目: okayman/ebgn
EC_BOOL __test_crfs_runner()
{
    UINT32 crfs_modi;

    CSTRING *crfsnp_root_dir;
    CSTRING *crfsdn_root_dir;

    crfsnp_root_dir = cstring_new((UINT8 *)CRFS_NP_ROOT_DIR, 0);
    ASSERT(NULL_PTR != crfsnp_root_dir);

    crfsdn_root_dir = cstring_new((UINT8 *)CRFS_DN_ROOT_DIR, 0);
    ASSERT(NULL_PTR != crfsdn_root_dir);    

    crfs_modi = crfs_start(crfsnp_root_dir, crfsdn_root_dir);
    ASSERT(ERR_MODULE_ID != crfs_modi);

    cstring_free(crfsnp_root_dir);
    cstring_free(crfsdn_root_dir);

    //crfs_end(crfs_modi);
    
    return (EC_TRUE);
}
示例#7
0
cstring cstring_left(cstring src, size_t n)
{
	cstring dest;

	assert(src != NULL);

	if( (dest = cstring_new()) == NULL || !cstring_extend(dest, n)) {
		cstring_free(dest);
		dest = NULL;
	}
	else
		cstring_ncopy(dest, src->data, n);

	return dest;
}
示例#8
0
/*
 * look for name=value as in $Version="1";foo=bar  and 
 * add name and value to the cookie .
 * Returns 1 on success, else a http error do
 */
static int parse_new_cookie_name(cookie c, const char* input, meta_error e)
{
	const char *s, *s2;
	cstring str;

	if( (s = strchr(input, ';')) == NULL) 
		return set_http_error(e, HTTP_400_BAD_REQUEST);

	/* skip ; and white space (if any) */
	if( (s = find_first_non_space(++s)) == NULL) {
		/* If all we had was ws */
		return set_http_error(e, HTTP_400_BAD_REQUEST);
	}

	if( (s2 = strchr(s, '=')) == NULL) {
		/* Missing = in Name= */
		return set_http_error(e, HTTP_400_BAD_REQUEST);
	}

	if( (str = cstring_new()) == NULL)  
		return set_os_error(e, errno);

	if(!cstring_ncopy(str, s, (size_t) (s2 - s + 1))) {
		cstring_free(str);
		return set_os_error(e, errno);
	}
		
	if(!cookie_set_name(c, c_str(str))) {
		cstring_free(str);
		return set_os_error(e, errno);
	}
		
	s = s2 + 1;
	cstring_recycle(str);
	if( (s2 = strchr(s, ';')) == NULL) {
		/* Missing ; in Name=value; */
		cstring_free(str);
		return set_http_error(e, HTTP_400_BAD_REQUEST);
	}

	if(!cstring_ncopy(str, s, (size_t)(s2 - s + 1))) {
		cstring_free(str);
		return set_os_error(e, errno);
	}

	if(!cookie_set_value(c, c_str(str))) {
		cstring_free(str);
		return set_os_error(e, errno);
	}

	cstring_free(str);
	return 1;
}
示例#9
0
int cstring_multinew(cstring* pstr, size_t nelem)
{
	size_t i;

	assert(pstr != NULL);
	assert(nelem > 0);

	for(i = 0; i < nelem; i++) {
		if( (pstr[i] = cstring_new()) == NULL) {
			while(i-- > 0) 
				cstring_free(pstr[i]);

			return 0;
		}
	}

	return 1;
}
示例#10
0
void
cstringList_free (cstringList s)
{
  if (cstringList_isDefined (s))
    {
      int i;

      DPRINTF (("cstringList free: [%p] %s",
		s, cstringList_unparse (s)));

      /* evans 2002-07-12: this was missing, not detected because of reldef */
      for (i = 0; i < s->nelements; i++)
	{
	  cstring_free (s->elements[i]);
	}

      sfree (s->elements);
      sfree (s);
    }
}
示例#11
0
文件: raw_data.c 项目: petercloud/RFS
uint8_t  rawFileExist(const uint8_t *file_name, const word_t cdfs_md_id)
{
    CSTRING *fname_cstr;
    MEM_CHECK(file_name);

    fname_cstr = cstring_new(file_name, LOC_RAW_0002);
    if(NULL_PTR == fname_cstr)
    {
        dbg_log(SEC_0132_RAW, 0)(LOGSTDOUT, "error:rawFileExist: new file name string failed\n");
        return RAW_FILE_FAIL;
    }

    if(EC_FALSE == cdfs_exists_npp(cdfs_md_id, fname_cstr))
    {
        cstring_free(fname_cstr);
        return RAW_FILE_FAIL;
    }

    return RAW_FILE_SUCC;
}
示例#12
0
dynamic_page dynamic_new(const char* uri, PAGE_FUNCTION handler, page_attribute a)
{
	dynamic_page p;

	if( (p = malloc(sizeof *p)) != NULL) {
		p->handler = handler;
		p->attr = NULL;
		if( (p->uri = cstring_dup(uri)) == NULL) {
			free(p);
			p = NULL;
		}
		else if(a != NULL && (p->attr = attribute_dup(a)) == NULL) {
			cstring_free(p->uri);
			free(p);
			p = NULL;
		}
	}

	return p;
}
示例#13
0
/*
 * The old cookie format is (hopefully) name=value
 * where value may be quoted.
 */
int parse_old_cookie(http_request req, const char* input, meta_error e)
{
	cookie c = NULL;
	cstring name = NULL, value = NULL;

	if( (name = cstring_new()) == NULL
	||  (value = cstring_new()) == NULL) 
		goto memerr;

	while(*input != '\0' && *input != '=') {
		if(!cstring_charcat(name, *input++)) 
			goto memerr;
	}

	if(*input != '=') {
		cstring_free(name);
		cstring_free(value);
		return set_http_error(e, HTTP_400_BAD_REQUEST);
	}

	input++; /* Skip '=' */
	if(!cstring_copy(value, input)) 
		goto memerr;

	if( (c = cookie_new()) == NULL) 
		goto memerr;

	if(!cookie_set_name(c, c_str(name)) 
	|| !cookie_set_value(c, c_str(value))) 
		goto memerr;

	cstring_free(name);
	cstring_free(value);
	cookie_set_version(c, 0);
	if(!request_add_cookie(req, c)) {
		set_os_error(e, errno);
		cookie_free(c);
		return 0;
	}

	return 1;

memerr:
	cstring_free(name);
	cstring_free(value);
	cookie_free(c);
	return set_os_error(e, ENOMEM);
}
示例#14
0
cstring cstring_right(cstring src, size_t n)
{
	cstring dest;

	/* Get mem */
	if( (dest = cstring_new()) == NULL || !cstring_extend(dest, n)) {
		cstring_free(dest);
		dest = NULL;
	}
	else {
		const char* s = src->data;
		size_t cb = strlen(s);

		/* Copy string */
		if(cb > n) 
			s += cb - n;
		cstring_copy(dest, s);
	}

	return dest;
}
示例#15
0
cstring cstring_substring(cstring src, size_t from, size_t to)
{
	cstring dest;
	size_t cb;

	assert(src != NULL);
	assert(from <= to);
	assert(to < src->cbUsed);

	if(to > src->cbUsed)
		to = src->cbUsed;

	cb = to - from + 1;
	if( (dest = cstring_new()) == NULL || !cstring_extend(dest, cb)) {
		cstring_free(dest);
		dest = NULL;
	}
	else 
		cstring_pcat(dest, &src->data[from], &src->data[to]);

	return dest;
}
示例#16
0
文件: chfsnpmgr.c 项目: okayman/ebgn
/*bind home_dir and name node, i.e., one name node owns unique home dir*/
EC_BOOL chfsnp_mgr_bind(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, const UINT32 chfsnp_id)
{
    CSTRING *home_dir;
    CSTRING *home_dir_old;
    uint32_t home_dir_pos;

    ASSERT(cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)) == CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr));
    if(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) <= chfsnp_id)
    {
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: max np num %u but chfsnp id %u overflow\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr), chfsnp_id);
        return (EC_FALSE);
    }

    home_dir_pos = __chfsnp_mgr_get_np_id_of_path(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path));
    if(CHFSNP_ERR_ID != home_dir_pos)
    {
        home_dir = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), home_dir_pos);
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: some dir %s already bound to np %u, thus cannot accept binding %s\n", 
                            (char *)cstring_get_str(home_dir), home_dir_pos, (char *)cstring_get_str(path));
        return (EC_FALSE);
    }    

    home_dir = cstring_dup(path);
    if(NULL_PTR == home_dir)
    {
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: dup %s failed\n", (char *)cstring_get_str(path));
        return (EC_FALSE);
    }

    home_dir_old = (CSTRING *)cvector_set(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_id, (void *)home_dir);
    if(NULL_PTR != home_dir_old)
    {
        cstring_free(home_dir_old);
    }
    return (EC_TRUE);
}
示例#17
0
void Test__cstring_free(CuTest* tc)
{
  CSTRING* a=NULL;
  CSTRING* b=NULL;
  CSTRING  c;
  int error = 0;

  // pass a null to the 'free' function
  cstring_free(NULL);
  error = errno;
  errno = 0;
  CuAssertIntEquals(tc, EFAULT, error);

  // send non-alloc'd - passing static non-alloc address
  a = cstring_import("ABCDE", 5);
  c = cstring_strchr(a, 'C');
  b=&c;
  cstring_free(&b);
  error = errno;
  errno = 0;
  CuAssertIntEquals(tc, EFAULT, error);
  cstring_free(&a);

  // passing argument returned from cstring_import
  a = cstring_import("ABCDE", 5);
  cstring_free(&a);

  // check that the structure is null'd
  CuAssertPtrEquals(tc, NULL, a);

  // trying to double free an imported cstring
  a = cstring_import("abcde", 5);
  cstring_free(&a);
  cstring_free(&a);
  error = errno;
  errno = 0;
  CuAssertIntEquals(tc, EFAULT, error);
}
示例#18
0
文件: demo_hsrfs.c 项目: okayman/ebgn
EC_BOOL test_case_82_crfs_read(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter)
{
    void *mod_mgr;
    void *task_mgr;

    UINT32 index;

    CSTRING    *path[CRFS_TEST_READ_MAX_FILES];
    CBYTES     *cbytes[CRFS_TEST_READ_MAX_FILES];/*read from dn*/
    CBYTES     *cbytes_des[CRFS_TEST_READ_MAX_FILES];/*benchmark*/
    EC_BOOL     ret[CRFS_TEST_READ_MAX_FILES];

    EC_BOOL     continue_flag;

    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++)
    {
        path[ index ]          = NULL_PTR;
        cbytes[ index ]     = NULL_PTR;
        cbytes_des[ index ] = NULL_PTR;
        ret[ index ]           = EC_FALSE;
    }

    mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP);
    mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr);
#if 0
    sys_log(LOGSTDOUT, "test_case_82_crfs_read: npp mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi));

    sys_log(LOGSTDOUT, "test_case_82_crfs_read: dn mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi));
#endif
    task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP);

    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++)
    {
        path[ index ] = cstring_new(NULL_PTR, 0);
        cstring_format(path[ index ], "%s/%ld.dat", home, (*counter));

        cbytes[ index ]     = cbytes_new(0);
        cbytes_des[ index ] = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files));

        ret[ index ] = EC_FALSE;

        task_inc(task_mgr, &(ret[ index ]), FI_crfs_read, ERR_MODULE_ID, path[ index ], cbytes[ index ]);
    }

    task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR);

    continue_flag = EC_TRUE;

    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++)
    {
        if(NULL_PTR != cbytes[ index ])
        {
            if(EC_TRUE == cbytes_ncmp(cbytes[ index ], cbytes_des[ index ], 16))
            {
                sys_log(LOGSTDOUT, "[SUCC] path: %s, len = %ld ",
                                  (char *)cstring_get_str(path[ index ]),
                                  cbytes_len(cbytes[ index ]));
                sys_print(LOGSTDOUT, "text = %.*s\n",
                                  cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/
                                  (char *)cbytes_buf(cbytes[ index ]));
            }
            else
            {
                continue_flag = EC_FALSE;

                sys_log(LOGCONSOLE, "[FAIL] path: %s, read len = %ld ",
                                  (char *)cstring_get_str(path[ index ]),
                                  cbytes_len(cbytes[ index ]));
                sys_print(LOGCONSOLE, "text = %.*s <--> ",
                                  cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/
                                  (char *)cbytes_buf(cbytes[ index ]));

                sys_print(LOGCONSOLE, "expect len = %ld ",
                                    cbytes_len(cbytes_des[ index ]));
                sys_print(LOGCONSOLE, "text = %.*s\n",
                                    cbytes_len(cbytes_des[ index ]) > 16 ? 16 : cbytes_len(cbytes_des[ index ]),
                                    (char *)cbytes_buf(cbytes_des[ index ]));
            }
        }

        if(NULL_PTR != path[ index ])
        {
            cstring_free(path[ index ]);
            path[ index ] = NULL_PTR;
        }

        if(NULL_PTR != cbytes[ index ])
        {
            cbytes_free(cbytes[ index ], 0);
            cbytes[ index ] = NULL_PTR;
        }

        if(NULL_PTR != cbytes_des[ index ])
        {
            cbytes_des[ index ] = NULL_PTR;
        }
    }

    mod_mgr_free(mod_mgr);
    return (continue_flag);
}
示例#19
0
文件: main.c 项目: wgm/cerb2-cparser
int main(int argc, char ** argv)
{
  int bytes = 0;
  CSOCKET* sock=NULL;
  CLOG_INFO* log=NULL;
  CSTRING* buf = NULL;

  // open the logfile
  log = clog_open("./test_csocket.log", CTRACE, NULL, 0);

  if(3>argc) {
    clog(log, CFATAL, "USAGE: %s host user password", argv[0]);
    clog_close(log);
    return 1;
  }
  
  // create the new socket  
  sock = csocket_new(log);

  // initialize the socket
  csocket_init(log, sock, argv[1], 110);

  // connect
  csocket_connect(log, sock);

  // read/write
  buf = cstring_new(1024);
  bytes=csocket_read(log, sock, buf->string, 1024);
  fprintf(stdout, "%s", buf->string);

  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  cstring_strcat_imp(buf, "USER ", 5);
  cstring_strcat_imp(buf, argv[2], strlen(argv[2]));  
  cstring_strcat_imp(buf, "\r\n", 2);
  csocket_write(log, sock, buf->string, buf->length);
  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  bytes=csocket_read(log, sock, buf->string, 1024);
  fprintf(stdout, "%s", buf->string);

  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  cstring_strcat_imp(buf, "PASS ", 5);
  cstring_strcat_imp(buf, argv[3], strlen(argv[3]));
  cstring_strcat_imp(buf, "\r\n", 2);
  csocket_write(log, sock, buf->string, buf->length);
  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  bytes=csocket_read(log, sock, buf->string, 1024);
  fprintf(stdout, "%s", buf->string);

  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  cstring_strcat_imp(buf, "STAT\r\n", 6);
  csocket_write(log, sock, buf->string, buf->length);
  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  bytes=csocket_read(log, sock, buf->string, 1024);
  fprintf(stdout, "%s", buf->string);

  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  cstring_strcat_imp(buf, "QUIT\r\n", 6);
  csocket_write(log, sock, buf->string, buf->length);
  buf->length=0;
  memset(buf->string, 0, buf->memsize);
  bytes=csocket_read(log, sock, buf->string, 1024);
  fprintf(stdout, "%s", buf->string);

  cstring_free(&buf);

  // close the connection
  csocket_close(log, sock);

  // free the socket
  csocket_free(log, sock);

  // close the log
  clog_close(log);
  
  return 0;
}
示例#20
0
文件: chfsnpmgr.c 项目: okayman/ebgn
static EC_BOOL __chfsnp_mgr_load_db(CHFSNP_MGR *chfsnp_mgr, int chfsnp_mgr_fd)
{
    UINT32 chfsnp_mgr_db_size;
    UINT8* chfsnp_mgr_db_buff;
    UINT32 chfsnp_mgr_db_offset;
    UINT32 chfsnp_home_dir_num;
    UINT32 chfsnp_home_dir_pos;

    uint32_t chfsnp_id;
    
    /*init offset*/
    chfsnp_mgr_db_offset = 0;

    /*CHFSNP_MGR_NP_MODEL*/
    chfsnp_mgr_db_size   = sizeof(uint8_t);
    chfsnp_mgr_db_buff   = (UINT8 *)&(CHFSNP_MGR_NP_MODEL(chfsnp_mgr));    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load np model failed\n");
        return (EC_FALSE);
    }

    /*CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID*/
    chfsnp_mgr_db_size   = sizeof(uint8_t);
    chfsnp_mgr_db_buff   = (UINT8 *)&(CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr));    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load 1st chash algo id failed\n");
        return (EC_FALSE);
    }    

    /*CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID*/
    chfsnp_mgr_db_size   = sizeof(uint8_t);
    chfsnp_mgr_db_buff   = (UINT8 *)&(CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr));    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load 2nd chash algo id failed\n");
        return (EC_FALSE);
    }     

    /*CHFSNP_MGR_NP_ITEM_MAX_NUM*/
    chfsnp_mgr_db_size   = sizeof(uint32_t);
    chfsnp_mgr_db_buff   = (UINT8 *)&(CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr));    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load item max num failed\n");
        return (EC_FALSE);
    }     

    /*CHFSNP_MGR_NP_MAX_NUM*/
    chfsnp_mgr_db_size   = sizeof(uint32_t);
    chfsnp_mgr_db_buff   = (UINT8 *)&(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr));    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load disk max num failed\n");
        return (EC_FALSE);
    }

    for(chfsnp_id = cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); chfsnp_id < CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr); chfsnp_id ++)
    {
        cvector_push_no_lock(CHFSNP_MGR_NP_VEC(chfsnp_mgr), NULL_PTR);
    }

    /*CHFSNP_MGR_NP_HOME_DIR_VEC*/
    chfsnp_mgr_db_size   = sizeof(UINT32);
    chfsnp_mgr_db_buff   = (UINT8 *)&(chfsnp_home_dir_num);    
    if(EC_FALSE == c_file_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset, chfsnp_mgr_db_size, chfsnp_mgr_db_buff))
    {
        sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load home dir vec size failed\n");
        return (EC_FALSE);
    }    

    for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++)
    {
        CSTRING *chfsnp_home_dir_cstr;

        chfsnp_home_dir_cstr = cstring_load(chfsnp_mgr_fd, &chfsnp_mgr_db_offset);
        if(NULL_PTR == chfsnp_home_dir_cstr)
        {
            sys_log(LOGSTDOUT, "error:__chfsnp_mgr_load_db: load home dir %u # failed\n", chfsnp_home_dir_pos);
            return (EC_FALSE);
        }

        if(EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr))
        {
            cstring_free(chfsnp_home_dir_cstr);
            cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), NULL_PTR);
        }
        else
        {
            cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), (void *)chfsnp_home_dir_cstr);
        }
    }

    return (EC_TRUE);
}
示例#21
0
void
dumpState (cstring cfname)
{
  FILE *f;
  cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX));
  
  f = fileTable_openWriteFile (context_fileTable (), fname);

  displayScanOpen (message ("Dumping to %s ", fname)); 
  
  if (f == NULL)
    {
      lldiagmsg (message ("Cannot open dump file for writing: %s", fname));
    }
  else
    {
      /*
      ** sequence is convulted --- must call usymtab_prepareDump before
      **    dumping ctype table to convert type uid's
      */

      printDot ();

      /*
      DPRINTF (("Before prepare dump:"));
      ctype_printTable ();
      DPRINTF (("Preparing dump..."));
      */

      usymtab_prepareDump ();

      /*
      ** Be careful, these lines must match loadLCDFile checking.
      */

      fprintf (f, "%s %s\n", LIBRARY_MARKER, cstring_toCharsSafe (fname));
      fprintf (f, ";;Splint %f\n", SPLINT_LIBVERSION);
      fprintf (f, ";;lib:%d\n", (int) context_getLibrary ());
      fprintf (f, ";;ctTable\n");
      
      DPRINTF (("Dumping types..."));
      printDot ();
      ctype_dumpTable (f);
      printDot ();
      
      DPRINTF (("Dumping type sets..."));
      fprintf (f, ";;tistable\n");
      typeIdSet_dumpTable (f);
      printDot ();
      
      DPRINTF (("Dumping usymtab..."));
      fprintf (f, ";;symTable\n");
      usymtab_dump (f);
      printDot ();

      DPRINTF (("Dumping modules..."));
      fprintf (f, ";; Modules access\n");
      context_dumpModuleAccess (f);
      fprintf (f, ";;End\n");
      check (fileTable_closeFile (context_fileTable (), f));
    }

  displayScanClose ();
  cstring_free (fname);
}
示例#22
0
void Test__cstring_strcat_imp(CuTest* tc)
{
  CSTRING* a = NULL;

  // pass all nulls
  a = cstring_strcat_imp(NULL, NULL, 0);
  CuAssertPtrEquals(tc, NULL, a);

  // pass a null first param
  a = cstring_strcat_imp(NULL, "abcde", 5);
  CuAssertPtrEquals(tc, NULL, a);

  // pass a NULL second parameter
  a = cstring_new(0);
  a = cstring_strcat_imp(a, NULL, 0);
  CuAssertPtrNotNull(tc, a);
  CuAssertTrue(tc, 0!=a->memsize);
  CuAssertIntEquals(tc, 1, a->canfree);
  CuAssertIntEquals(tc, 0, a->length);
  CuAssertPtrNotNull(tc, a->string);
  CuAssertStrEquals(tc, "", a->string);
  cstring_free(&a);

  // pass good both, second zero length
  a = cstring_new(0);
  a = cstring_strcat_imp(a, "", 0);
  CuAssertPtrNotNull(tc, a);
  CuAssertTrue(tc, 0!=a->memsize);
  CuAssertIntEquals(tc, 1, a->canfree);
  CuAssertIntEquals(tc, 0, a->length);
  CuAssertPtrNotNull(tc, a->string);
  CuAssertStrEquals(tc, "", a->string);
  cstring_free(&a);

  // pass good both, "abcde" for second and length zero
  a = cstring_new(0);
  a = cstring_strcat_imp(a, "abcde", 0);
  CuAssertPtrNotNull(tc, a);
  CuAssertTrue(tc, 0!=a->memsize);
  CuAssertIntEquals(tc, 1, a->canfree);
  CuAssertIntEquals(tc, 0, a->length);
  CuAssertPtrNotNull(tc, a->string);
  CuAssertStrEquals(tc, "", a->string);
  cstring_free(&a);

  // pass good both, "abcde" for second and length 3
  a = cstring_new(0);
  a = cstring_strcat_imp(a, "abcde", 3);
  CuAssertPtrNotNull(tc, a);
  CuAssertTrue(tc, 0!=a->memsize);
  CuAssertIntEquals(tc, 1, a->canfree);
  CuAssertIntEquals(tc, 3, a->length);
  CuAssertPtrNotNull(tc, a->string);
  CuAssertStrEquals(tc, "abc", a->string);
  cstring_free(&a);

  // pass good both, "abcde" for second and length 5
  a = cstring_new(0);
  a = cstring_strcat_imp(a, "abcde", 5);
  CuAssertPtrNotNull(tc, a);
  CuAssertTrue(tc, 0!=a->memsize);
  CuAssertIntEquals(tc, 1, a->canfree);
  CuAssertIntEquals(tc, 5, a->length);
  CuAssertPtrNotNull(tc, a->string);
  CuAssertStrEquals(tc, "abcde", a->string);
  cstring_free(&a);
}
示例#23
0
文件: osd.c 项目: Safe3/themis
void osd_destroyMod (void)
{
  cstring_free (osd_cwd);
  osd_cwd = cstring_undefined;
}
示例#24
0
int main(int argc, char **argv) {
  int       exit_code=0;

  CERBFIG*  cer_config=NULL;

  // linked list to store the messages in
  struct linkedlist* messages=NULL;

  CXMLROOT* xml_root=NULL;
  CFILE*    file=NULL;
  CFSYS*    cfsys=NULL;

  // log struct
  CLOG_INFO* log=NULL;

#ifdef MEMWATCH
  EF_ALIGNMENT=1;
  EF_PROTECT_BELOW=1;
  EF_PROTECT_FREE=1;
#endif

// memory checking
// mtrace();

// ##########################################################################
// ############=- CHECK CMD LINE PARAMETERS -=###############################
// ##########################################################################

  // start the logging so we can log!
  if( !(argc==4) ) {
    fprintf(stderr, "\nUsage:\n%.80s xml_config_file log_level log.txt \n\n", argv[0]);
  }

// ##########################################################################
// ############=- Run Test Suite -=##########################################
// ##########################################################################
#ifndef NOTEST
  if(1==argc) {
    CuString *output = CuStringNew();
    CuSuite* suite = CuSuiteNew();

    printf("Running Test Suite\n");

    CuSuiteAddSuite(suite, CuGetSuite());
    CuSuiteAddSuite(suite, CuStringGetSuite());
    CuSuiteAddSuite(suite, TestSuite__cstring());
    CuSuiteAddSuite(suite, TestSuite__cfile());
    CuSuiteAddSuite(suite, TestSuite__cxml());
//    CuSuiteAddSuite(suite, TestSuite__cmime());

    CuSuiteRun(suite);
    CuSuiteSummary(suite, output);
    CuSuiteDetails(suite, output);
    printf("%s\n", output->buffer);

    CuStringFree(output);
    CuSuiteFree(suite);

    return EX_USAGE;
  }
#endif

  log = clog_open(argv[3], clog_getlevel(argv[2]), NULL, 0);

  // if we couldn't log to the file, let's log to stderr!
  if(NULL!=log && NULL==log->s_logfile) {
    clog_setcallback(log, clog_stderr);
    clog_setcallbacklevel(log, clog_getlevel(argv[2]));
    clog(log, CERROR, "Could not log to file, logging to stderr!");
  }

  clog(log, CMARK, "Cerberus v. 2.x build %s Starting", BUILDNUMBER);

  clog(log, CDEBUG, "CMDLINE: Command line: %.80s %.80s %.80s", argv[0], argv[1], argv[2]);

  clog(log, CDEBUG, "CMDLINE: Command line arguments check passed");

  clog(log, CMARK, "Cerberus Starting...");

// ##########################################################################
// ############=- LOAD XML CONFIG FILE -=####################################
// ##########################################################################

  // parse the XML now
  clog(log, CDEBUG, "XML: Starting XML config file parsing");

  clog(log, CDEBUG, "XML: Creating XML DOM Variable");
  xml_root = cxml_root_new(log);
  clog(log, CDEBUG, "XML: XML DOM Variable Created");

  // make a new cer filesystem obj
  cfsys = cfile_init(0);
  
  cer_config = malloc(sizeof(CERBFIG));
  memset(cer_config, 0, sizeof(CERBFIG));

  cer_config->cfsys = cfsys;
  
  exit_code = cer_load_config(log, &xml_root, argv[1], &cer_config);

  // ##########################################################################
  // ################=- READ IN FILES -=#######################################
  // ##########################################################################

  if(0==exit_code) {
    CPOP3* pop3 = NULL;
    char *filename = NULL;

    messages = linkedlist_new(0);
    // if there is something in the list, process via pop3
    if(NULL!=cer_config->poplist) {

      exit_code = cer_curl_init(log, &cer_config, cer_config->curl_location);

      clog(log, CMARK, "Parser is in POP3 mode.");


      while(NULL!=(pop3=linkedlist_remove_last(cer_config->poplist))) {
        if(0==exit_code) {
          if(NULL!=pop3->user && NULL!=pop3->pass) {
            if(0==cpop3_connect(log, pop3)){
              if(0==cpop3_user(log, pop3, pop3->user)) {
                if(0==cpop3_pass(log, pop3, pop3->pass)) {
                  int x=0;
                  int y=0;
                  x = cpop3_stat(log, pop3);
                  while(y<x && y<cer_config->pop3_max) {
                    if(NULL!=(filename = cpop3_retr(log, pop3, cer_config->tmp_cerbmail->string))) {
                      int pid = 0;
                      linkedlist_add(messages, filename);

                      pid = cer_fork();
                      if(-1==pid) {
                        clog(log, CDEBUG, "FORK: Could not fork, running straight through");
                        // if we couldn't fork run the parser and risk killing entire process
                        exit_code = cer_parse_files(log, &cer_config, xml_root, &messages);

                        if(pop3->dele) {
                          if(1==cer_config->pop3_max_delete) {
                            cpop3_dele(log, pop3);
                          }
                          else if(0==exit_code) {
                            cpop3_dele(log, pop3);
                          }
                        }
                      }
                      else if(0==pid) {
                        clog(log, CDEBUG, "FORK: Forked, running file parser");
                        exit_code = cer_parse_files(log, &cer_config, xml_root, &messages);

                        if(pop3->dele) {
                          if(1==cer_config->pop3_max_delete) {
                            cpop3_dele(log, pop3);
                          }
                          else if(0==exit_code) {
                            cpop3_dele(log, pop3);
                          }
                        }
                        // didn't send quit, just close the fork'd connection
                        cpop3_disconnect(log, pop3);
                        cpop3_free(log, &pop3);

                        // remove the emails from the list that we've processed
                        linkedlist_iterate(messages);
                        while(NULL!=(filename=linkedlist_remove_last(messages))) {
                          free(filename);
                          filename = NULL;
                        }
                        linkedlist_del(cer_config->poplist, free);
                        linkedlist_del(messages, free);
                        goto CLEANUP;
                      }
                      else {
                        // must be the parent process
                        // clean up any forked children that are sitting around
                        clog(log, CDEBUG, "FORK: Forked, am parent waiting for child process");
                        while(0<(pid=cer_wait4(0, NULL, 0, NULL))) {
                          clog(log, CDEBUG, "WAIT: cleaned up after child %d!", pid);
                        };
                      }
                      // remove the emails from the list that we've processed
                      linkedlist_iterate(messages);
                      while(NULL!=(filename=linkedlist_remove_last(messages))) {
                        free(filename);
                        filename = NULL;
                      }
                    }
                    ++y;
                  }
                }
              }
              cpop3_quit(log, pop3);
              cpop3_disconnect(log, pop3);
            }
          }
          else {
            clog(log, CERROR, "POP3: User or Password was NULL, skipping");
          }

        }
        cpop3_free(log, &pop3);
      }

      linkedlist_del(cer_config->poplist, free);
    }
    // otherwise it's stdin
    else {
      clog(log, CMARK, "Parser is in PIPE mode, waiting for input");
      file = cer_save_input(log, cfsys, cer_config->tmp_cerbmail->string);
      if(NULL!=file) {
        filename = strdup(file->filename);
        linkedlist_add(messages, filename);
        cfile_close(&file);
        cfile_free(&file);
  
        exit_code = cer_curl_init(log, &cer_config, cer_config->curl_location);
  
        if(0==exit_code) {
          exit_code = cer_parse_files(log, &cer_config, xml_root, &messages);
        }
      }
    }

    // free the linked list
    linkedlist_del(messages, free);
  }

  // this is above cleanup to keep the forks from clobbering each other
  cfile_cleanup(&cfsys);
  
CLEANUP:

  if(NULL!=dl_curl_easy_cleanup) {
    // clean up the info in cURL
    dl_curl_easy_cleanup(cer_config->curl);
  }
  if(NULL!=dl_curl_global_cleanup) {
    // close down curl
    dl_curl_global_cleanup();
  }

#ifndef WIN32
  if(NULL!=dl_curl) {
     dlclose(dl_curl);
     dl_curl=NULL;
  }
#endif

  dl_curl = NULL;
  dl_curl_formadd=NULL;
  dl_curl_formfree=NULL;
  dl_curl_global_init=NULL;
  dl_curl_easy_init=NULL;
  dl_curl_easy_setopt=NULL;
  dl_curl_easy_perform=NULL;
  dl_curl_easy_cleanup=NULL;
  dl_curl_global_cleanup=NULL;

  // free the xml data
  cxml_root_free(log, &xml_root);
  if(NULL!=cer_config->xsp) cstring_free(&cer_config->xsp);

  cstring_free(&cer_config->curl_location);

  cstring_free(&cer_config->tmp_cerbmail);
  cstring_free(&cer_config->tmp_cerbmime);

  // free the optional SSL data
  cstring_free(&cer_config->curl_cainfo);
  cstring_free(&cer_config->curl_capath);
  cer_config->curl_verifyhostpeer = 0;

  clog(log, CMARK, "Shutting Down");

  // close the log file
  clog_close(log);
  
  free(cer_config);
  cer_config=NULL;

  return exit_code;
}
示例#25
0
bool
loadStandardState ()
{
  cstring fpath;
  FILE *stdlib;
  bool result;
  cstring libname = fileLib_addExtension (context_selectedLibrary (), 
					  cstring_makeLiteralTemp (DUMP_SUFFIX));
  
  if (osd_findOnLarchPath (libname, &fpath) != OSD_FILEFOUND)
    {
      lldiagmsg (message ("Cannot find %sstandard library: %s", 
			  cstring_makeLiteralTemp 
			  (context_getFlag (FLG_STRICTLIB) ? "strict " 
			   : (context_getFlag (FLG_UNIXLIB) ? "unix " : "")),
			  libname));
      lldiagmsg (cstring_makeLiteral ("     Check LARCH_PATH environment variable."));
      result = FALSE;
    }
  else
    {
      stdlib = fileTable_openReadFile (context_fileTable (), fpath);

      if (stdlib == NULL)
	{
	  lldiagmsg (message ("Cannot read standard library: %s",
			      fpath));
	  lldiagmsg (cstring_makeLiteral ("     Check LARCH_PATH environment variable."));

	  result = FALSE;
	}
      else
	{
	  if (context_getFlag (FLG_WHICHLIB))
	    {
	      char *t = mstring_create (MAX_NAME_LENGTH);
	      char *ot = t;

	      if ((t = reader_readLine (stdlib, t, MAX_NAME_LENGTH)) == NULL)
		{
		  llfatalerror (cstring_makeLiteral ("Standard library format invalid"));
		}

	      if ((t = reader_readLine (stdlib, t, MAX_NAME_LENGTH)) != NULL)
		{
		  if (*t == ';' && *(t + 1) == ';') 
		    {
		      t += 2;
		    }
		}

	      if (t == NULL)
		{
		  lldiagmsg (message ("Standard library: %s <cannot read creation information>", 
				      fpath));
		}
	      else
		{
		  char *tt;

		  tt = strrchr (t, '\n');
		  if (tt != NULL)
		    *tt = '\0';

		  lldiagmsg (message ("Standard library: %s", fpath));
		  /* evans 2004-01-13: removed this (it is the libversion which is confusing) */
		  /*   lldiagmsg (message ("   (created using %s)", cstring_fromChars (t)));		    */
		}

	      sfree (ot);
	      
	      check (fileTable_closeFile (context_fileTable (), stdlib));
	      stdlib = fileTable_openReadFile (context_fileTable (), fpath);
	    }

	  llassert (stdlib != NULL);

	  fileloc_reallyFree (g_currentloc);
	  g_currentloc = fileloc_createLib (libname);

	  DPRINTF (("Loading: %s", fpath));

	  displayScanOpen (message ("loading standard library %s ", fpath));
	  result = loadLCDFile (stdlib, fpath);
	  displayScanClose ();

	  check (fileTable_closeFile (context_fileTable (), stdlib));
	}
    }

  cstring_free (libname);
  return result;
}
示例#26
0
文件: demo_hsrfs.c 项目: okayman/ebgn
EC_BOOL test_case_83_crfs_write(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter)
{
    void *mod_mgr;
    void *task_mgr;

    UINT32 index;

    EC_BOOL continue_flag;

    CSTRING    *path[CRFS_TEST_WRITE_MAX_FILES];
    EC_BOOL     ret[CRFS_TEST_WRITE_MAX_FILES];

    for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++)
    {
        path[ index ]      = NULL_PTR;
        ret[ index ]       = EC_FALSE;
    }

    mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP);
    mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr);
#if 0
    sys_log(LOGSTDOUT, "test_case_83_crfs_write: npp mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi));

    sys_log(LOGSTDOUT, "test_case_83_crfs_write: dn mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi));
#endif
    task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP);
    for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++, (*counter) ++)
    {
        void *cbytes;

        path[ index ] = cstring_new(NULL_PTR, 0);
        cstring_format(path[ index ], "%s/%ld.dat", home, (*counter));

        ret[ index ] = EC_FALSE;
        cbytes = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files));
        if(NULL_PTR == cbytes)
        {
            sys_log(LOGSTDOUT, "error:test_case_83_crfs_write: crfs buff is null where index = %ld, max_test_data_files = %ld\n", index, max_test_data_files);
            cstring_free(path[ index ]);
            path[ index ] = NULL_PTR;
            break;
        }

        task_inc(task_mgr, &(ret[ index ]), FI_crfs_write, ERR_MODULE_ID, path[ index ], cbytes);
    }

    task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NOT_NEED_RESCHEDULE_FLAG, NULL_PTR);

    continue_flag = EC_TRUE;

    for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++)
    {
        if(EC_FALSE == ret[ index ] && NULL_PTR != path[ index ])
        {
            continue_flag = EC_FALSE;
            sys_log(LOGCONSOLE, "test_case_83_crfs_write: [FAIL] %s\n", (char *)cstring_get_str(path[ index ]));
        }
        if(NULL_PTR != path[ index ])
        {
            cstring_free(path[ index ]);
            path[ index ] = NULL_PTR;
        }
    }

    mod_mgr_free(mod_mgr);

    return (continue_flag);
}
示例#27
0
文件: demo_hsrfs.c 项目: okayman/ebgn
/*check replica files*/
EC_BOOL test_case_85_crfs_check_file_content(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter)
{
    MOD_MGR  *mod_mgr;
    TASK_MGR *task_mgr;

    UINT32 index;

    CSTRING    *path[CRFS_TEST_READ_MAX_FILES];
    EC_BOOL     ret[CRFS_TEST_READ_MAX_FILES];

    EC_BOOL     continue_flag;

    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++)
    {
        path[ index ]      = NULL_PTR;
        ret[ index ]       = EC_FALSE;
    }

    mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP);
    mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr);

    sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: npp mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi));

    sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: dn mod mgr is\n");
    mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi));

    task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP);
    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++)
    {
        CBYTES *cbytes_des;
        cbytes_des = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files));

        path[ index ] = cstring_new(NULL_PTR, 0);
        cstring_format(path[ index ], "%s/%ld.dat", home, (*counter));

        ret[ index ] = EC_FALSE;

        task_inc(task_mgr, &(ret[ index ]),
                        FI_crfs_check_file_is, ERR_MODULE_ID, path[ index ], cbytes_des);
    }

    task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR);

    continue_flag = EC_TRUE;

    for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++)
    {
        if(EC_TRUE == ret[ index ])
        {
            sys_log(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ]));
        }
        else
        {
            continue_flag = EC_FALSE;
            sys_log(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ]));
        }

        if(NULL_PTR != path[ index ])
        {
            cstring_free(path[ index ]);
            path[ index ] = NULL_PTR;
        }

        if(NULL_PTR != path[ index ])
        {
            cstring_free(path[ index ]);
            path[ index ] = NULL_PTR;
        }
    }

    mod_mgr_free(mod_mgr);
    
    return (continue_flag);
}
示例#28
0
int main(void)
{
	cstring s, dest, *pstr;
	int rc;
	const char* start = "This is a string";
	const char* end = start + strlen(start);

	char longstring[10000];

	size_t i, nelem = 100;

	memset(longstring, 'A', sizeof(longstring));
	longstring[sizeof(longstring) - 1] = '\0';


	for(i = 0; i < nelem; i++) {
		s = cstring_new();
		assert(s != NULL);

		rc = cstring_copy(s, "Hello");
		assert(rc == 1);

		rc = cstring_compare(s, "Hello");
		assert(rc == 0);

		rc = cstring_compare(s, "hello");
		assert(rc != 0);

		rc = cstring_concat(s, ", world");
		assert(rc == 1);

		rc = cstring_compare(s, "Hello, world");
		assert(rc == 0);

		rc = cstring_concat(s, longstring);
		assert(rc == 1);

		rc = cstring_charcat(s, 'A');
		assert(rc == 1);

		cstring_recycle(s);
		rc = cstring_concat(s, longstring);
		assert(rc == 1);

		rc = cstring_concat2(s, longstring, longstring);
		assert(rc == 1);

		rc = cstring_concat3(s, longstring, longstring, longstring);
		assert(rc == 1);

		/* Test strpcat */
		cstring_recycle(s);
		rc = cstring_pcat(s, start, end);
		assert(rc == 1);

		rc = cstring_compare(s, start);
		assert(rc == 0);

		/* Test cstring_left() */
		cstring_copy(s, "hello, world");
		dest = cstring_left(s, 5);
		rc = cstring_compare(dest, "hello");
		assert(rc == 0);
		cstring_free(dest);

		/* Test cstring_left() with short strings */
		dest = cstring_left(s, 5000);
		rc = cstring_compare(dest, "hello, world");
		assert(rc == 0);
		cstring_free(dest);

		/* cstring_right() */
		cstring_copy(s, "hello, world");
		dest = cstring_right(s, 5);
		rc = cstring_compare(dest, "world");
		assert(rc == 0);
		cstring_free(dest);

		dest = cstring_right(s, 5000);
		rc = cstring_compare(dest, "hello, world");
		assert(rc == 0);
		cstring_free(dest);

		/* cstring_substring */
		cstring_copy(s, "hello, world");
		dest = cstring_substring(s, 0, 5);
		rc = cstring_compare(dest, "hello");
		assert(rc == 0);
		cstring_free(dest);

		dest = cstring_substring(s, 1, 5);
		rc = cstring_compare(dest, "ello");
		assert(rc == 0);
		cstring_free(dest);

		dest = cstring_substring(s, 7, 12);
		rc = cstring_compare(dest, "world");
		assert(rc == 0);
		cstring_free(dest);

		/* cstring_reverse */
		cstring_copy(s, "hello, world");
		cstring_reverse(s);
		rc = cstring_compare(s, "dlrow ,olleh");
		assert(rc == 0);
		/* cstring_strip */

		cstring_copy(s, "  a b c d e f  ");
		cstring_strip(s);
		rc = cstring_compare(s, "a b c d e f");
		assert(rc == 0);

		cstring_upper(s);
		rc = cstring_compare(s, "A B C D E F");
		assert(rc == 0);

		cstring_lower(s);
		rc = cstring_compare(s, "a b c d e f");
		assert(rc == 0);

		cstring_free(s);

		/* cstring_split() */
		rc = cstring_split(&pstr, "foo bar baz", " ");
		assert(rc == 3);
		cstring_multifree(pstr, rc);
		mem_free(pstr);


		rc = cstring_split(&pstr, "       foo bar baz", " ");
		assert(rc == 3);
		cstring_multifree(pstr, rc);
		mem_free(pstr);
		rc = cstring_split(&pstr, "    foo bar baz    ", " ");
		assert(rc == 3);
		cstring_multifree(pstr, rc);
		mem_free(pstr);
		rc = cstring_split(&pstr, "    foo ", " ");
		assert(rc == 1);
		cstring_multifree(pstr, rc);
		mem_free(pstr);


	}

	return 0;
}
示例#29
0
文件: osd.c 项目: Safe3/themis
cstring osd_outputPath (cstring filename)
{
# if defined (UNIX) || defined (OS2)
  char *rel_buffer;
  char *rel_buf_p;
  cstring cwd_p = osd_cwd;
  char *path_p;
  int unmatched_slash_count = 0;
  size_t filename_len = cstring_length (filename);
  
  llassertretval (filename_len > 0, filename);

  /*@access cstring@*/
  path_p = filename;
  rel_buffer = (char *) dmalloc (filename_len);
  rel_buf_p = rel_buffer;
  *rel_buf_p = '\0';

  if (cwd_p == NULL) 
    {
      /* Need to prevent recursive assertion failures */
      return cstring_copy (filename);
    }

  llassert (cwd_p != NULL);
  llassert (path_p != NULL);

  while ((*cwd_p != '\0') && (*cwd_p == *path_p))
    {
      cwd_p++;
      path_p++;
    }
  
  if ((*cwd_p == '\0') && (*path_p == '\0' || osd_isConnectChar (*path_p)))  /* whole pwd matched */
    {
      if (*path_p == '\0')             /* input *is* the current path! */
	{
	  cstring_free (rel_buffer);
	  return cstring_makeLiteral (".");
	}
      else
	{
	  cstring_free (rel_buffer);
	  return cstring_fromCharsNew (path_p + 1);
	}
    }
  else
    {

      /* drl   2002-10/14 I had to put this code back*/
      /* the case that needs it is when splint is given an absolute path name of a file outside of the current directory and the subdirectories below the current directory. e.g. cd /home/; splint /tmp/prog.c
       */
      
      /* evans 2002-02-05 This is horrible code, which I've removed.  I couldn't find any
      ** test cases that need it, so I hope I'm not breaking anything.
      */
      /*#if 0*/

      if (*path_p != '\0')
        {
          --cwd_p;
          --path_p;

          while (cwd_p >= osd_cwd && !osd_isConnectChar (*cwd_p)) /* backup to last slash */
            {
              --cwd_p;
              --path_p;
            }
          cwd_p++;
          path_p++;
          unmatched_slash_count++;
        }

      /* Find out how many directory levels in cwd were *not* matched.  */
      while (*cwd_p != '\0')
	{
	  if (osd_isConnectChar (*cwd_p++))
	    unmatched_slash_count++;
	}
      
      /* Now we know how long the "short name" will be.
         Reject it if longer than the input.  */
      if (unmatched_slash_count * 3 + strlen (path_p) >= filename_len)
	{
	  cstring_free (rel_buffer);
	  /* fprintf (stderr, "Returning filename: %s [%p]\n", filename); */
	  return cstring_copy (filename);
	}

      /*drl 10-14-2002 end previously removed code */
      /*#endif*/
      /* For each of them, put a `../' at the beginning of the short name.  */
      while (unmatched_slash_count-- > 0)
        {
          /* Give up if the result gets to be longer
             than the absolute path name.  */
	  char * temp_rel_buf_p;

	  /*drl This comment is necessary because for some reason Splint
	    does not realize that the pasts where rel_buf_p is released
	    do not reach here*/
	  /*@-usereleased@*/
	  temp_rel_buf_p = rel_buf_p;
	  /*@-usereleased@*/
	  
          if (rel_buffer + filename_len <= temp_rel_buf_p + 3)
	    {
	      sfree (rel_buffer);
	      return cstring_copy (filename);
	    }

          *rel_buf_p++ = '.';
          *rel_buf_p++ = '.';
          *rel_buf_p++ = CONNECTCHAR;
        }
      
      /* Then tack on the unmatched part of the desired file's name.  */

      do
        {
          if (rel_buffer + filename_len <= rel_buf_p)
	    {
	      cstring_free (rel_buffer);
	      return cstring_copy (filename);
	    }
        } /*@-usereleased@*/
      while ((*rel_buf_p++ = *path_p++) != '\0') ;

      
      /*@=usereleased@*/ /* Splint limitation: shouldn't need these */
      --rel_buf_p;

      if (osd_isConnectChar (*(rel_buf_p-1)))
        *--rel_buf_p = '\0';

      /* fprintf (stderr, "Returning buffer: %s [%p]\n", rel_buffer, rel_buffer); */
      return rel_buffer;
    }
  /*@noaccess cstring@*/
# else
  return cstring_copy (filename);
# endif
}
示例#30
0
bool
lcllib_isSkipHeader (cstring sname)
{
  int i;
  bool posixlib = FALSE;
  char *libname;
  char *matchname;
  cstring xname;

  llassert (cstring_isDefined (sname));
  xname = fileLib_withoutExtension (sname, cstring_makeLiteralTemp (".h"));

  DPRINTF (("Include? %s", sname));

  /*@access cstring@*/
  llassert (cstring_isDefined (xname));
# if defined (OS2)
  {
    /* Posixlibs use forward slashes, so we use them here, too */
    cstring_replaceAll (xname, '\\', '/');
    libname = strrchr (xname, '/');
    DPRINTF (("libname: %s", libname));
  }
# else
  libname = strrchr (xname, CONNECTCHAR);
# endif
  matchname = libname;

  if (libname == NULL) 
    {
      libname = xname;
    }
  else
    {
      libname++;
      /*@-branchstate@*/
    }
  /*@=branchstate@*/

  if (mstring_equal (libname, "varargs"))
    {
      fileloc tmp = fileloc_makePreprocPrevious (g_currentloc);
      
      voptgenerror 
	(FLG_USEVARARGS,
	 message ("Include file <%s.h> is inconsistent with "
		  "ANSI library (should use <stdarg.h>)",
		  cstring_fromChars (libname)),
	 tmp);
      
      fileloc_free (tmp);
      cstring_free (xname);
      return TRUE;
    }

  if (context_getFlag (FLG_SKIPISOHEADERS)
      && context_usingAnsiLibrary ())
    {
      for (i = 0; i < NUMLIBS; i++)
	{
	  if (mstring_equal (libname, stdlibs[i]))
	    {
	      sfree (xname);
	      return TRUE;
	    }
	}
    }

  for (i = 0; i < NUMPOSIXLIBS; i++)
    {
      if (strchr (posixlibs[i], CONNECTCHAR) != NULL
# if defined (OS2)
	  || strchr (posixlibs[i], ALTCONNECTCHAR) != NULL
# endif
	  )
	{
	  char *ptr;
	  
	  DPRINTF (("xname: %s, posix: %s", xname, posixlibs[i]));
	  if ((ptr = strstr (xname, posixlibs[i])) != NULL) 
	    {
	      if (ptr[strlen (posixlibs[i])] == '\0')
		{
		  posixlib = TRUE;
		  matchname = ptr;
		  break;
		}
	      else
		{
		  ; /* no match */
		}
	    }
	}
      else
	{
	  if (mstring_equal (libname, posixlibs[i]))
	    {
	      posixlib = TRUE;
	      matchname = libname;
	      break;
	    }
	  /*@-branchstate@*/ 
	}
    } /*@=branchstate@*/
  
  if (posixlib)
    {
      if (context_usingPosixLibrary ())
	{
	  if (context_getFlag (FLG_SKIPPOSIXHEADERS))
	    {
	      cstring_free (xname);
	      /*@-nullstate@*/ 
	      return TRUE; 
	      /*@=nullstate@*/

	      /* evans 2002-03-02: 
		   the returned reference is possibly null,
  		   but this should not change the null state of the parameter
	      */
	    }
	}
      else
	{	
	  fileloc tmp = fileloc_makePreprocPrevious (g_currentloc);	      
	  
	  voptgenerror 
	    (FLG_WARNPOSIX,
	     message ("Include file <%s.h> matches the name of a "
		      "POSIX library, but the POSIX library is "
		      "not being used.  Consider using +posixlib "
		      "or +posixstrictlib to select the POSIX "
		      "library, or -warnposix "
		      "to suppress this message.",
		      cstring_fromChars (matchname)),
	     tmp);
	  
	  fileloc_free (tmp);
	}
    }

  cstring_free (xname);
  /*@noaccess cstring@*/
  /*@-nullstate@*/ /* same problem as above */
  return FALSE;
  /*@=nullstate@*/
}