/* - utilities ---------------------------------------------------------- */ struct json_object* asterisk_sip_peers_parser(const char* line, size_t length) { char* name; char* host; char* port; char* status; char* latency; const char* cursor = line; if (strncasecmp(line, "Name/username", 13) == 0 || strcasestr(line, "[Monitored:") != 0) { return NULL; } /* 1 2 3 4 5 6 7 8 012345678901234567890123456789012345678901234567890123456789012345678901234567890 Name/username Host Dyn Nat ACL Port Status */ struct json_object* peer = json_object_new_object(); json_object_object_add(peer, "name", json_object_new_string (trimr(cut_field(line, 0, 26)))); json_object_object_add(peer, "host", json_object_new_string (trimr(cut_field(line, 27, 42)))); json_object_object_add(peer, "port", json_object_new_string (trimr(cut_field(line, 55, 63)))); cursor = parse_field(line + 64, length, (char[]){' ',-1}, &status);
std::string trim( const std::string &s ) { std::string s2 = trimr( s ); unsigned int i; for ( i = 0; i < s2.length(); i++ ) { if ( !iscntrl( s[ i ] ) && !isspace( s[ i ] ) ) break; } std::string s3 = s2.substr( i, s2.length() ); return s3; }
void trimComment(char ** buffer) { int sizeStr = strlen(*buffer); int i; assert(*buffer != NULL); for(i = 0; i < sizeStr ; i++) { if((*buffer)[i] == '#') { (*buffer)[i] = '\0'; trimr(buffer); // Trim the string i = sizeStr; // Stop the for(;;) } } }
User* init_connection(ServerSocket *socket){ User *user = new User( (ServerSocket *) socket ); std::string *request, username; int is_utf8 = 0; user->send("Welcome to Monolipe\n\n==========\n"); user->send("Enter your codepage (cp1251 on default): "); while (username.length() == 0){ request = user->recive(); if ( (*request)[0] == (char) 255){ if ((*request)[1] == (char) 251){ // WILL (option code) 251 Указывает на желание исполнять или подтверждает, что сейчас исполняется указанная опция. printf("It's telnet\n"); continue; } } *request = trimr(*request); if (request->compare("utf8") == 0){ is_utf8 = 1; } else { if (!is_utf8){ user->setEncoding("cp1251", "utf-8"); } username = *request; } user->send("Ваше имя: "); } user->setName(username); return user; }
/** * \param input The string. */ inline void trim(std::string & s) { triml(s); trimr(s); }
bool reg1test::exportTest( HANDLE expfd ) { // export current contest as REG1TEST writer wr( expfd ); char lbuff[ 1024 ]; wr.lwrite( "[REG1TEST;1]" ); // First the header info // calc mult count int ltot = 0; int nctry = 0; int ndistrict = 0; int nlocs = 0; if ( ct->countryMult.getValue() ) { ltot += ct->nctry ; nctry = ct->nctry; } if ( ct->districtMult.getValue() ) { ltot += ct->ndistrict; ndistrict = ct->ndistrict; } if ( ct->locMult.getValue() ) { ltot += ct->nlocs; nlocs = ct->nlocs; } if ( ltot == 0 ) ltot = 1; std::vector <std::string> remarks; remarks.push_back( ct->entCondx1.getValue() ); remarks.push_back( ct->entCondx2.getValue() ); remarks.push_back( ct->entCondx3.getValue() ); remarks.push_back( ct->entCondx4.getValue() ); int nvalid = 0; // valid QSOs int nlines = 0; // QSO records for ( unsigned int i = 0; i < ct->ctList.size(); i++ ) { BaseContact *dct = ct->ctList[ i ]; ContestContact *cct = dynamic_cast<ContestContact *>( dct ); // Extract comments for "Remarks" section cct->addReg1TestComment( remarks ); if ( cct->contactFlags.getValue() & ( LOCAL_COMMENT | COMMENT_ONLY | DONT_PRINT ) ) continue; nlines++; if ( cct->contactScore.getValue() > 0 ) nvalid++; } // get the best DX contact BaseContact *bestdx = ct->getBestDX(); /* // build the list of main operators std::set <std::string> op1list; for ( LogIterator i = ct->ctList.begin(); i != ct->ctList.end(); i++ ) { op1list.insert( ( *i ) ->op1.getValue() ); } */ linelist[ ( int ) TName ] = reg1testLine( "TName", ct->name.getValue() /*, "Contest Name"*/ ), linelist[ ( int ) TdDate ] = reg1testLine( "TDate", ct->dateRange( DTGFULL ) /*, "Start Date;End Date"*/ ); linelist[ ( int ) PCall ] = reg1testLine( "PCall", ct->mycall.fullCall.getValue() /*, "Callsign Used"*/ ); linelist[ ( int ) PWWLo ] = reg1testLine( "PWWLo", ct->myloc.loc.getValue() /*, "Locator Used"*/ ); linelist[ ( int ) PExch ] = reg1testLine( "PExch", ct->location.getValue() /*, "Exchange Used"*/ ); linelist[ ( int ) PAdr1 ] = reg1testLine( "PAdr1", ct->sqth1.getValue() /*, "Address line 1/2 of station"*/ ); linelist[ ( int ) PAdr2 ] = reg1testLine( "PAdr2", ct->sqth2.getValue() /*, "Address line 2/2 of station"*/ ); linelist[ ( int ) PSect ] = reg1testLine( "PSect", ct->entSect.getValue() /*, "Section Entered"*/ ); linelist[ ( int ) PBand ] = reg1testLine( "PBand", ct->band.getValue() /*, "Band Used"*/ ); linelist[ ( int ) PClub ] = reg1testLine( "PClub", ct->entrant.getValue() /*, "Name of club/group"*/ ); linelist[ ( int ) RName ] = reg1testLine( "RName", ct->entName.getValue() /*, "Name of responsible operator"*/ ); linelist[ ( int ) RCall ] = reg1testLine( "RCall", ct->entCall.getValue() /*, "Callsign of responsible operator"*/ ); linelist[ ( int ) RAdr1 ] = reg1testLine( "RAdr1", ct->entAddr1.getValue() /*, "Address line 1/2 of responsible operator"*/ ); linelist[ ( int ) RAdr2 ] = reg1testLine( "RAdr2", ct->entAddr2.getValue() /*, "Address line 2/2 of responsible operator"*/ ); linelist[ ( int ) RCity ] = reg1testLine( "RCity", ct->entCity.getValue() /*, "City of responsible operator"*/ ); linelist[ ( int ) RPoCo ] = reg1testLine( "RPoCo", ct->entPostCode.getValue() /*, "Post Code of responsible operator"*/ ); linelist[ ( int ) RCoun ] = reg1testLine( "RCoun", ct->entCountry.getValue() /*, "Country of responsible operator"*/ ); linelist[ ( int ) RPhon ] = reg1testLine( "RPhon", ct->entPhone.getValue() /*, "Phone no. of responsible operator"*/ ); linelist[ ( int ) RHBBS ] = reg1testLine( "RHBBS", ct->entEMail.getValue() /*, "EMAIL address of responsible operator"*/ ); linelist[ ( int ) MOpe1 ] = reg1testLine( "MOpe1", ct->ops1.getValue() /*, "Operators line 1/2"*/ ); linelist[ ( int ) MOpe2 ] = reg1testLine( "MOpe2", ct->ops2.getValue() /*, "Operators line 2/2"*/ ); linelist[ ( int ) STXEq ] = reg1testLine( "STXEq", ct->entTx.getValue() /*, "TX Equipment"*/ ); linelist[ ( int ) SPowe ] = reg1testLine( "SPowe", ct->power.getValue() /*, "TX Power (W)"*/ ); linelist[ ( int ) SRXEq ] = reg1testLine( "SRXEq", ct->entRx.getValue() /*, "RX Equipment"*/ ); linelist[ ( int ) SAnte ] = reg1testLine( "SAnte", ct->entAnt.getValue() /*, "Antenna"*/ ); linelist[ ( int ) SAntH ] = reg1testLine( "SAntH", ct->entAGL.getValue() + ";" + ct->entASL.getValue() /*, "Antenna Height agl;height asl"*/ ); linelist[ ( int ) CQSOs ] = reg1testLine( "CQSOs", makeStr( nvalid ) + ";1" /*, "Claimed no. of valid QSOs;Band multiplier"*/ ); linelist[ ( int ) CQSOP ] = reg1testLine( "CQSOP", makeStr( ct->contestScore ) ); /*, "Claimed no. of QSO points"*/ linelist[ ( int ) CWWLs ] = reg1testLine( "CWWLs", makeStr( nlocs ) + ";0;1" ); /*, "Claimed no. of WWLs;Bonus per new WWL;WWL multiplier"*/ linelist[ ( int ) CWWLB ] = reg1testLine( "CWWLB", "0" ); /*, "Claimed no. of WWL bonus points"*/ linelist[ ( int ) CExcs ] = reg1testLine( "CExcs", makeStr( ndistrict ) + ";0;1" ); /*, "Claimed no. of exchanges; Bonus for each new exchange; Exchange Multiplier"*/ linelist[ ( int ) CExcB ] = reg1testLine( "CExcB", "0" ); /*, "Claimed no. of exchange bonus points"*/ linelist[ ( int ) CDXCs ] = reg1testLine( "CDXCs", makeStr( nctry ) + ";0;1" ); /*, "Claimed no. of DXCCs; Bonus for each new DXCC;DXCC multiplier"*/ linelist[ ( int ) CDXCB ] = reg1testLine( "CDXCB", "0" ); /*, "Claimed no of DXCC bonus points"*/ linelist[ ( int ) CToSc ] = reg1testLine( "CToSc", makeStr( ct->contestScore * ltot ) ); /*, "Claimed total score"*/ linelist[ ( int ) CODXC ] = reg1testLine( "CODXC", bestdx ? ( ( bestdx->cs.fullCall.getValue() + ";" + bestdx->loc.loc.getValue() + ";" + makeStr( bestdx->contactScore.getValue() ).c_str() ).c_str() ) : ";;" ); /*, "(Best DX) Callsign; Locator; Distance"*/ for ( int i = 0; i < LineCount; i++ ) { sprintf( lbuff, "%s=%s", linelist[ i ].prefix.c_str(), linelist[ i ].data.c_str() ); wr.lwrite( lbuff ); } /* [Remarks]Remarks identifier F Remarks lines */ wr.lwrite( "[Remarks]" ); for ( unsigned int i = 0; i < remarks.size(); i++ ) { wr.lwrite( remarks[ i ].c_str() ); } TMyRCVersion RCVersion; RCVersion.initialise(); String ProductName = RCVersion.ProductName; String Version = RCVersion.FileVersion; String pver = "Produced by " + ProductName + " version " + Version; wr.lwrite( pver.c_str() ); /* [QSORecords;Number of QSO records following]QSO records identifier;number of QSO records following */ sprintf( lbuff, "[QSORecords;%d]", nlines ); wr.lwrite( lbuff ); // and then the contact list for ( unsigned int i = 0; i < ct->ctList.size(); i++ ) { BaseContact *dct = ct->ctList[ i ]; ContestContact *cct = dynamic_cast<ContestContact *>( dct ); if ( cct->contactFlags.getValue() & ( LOCAL_COMMENT | COMMENT_ONLY | DONT_PRINT ) ) { // should all COMMENT_ONLY records go into remarks? // and also comments on individual QSOs? continue; } std::string sbuff; cct->getReg1TestText( sbuff ); // lbuff if "bsize" = 256 if ( sbuff.length() == 0 ) continue; trimr( sbuff ); // No need to pad to 250!! wr.lwrite( sbuff.c_str() ); } return true; }
char callsign::validate( ) { if ( valRes != CS_NOT_VALIDATED ) return valRes; // NB that leading spaces may be genuine wildcards, and so may // actually be significant; we should reject as invalid // calls with leading spaces, even though this isn't very friendly TEMPBUFF( csv, CALLSIGNLENGTH + 1 ); strncpy( csv, fullCall.getValue().c_str(), CALLSIGNLENGTH ); // set up a modifiable buffer csv[ CALLSIGNLENGTH ] = 0; trimr( csv ); valRes = ERR_NOCS; if ( csv[ 0 ] == 0 ) // all spaces return valRes; // first check no funny characters; only alphanum and / allowed // (spaces are now invalid) valRes = ERR_INVCS; int cslen = strlen( csv ); for ( int i = 0; i < cslen; i++ ) { if ( ( csv[ i ] != '/' ) && ( !isalnum( csv[ i ] ) ) ) { return valRes; } } prefix = ""; prefix2 = ""; suffix = ""; number = ""; body = ""; const char *f = csv; char *spt = 0; // CEPT separator char *spt2 = 0; // suffix separator char *cse = &csv[ cslen ]; // zero termination if ( cse - f < 3 ) { return valRes; // cs too short } // find any separators spt = strchr( csv, '/' ); if ( spt ) { *spt = 0; spt++; spt2 = strchr( spt, '/' ); if ( cse - spt <= 0 ) return valRes; // nothing after end if ( spt == f ) return valRes; // nothing before first / if ( spt2 ) { *spt2 = 0; spt2++; if ( strchr( spt2, '/' ) ) return valRes; // too many separators if ( spt2 >= cse ) return valRes; // nothing after end if ( spt2 - spt < 3 ) return valRes; // too little in the middle } } if ( spt && spt2 ) { // two separators. // Usually F/G0GJV/P //What about F0ABC/RVI/P The /RVI is a country... if ( spt2 - spt <= TRAILBITLENGTH + 1 ) // assume the RVI case, allow for the '/' { prefix = "/"; prefix += std::string( spt ).substr( 1, BITLENGTH ); spt = csv; // main body is at the start } else { // current country prefix at the start prefix = std::string( spt ).substr( 0, BITLENGTH ); } suffix = std::string( spt2 ).substr( 0, TRAILBITLENGTH ); } else if ( spt && ( cse - spt <= TRAILBITLENGTH ) ) { // tail shorter than 4 chars, therefor e.g. /p or /mm - or /RVI // we will eventually search for mults on suffix first then prefix suffix = std::string( spt ).substr( 0, TRAILBITLENGTH ); *spt = 0; spt = csv; } else if ( spt ) { // long tail, must be normal prefix only, no suffix prefix = std::string( csv ).substr( 0, BITLENGTH ); } else { spt = csv; } // spt now points to main callsign, no CEPT/, no /P // suffix and prefix are set up f = spt; int j = 0; while ( isdigit( *f ) && ( j < BITLENGTH ) ) // leading digits (2 of 2E0...) { prefix2 += *f++; } while ( *f && ( prefix2.length() < BITLENGTH ) ) // prefix letters (E of 2E0) { if ( isdigit( *f ) ) { break ; } else { prefix2 += *f++; } } j = 0; while ( isdigit( *f ) && ( number.length() < NUMBITLENGTH ) ) // central number (0 of 2E0) number += *f++; // main CS letters body = std::string( f ).substr( 0, BITLENGTH ); if ( prefix.length() == 0 ) { prefix = prefix2.substr( 0, BITLENGTH ); // prefix is country of location // prefix2 is country of issue } valRes = ERR_CSDIGIT; if ( number.length() == 0 ) return valRes; // trim any numbers off tail of prefix (CEPT) // But with e.g. HB0 and HB9 both being new countries, HB0/G0GJV is valid(?) // So I think that we have to trust the user(YUCK!) // Replace real prefix2 with the dup check prefix2 - for dup checking // Need to implement the G list here... CountrySynonym *syn = MultLists::getMultLists() ->searchCountrySynonym( prefix2 ); if ( syn ) { syn->getDupPrefix( prefix2 ); } // We maybe ought to do the WGV trick here - apart from /P, etc the shortest // part of prefix/suffix is the country of operation // But I think we have it reasonably correct... until someone comes up // with a counter-example valRes = CS_OK; if ( ( prefix.length() == 0 ) || ( prefix2.length() == 0 ) || ( number.length() == 0 ) || ( body.length() == 0 ) ) // suffix can be null { valRes = ERR_INVCS; } return ( valRes ); }
bool INIFile::loadINIFile() { FILE * inf; TEMPBUFF( buffer, 256 ); INISection *thisSect; IniEntryPtr this_entry; bool realSections = false; if ( fileLoaded ) { if ( !checkStat() ) return false; // no change, so don't re-read writePrivateProfileString( 0, 0, 0 ); for ( std::vector <IniSectionPtr>::iterator thisSect = sections.begin(); thisSect != sections.end(); thisSect++ ) { delete ( *thisSect ); } sections.clear(); fileLoaded = false; } fileLoaded = true; if ( ( inf = fopen( loadedFileName.c_str(), "rt" ) ) == 0 ) { MinosParameters::getMinosParameters() ->mshowMessage( String( "Initialisation file \"" ) + loadedFileName.c_str() + "\" not found." ); // invalid = false; return false; } thisSect = new INISection( this, "?Comments", false ); // create dummy section for leading comments while ( fgets( buffer, 256, inf ) != 0 ) { TEMPBUFF ( Parameter, 256 ); if ( strchr( buffer, '[' ) && ( sscanf( buffer, " [ %255[^\n]", Parameter ) == 1 ) ) { char * p = strchr( Parameter, ']' ); if ( p != 0 ) { *p = '\0'; thisSect = new INISection( this, Parameter, true ); realSections = true; continue; } // and if no trailing ']' should we be lenient? } if ( buffer[ strlen( buffer ) - 1 ] == '\n' ) buffer[ strlen( buffer ) - 1 ] = 0; // take off trailing new line char *a[ 3 ]; bool sep2seen; int scnt = parseLine( buffer, '=', a, 2, 0, sep2seen ); trimr( a[ 0 ] ); trimr( a[ 1 ] ); if ( scnt ) { this_entry = new INIEntry( thisSect, a[ 0 ], true ); // somewhere we need to cope with quoted parameters this_entry->setValue( a[ 1 ] ); this_entry->setClean(); } else { // create comment entry this_entry = new INIEntry( thisSect, "??", false ); this_entry->setValue( a[ 0 ] ); this_entry->setClean(); } } fclose( inf ); // now stat the file so we can check for changes checkStat(); /* if ( !realSections ) { mshowMessage( String( "Initialisation file \"" ) + loadedFileName.c_str() + "\" invalid (no sections)." ); invalid = true; } else { invalid = false; } */ return realSections; }
char * trimCpy(char * buffer) { triml(&buffer); trimr(&buffer); return buffer; }
void* rundle(void* socket){ ServerSocket *client = (ServerSocket *) socket; std::string data; MessageStack messages; UserStack users; User *user; try { user = init_connection(client); } catch (SocketException& e) { printf("Error initial connection in function rundle()\n"); return NULL; } try { users.join(user); user->send("Добро пожаловать, о "); user->send("\n---- // enter \"quit\" for exit\n\n"); user->send(messages.viewLast()); while (true) { data = *user->recive("> "); data = trimr(data); if ( data.compare("quit") == 0) { user->send("Bye! До скорых встреч"); sleep(2); break; } if ( data.compare("help") == 0){ user->send("\r==== Список пользователей ====\n"); } if ( data.compare("who") == 0){ user->send("\r==== Список пользователей ====\n"); std::vector <User*> list = users.list(); for (int i = list.size() - 1; i >= 0; --i){ user->send(list[i]->id); user->send(": "); user->send(list[i]->getName()); user->send("\n"); } continue; } if ( data.length() == 0){ continue; } Message *message = new Message(user->getName(), data); messages.append( message ); users.sendMessage(message->get().c_str()); } } catch (SocketException& e) { std::cout << "Exception was caught:" << e.description() << "\nExiting.\n"; } users.disconnect(user); delete client; return NULL; }
//! \return modified string ``s'' with spaces trimmed from edges inline std::string& trim(std::string& s) { return triml(trimr(s)); }
void BaseContact::getText( std::string &dest, const BaseContestLog * const curcon ) const { ContactBuffs::brgbuff[ 0 ] = 0; ContactBuffs::scorebuff[ 0 ] = 0; ContactBuffs::qthbuff[ 0 ] = 0; if ( contactFlags.getValue() & ( LOCAL_COMMENT | COMMENT_ONLY | DONT_PRINT ) ) { sprintf( ContactBuffs::buff, "%-5.5s %s %-60.60s", time.getTime( DTGDISP ).c_str(), ( contactFlags.getValue() & DONT_PRINT ) ? "DELETED" : ( contactFlags.getValue() & LOCAL_COMMENT ) ? "LOCAL COMMENT" : "COMMENT FOR ADJUDICATOR", comments.getValue().c_str() ); } else { // if contest requires a serial makestrings( curcon ->serialField.getValue() ); mystrncpy( ContactBuffs::qthbuff, extraText.getValue().c_str(), 100 ); if ( contactFlags.getValue() & MANUAL_SCORE ) strcpy( ContactBuffs::brgbuff, "MAN" ); if ( contactFlags.getValue() & DONT_PRINT ) strcpy( ContactBuffs::scorebuff, "DEL" ); else if ( contactFlags.getValue() & NON_SCORING ) strcpy( ContactBuffs::scorebuff, "N/S" ); else { // look at the contest dup if ( ( cs.valRes == ERR_DUPCS ) && ( curcon == contest ) ) strcpy( ContactBuffs::scorebuff, "DUP" ); } } int nbuff = 4; if ( contactFlags.getValue() & VALID_DUPLICATE ) strcpy( ContactBuffs::buff2, "BP " ); else if ( contactFlags.getValue() & XBAND ) strcpy( ContactBuffs::buff2, "XB " ); else { nbuff = 0; ContactBuffs::buff2[ 0 ] = 0; } strcpysp( ContactBuffs::buff, comments.getValue(), 42 ); if ( ContactBuffs::buff[ 0 ] ) { strcpysp( &ContactBuffs::buff2[ nbuff ], ContactBuffs::qthbuff, 20 ); strcat( ContactBuffs::buff2, " | " ); strcat( ContactBuffs::buff2, ContactBuffs::buff ); } else strcpysp( &ContactBuffs::buff2[ nbuff ], ContactBuffs::qthbuff, 42 ); memset( ContactBuffs::buff, ' ', 255 ); int next = 0; next = placestr( ContactBuffs::buff, time.getDate( DTGDISP ), next, 8 ); next += 1; next = placestr( ContactBuffs::buff, time.getTime( DTGDISP ), next, 5 ); next += 1; next = placestr( ContactBuffs::buff, cs.fullCall.getValue(), next, 11 ); if ( curcon ->RSTField.getValue() ) next = placestr( ContactBuffs::buff, reps.getValue(), next, 3 ); next = placestr( ContactBuffs::buff, ContactBuffs::ssbuff, next, -4 ); if ( curcon ->RSTField.getValue() ) next = placestr( ContactBuffs::buff, repr.getValue(), next + 1, 3 ); next = placestr( ContactBuffs::buff, ContactBuffs::srbuff, next, -4 ); next = placestr( ContactBuffs::buff, loc.loc.getValue(), next + 1, ( curcon ->allowLoc8.getValue() ) ? 8 : 6 ); next = placestr( ContactBuffs::buff, ContactBuffs::brgbuff, next + 1, 4 ); next = placestr( ContactBuffs::buff, ContactBuffs::scorebuff, next, -5 ); next = placestr( ContactBuffs::buff, op1.getValue(), next, -8 ); next += 1; next = placestr( ContactBuffs::buff, op2.getValue(), next, -8 ); next = placestr( ContactBuffs::buff, ContactBuffs::buff2, next + 1, 90 ); dest = trimr( ContactBuffs::buff ); }
//========================================================================== CountryEntry *findCtryPrefix( const callsign &cs ) { CountryEntry * ctryMult; std::string testpart = "/"; // look for e.g. /RVI as a country suffix testpart += cs.suffix; // look for e.g. /RVI as a country suffix CountrySynonym *csyn = 0; if ( cs.suffix.length() ) csyn = MultLists::getMultLists() ->searchCountrySynonym( testpart ); if ( !csyn ) // look with number { /* // eg for <pe/f0ctt/mm> (g0gjv/p) [F6CTT/RVI/P] ?F6CTT/RVI? char prefix[BITLENGTH + 1]; // <pe> (g) [RVI] ???? country of location char prefix2[BITLENGTH + 1]; // <f> (g) [F] ?F?country of issue char number[NUMBITLENGTH + 1]; // <0> (0) [6] ?6?numeric part char body[BITLENGTH + 1]; // <ctt> (gjv) [CTT] ?CTT?main body char suffix[TRAILBITLENGTH + 1]; // <mm> (p) [P] ?RVI?trailer */ if ( cs.prefix != cs.prefix2 ) { // we have a leading / for a pre-pended prefix, so callsign itself is // not relevant csyn = MultLists::getMultLists() ->searchCountrySynonym( cs.prefix ); } if ( !csyn ) { // take the whole callsign, extra prefix, suffix, the lot and look for the // longest matching synonym. If the list is incomplete then this may // misidentify the country - e.g. if GW were missed out then this algorithm // would (wrongly?) allow a match on G. This might be a benefit for e.g. // PA or DL, as we don't need to put all the synonyms in, just the base // letter // There are really foul callsigns, such as // Glorioso Island: FR-G e.g. FR7GL // Callbook implies that FR#*/G (see below) is also valid // Short of entering ALL these, not sure what to do // How about a '#' in the synonym meaning any number? // Also need an "any letter" - what about '?', to match // DOS wild cards? As well as * to mean a sequence of letters // This coding cannot be fully expanded into the synonym list; maybe // some kind of synonym decision tree needs to be built // This is getting VERY nasty; maybe we just say to enter the actual call // as a synonym (but of what... we need a placeholder for the main country)! testpart = cs.fullCall.getValue(); trimr( testpart ); int clen = testpart.length(); int minlen; for ( minlen = 0; minlen < clen; minlen++ ) { // go past any leading digits if ( !isdigit( testpart[ minlen ] ) ) break; } for ( ; minlen < clen; minlen++ ) { // and then to end of leading alpha part if ( !isalpha( testpart[ minlen ] ) ) break; } while ( ( clen >= minlen ) && ( !csyn ) ) { // we need to stop when we get to the basic prefix... // otherwise RVI6ABC ends up matching R, which is UA testpart[ clen ] = 0; clen--; csyn = MultLists::getMultLists() ->searchCountrySynonym( testpart ); } if ( !csyn ) { csyn = MultLists::getMultLists() ->searchCountrySynonym( cs.prefix ); } } } ctryMult = ( csyn ) ? ( csyn->country ) : 0; return ctryMult; }
bool LoggerContestLog::importLOG( HANDLE hLogFile ) { THandleStream * hs = new THandleStream( ( int ) hLogFile ); TStringList *ls = new TStringList(); ls->LoadFromStream( hs ); TEMPBUFF( temp, 100 ); // Import from LOG format // Needs modification for "new" log format locValid = false; // save(); // read remainder of lines; write each line as we go long next_block = 1; bool started = false; DisplayContestContact *ct = 0; int lineNo = -1; while ( ++lineNo < ls->Count ) { // skip new format header information, until we can cope // properly with it std::string stemp = trimr( ls->Strings[ lineNo ].c_str() ); if ( stemp.length() == 0 || ( !started && !isdigit( ls->Strings[ lineNo ][ 1 ] ) ) ) { // GJV.LOG /* Contest Title : VHFNFD Band in MHz : 432 Section Entered : Multi Operator Name of Entrant/Club/Contest Group : Bracknell Amateur Radio Club Band in MHz : %band% Section Entered : %section% Callsign Used : %call% QRH Locator Sent : %locator% Location as sent(District or QTH) : %QTH% Brief Details of Transmitter Used : %Transmitter% Brief Details of Receiver Used : %Receiver% Power Output (Watts) : %power% Antenna Type : %Antenna% Antenna Height AGL(metres) : %AGL% QTH Height ASL(metres) : %ASL% Difficult ones: Name and Callsign of all Operators : G0GJV G4AUC G0FCT G0HVS Name, Callsign, Telephone Number, Address for Correspondence : : M. J. Goodey : G0GJV : 62, Rose Hill : Binfield : Berkshire : RG42 5LG Phone : 01344 428614 Email : [email protected] */ unsigned int spos = stemp.find( ":" ); if ( spos != std::string::npos ) { std::string text = trim( stemp.substr( spos + 1, stemp.size() ) ); if ( strupr( stemp ).find( "CONTEST TITLE" ) == 0 ) { name.setValue( text ); } else if ( strupr( stemp ).find( "BAND IN MHZ" ) == 0 ) { band.setValue( text ); } else if ( strupr( stemp ).find( "SECTION ENTERED" ) == 0 ) { entSect.setValue( text ); } else if ( strupr( stemp ).find( "NAME OF ENTRANT/CLUB/CONTEST GROUP" ) == 0 ) { entrant.setValue( text ); } else if ( strupr( stemp ).find( "CALLSIGN USED" ) == 0 ) { // we need to tail clip the callsign - or we end up with things like // M1DUD/QRP CLASS : SO / 50MHZ FIXED unsigned int spos = text.find( " " ); if ( spos != std::string::npos ) { text = trim( text.substr( 0, spos ) ); } mycall.fullCall.setValue( strupr( text ) ); mycall.valRes = CS_NOT_VALIDATED; mycall.validate(); } else if ( strupr( stemp ).find( "QRH LOCATOR SENT" ) == 0 || strupr( stemp ).find( "QTH LOCATOR SENT" ) == 0 ) { // yes, contestx DOES say QRH! myloc.loc.setValue( strupr( text ) ); validateLoc(); } else if ( strupr( stemp ).find( "POWER OUTPUT" ) == 0 ) { power.setValue( text ); } else if ( strupr( stemp ).find( "LOCATION AS SENT" ) == 0 ) { location.setValue( text ); } else if ( strupr( stemp ).find( "ANTENNA TYPE" ) == 0 ) { entAnt.setValue( text ); } else if ( strupr( stemp ).find( "ANTENNA HEIGHT" ) == 0 ) { entAGL.setValue( text ); } else if ( strupr( stemp ).find( "QTH HEIGHT" ) == 0 ) { entASL.setValue( text ); } else if ( strupr( stemp ).find( "BRIEF DETAILS OF TRANSMITTER USED" ) == 0 ) { entTx.setValue( text ); } else if ( strupr( stemp ).find( "BRIEF DETAILS OF RECEIVER USED" ) == 0 ) { entRx.setValue( text ); } } continue; } started = true; makeContact( false, ( BaseContact * ) ct ); ct->setLogSequence( 0 ); stemp += std::string( 200, ' ' ); // make sure there is plenty more... const char *lbuff = stemp.c_str(); // parse contact line in strcpysp( temp, &lbuff[ 0 ], 6 ); ct->time.setDate( temp, DTGLOG ); strcpysp( temp, &lbuff[ 7 ], 4 ); ct->time.setTime( temp, DTGLOG ); strcpysp( temp, &lbuff[ 21 ], 15 ); ct->cs = callsign( strupr( temp ) ); ct->cs.valRes = CS_NOT_VALIDATED; strcpysp( temp, &lbuff[ 37 ], 3 ); ct->reps.setValue( temp ); strcpysp( temp, &lbuff[ 41 ], 4 ); ct->serials.setValue( temp ); int maxct = atoi( ct->serials.getValue().c_str() ); if ( maxct > maxSerial ) maxSerial = maxct; strcpysp( temp, &lbuff[ 46 ], 3 ); ct->repr.setValue( temp ); strcpysp( temp, &lbuff[ 51 ], 4 ); ct->serialr.setValue( temp ); // here is the score field strcpysp( temp, &lbuff[ 59 ], 5 ); if ( atoi( temp ) == 0 ) ct->contactFlags.setValue( NON_SCORING ); strcpysp( temp, &lbuff[ 65 ], 6 ); ct->op1.setValue( temp ); strcpysp( temp, &lbuff[ 72 ], 6 ); ct->loc.loc.setValue( temp ); ct->loc.valRes = LOC_NOT_VALIDATED; //ct->comments = ""; TEMPBUFF( extra, EXTRALENGTH + 1 ); TEMPBUFF( comments, COMMENTLENGTH + 1 ); strcpysp( extra, &lbuff[ 81 ], 2 ); // 81 is district code if ( extra[ 0 ] && extra[ 1 ] && ( extra[ 0 ] != ' ' && extra[ 1 ] != ' ' ) ) { // we always attempt to import the district mult field strcpysp( comments, &lbuff[ 93 ], COMMENTLENGTH ); ct->comments.setValue( comments ); } else { strcpysp( extra, &lbuff[ 93 ], EXTRALENGTH ); } ct->extraText.setValue( extra ); // strcpysp(ct->power, power, 7); // ct->PowerWatts = PowerWatts; // save contact // we have to have logSequence set before we insert - or it will cause // duplicates next_block++ ; ct->setLogSequence( next_block << 16 ); ctList.insert( ct ); } delete ls; delete hs; return true; }
/* * Receive HTTP request/response from the given socket. Fill in pre-allocated * rr_data_t structure. * Returns: 1 if OK, 0 in case of socket EOF or other error */ int headers_recv(int fd, rr_data_t data) { char *tok, *s3 = 0; int len; char *buf; char *ccode = NULL; char *host = NULL; int i, bsize; bsize = BUFSIZE; buf = new(bsize); i = so_recvln(fd, &buf, &bsize); if (i <= 0) goto bailout; if (debug) printf("HEAD: %s", buf); /* * Are we reading HTTP request (from client) or response (from server)? */ trimr(buf); len = strlen(buf); tok = strtok_r(buf, " ", &s3); if (!strncasecmp(buf, "HTTP/", 5) && tok) { data->req = 0; data->http = NULL; data->msg = NULL; data->http = substr(tok, 7, 1); tok = strtok_r(NULL, " ", &s3); if (tok) { ccode = strdup(tok); tok += strlen(ccode); while (tok < buf+len && *tok++ == ' '); if (strlen(tok)) data->msg = strdup(tok); } if (!data->msg) data->msg = strdup(""); if (!ccode || strlen(ccode) != 3 || (data->code = atoi(ccode)) == 0 || !data->http) { i = -1; goto bailout; } } else if (tok) { data->req = 1; data->method = NULL; data->url = NULL; data->http = NULL; data->method = strdup(tok); tok = strtok_r(NULL, " ", &s3); if (tok) data->url = strdup(tok); tok = strtok_r(NULL, " ", &s3); if (tok) data->http = substr(tok, 7, 1); if (!data->url || !data->http) { i = -1; goto bailout; } tok = strstr(data->url, "://"); if (tok) { s3 = strchr(tok+3, '/'); host = substr(tok+3, 0, s3 ? s3-tok-3 : 0); } } else { if (debug) printf("headers_recv: Unknown header (%s).\n", buf); i = -1; goto bailout; } /* * Read in all headers, do not touch any possible HTTP body */ do { i = so_recvln(fd, &buf, &bsize); trimr(buf); if (i > 0 && head_ok(buf)) { data->headers = hlist_add(data->headers, head_name(buf), head_value(buf), 0, 0); } } while (strlen(buf) != 0 && i > 0); if (host && !hlist_in(data->headers, "Host")) data->headers = hlist_add(data->headers, "Host", host, 1, 1); bailout: if (ccode) free(ccode); if (host) free(host); free(buf); if (i <= 0) { if (debug) printf("headers_recv: fd %d warning %d (connection closed)\n", fd, i); return 0; } return 1; }
int repl() { global_env = null_import_environment(); environment_t *env = global_env; print_banner(env); #if HAVE_LIBREADLINE init_readline(); #endif for(;;) { static char *input = reinterpret_cast<char*>(1); /* * input == 1 is the ugliest hack ever to * disoplay the imported_defaults message below, * and also because of ANOTHER hack, the home-brewed * exception system using longjumps. I think I need to * rewrite... :) */ if ( input != reinterpret_cast<char*>(1) ) { if ( (input = readline("#; mickey> ")) == NULL ) break; // end of input stream if ( *trimr(input) == '\0' ) continue; // empty command #ifdef HAVE_LIBREADLINE add_history(input); #endif if ( exception_raised() ) { backtrace(); backtrace_clear(); continue; } } else input = strdup(""); TRY { /* * Must wrap import_defaults in try-catch */ { static bool imported_defaults = false; if ( !imported_defaults ) { printf("\n"); printf(" To quit, hit CTRL+D or type (exit). Use (help) for an introduction.\n"); printf(" Distributed under the LGPL 2.1; see LICENSE\n"); printf("\n"); printf(" WARNING: There's no garbage collector in Mickey yet!\n"); printf("|#\n\n"); import_defaults(env); imported_defaults = true; // import (help) and (top-level) etc. if ( !global_opts.empty_repl_env ) import(env, exports_repl, "(scheme repl)"); } } program_t *p = parse(input, env); if ( p->parens < 0 ) raise(runtime_exception(format( "parser: unbalanced parenthesis -> %ld", p->parens))); // Read until we have balanced parenthesis std::string s(input); while ( p->parens != 0 ) { if ( (input = readline("")) == NULL ) break; if ( *trimr(input) == '\0' ) continue; s += " "; s += input; delete p; #ifdef HAVE_LIBREADLINE free(input); input = NULL; #endif p = parse(s.c_str(), env); } #ifdef HAVE_LIBREADLINE if ( input ) free(input); #endif for ( cons_t *i = p->root; !nullp(i); i = cdr(i) ) { cons_t *result = eval(car(i), p->globals); if ( circularp(result) ) { fflush(stdout); fprintf(stderr, "Warning: List is circular\n"); cons_t *l = list(), *end = l; for ( int n=0; n < MAX_CIRCULAR_DISPLAY_ITEMS; ++n ) { end->car = car(result); end->cdr = cons(nil()); end = cdr(end); result = cdr(result); } end->car = symbol("...etc"); end->cdr = cons(nil()); printf("%s\n", sprint(l).c_str()); } else { std::string s = sprint(result); if ( !s.empty() ) printf("%s\n", s.c_str()); } } delete p; } CATCH (const exception_t& e) { if ( *e.what() != '\0' ) fprintf(stderr, "%s\n", e.what()); backtrace(); backtrace_clear(); } } printf("\n"); return 0; }
void trim(char ** buffer) { triml(buffer); trimr(buffer); }