static void two_major_two_minor( char * buf, size_t buflen, const char * name, const uint8_t * digits ) { tr_snprintf( buf, buflen, "%s %d.%02d", name, strint( digits, 2 ), strint( digits+2, 2 ) ); }
void PosteriorDecoder::exclude_template_regions(char* exclstr, HMM & q_hmm, HMM & t_hmm, ViterbiMatrix& viterbiMatrix) { char* ptr = exclstr; while (true) { const int j0 = abs(strint(ptr)); const int j1 = abs(strint(ptr)); if (!ptr) break; for (int j = j0; j <= std::min(j1, t_hmm.L); ++j) { for (int i = 1; i <= q_hmm.L; ++i) { viterbiMatrix.setCellOff(i, j, 0, true); } } } }
eventhandler* parse_eventhandler(char* line) { char *token = NULL; char *sptr = NULL; char *cp = strdup(line); /* ignore everything behind # */ char *comment = strchr(line, '#'); if ( comment != NULL ) { *comment = '\0'; } char *delim = " \t\n"; char *evname = ct( strtok_r(cp, delim, &sptr) ); int value = strint( strtok_r(NULL, delim, &sptr) ); char *cmd = ct( strtok_r(NULL, "\n", &sptr) ); free(cp); /* all fields filled? */ if (evname && cmd && (value >= 0)) { eventhandler *eh = malloc( sizeof(eventhandler) ); eh->type = lookup_event_type( evname ); eh->code = lookup_event_code( evname ); eh->value = value; eh->cmdline = cmd; eh->next = NULL; return eh; } else { free(evname); free(cmd); return NULL; } }
void ViterbiRunner::exclude_template_regions(char* exclstr, int maxResElem, HMMSimd* q_hmm_simd, HMMSimd* t_hmm_simd, ViterbiMatrix* viterbiMatrix) { char* ptr = exclstr; while (true) { int j0 = abs(strint(ptr)); int j1 = abs(strint(ptr)); if (!ptr) break; for (int elem = 0; elem < maxResElem; elem++) { HMM * curr_t_hmm = t_hmm_simd->GetHMM(elem); HMM * curr_q_hmm = q_hmm_simd->GetHMM(elem); for (int j=j0; j <= std::min(j1, curr_t_hmm->L); ++j) { for (int i = 1; i <= curr_q_hmm->L; ++i) { viterbiMatrix->setCellOff(i, j, elem, true); } } } } }
void tr_clientForId( char * buf, size_t buflen, const void * id_in ) { const uint8_t * id = id_in; *buf = '\0'; if( !id ) return; /* Azureus-style */ if( id[0] == '-' && id[7] == '-' ) { if( !memcmp( id+1, "UT", 2 ) ) { tr_snprintf( buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s", strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) ); } if( !memcmp( id+1, "UM", 2 ) ) { tr_snprintf( buf, buflen, "\xc2\xb5Torrent Mac %d.%d.%d%s", strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) ); } else if( !memcmp( id+1, "TR", 2 ) ) { if( !memcmp( id+3, "000", 3 ) ) /* very old client style: -TR0006- is 0.6 */ tr_snprintf( buf, buflen, "Transmission 0.%c", id[6] ); else if( !memcmp( id+3, "00", 2) ) /* previous client style: -TR0072- is 0.72 */ tr_snprintf( buf, buflen, "Transmission 0.%02d", strint(id+5,2) ); else /* current client style: -TR111Z- is 1.11+ */ tr_snprintf( buf, buflen, "Transmission %d.%02d%s", strint(id+3,1), strint(id+4,2), id[6]=='Z' || id[6]=='X' ? "+" : "" ); } else if( !memcmp( id+1, "AZ", 2 ) ) { if( id[3] > '3' || ( id[3] == '3' && id[4] >= '1' ) ) /* Vuze starts at version 3.1.0.0 */ four_digits( buf, buflen, "Vuze", id+3 ); else four_digits( buf, buflen, "Azureus", id+3 ); } else if( !memcmp( id+1, "KT", 2 ) ) { if( id[5] == 'D' ) tr_snprintf( buf, buflen, "KTorrent %d.%d Dev %d", charint(id[3]), charint(id[4]), charint(id[6]) ); else if( id[5] == 'R' ) tr_snprintf( buf, buflen, "KTorrent %d.%d RC %d", charint(id[3]), charint(id[4]), charint(id[6]) ); else three_digits( buf, buflen, "KTorrent", id+3 ); } else if( !memcmp( id+1, "AR", 2 ) ) four_digits( buf, buflen, "Ares", id+3 ); else if( !memcmp( id+1, "AT", 2 ) ) four_digits( buf, buflen, "Artemis", id+3 ); else if( !memcmp( id+1, "AV", 2 ) ) four_digits( buf, buflen, "Avicora", id+3 ); else if( !memcmp( id+1, "BG", 2 ) ) four_digits( buf, buflen, "BTGetit", id+3 ); else if( !memcmp( id+1, "BM", 2 ) ) four_digits( buf, buflen, "BitMagnet", id+3 ); else if( !memcmp( id+1, "BP", 2 ) ) four_digits( buf, buflen, "BitTorrent Pro (Azureus + Spyware)", id+3 ); else if( !memcmp( id+1, "BX", 2 ) ) four_digits( buf, buflen, "BittorrentX", id+3 ); else if( !memcmp( id+1, "bk", 2 ) ) four_digits( buf, buflen, "BitKitten (libtorrent)", id+3 ); else if( !memcmp( id+1, "BS", 2 ) ) four_digits( buf, buflen, "BTSlave", id+3 ); else if( !memcmp( id+1, "BW", 2 ) ) four_digits( buf, buflen, "BitWombat", id+3 ); else if( !memcmp( id+1, "BX", 2 ) ) four_digits( buf, buflen, "BittorrentX", id+3 ); else if( !memcmp( id+1, "EB", 2 ) ) four_digits( buf, buflen, "EBit", id+3 ); else if( !memcmp( id+1, "DE", 2 ) ) four_digits( buf, buflen, "Deluge", id+3 ); else if( !memcmp( id+1, "DP", 2 ) ) four_digits( buf, buflen, "Propogate Data Client", id+3 ); else if( !memcmp( id+1, "FC", 2 ) ) four_digits( buf, buflen, "FileCroc", id+3 ); else if( !memcmp( id+1, "FT", 2 ) ) four_digits( buf, buflen, "FoxTorrent/RedSwoosh", id+3 ); else if( !memcmp( id+1, "GR", 2 ) ) four_digits( buf, buflen, "GetRight", id+3 ); else if( !memcmp( id+1, "HN", 2 ) ) four_digits( buf, buflen, "Hydranode", id+3 ); else if( !memcmp( id+1, "LC", 2 ) ) four_digits( buf, buflen, "LeechCraft", id+3 ); else if( !memcmp( id+1, "LH", 2 ) ) four_digits( buf, buflen, "LH-ABC", id+3 ); else if( !memcmp( id+1, "NX", 2 ) ) four_digits( buf, buflen, "Net Transport", id+3 ); else if( !memcmp( id+1, "MO", 2 ) ) four_digits( buf, buflen, "MonoTorrent", id+3 ); else if( !memcmp( id+1, "MR", 2 ) ) four_digits( buf, buflen, "Miro", id+3 ); else if( !memcmp( id+1, "MT", 2 ) ) four_digits( buf, buflen, "Moonlight", id+3 ); else if( !memcmp( id+1, "OT", 2 ) ) four_digits( buf, buflen, "OmegaTorrent", id+3 ); else if( !memcmp( id+1, "PD", 2 ) ) four_digits( buf, buflen, "Pando", id+3 ); else if( !memcmp( id+1, "QD", 2 ) ) four_digits( buf, buflen, "QQDownload", id+3 ); else if( !memcmp( id+1, "RS", 2 ) ) four_digits( buf, buflen, "Rufus", id+3 ); else if( !memcmp( id+1, "RT", 2 ) ) four_digits( buf, buflen, "Retriever", id+3 ); else if( !memcmp( id+1, "SS", 2 ) ) four_digits( buf, buflen, "SwarmScope", id+3 ); else if( !memcmp( id+1, "SZ", 2 ) ) four_digits( buf, buflen, "Shareaza", id+3 ); else if( !memcmp( id+1, "S~", 2 ) ) four_digits( buf, buflen, "Shareaza", id+3 ); else if( !memcmp( id+1, "st", 2 ) ) four_digits( buf, buflen, "SharkTorrent", id+3 ); else if( !memcmp( id+1, "TN", 2 ) ) four_digits( buf, buflen, "Torrent .NET", id+3 ); else if( !memcmp( id+1, "TS", 2 ) ) four_digits( buf, buflen, "TorrentStorm", id+3 ); else if( !memcmp( id+1, "UL", 2 ) ) four_digits( buf, buflen, "uLeecher!", id+3 ); else if( !memcmp( id+1, "VG", 2 ) ) four_digits( buf, buflen, "Vagaa", id+3 ); else if( !memcmp( id+1, "WT", 2 ) ) four_digits( buf, buflen, "BitLet", id+3 ); else if( !memcmp( id+1, "WY", 2 ) ) four_digits( buf, buflen, "Wyzo", id+3 ); else if( !memcmp( id+1, "XL", 2 ) ) four_digits( buf, buflen, "Xunlei", id+3 ); else if( !memcmp( id+1, "XT", 2 ) ) four_digits( buf, buflen, "XanTorrent", id+3 ); else if( !memcmp( id+1, "ZT", 2 ) ) four_digits( buf, buflen, "Zip Torrent", id+3 ); else if( !memcmp( id+1, "AG", 2 ) ) three_digits( buf, buflen, "Ares", id+3 ); else if( !memcmp( id+1, "A~", 2 ) ) three_digits( buf, buflen, "Ares", id+3 ); else if( !memcmp( id+1, "ES", 2 ) ) three_digits( buf, buflen, "Electric Sheep", id+3 ); else if( !memcmp( id+1, "HL", 2 ) ) three_digits( buf, buflen, "Halite", id+3 ); else if( !memcmp( id+1, "LT", 2 ) ) three_digits( buf, buflen, "libtorrent (Rasterbar)", id+3 ); else if( !memcmp( id+1, "lt", 2 ) ) three_digits( buf, buflen, "libTorrent (Rakshasa)", id+3 ); else if( !memcmp( id+1, "MP", 2 ) ) three_digits( buf, buflen, "MooPolice", id+3 ); else if( !memcmp( id+1, "TT", 2 ) ) three_digits( buf, buflen, "TuoTu", id+3 ); else if( !memcmp( id+1, "qB", 2 ) ) three_digits( buf, buflen, "qBittorrent", id+3 ); else if( !memcmp( id+1, "AX", 2 ) ) two_major_two_minor( buf, buflen, "BitPump", id+3 ); else if( !memcmp( id+1, "BC", 2 ) ) two_major_two_minor( buf, buflen, "BitComet", id+3 ); else if( !memcmp( id+1, "CD", 2 ) ) two_major_two_minor( buf, buflen, "Enhanced CTorrent", id+3 ); else if( !memcmp( id+1, "LP", 2 ) ) two_major_two_minor( buf, buflen, "Lphant", id+3 ); else if( !memcmp( id+1, "BF", 2 ) ) no_version( buf, buflen, "BitFlu" ); else if( !memcmp( id+1, "LW", 2 ) ) no_version( buf, buflen, "LimeWire" ); else if( !memcmp( id+1, "BB", 2 ) ) { tr_snprintf( buf, buflen, "BitBuddy %c.%c%c%c", id[3], id[4], id[5], id[6] ); } else if( !memcmp( id+1, "BR", 2 ) ) { tr_snprintf( buf, buflen, "BitRocket %c.%c (%c%c)", id[3], id[4], id[5], id[6] ); } else if( !memcmp( id+1, "CT", 2 ) ) { tr_snprintf( buf, buflen, "CTorrent %d.%d.%02d", charint(id[3]), charint(id[4]), strint(id+5,2) ); } else if( !memcmp( id+1, "XX", 2 ) ) { tr_snprintf( buf, buflen, "Xtorrent %d.%d (%d)", charint(id[3]), charint(id[4]), strint(id+5,2) ); } else if( !memcmp( id+1, "BOW", 3 ) ) { if( !memcmp( &id[4], "A0B", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.5" ); else if( !memcmp( &id[4], "A0C", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.6" ); else tr_snprintf( buf, buflen, "Bits on Wheels %c.%c.%c", id[4], id[5], id[5] ); } if( *buf ) return; } /* Mainline */ if( isMainlineStyle( id ) ) { if( *id=='M' ) mainline_style( buf, buflen, "BitTorrent", id ); if( *id=='Q' ) mainline_style( buf, buflen, "Queen Bee", id ); if( *buf ) return; } if( decodeBitCometClient( buf, buflen, id ) ) return; if( decodeBitSpiritClient( buf, buflen, id ) ) return; /* Clients with no version */ if( !memcmp( id, "AZ2500BT", 8 ) ) no_version( buf, buflen, "BitTyrant (Azureus Mod)" ); else if( !memcmp( id, "LIME", 4 ) ) no_version( buf, buflen, "Limewire" ); else if( !memcmp( id, "martini", 7 ) ) no_version( buf, buflen, "Martini Man" ); else if( !memcmp( id, "Pando", 5 ) ) no_version( buf, buflen, "Pando" ); else if( !memcmp( id, "a00---0", 7 ) ) no_version( buf, buflen, "Swarmy" ); else if( !memcmp( id, "a02---0", 7 ) ) no_version( buf, buflen, "Swarmy" ); else if( !memcmp( id, "-G3", 3 ) ) no_version( buf, buflen, "G3 Torrent" ); else if( !memcmp( id, "10-------", 9 ) ) no_version( buf, buflen, "JVtorrent" ); else if( !memcmp( id, "346-", 4 ) ) no_version( buf, buflen, "TorrentTopia" ); else if( !memcmp( id, "eX", 2 ) ) no_version( buf, buflen, "eXeem" ); else if( !memcmp( id, "-FG", 3 ) ) two_major_two_minor( buf, buflen, "FlashGet", id+3 ); /* Everything else */ else if( !memcmp( id, "S3", 2 ) && id[2] == '-' && id[4] == '-' && id[6] == '-' ) { tr_snprintf( buf, buflen, "Amazon S3 %c.%c.%c", id[3], id[5], id[7] ); } else if( !memcmp( id, "OP", 2 ) ) { tr_snprintf( buf, buflen, "Opera (Build %c%c%c%c)", id[2], id[3], id[4], id[5] ); } else if( !memcmp( id, "-ML", 3 ) ) { tr_snprintf( buf, buflen, "MLDonkey %c%c%c%c%c", id[3], id[4], id[5], id[6], id[7] ); } else if( !memcmp( id, "DNA", 3 ) ) { tr_snprintf( buf, buflen, "BitTorrent DNA %d.%d.%d", strint(id+3,2), strint(id+5,2), strint(id+7,2) ); } else if( !memcmp( id, "Plus", 4 ) ) { tr_snprintf( buf, buflen, "Plus! v2 %c.%c%c", id[4], id[5], id[6] ); } else if( !memcmp( id, "XBT", 3 ) ) { tr_snprintf( buf, buflen, "XBT Client %c.%c.%c%s", id[3], id[4], id[5], getMnemonicEnd(id[6]) ); } else if( !memcmp( id, "Mbrst", 5 ) ) { tr_snprintf( buf, buflen, "burst! %c.%c.%c", id[5], id[7], id[9] ); } else if( !memcmp( id, "btpd", 4 ) ) { tr_snprintf( buf, buflen, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] ); } else if( !memcmp( id, "BLZ", 3 ) ) { tr_snprintf( buf, buflen, "Blizzard Downloader %d.%d", id[3]+1, id[4] ); } else if( '\0' == id[0] && !memcmp( &id[1], "BS", 2 ) ) { tr_snprintf( buf, buflen, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) ); } else if( !memcmp( id, "QVOD", 4 ) ) { four_digits( buf, buflen, "QVOD", id+4 ); } else if( !memcmp( id, "-NE", 3 ) ) { four_digits( buf, buflen, "BT Next Evolution", id+3 ); } /* Shad0w-style */ { int a, b, c; if( strchr( "AOQRSTU", id[0] ) && getShadowInt( id[1], &a ) && getShadowInt( id[2], &b ) && getShadowInt( id[3], &c ) ) { const char * name = NULL; switch( id[0] ) { case 'A': name = "ABC"; break; case 'O': name = "Osprey"; break; case 'Q': name = "BTQueue"; break; case 'R': name = "Tribler"; break; case 'S': name = "Shad0w"; break; case 'T': name = "BitTornado"; break; case 'U': name = "UPnP NAT Bit Torrent"; break; } if( name ) { tr_snprintf( buf, buflen, "%s %d.%d.%d", name, a, b, c ); return; } } } /* No match */ if( !*buf ) { struct evbuffer * out = evbuffer_new( ); const char *in, *in_end; for( in=(const char*)id, in_end=in+8; in!=in_end; ++in ) { if( isprint( *in ) ) evbuffer_add_printf( out, "%c", *in ); else evbuffer_add_printf( out, "%%%02X", (unsigned int)*in ); } tr_strlcpy( buf, EVBUFFER_DATA( out ), buflen ); evbuffer_free( out ); } }
void evali(const char *str, char *err, int *eval) { // Mathematical Expression Evaluation Function // ----------------------------------------------- // This functions solves mathematical equations. // When a complex equation is passed via *str, // the equation is broken into parts, and the // simplest part is passed on recursively onto // the function itself. This recurvise process is // repeated until the whole equation has been solved. // Results of the evaluation are stored in int eval. if(!bcheck(str)) { /* this is the core of eval where the calculations are done. at this level, the equation does not have any brackets. */ const char symbols[]="^*/%+-&"; const char se[]="Invalid Syntax"; char *tmp = NULL; if((tmp=(char *)(malloc(sizeof(char)* (strlen(str)+1))))==NULL) allocerr(); *tmp='\0'; /* check wether str has reached the absolute stage */ if(prechar(tmp,str,symbols)==0) { printf("\n[simple]"); if(!ncheck(str)) { printf("\nequation solved!"); *eval = strint(str); free(tmp); tmp = NULL; return; } else if(!id_check(str)) { printf("\nit's a variable!"); free(tmp); tmp = NULL; return; } else { strcpy(err,se); stradd(err,": "); stradd(err,str); free(tmp); tmp = NULL; return; } } else /* there are symbols in str */ { free(tmp); tmp = NULL; } /* now the real maths */ printf("\n[complex]"); char *pre = NULL; /* string preceding of operator */ char *pos = NULL; /* string succeding the operator */ /* now allocate the variables */ if((pre=(char *)(malloc(sizeof(char)* (strlen(str)+1))))==NULL) allocerr(); *pre='\0'; if((pos=(char *)(malloc(sizeof(char)* (strlen(str)+1))))==NULL) allocerr(); *pos='\0'; char symbol = 0; if(prechar(pre,str,"^")) { if(postchar(pos,str,"^")) symbol = '^'; } else if(prechar(pre,str,"*")) { if(postchar(pos,str,"*")) symbol = '*'; } else if(prechar(pre,str,"/")) { if(postchar(pos,str,"/")) symbol = '/'; } else if(prechar(pre,str,"%")) { if(postchar(pos,str,"%")) symbol = '%'; } else if(prechar(pre,str,"+")) { if(postchar(pos,str,"+")) symbol = '+'; } else if(prechar(pre,str,"-")) { if(postchar(pos,str,"-")) symbol = '-'; } else if(prechar(pre,str,"&")) { if(postchar(pos,str,"&")) symbol = '&'; } char *ax = NULL; /* value preceding of operator */ char *bx = NULL; /* value succeding the operator */ char *cx = NULL; /* value of ax and bx processed */ /* now allocate the variables */ if((ax=(char *)(malloc(sizeof(char)* (strlen(pre)+1))))==NULL) allocerr(); *ax='\0'; if((bx=(char *)(malloc(sizeof(char)* (strlen(pos)+1))))==NULL) allocerr(); *bx='\0'; if((cx=(char *)(malloc(sizeof(char)* (strlen(str)+1))))==NULL) allocerr(); *cx='\0'; /* find out the contents of bx */ char *ebx = NULL; /* temp string to build bx */ if((ebx=(char *)(malloc(sizeof(char)* (strlen(pos)+1))))==NULL) allocerr(); *ebx='\0'; strcpy(bx,pos); strcpy(ebx,bx); for(;;) /* infinite loop */ { if(!prechar(bx,ebx,symbols)) { strcpy(bx,ebx); free(ebx); ebx = NULL; /* de-allocate ebx */ break; } else /* here ebx is build */ strcpy(ebx,bx); } /* find out the contents of ax */ char *eax = NULL; /* temp string to build ax */ if((eax=(char *)(malloc(sizeof(char)* (strlen(pre)+1))))==NULL) allocerr(); *eax='\0'; strcpy(ax,pre); strcpy(eax,ax); for(;;) /* infinite loop */ { if(!postchar(ax,eax,symbols)) { strcpy(ax,eax); free(eax); eax = NULL; /* de-allocate eax */ break; } else /* here eax is build */ strcpy(eax,ax); } /* variables to store (pre-ax) and (pre-bx) */ char *prex = NULL; /* string of (pre-ax) */ char *posx = NULL; /* string of (pos-ax) */ /* now allocate prex and posx */ if((prex=(char *)(malloc(sizeof(char)* (strlen(pre)+1))))==NULL) allocerr(); *prex='\0'; if((posx=(char *)(malloc(sizeof(char)* (strlen(pos)+1))))==NULL) allocerr(); *posx='\0'; /* find prex and posx */ strlft(prex,pre,(strlen(pre)-strlen(ax))); strrht(posx,pos,(strlen(pos)-strlen(bx))); /* de-allocate pre & pos */ printf("\nsym: %c",symbol); printf("\npre: %s",pre); printf("\npos: %s",pos); free(pre); pre = NULL; free(pos); pos = NULL; /* process ax and bx to find cx */ // ***************** /* de-allocate ax & bx */ printf("\n*ax: %s",ax); printf("\n*bx: %s",bx); printf("\n*cx: %s",cx); printf("\nprx: %s",prex); printf("\npox: %s",posx); free(ax); ax = NULL; free(bx); bx = NULL; /* variable to store one-step solved equation */ char *ex = NULL; if((ex=(char *)(malloc(sizeof(char)* (strlen(str)+1))))==NULL) allocerr(); *ex='\0'; /* find ex using cx in prex and posx */ // ***************** /* now de-allocate cx, prex & posx */ free(cx); cx = NULL; free(prex); cx = NULL; free(posx); cx = NULL; /* recurse ex on eval for next-step solving */ // ***************** /* de-allocate ex & return */ free(ex); ex = NULL; return; } else { if(!bcount(str)) { printf("\nEquation has brackets."); return; } else { strcpy(err,"Illegal Equation, inequal number of brackets."); return; } } }