static void NS(test_main)(void *arg) { routerset_t *set, *bad_set; (void)arg; set = routerset_new(); bad_set = routerset_new(); smartlist_free(bad_set->list); bad_set->list = NULL; NS_MOCK(smartlist_new); routerset_union(set, NULL); tt_int_op(CALLED(smartlist_new), ==, 0); routerset_union(set, bad_set); tt_int_op(CALLED(smartlist_new), ==, 0); done: NS_UNMOCK(smartlist_new); routerset_free(set); /* Just recreate list, so we can simply use routerset_free. */ bad_set->list = smartlist_new(); routerset_free(bad_set); }
void refreshBannedNodes(void) { r1=tmpOptions->ExcludeExitNodes; r2=routerset_new(); char *tmp1=tor_malloc(65536),*tmp2,*tmp3;tmp2=tmp1;tmp3=tmp1;GetDlgItemText(hDlgRouterRestrictions,15100,tmp1,65536); while(*tmp1) { while((*tmp1==32)||(*tmp1==9)) tmp1++; if((*tmp1==13)||(*tmp1==10)) { while((*tmp1==13)||(*tmp1==10)){ tmp1++;} *tmp2++=','; } else if((*tmp1=='[')&&(*(tmp1+2)==']')) { if((*(tmp1+1)=='x')||(*(tmp1+1)=='X')) { tmp1+=3; while((*tmp1==32)||(*tmp1==9)) tmp1++; while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) *tmp2++=*tmp1++; } else while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) tmp1++; } else while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) tmp1++; } *tmp2=0;routerset_parse(r2,tmp3,"ExcludeExitNodes"); tmpOptions->ExcludeExitNodes=r2; if(r1) routerset_free(r1); r1=tmpOptions->ExcludeNodes; r2=routerset_new(); tmp1=tmp3;tmp2=tmp3;GetDlgItemText(hDlgRouterRestrictions,15100,tmp1,65536); while(*tmp1) { while((*tmp1==32)||(*tmp1==9)) tmp1++; if((*tmp1==13)||(*tmp1==10)) { while((*tmp1==13)||(*tmp1==10)){ tmp1++;} *tmp2++=','; } else if((*tmp1=='[')&&(*(tmp1+2)==']')) { if((*(tmp1+1)=='x')||(*(tmp1+1)=='X')) { while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) tmp1++; } else { while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) *tmp2++=*tmp1++; } } else { while((*tmp1!=0)&&(*tmp1!=13)&&(*tmp1!=10)) *tmp2++=*tmp1++; } } *tmp2=0;routerset_parse(r2,tmp3,"ExcludeNodes"); tmpOptions->ExcludeNodes=r2; if(r1) routerset_free(r1); 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); } tor_free(tmp3); }
static void NS(test_main)(void *arg) { routerset_t *src = routerset_new(); routerset_t *tgt; (void)arg; tgt = routerset_new(); smartlist_add(src->list, tor_strdup("{xx}")); routerset_union(tgt, src); tt_int_op(smartlist_len(tgt->list), !=, 0); done: routerset_free(src); routerset_free(tgt); }
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); } } }