Пример #1
0
/* dumps the current stats to json format .. */
void
stats_dump_json(char **str)
{
	void *ptr = 0;
	char *buf = 0;
	int buflen = 0, datalen = 0;
	char *tmp = 0;
	pdd_stat_t *stat = 0;
	
	ship_lock(done_stats);
	ASSERT_TRUE(buf = append_str("var p2pship_pdds = [\n", buf, &buflen, &datalen), err);
	while ((stat = ship_list_next(done_stats, &ptr))) {
		int len = strlen(stat->from) + strlen(stat->to) + strlen(stat->msg_type) + 128;
		
		ASSERT_TRUE(tmp = mallocz(len), err);
		sprintf(tmp, " [ \"%s\", \"%s\", \"%s\", \"%d\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\" ],\n",
			stat->from, stat->to, stat->msg_type, (int)stat->created, 
			(unsigned int)(stat->end - stat->start), (unsigned int)(stat->lookup_done - stat->lookup_start), 
			(unsigned int)(stat->connect_done - stat->connect_start),
			(unsigned int)(stat->connect_done? stat->sip_sent - stat->connect_done : 0),
			(unsigned int)(stat->remote_done - stat->remote_start));
		ASSERT_TRUE(buf = append_str(tmp, buf, &buflen, &datalen), err);
		freez(tmp);
	}
	ASSERT_TRUE(replace_end(buf, &buflen, &datalen, ",\n", "\n"), err);
	ASSERT_TRUE(buf = append_str("];\n", buf, &buflen, &datalen), err);
	*str = buf;
	buf = 0;
 err:
	ship_unlock(done_stats);
	freez(buf);
	freez(tmp);
}
Пример #2
0
Файл: stem.c Проект: DrDub/bow
int
bow_stem_porter (char *word)
{
  int rule;    /* which rule is fired in replacing an end */
  char *post_infix;

  /* skip past the infix separator if it's there */
  if (bow_lexer_infix_separator &&
      (post_infix = strstr (word, bow_lexer_infix_separator)))
    word = post_infix + bow_lexer_infix_length;

  /* Part 1: Check to ensure the word is all alphabetic */
  for (end = word; *end != EOS; end++)
    {
      if (!isalpha(*end))
	return (FALSE);
      else
	*end = tolower (*end);
    }
  end--;

  /*  Part 2: Run through the Porter algorithm */
  replace_end (word, step1a_rules);
  rule = replace_end (word, step1b_rules);
  if ((106 == rule) || (107 == rule))
    replace_end (word, step1b1_rules);
  replace_end (word, step1c_rules);
  replace_end (word, step2_rules);
  replace_end (word, step3_rules);
  replace_end (word, step4_rules);
  replace_end (word, step5a_rules);
  replace_end (word, step5b_rules);

  /* Part 3: Return an indication of successful stemming */
  return (TRUE);

}
Пример #3
0
/* dumps the current status of all mediaproxies as a json blob */
int
sipp_mp_dump_json(char **msg)
{
	int buflen = 0, datalen = 0;
	char *buf = 0;
	void *ptr = 0, *ptr2 = 0;
        sipp_media_proxy_t *mp = NULL;
	char *tmpaddr1 = 0, *tmpaddr2 = 0, *tmp = 0;
	ship_list_t *callids = 0;
	char *str = 0;
	int ret = -1;
	ship_lock(sipp_mps);
	
	/* collect callids */
	ASSERT_TRUE(callids = ship_list_new(), err);
	while ((mp = ship_list_next(sipp_mps, &ptr))) {
		int found = 0;
		while (!found && (str = ship_list_next(callids, &ptr2))) {
			if (!strcmp(str, mp->callid))
				found = 1;
		}
		
		if (!found) {
			ship_list_add(callids, mp->callid);
		}
	}
	
	/* for each call id .. */
	ASSERT_TRUE(buf = append_str("var p2pship_mps = {\n", buf, &buflen, &datalen), err);
	ptr2 = 0;
	while ((str = ship_list_next(callids, &ptr2))) {
		ASSERT_TRUE(buf = append_str("     \"", buf, &buflen, &datalen), err);
		ASSERT_TRUE(buf = append_str(str, buf, &buflen, &datalen), err);
		ASSERT_TRUE(buf = append_str("\" : [\n", buf, &buflen, &datalen), err);

		ptr = 0;
		while ((mp = ship_list_next(sipp_mps, &ptr))) {
			int len = 0;
			
			if (!strcmp(mp->callid, str)) {
				ASSERT_ZERO(ident_addr_addr_to_str(&(mp->local_addr), &tmpaddr1), err);
				ASSERT_ZERO(ident_addr_addr_to_str(&(mp->remote_addr), &tmpaddr2), err);
				
				len = zstrlen(mp->sip_aor) + zstrlen(tmpaddr1) + zstrlen(mp->remote_aor) + zstrlen(tmpaddr2) + 
					zstrlen(mp->callid) + zstrlen(mp->mediatype) + 512;
				ASSERT_TRUE(tmp = mallocz(len), err);
				
				sprintf(tmp, "         [ \"%s\", \"%s\", \"%s\", \"%s\", \"%s\",\n           \"%s\", \"%s\", \"%d\", \"%d\", \"%d\", \"%d\" ],\n",
					mp->sip_aor, tmpaddr1, mp->remote_aor, tmpaddr2, sipp_mp_sendby_str(mp->sendby),
					mp->callid, mp->mediatype,
					mp->started, (int)mp->start_time, (int)mp->last, mp->counter);
				
				ASSERT_TRUE(buf = append_str(tmp, buf, &buflen, &datalen), err);
				freez(tmp);
				freez(tmpaddr1);
				freez(tmpaddr2);
			}
		}
		ASSERT_TRUE(replace_end(buf, &buflen, &datalen, ",\n", "\n"), err);
		ASSERT_TRUE(buf = append_str("     ],\n", buf, &buflen, &datalen), err);
	}

	ASSERT_TRUE(replace_end(buf, &buflen, &datalen, ",\n", "\n"), err);
	ASSERT_TRUE(buf = append_str("};\n", buf, &buflen, &datalen), err);
	*msg = buf;
	buf = 0;
	ret = 0;
 err:
	ship_unlock(sipp_mps);
	ship_list_free(callids);
	freez(buf);
	freez(tmpaddr1);
	freez(tmpaddr2);
	freez(tmp);
	return ret;
}