Exemple #1
0
void show_favorites(void)
{	char *tmp1,*tmp2,*tmp3,*tmp4;
	if((tmpOptions->EntryNodes)||(tmpOptions->ExitNodes))
	{	tmp3=tor_malloc(65536);tmp4=tmp3;
		if(tmpOptions->EntryNodes)
		{	tmp1=routerset_to_string(tmpOptions->EntryNodes);
			tmp2=tmp1;
			while(*tmp2)
			{	if((*tmp2!=0)&&(*tmp2!=','))
				{	*tmp3++='[';*tmp3++='E';*tmp3++=']';*tmp3++=32;
					while((*tmp2!=0)&&(*tmp2!=','))	*tmp3++=*tmp2++;
				}
				else if(*tmp2==',')
				{	*tmp3++=13;*tmp3++=10;tmp2++;}
			}
			tor_free(tmp1);
			if(tmp3!=tmp4){*tmp3++=13;*tmp3++=10;}
		}
		if(tmpOptions->ExitNodes)
		{	tmp1=routerset_to_string(tmpOptions->ExitNodes);
			tmp2=tmp1;
			while(*tmp2)
			{	if((*tmp2!=0)&&(*tmp2!=','))
				{	*tmp3++='[';*tmp3++='X';*tmp3++=']';*tmp3++=32;
					while((*tmp2!=0)&&(*tmp2!=','))	*tmp3++=*tmp2++;
				}
				else if(*tmp2==',')
				{	*tmp3++=13;*tmp3++=10;tmp2++;}
			}
			tor_free(tmp1);
		}
		*tmp3=0;
		SetDlgItemText(hDlgRouterRestrictions,15101,tmp4);tor_free(tmp4);
	}
}
Exemple #2
0
void add_router_to_favorites(HWND hDlg,char *router,char favtype)
{	if(hDlgRouterRestrictions)
	{	char *favtmp2,*favtmp3;
		int favtmpsize;
		int i;
		favtmpsize=SendDlgItemMessage(hDlgRouterRestrictions,15101,WM_GETTEXTLENGTH,0,0);
		favtmp2=tor_malloc(favtmpsize+256+5);favtmp3=favtmp2;
		GetDlgItemText(hDlgRouterRestrictions,15101,favtmp2,favtmpsize+1);favtmp2+=favtmpsize;
		if((favtmpsize>2)&&((*(favtmp2-1)!=0x0d)&&(*(favtmp2-1)!=0x0a)))
		{	*favtmp2++=0x0d;*favtmp2++=0x0a;}
		*favtmp2++='[';*favtmp2++=favtype;*favtmp2++=']';*favtmp2++=32;
		for(i=0;router[i];i++)	*favtmp2++=router[i];
		*favtmp2++=13;*favtmp2++=10;*favtmp2++=0;
		tor_snprintf(favtmp2,100,get_lang_str(LANG_MB_FAV_ADDED),favtmp3+favtmpsize);
		LangMessageBox(hDlg,favtmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,favtmp2);
		SetDlgItemText(hDlgRouterRestrictions,15101,favtmp3);
		refreshFavoriteNodes();
		tor_free(favtmp3);
	}
	else if(favtype=='X')
	{	char *tmp1=routerset_to_string(tmpOptions->ExitNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExitNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExitNodes");
		tmpOptions->ExitNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[X] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_FAV_ADDED),tmp3);
		LangMessageBox(hDlg,tmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
	}
	else if(favtype=='E')
	{	char *tmp1=routerset_to_string(tmpOptions->EntryNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->EntryNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"EntryNodes");
		tmpOptions->EntryNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[E] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_FAV_ADDED),tmp3);
		LangMessageBox(hDlg,tmp2,LANG_MB_FAVORITES,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
	}
}
Exemple #3
0
static void
NS(test_main)(void *arg)
{
  routerset_t *set = NULL;
  char *s = NULL;
  (void)arg;

  set = NULL;
  s = routerset_to_string(set);
  tt_str_op(s, ==, "");
  tor_free(s);

  set = routerset_new();
  s = routerset_to_string(set);
  tt_str_op(s, ==, "");
  tor_free(s);
  routerset_free(set); set = NULL;

  set = routerset_new();
  smartlist_add(set->list, tor_strndup("a", 1));
  s = routerset_to_string(set);
  tt_str_op(s, ==, "a");
  tor_free(s);
  routerset_free(set); set = NULL;

  set = routerset_new();
  smartlist_add(set->list, tor_strndup("a", 1));
  smartlist_add(set->list, tor_strndup("b", 1));
  s = routerset_to_string(set);
  tt_str_op(s, ==, "a,b");
  tor_free(s);
  routerset_free(set); set = NULL;

 done:
  tor_free(s);
  routerset_free((routerset_t *)set);
}
Exemple #4
0
void add_router_to_banlist(HWND hDlg,char *router,char bantype)
{	if(hDlgRouterRestrictions)
	{	char *bantmp2,*bantmp3;
		int bantmpsize,i;
		bantmpsize=SendDlgItemMessage(hDlgRouterRestrictions,15100,WM_GETTEXTLENGTH,0,0);
		bantmp2=tor_malloc(bantmpsize+256+5);bantmp3=bantmp2;
		GetDlgItemText(hDlgRouterRestrictions,15100,bantmp2,bantmpsize+1);bantmp2+=bantmpsize;
		if((bantmpsize>2)&&((*(bantmp2-1)!=0x0d)&&(*(bantmp2-1)!=0x0a)))
		{	*bantmp2++=0x0d;*bantmp2++=0x0a;}
		if(bantype){	*bantmp2++='[';*bantmp2++=bantype;*bantmp2++=']';*bantmp2++=32;}
		for(i=0;router[i];i++)	*bantmp2++=router[i];
		*bantmp2++=13;*bantmp2++=10;*bantmp2++=0;
		tor_snprintf(bantmp2,100,get_lang_str(LANG_MB_BAN_ADDED),bantmp3+bantmpsize);
		if(hDlg) LangMessageBox(hDlg,bantmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,bantmp2);
		SetDlgItemText(hDlgRouterRestrictions,15100,bantmp3);
		refreshBannedNodes();
		tor_free(bantmp3);
	}
	else if(bantype)
	{	char *tmp1=routerset_to_string(tmpOptions->ExcludeExitNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i),*tmp3=tor_malloc(256);;
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExcludeExitNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExcludeExitNodes");
		tmpOptions->ExcludeExitNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp3,256,"[X] %s",router);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_BAN_ADDED),tmp3);
		if(hDlg) LangMessageBox(hDlg,tmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);tor_free(tmp3);
		if(tmpOptions->ExcludeExitNodes || tmpOptions->ExcludeNodes)
		{	r2 = tmpOptions->_ExcludeExitNodesUnion;
			r1 = routerset_new();
			routerset_union(r1,tmpOptions->ExcludeExitNodes);
			routerset_union(r1,tmpOptions->ExcludeNodes);
			tmpOptions->_ExcludeExitNodesUnion = r1;
			if(r2)	routerset_free(r2);
		}
	}
	else
	{	char *tmp1=routerset_to_string(tmpOptions->ExcludeNodes);
		int i=strlen(tmp1)+256+5;
		char *tmp2=tor_malloc(i);
		tor_snprintf(tmp2,i,"%s,%s",tmp1,router);
		r1=tmpOptions->ExcludeNodes;
		r2=routerset_new();
		routerset_parse(r2,tmp2,"ExcludeNodes");
		tmpOptions->ExcludeNodes=r2;
		if(r1)	routerset_free(r1);
		tor_snprintf(tmp2,100,get_lang_str(LANG_MB_BAN_ADDED),router);
		if(hDlg) LangMessageBox(hDlg,tmp2,LANG_MB_BANS,MB_OK);
		log(LOG_NOTICE,LD_APP,tmp2);
		tor_free(tmp1);tor_free(tmp2);
		if(tmpOptions->ExcludeExitNodes || tmpOptions->ExcludeNodes)
		{	r2 = tmpOptions->_ExcludeExitNodesUnion;
			r1 = routerset_new();
			routerset_union(r1,tmpOptions->ExcludeExitNodes);
			routerset_union(r1,tmpOptions->ExcludeNodes);
			tmpOptions->_ExcludeExitNodesUnion = r1;
			if(r2)	routerset_free(r2);
		}
	}
}