BaseFormat& BaseFormat::operator<<(wchar_t Value) { return Put(&Value,1); }
/* * Finalize an OpenID authentication */ void cmd_oidf(char *argbuf) { long len; char buf[2048]; char thiskey[1024]; char thisdata[1024]; HashList *keys = NULL; const char *Key; void *Value; ctdl_openid *oiddata = (ctdl_openid *) CC->openid_data; if (CtdlGetConfigInt("c_disable_newu")) { cprintf("%d this system does not support openid.\n", ERROR + CMD_NOT_SUPPORTED); return; } if (oiddata == NULL) { cprintf("%d run OIDS first.\n", ERROR + INTERNAL_ERROR); return; } if (StrLength(oiddata->op_url) == 0){ cprintf("%d No OpenID Endpoint URL has been obtained.\n", ERROR + ILLEGAL_VALUE); return; } keys = NewHash(1, NULL); if (!keys) { cprintf("%d NewHash() failed\n", ERROR + INTERNAL_ERROR); return; } cprintf("%d Transmit OpenID data now\n", START_CHAT_MODE); while (client_getln(buf, sizeof buf), strcmp(buf, "000")) { len = extract_token(thiskey, buf, 0, '|', sizeof thiskey); if (len < 0) { len = sizeof(thiskey) - 1; } extract_token(thisdata, buf, 1, '|', sizeof thisdata); Put(keys, thiskey, len, strdup(thisdata), NULL); } /* Check to see if this is a correct response. * Start with verified=1 but then set it to 0 if anything looks wrong. */ oiddata->verified = 1; char *openid_ns = NULL; if ( (!GetHash(keys, "ns", 2, (void *) &openid_ns)) || (strcasecmp(openid_ns, "http://specs.openid.net/auth/2.0")) ) { syslog(LOG_DEBUG, "This is not an an OpenID assertion"); oiddata->verified = 0; } char *openid_mode = NULL; if ( (!GetHash(keys, "mode", 4, (void *) &openid_mode)) || (strcasecmp(openid_mode, "id_res")) ) { oiddata->verified = 0; } char *openid_claimed_id = NULL; if (GetHash(keys, "claimed_id", 10, (void *) &openid_claimed_id)) { FreeStrBuf(&oiddata->claimed_id); oiddata->claimed_id = NewStrBufPlain(openid_claimed_id, -1); syslog(LOG_DEBUG, "Provider is asserting the Claimed ID '%s'", ChrPtr(oiddata->claimed_id)); } /* Validate the assertion against the server */ syslog(LOG_DEBUG, "Validating..."); CURL *curl; CURLcode res; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; char errmsg[1024] = ""; StrBuf *ReplyBuf = NewStrBuf(); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "openid.mode", CURLFORM_COPYCONTENTS, "check_authentication", CURLFORM_END ); HashPos *HashPos = GetNewHashPos(keys, 0); while (GetNextHashPos(keys, HashPos, &len, &Key, &Value) != 0) { if (strcasecmp(Key, "mode")) { char k_o_keyname[1024]; snprintf(k_o_keyname, sizeof k_o_keyname, "openid.%s", (const char *)Key); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, k_o_keyname, CURLFORM_COPYCONTENTS, (char *)Value, CURLFORM_END ); } } DeleteHashPos(&HashPos); curl = ctdl_openid_curl_easy_init(errmsg); curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(oiddata->op_url)); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ReplyBuf); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); if (res) { syslog(LOG_DEBUG, "cmd_oidf() libcurl error %d: %s", res, errmsg); oiddata->verified = 0; } curl_easy_cleanup(curl); curl_formfree(formpost); /* syslog(LOG_DEBUG, "Validation reply: \n%s", ChrPtr(ReplyBuf)); */ if (cbmstrcasestr(ChrPtr(ReplyBuf), "is_valid:true") == NULL) { oiddata->verified = 0; } FreeStrBuf(&ReplyBuf); syslog(LOG_DEBUG, "OpenID authentication %s", (oiddata->verified ? "succeeded" : "failed") ); /* Respond to the client */ if (oiddata->verified) { /* If we were already logged in, attach the OpenID to the user's account */ if (CC->logged_in) { if (attach_openid(&CC->user, oiddata->claimed_id) == 0) { cprintf("attach\n"); syslog(LOG_DEBUG, "OpenID attach succeeded"); } else { cprintf("fail\n"); syslog(LOG_DEBUG, "OpenID attach failed"); } } /* Otherwise, a user is attempting to log in using the verified OpenID */ else { /* * Existing user who has claimed this OpenID? * * Note: if you think that sending the password back over the wire is insecure, * check your assumptions. If someone has successfully asserted an OpenID that * is associated with the account, they already have password equivalency and can * login, so they could just as easily change the password, etc. */ if (login_via_openid(oiddata->claimed_id) == 0) { cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password); logged_in_response(); syslog(LOG_DEBUG, "Logged in using previously claimed OpenID"); } /* * If this system does not allow self-service new user registration, the * remaining modes do not apply, so fail here and now. */ else if (CtdlGetConfigInt("c_disable_newu")) { cprintf("fail\n"); syslog(LOG_DEBUG, "Creating user failed due to local policy"); } /* * New user whose OpenID is verified and Attribute Exchange gave us a name? */ else if (openid_create_user_via_ax(oiddata->claimed_id, keys) == 0) { cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password); logged_in_response(); syslog(LOG_DEBUG, "Successfully auto-created new user"); } /* * OpenID is verified, but the desired username either was not specified or * conflicts with an existing user. Manual account creation is required. */ else { char *desired_name = NULL; cprintf("verify_only\n"); cprintf("%s\n", ChrPtr(oiddata->claimed_id)); if (GetHash(keys, "sreg.nickname", 13, (void *) &desired_name)) { cprintf("%s\n", desired_name); } else { cprintf("\n"); } syslog(LOG_DEBUG, "The desired display name is already taken."); } } } else { cprintf("fail\n"); } cprintf("000\n"); if (oiddata->sreg_keys != NULL) { DeleteHash(&oiddata->sreg_keys); oiddata->sreg_keys = NULL; } oiddata->sreg_keys = keys; }
void enter_emote(User *usr) { char name[MAX_NAME], line[MAX_LINE], *p, *endp; XMsg *x; int sent; if ((x = new_XMsg()) == NULL) { Put(usr, "<red>Due to an error, you can not send messages now\n"); return; } if (edit_recipients(usr, multi_x_access) == -1) { destroy_XMsg(x); return; } if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } check_recipients(usr); if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } /* enter the message text */ Print(usr, "<cyan>* <white>%s <yellow>", usr->name); if (edit_line(usr, line, MAX_LINE) == -1 || !line[0]) { Put(usr, "<red>Message not sent\n"); destroy_XMsg(x); return; } ctrim_line(line); if (!line[0]) { Put(usr, "<red>Message not sent\n"); destroy_XMsg(x); return; } if (add_XMsg_line(x, line) == -1) { Put(usr, "<red>Due to an error, you can not send messages now\n"); destroy_XMsg(x); return; } check_recipients(usr); if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } set_XMsg(x, XMSG_EMOTE, usr->name, usr->recipients.str, time(NULL)); sent = 0; p = usr->recipients.str; while((endp = cstrchr(p, ',')) != NULL) { *endp = 0; cstrcpy(name, p, MAX_NAME); *endp = ','; endp++; p = endp; sent += send_xmsg(usr, x, name); } cstrcpy(name, p, MAX_NAME); sent += send_xmsg(usr, x, name); if (sent) send_xmsg_bcc(usr, x); /* remember message as sent in 'this' user */ else destroy_XMsg(x); }
bool cRemote::Put(uint64_t Code, bool Repeat, bool Release) { char buffer[32]; snprintf(buffer, sizeof(buffer), "%016llX", Code); return Put(buffer, Repeat, Release); }
/* select the next helper to ask a question if we previously called for help, go back to the same helper (if available) helpers are selected in an LRU manner silent can be GH_SILENT, which means to be silent */ User *get_helper(User *usr, int silent) { User *u; PList *pl; char instead[24] = ""; if (usr == NULL || !PARAM_HAVE_QUESTIONS) return NULL; if (usr->question_asked != NULL) { for(pl = (PList *)helpers.tail; pl != NULL; pl = pl->next) { u = (User *)pl->p; if (!strcmp(u->name, usr->name)) continue; if (!strcmp(usr->question_asked, u->name)) { (void)remove_PQueue(&helpers, pl); if (!(u->flags & USR_HELPING_HAND) || u->total_time / SECS_IN_DAY < PARAM_HELPER_AGE) { u->flags &= ~USR_HELPING_HAND; destroy_PList(pl); break; } (void)add_PQueue(&helpers, pl); if (!silent) Print(usr, "<green>The question goes to <yellow>%s\n", usr->question_asked); return u; } } Print(usr, "<yellow>%s<red> is no longer available to help you\n", usr->question_asked); Free(usr->question_asked); usr->question_asked = NULL; strcpy(instead, " <green>instead"); } while(count_Queue(&helpers) > 0) { if ((pl = pop_PQueue(&helpers)) == NULL) { Put(usr, "<red>Sorry, but currently there is no one available to help you\n"); return NULL; } u = (User *)pl->p; if (!u->name[0] || !(u->flags & USR_HELPING_HAND) || u->total_time / SECS_IN_DAY < PARAM_HELPER_AGE) { u->flags &= ~USR_HELPING_HAND; destroy_PList(pl); continue; } (void)add_PQueue(&helpers, pl); if (!strcmp(u->name, usr->name)) { if (count_Queue(&helpers) > 1) continue; Put(usr, "<red>Sorry, but currently there is no one available to help you\n"); return NULL; } Free(usr->question_asked); usr->question_asked = cstrdup(u->name); if (!silent || instead[0]) Print(usr, "<green>The question goes to <yellow>%s%s\n", usr->question_asked, instead); return u; } Put(usr, "<red>Sorry, but currently there is no one available to help you\n"); return NULL; }
int main() { // Create the main SFML window sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Layout Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; // Create our main SFGUI window auto window = sfg::Window::Create(); window->SetTitle( "Resize me!" ); // Create a box with 20 pixels spacing. auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 20.f ); // Create some buttons. auto button_aligned = sfg::Button::Create( "Aligned 0.8f right and bottom" ); auto button_fixed = sfg::Button::Create( "Fixed at (200, 50)" ); // Create a fixed. auto fixed = sfg::Fixed::Create(); // Add button_fixed to the fixed at (200, 50). fixed->Put( button_fixed, sf::Vector2f( 200.f, 50.f ) ); // Add our fixed to the box and set not to expand. box->Pack( fixed, false, true ); // Create a separator. auto separator = sfg::Separator::Create( sfg::Separator::Orientation::HORIZONTAL ); // Add separator to box and set not to expand. box->Pack( separator, false, true ); // Create an alignment. auto alignment = sfg::Alignment::Create(); // Because we want to align our button horizontally, we need // to place our alignment in a horizontal box set to expand and fill. auto alignment_box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL ); alignment_box->Pack( alignment, true, true ); // Add button_aligned to the alignment. alignment->Add( button_aligned ); // Set scaling parameters. // Scaling sets how much of the total space in the alignment // the child gets to fill up. 1.0f for x and y would mean the // child gets to use the whole space. Setting it to 0.0f for // x and y makes the child get as little space as possible. alignment->SetScale( sf::Vector2f( .0f, .0f ) ); // Set alignment parameters. // Alignment aligns the child widget within the alignment's area. // 0.0f for x aligns to the left, 1.0f for x aligns to the right. // 0.0f for y aligns to the top, 1.0f for y aligns to the bottom. alignment->SetAlignment( sf::Vector2f( .8f, .8f ) ); // Create our frame. auto frame = sfg::Frame::Create( "Frame Title" ); // We can align the frame title just like an alignment. frame->SetAlignment( sf::Vector2f( .8f, .5f ) ); // Add our alignment box into the frame. frame->Add( alignment_box ); // Add our frame to the box. box->Pack( frame, true, true ); // Add the box to the window. window->Add( box ); // Start the game loop while ( app_window.isOpen() ) { // Process events sf::Event event; while ( app_window.pollEvent( event ) ) { // Handle events window->HandleEvent( event ); // Close window : exit if ( event.type == sf::Event::Closed ) { app_window.close(); } } // Update the GUI, note that you shouldn't normally // pass 0 seconds to the update method. window->Update( 0.f ); // Clear screen app_window.clear(); // Draw the GUI sfgui.Display( app_window ); // Update the window app_window.display(); } return EXIT_SUCCESS; }
const long * KTextPipe::Percent(TCHAR tag, const long * data, const DicItem * dic) { static double dummy = sin(0.0); // just to link-in floating point support int len = 0; switch ( tag ) { case '_': len = 4; break; // skip 4 bytes case '0': WriteDec(data[0]); break; // decimal signed long case '1': WriteDec(data[1]); break; // decimal signed long case '2': WriteDec(data[2]); break; // decimal signed long case '3': WriteDec(data[3]); break; // decimal signed long case '4': WriteDec(data[4]); break; // decimal signed long case '5': WriteDec(data[5]); break; // decimal signed long case '6': WriteDec(data[6]); break; // decimal signed long case '7': WriteDec(data[7]); break; // decimal signed long case '8': WriteDec(data[8]); break; // decimal signed long case '9': WriteDec(data[9]); break; // decimal signed long case 'b': WriteDec((long)(* ((unsigned char *) data))); // signed char len = 1; break; case 'c': { char ch = * data & 0xFF; if ( (ch>=' ') && (ch<=0x7F) ) Put(ch); else Put('.'); len = 1; } break; case 'd': WriteDec( data[0]); len=4; break; // decimal signed long case 'u': WriteDec((unsigned long) data[0]); len=4; break; // decimal unsigned long case 'x': WriteHex( data[0]); len=4; break; // hex unsigned long case 'D': WriteDec((long) (* ((short *) data))); len=2; break; // signed short case 'U': WriteDec((unsigned long)(* ((unsigned short *) data))); len=2; break; // signed short case 'X': WriteHex( * ((unsigned short *) data)); len=2; break; // unsigned short case 'S': WriteString(data, -1, true); break; // wide string case 's': WriteString(data, -1, false); break; // ascii string case 'f': { TCHAR t[32]; float f = * (float *) data; _stprintf(t, _T("%8.5f"), f); Write(t); } // float len = 4; break; case 'n': m_nCount++; // sequence count: 1 1 2 2 ... WriteDec((long)(m_nCount/2)); break; case 'm': m_mCount++; // sequence count: 1 1 2 2 ... WriteDec((long)(m_mCount/2)); break; case 'L': Write(data[0], dic); len = 4; // dic break; default : assert(false); } return (const long *) ( (const char *) data + len); }
nString & nString::operator+=(const nString & right){ for(int i = 0; right.data[i] != '\0'; i++) Put(right.data[i]); return *this; }
nString & nString::operator+=(const char * zstr){ for(int i = 0; zstr[i] != '\0'; i++) Put(zstr[i]); return *this; }
void state_help_menu(User *usr, char c) { char filename[MAX_PATHLEN]; if (usr == NULL) return; Enter(state_help_menu); switch(c) { case INIT_PROMPT: break; case INIT_STATE: usr->runtime_flags |= RTF_BUSY; buffer_text(usr); Put(usr, "<magenta>\n" "<hotkey>Introduction Editing recipient <hotkey>lists\n" "e<hotkey>Xpress messages Editing with <hotkey>colors\n" "<hotkey>Friends and enemies <hotkey>Navigating the --More-- prompt\n" ); Put(usr, "Reading and posting <hotkey>messages\n" "The <hotkey>room system\n" "Customizing your <hotkey>profile <hotkey>Other commands\n" ); read_menu(usr); Return; case ' ': case KEY_RETURN: case KEY_CTRL('C'): case KEY_CTRL('D'): case KEY_BS: Put(usr, "\n"); RET(usr); Return; case KEY_CTRL('L'): Put(usr, "\n"); CURRENT_STATE(usr); Return; case '`': CALL(usr, STATE_BOSS); Return; case 'i': case 'I': Put(usr, "Introduction\n"); HELP_TEXT("intro"); case 'x': case 'X': Put(usr, "eXpress Messages\n"); HELP_TEXT("xmsg"); case 'f': case 'F': Put(usr, "Friends and Enemies\n"); HELP_TEXT("friends"); case 'm': case 'M': Put(usr, "Reading and posting messages\n"); HELP_TEXT("msgs"); case 'r': case 'R': Put(usr, "The room system\n"); HELP_TEXT("rooms"); case 'p': case 'P': Put(usr, "Customizing your profile\n"); HELP_TEXT("profile"); case 'l': case 'L': Put(usr, "Editing recipient lists\n"); HELP_TEXT("recipients"); case 'c': case 'C': Put(usr, "Editing with colors\n"); HELP_TEXT("colors"); case 'n': case 'N': Put(usr, "Navigating the --More-- prompt\n"); HELP_TEXT("more"); case 'o': case 'O': Put(usr, "Other commands\n"); HELP_TEXT("other"); } Print(usr, "<yellow>\n[Help] %c <white>", (usr->runtime_flags & RTF_SYSOP) ? '#' : '>'); Return; }
/************************************************************************ Function : ProcessLine Parameters: Line a pointer to the current line of characters to process Returns : nothing Analyze line to determine if it is an error message. If so, output relevant information to the message window. To be considered an error message, a line must NOT : . be blank . start with "Microsoft" or "Copyright" (these lines form the Resource Compiler header) Any lines passing the above conditions are considered error messages. If the line contains a line number, it is of the form: source-file(LINE #) : message text OR source-file (LINE #) : message text that is, it contains a '(' followed by a ':'. The line number is sent to the Message Window followed by the message text. If the line does not contain a line number, it is sent verbatim to the Message Window. ************************************************************************/ void ProcessLine(char *Line) { static int HavePutFile = FALSE; int HasLineNumber; char Type; unsigned i; char *s, *LeftParen, *Colon; /* if blank line, return */ while( *Line && ( (*Line == '\r') || (*Line == '\n') ) ) Line++; if( *Line == '\0' ) return; /* if line starts with "Microsoft" or "Copyright", it's not an error line */ if( strncmp( Line, "Microsoft", 9 ) == 0 || strncmp( Line, "Copyright", 9 ) == 0 ) return; HasLineNumber = FALSE; LeftParen = strchr( Line, '(' ); /* if '(' in the line */ if( LeftParen != NULL ) /* Line may contain line number */ HasLineNumber = TRUE; if( HasLineNumber ) { Colon = strchr(LeftParen, ':' ); /* if no ':' following the '(' */ if( Colon == NULL ) /* Line doesn't contain line number */ HasLineNumber = FALSE; } if( HasLineNumber ) { s = LeftParen-1; /* position s after last char */ while( *s == ' ' ) /* in filename */ s--; s++; *s = 0; /* and null-terminate */ if( strcmp(Line,CurFile) != 0 ) /* if new filename */ { Type = MsgNewFile; /* indicate by sending type out to message window */ strcpy(CurFile,Line); Put(&Type,1); Put(CurFile,strlen(CurFile)+1); /* along with the new name */ HavePutFile = TRUE; } s = strchr(Line,')'); /* find the right paren */ *s = 0; /* and null-terminate line# */ i = atoi(LeftParen+1); /* line# starts after ( */ /* convert line# to integer */ Type = MsgNewLine; /* set type to new line */ Put(&Type,1); /* indicate need for new line */ Put((char *)&i,2); /* put the number out */ i=1; /* set column in message box */ Put((char *)&i,2); /* tab over to put message */ s = Colon+1; /* position s at first */ while( *s == ' ' ) /* non-blank char after : */ s++; /* Rest of line is message */ Put( s,strlen(s)+1); /* output the message */ } else { /* no line number */ if( !HavePutFile ) { /* IDE expects the first message to be preceded by a filename. Since we don't have one, fake it by sending a NULL file before the message. */ Type = MsgNewFile; /* indicate by sending type out to message window */ *CurFile = '\0'; Put(&Type,1); Put(CurFile,1); /* along with null filename */ HavePutFile = TRUE; } Type = MsgNewLine; /* Fake line # etc. */ i = 1; Put(&Type,1); Put((char *)&i,2); Put((char *)&i,2); Put(Line,strlen(Line)+1); } }
void AutoSeededRandomPool::Reseed(bool blocking, unsigned int seedSize) { SecByteBlock seed(seedSize); OS_GenerateRandomBlock(blocking, seed, seedSize); Put(seed, seedSize); }
BaseFormat& BaseFormat::operator<<(const string& String) { return Put(String,String.GetLength()); }
BaseFormat& BaseFormat::operator<<(LPCWSTR Data) { Data = NullToEmpty(Data); return Put(Data, StrLength(Data)); }
int AbstractDeltaRowCompressor::CompressRaw(const uchar* row, bool updateSeedRow, bool updateDeltaRow) { int index = DiffersIndex(row, 0); if (index == -1) { // no differences return 0; } fUpdateDeltaRow = updateDeltaRow; fDeltaRowIndex = 0; int seedRowIndex = 0; do { int length = DiffersLength(row, index); // delta starts at index and contains length bytes do { // control byte limits data bytes to 8 bytes int deltaBytes = length; if (length > 8) { deltaBytes = 8; } // calculate offset int totalOffset = index - seedRowIndex; bool needsOffsetBytes = totalOffset > 30; int offset = totalOffset; // control byte limits offset value to 31 if (needsOffsetBytes) { offset = 31; } // write control byte (delta bytes bits 5-7; offset bits 0-4) Put(((deltaBytes-1) << 5) | offset); if (needsOffsetBytes) { // write additional offset bytes after control byte // the last offset byte must be less than 255 totalOffset -= offset; while (totalOffset >= 255) { Put(255); totalOffset -= 255; } Put(totalOffset); } // write data bytes for (int i = 0; i < deltaBytes; i ++) { // copy row to seed row and delta row uchar byte = row[index]; if (updateSeedRow) { ASSERT (index < fSize); fSeedRow[index] = byte; } Put(byte); index ++; } seedRowIndex = index; length -= deltaBytes; } while (length > 0); index = DiffersIndex(row, index); } while (index != -1); return fDeltaRowIndex; }
nString & nString::operator+=(const char c){ Put(c); return *this; }
void cmd_gvdn(char *argbuf) { const ConfType *pCfg; char *confptr; long min = atol(argbuf); const char *Pos = NULL; const char *PPos = NULL; const char *HKey; long HKLen; StrBuf *Line; StrBuf *Config; StrBuf *Cfg; StrBuf *CfgToken; HashList *List; HashPos *It; void *vptr; List = NewHash(1, NULL); Cfg = NewStrBufPlain(config.c_fqdn, -1); Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; confptr = CtdlGetSysConfig(INTERNETCFG); Config = NewStrBufPlain(confptr, -1); free(confptr); Line = NewStrBufPlain(NULL, StrLength(Config)); CfgToken = NewStrBufPlain(NULL, StrLength(Config)); while (StrBufSipLine(Line, Config, &Pos)) { if (Cfg == NULL) Cfg = NewStrBufPlain(NULL, StrLength(Line)); PPos = NULL; StrBufExtract_NextToken(Cfg, Line, &PPos, '|'); StrBufExtract_NextToken(CfgToken, Line, &PPos, '|'); if (GetHash(CfgNameHash, SKEY(CfgToken), &vptr) && (vptr != NULL)) { pCfg = (ConfType *) vptr; if (pCfg->Type <= min) { Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; } } } cprintf("%d Valid Domains\n", LISTING_FOLLOWS); It = GetNewHashPos(List, 1); while (GetNextHashPos(List, It, &HKLen, &HKey, &vptr)) { cputbuf(vptr); cprintf("\n"); } cprintf("000\n"); DeleteHashPos(&It); DeleteHash(&List); FreeStrBuf(&Cfg); FreeStrBuf(&Line); FreeStrBuf(&CfgToken); FreeStrBuf(&Config); }
inline TX push_back(TX const & obj) { Put(obj); }
void KTextPipe::WriteArray(const void * Array, long count, long elmsize, bool decimal) { if ( ! m_bOpened ) return; assert(Array); const char * bArray = (const char *) Array; const short * sArray = (const short *) Array; const long * lArray = (const long *) Array; const RECT * rArray = (const RECT *) Array; Put('{'); Put(' '); for (long i=0; i<count; i++) { if ( i ) { Put(','); if ( m_linelen > 78 ) Newline(); else Put(' '); } switch ( elmsize ) { case 1: if (decimal) WriteDec((long) bArray[i]); else WriteHex(bArray[i] & 0xFF); break; case 2: if (decimal) WriteDec((long) sArray[i]); else WriteHex(sArray[i] & 0xFFFF); break; case 4: if (decimal) WriteDec(lArray[i]); else WriteHex(lArray[i]); break; case sizeof(RECT): Write("{ "); WriteDec(rArray[i].left); Put(','); WriteDec(rArray[i].top); Put(','); WriteDec(rArray[i].right); Put(','); WriteDec(rArray[i].bottom); Write(" }"); break; default: assert(FALSE); } } Put(' '); Put('}'); }
void cLircRemote::Action(void) { cTimeMs FirstTime; cTimeMs LastTime; cTimeMs ThisTime; char buf[LIRC_BUFFER_SIZE]; char LastKeyName[LIRC_KEY_BUF] = ""; bool pressed = false; bool repeat = false; int timeout = -1; while (Running()) { bool ready = f >= 0 && cFile::FileReady(f, timeout); int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1; if (f < 0 || ready && ret <= 0) { esyslog("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000); if (f >= 0) close(f); f = -1; while (Running() && f < 0) { cCondWait::SleepMs(RECONNECTDELAY); if (Connect()) { isyslog("reconnected to lircd"); break; } } } if (ready && ret > 0) { buf[ret - 1] = 0; int count; char KeyName[LIRC_KEY_BUF]; if (sscanf(buf, "%*x %x %29s", &count, KeyName) != 2) { // '29' in '%29s' is LIRC_KEY_BUF-1! esyslog("ERROR: unparseable lirc command: %s", buf); continue; } int Delta = ThisTime.Elapsed(); // the time between two subsequent LIRC events ThisTime.Set(); if (count == 0) { if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < (uint)Setup.RcRepeatDelay) continue; // skip keys coming in too fast if (repeat) Put(LastKeyName, false, true); strcpy(LastKeyName, KeyName); pressed = true; repeat = false; FirstTime.Set(); timeout = -1; } else if (FirstTime.Elapsed() < (uint)Setup.RcRepeatDelay) continue; // repeat function kicks in after a short delay else if (LastTime.Elapsed() < (uint)Setup.RcRepeatDelta) continue; // skip same keys coming in too fast else { pressed = true; repeat = true; timeout = Delta * 10 / 9; } if (pressed) { LastTime.Set(); Put(KeyName, repeat); } } else if (pressed && repeat) { // the last one was a repeat, so let's generate a release Put(LastKeyName, false, true); pressed = false; repeat = false; *LastKeyName = 0; timeout = -1; } else { pressed = false; repeat = false; *LastKeyName = 0; timeout = -1; } } }
int main_client(int argc, char *const *argv) { int ch; struct ntp_peer *np; struct ntp_peerset *npl; struct todolist *tdl; struct combine_delta *cd; int fd; int npeer = 0; setbuf(stdout, NULL); setbuf(stderr, NULL); tdl = TODO_NewList(); Time_Unix(tdl); PLL_Init(); npl = NTP_PeerSet_New(NULL); Param_Register(client_param_table); NF_Init(); while ((ch = getopt(argc, argv, "p:t:")) != -1) { switch(ch) { case 'p': Param_Tweak(NULL, optarg); break; case 't': ArgTracefile(optarg); break; default: Fail(NULL, 0, "Usage %s [-p param] [-t tracefile] servers...", argv[0]); break; } } argc -= optind; argv += optind; for (ch = 0; ch < argc; ch++) npeer += NTP_PeerSet_Add(NULL, npl, argv[ch]); if (npeer == 0) Fail(NULL, 0, "No NTP peers found"); Put(NULL, OCX_TRACE, "# NTIMED Format client 1.0\n"); Put(NULL, OCX_TRACE, "# Found %d peers\n", npeer); Param_Report(NULL, OCX_TRACE); #ifndef NOIPV6 /* Attempt IPv6, fall back to IPv4 */ fd = UdpTimedSocket(NULL, AF_INET6); if (fd < 0) fd = UdpTimedSocket(NULL, AF_INET); #else fd = UdpTimedSocket(NULL, AF_INET); #endif if (fd < 0) Fail(NULL, errno, "Could not open UDP socket"); cd = CD_New(); NTP_PeerSet_Foreach(np, npl) { NF_New(np); np->combiner = CD_AddSource(cd, np->hostname, np->ip); }
/* * Scan a room's netconfig to determine whether it requires POP3 aggregation */ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *OneRNCFG) { const RoomNetCfgLine *pLine; void *vptr; pthread_mutex_lock(&POP3QueueMutex); if (GetHash(POP3QueueRooms, LKEY(qrbuf->QRnumber), &vptr)) { pthread_mutex_unlock(&POP3QueueMutex); EVP3CQ_syslog(LOG_DEBUG, "pop3client: [%ld] %s already in progress.", qrbuf->QRnumber, qrbuf->QRname); return; } pthread_mutex_unlock(&POP3QueueMutex); if (server_shutting_down) return; pLine = OneRNCFG->NetConfigs[pop3client]; while (pLine != NULL) { pop3aggr *cptr; cptr = (pop3aggr *) malloc(sizeof(pop3aggr)); memset(cptr, 0, sizeof(pop3aggr)); ///TODO do we need this? cptr->roomlist_parts=1; cptr->RoomName = NewStrBufPlain(qrbuf->QRname, -1); cptr->pop3user = NewStrBufDup(pLine->Value[1]); cptr->pop3pass = NewStrBufDup(pLine->Value[2]); cptr->Url = NewStrBuf(); cptr->Host = NewStrBufDup(pLine->Value[0]); cptr->keep = atol(ChrPtr(pLine->Value[3])); cptr->interval = atol(ChrPtr(pLine->Value[4])); StrBufAppendBufPlain(cptr->Url, HKEY("pop3://"), 0); StrBufUrlescUPAppend(cptr->Url, cptr->pop3user, NULL); StrBufAppendBufPlain(cptr->Url, HKEY(":"), 0); StrBufUrlescUPAppend(cptr->Url, cptr->pop3pass, NULL); StrBufAppendBufPlain(cptr->Url, HKEY("@"), 0); StrBufAppendBuf(cptr->Url, cptr->Host, 0); StrBufAppendBufPlain(cptr->Url, HKEY("/"), 0); StrBufUrlescAppend(cptr->Url, cptr->RoomName, NULL); ParseURL(&cptr->IO.ConnectMe, cptr->Url, 110); #if 0 /* todo: we need to reunite the url to be shure. */ pthread_mutex_lock(&POP3ueueMutex); GetHash(POP3FetchUrls, SKEY(ptr->Url), &vptr); use_this_cptr = (pop3aggr *)vptr; if (use_this_rncptr != NULL) { /* mustn't attach to an active session */ if (use_this_cptr->RefCount > 0) { DeletePOP3Cfg(cptr); /// Count->count--; } else { long *QRnumber; StrBufAppendBufPlain( use_this_cptr->rooms, qrbuf->QRname, -1, 0); if (use_this_cptr->roomlist_parts == 1) { use_this_cptr->OtherQRnumbers = NewHash(1, lFlathash); } QRnumber = (long*)malloc(sizeof(long)); *QRnumber = qrbuf->QRnumber; Put(use_this_cptr->OtherQRnumbers, LKEY(qrbuf->QRnumber), QRnumber, NULL); use_this_cptr->roomlist_parts++; } pthread_mutex_unlock(&POP3QueueMutex); continue; } pthread_mutex_unlock(&RSSQueueMutex); #endif cptr->n = Pop3ClientID++; pthread_mutex_lock(&POP3QueueMutex); Put(POP3FetchUrls, SKEY(cptr->Url), cptr, DeletePOP3Aggregator); pthread_mutex_unlock(&POP3QueueMutex); pLine = pLine->next; } }
//---------------------------------------- void CProductErs::ProcessHighResolutionWithoutFieldCalculation() { if (m_dataSet.size() <= 0) { return; } // Get the current recordset (that which has been just read) CRecordSet* recordSetToProcess = m_dataSet.GetCurrentRecordSet(); if (recordSetToProcess == NULL) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - No current recordset"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_LOGIC_ERROR); throw (e); } CFieldSetDbl *fieldSetLat = m_dataSet.GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_latitudeFieldName) ); CFieldSetDbl *fieldSetLon = m_dataSet.GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_longitudeFieldName) ); CFieldSetDbl *fieldSetTimeStampSecond = m_dataSet.GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_timeStampSecondFieldName) ); CFieldSetDbl *fieldSetTimeStampMicrosecond = m_dataSet.GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_timeStampMicrosecondFieldName) ); if (fieldSetLat == NULL) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - latitude field has not been read"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_LOGIC_ERROR); throw (e); } if (fieldSetLon == NULL) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - longitude field has not been read"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_LOGIC_ERROR); throw (e); } if (fieldSetTimeStampSecond == NULL) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - timestamp second field has not been read"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_LOGIC_ERROR); throw (e); } if (fieldSetTimeStampMicrosecond == NULL) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - timestamp microsecond field has not been read"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_LOGIC_ERROR); throw (e); } // if time difference between the the current timestamp and the previous timestamp is greater than 2 seconds // or if current timestamp is less or equal than the previous timestamp // skip the current recordset (data will be lost) // WARNING - fieldSetTimeStampSecond, fieldSetTimeStampMicrosecond are converted to SI // after they have been read. So their value are stated in seconds double timeStamp = 0; timeStamp = CTools::Plus(timeStamp, fieldSetTimeStampSecond->m_value); timeStamp = CTools::Plus(timeStamp, fieldSetTimeStampMicrosecond->m_value); if ( (timeStamp - m_previousTimeStamp > 2.0) || (timeStamp <= m_previousTimeStamp) ) { string msg = CTools::Format("INFO - record skipped due to inconsistency between two measures\n" "\t previous record --> timestamp %f seconds\n" "\t current record --> timestamp %f seconds\n" "\t timestamp difference is %f seconds\n", m_previousTimeStamp, timeStamp, timeStamp - m_previousTimeStamp); CTrace::Tracer(3, msg); m_previousLatitude = fieldSetLat->m_value; m_previousLongitude = fieldSetLon->m_value; m_previousTimeStamp = timeStamp; // Erase the current recordset in the main dataset (data are lost) m_dataSet.Erase(recordSetToProcess); recordSetToProcess = NULL; m_nSkippedRecord++; return; } // Create a new dataset which contains 'normal' fields of the current recordset of the main dataset and // high resolution fields // This dataset will contains as many records as number of high resolution measures (m_numHighResolutionMeasure) CDataSet dataSetHighResolution("HighResolution", false); if (CTools::IsDefaultValue(m_previousLatitude)) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - previous latitude value read is inconsistent (is default value)"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_INCONSISTENCY_ERROR); throw (e); } if (CTools::IsDefaultValue(m_previousLongitude)) { string msg = "ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - previous longitude value read is inconsistent (is default value)"; CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_INCONSISTENCY_ERROR); throw (e); } // Compute delta latitude an deltat longitude. double deltaLat = (fieldSetLat->m_value - m_previousLatitude) / m_numHighResolutionMeasure; double deltaLon = (fieldSetLon->m_value - m_previousLongitude) / m_numHighResolutionMeasure; if ( (m_numHighResolutionMeasure * deltaLon) < -1.0) { deltaLon += 360 / m_numHighResolutionMeasure; } else if ( (m_numHighResolutionMeasure * deltaLon) > 1.0) { deltaLon -= 360 / m_numHighResolutionMeasure; } if ( (m_numHighResolutionMeasure * CTools::Abs(deltaLon)) > 1.0) { string msg = CTools::Format("ERROR in CProductErs::ProcessHighResolutionWithoutFieldCalculation - delta of longitude is set to an unexpected value: %f " "\n\tcurrent datetime: %f current latitude: %f current longitude: %f" "\n\tprevious datetime: %f previous latitude: %f previous longitude: %f", deltaLon, timeStamp, fieldSetLat->m_value, fieldSetLon->m_value, m_previousTimeStamp, m_previousLatitude, m_previousLongitude); CProductException e(msg, m_currFileName, GetProductClass(), GetProductType(), BRATHL_INCONSISTENCY_ERROR); throw (e); } CRecordSet::iterator it; for (it = recordSetToProcess->begin() ; it != recordSetToProcess->end() ; it++) { CFieldSet* fieldSet = recordSetToProcess->GetFieldSet(it); CFieldSetDbl* fieldSetDbl = dynamic_cast<CFieldSetDbl*>(fieldSet); CFieldSetArrayDbl* fieldSetArrayDbl = dynamic_cast<CFieldSetArrayDbl*>(fieldSet); // the field is hidden, it is just use for calculation, don't set it in output if (fieldSet->GetField()->IsHidden()) { continue; } // data is an array of double if (fieldSetArrayDbl != NULL) { // field is a high resolution field // transform array of double in a set of records with a double value if ( fieldSetArrayDbl->GetField()->IsHighResolution() ) { PutFlatHighResolution(&dataSetHighResolution, fieldSetArrayDbl); } else { // field is an array // put it into the set of records (array is repeated for each record) Put(&dataSetHighResolution, fieldSetArrayDbl, m_numHighResolutionMeasure); } } // data is a double if (fieldSetDbl != NULL) { // field is a double // put it into the set of records (value is repeated for each record) Put(&dataSetHighResolution, fieldSetDbl); } } // Compute high resolution fields ComputeHighResolutionFields(&dataSetHighResolution, deltaLat, deltaLon); m_previousLatitude = fieldSetLat->m_value; m_previousLongitude = fieldSetLon->m_value; m_previousTimeStamp = timeStamp; // Erase the current recordset in the main dataset m_dataSet.Erase(recordSetToProcess); recordSetToProcess = NULL; fieldSetLat = NULL; fieldSetLon = NULL; fieldSetTimeStampSecond = NULL; fieldSetTimeStampMicrosecond = NULL; // Insert the record of the new dataset in the main dataset m_dataSet.InsertDataset(&dataSetHighResolution); }
/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null. * The value can be retrieved by calling the get method with a key that is equal to the original key. * @param keyName the key * @param value the value */ void NetworkTable::PutInt(const char *keyName, int value) { Put(keyName, std::auto_ptr<NetworkTables::Entry>(new NetworkTables::IntegerEntry(value))); }
void Report::Put(const char *qtf) { Put(ParseQTF(qtf)); }
/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null. * The value can be retrieved by calling the get method with a key that is equal to the original key. * @param keyName the key * @param value the value */ void NetworkTable::PutBoolean(const char *keyName, bool value) { Put(keyName, std::auto_ptr<NetworkTables::Entry>(new NetworkTables::BooleanEntry(value))); }
void enter_xmsg(User *usr) { char name[MAX_NAME], *p, *endp; XMsg *x; GString gstr; int sent; if ((x = new_XMsg()) == NULL) { Put(usr, "<red>Due to an error, you can not send messages now\n"); return; } if (edit_recipients(usr, multi_x_access) == -1) { destroy_XMsg(x); return; } if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } check_recipients(usr); if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } /* enter the message text */ Put(usr, "<green>"); init_GString(&gstr); if (edit_lines(usr, &gstr, ">", MAX_X_LINES) == -1) { Put(usr, "<red>Message not sent\n"); destroy_XMsg(x); deinit_GString(&gstr); return; } if (gstr.len <= 0) { Put(usr, "<red>Message not sent\n"); destroy_XMsg(x); deinit_GString(&gstr); return; } ctrim_line(gstr.str); if (add_XMsg_line(x, gstr.str) == -1) { Put(usr, "<red>Due to an error, you can not send messages now\n"); destroy_XMsg(x); deinit_GString(&gstr); return; } deinit_GString(&gstr); check_recipients(usr); if (usr->recipients.len <= 0) { destroy_XMsg(x); return; } set_XMsg(x, XMSG_X, usr->name, usr->recipients.str, time(NULL)); sent = 0; p = usr->recipients.str; while((endp = cstrchr(p, ',')) != NULL) { *endp = 0; cstrcpy(name, p, MAX_NAME); *endp = ','; endp++; p = endp; sent += send_xmsg(usr, x, name); } cstrcpy(name, p, MAX_NAME); sent += send_xmsg(usr, x, name); if (sent) send_xmsg_bcc(usr, x); /* remember message as sent in 'this' user */ else destroy_XMsg(x); }
/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null. * The value can be retrieved by calling the get method with a key that is equal to the original key. * @param keyName the key * @param value the value */ void NetworkTable::PutDouble(const char *keyName, double value) { Put(keyName, std::auto_ptr<NetworkTables::Entry>(new NetworkTables::DoubleEntry(value))); }
void Stream::Put16le(word q) { byte *h = (byte *) &q; Put(h[0]); Put(h[1]); }
static DECLSPEC_NOINLINE VOID LogVPrintf( IN VOID (*Put)(CHAR), IN const CHAR *Format, IN va_list Arguments ) { CHAR Character; while ((Character = *Format++) != '\0') { UCHAR Pad = 0; UCHAR Long = 0; BOOLEAN ZeroPrefix = FALSE; BOOLEAN LeftJustify = FALSE; if (Character != '%') { Put(Character); continue; } Character = *Format++; ASSERT(Character != '\0'); if (Character == '-') { LeftJustify = TRUE; Character = *Format++; ASSERT(Character != '\0'); } if (isdigit((UCHAR)Character)) { ZeroPrefix = (Character == '0') ? TRUE : FALSE; while (isdigit((UCHAR)Character)) { Pad = (Pad * 10) + (Character - '0'); Character = *Format++; ASSERT(Character != '\0'); } } while (Character == 'l') { Long++; Character = *Format++; ASSERT(Character != '\0'); } ASSERT3U(Long, <=, 2); switch (Character) { case 'c': { CHAR Value = va_arg(Arguments, CHAR); Put(Value); break; } case 'p': ZeroPrefix = TRUE; Pad = sizeof (ULONG_PTR) * 2; Long = sizeof (ULONG_PTR) / sizeof (ULONG); /* FALLTHRU */ case 'd': case 'u': case 'o': case 'x': case 'X': { CHAR Buffer[23]; // Enough for 8 bytes in octal plus the NUL terminator ULONG Length; ULONG Index; if (Long == 2) LOG_FORMAT_NUMBER(Arguments, LONGLONG, Character, Buffer); else LOG_FORMAT_NUMBER(Arguments, LONG, Character, Buffer); Length = (ULONG)strlen(Buffer); while (Pad > Length) { Put((ZeroPrefix) ? '0' : ' '); --Pad; } for (Index = 0; Index < Length; Index++) Put(Buffer[Index]); break; } case 's': { PCHAR Value = va_arg(Arguments, PCHAR); ULONG Length; ULONG Index; Length = (ULONG)strlen(Value); if (!LeftJustify) { while (Pad > Length) { Put(' '); --Pad; } } for (Index = 0; Index < Length; Index++) Put(Value[Index]); if (LeftJustify) { while (Pad > Length) { Put(' '); --Pad; } } break; } default: Put(Character); break; } } }