void RegisterCommand::watcher() { gg_pubdir* pubDir; if ( state == RegisterStateWaitingForToken ) { disableNotifiers(); if ( gg_token_watch_fd( session_ ) == -1 ) { deleteNotifiers(); emit error( i18n( "Gadu-Gadu" ), i18n( "Unknown connection error while retrieving token." ) ); gg_token_free( session_ ); session_ = NULL; state = RegisterStateNoToken; return; } pubDir = (struct gg_pubdir *)session_->data; emit operationStatus( i18n( "Token retrieving status: %1", GaduSession::stateDescription( session_->state ) ) ); switch ( session_->state ) { case GG_STATE_CONNECTING: kDebug( 14100 ) << "Recreating notifiers "; deleteNotifiers(); checkSocket( session_->fd, 0); break; case GG_STATE_ERROR: deleteNotifiers(); emit error( i18n( "Gadu-Gadu token retrieve problem" ), GaduSession::errorDescription( session_->error ) ); gg_token_free( session_ ); session_ = NULL; state = RegisterStateNoToken; return; break; case GG_STATE_DONE: struct gg_token* sp = ( struct gg_token* )session_->data; tokenId = (char *)sp->tokenid; kDebug( 14100 ) << "got Token!, ID: " << tokenId; deleteNotifiers(); if ( pubDir->success ) { QPixmap tokenImg; tokenImg.loadFromData( (const unsigned char *)session_->body, session_->body_size ); state = RegisterStateGotToken; emit tokenRecieved( tokenImg, tokenId ); } else { emit error( i18n( "Gadu-Gadu" ), i18n( "Unable to retrieve token." ) ); state = RegisterStateNoToken; deleteLater(); } gg_token_free( session_ ); session_ = NULL; disconnect( this, SLOT(watcher()) ); return; break; } enableNotifiers( session_->check ); } if ( state == RegisterStateWaitingForNumber ) { disableNotifiers(); if ( gg_register_watch_fd( session_ ) == -1 ) { deleteNotifiers(); emit error( i18n( "Gadu-Gadu" ), i18n( "Unknown connection error while registering." ) ); gg_free_register( session_ ); session_ = NULL; state = RegisterStateGotToken; return; } pubDir = (gg_pubdir*) session_->data; emit operationStatus( i18n( "Registration status: %1", GaduSession::stateDescription( session_->state ) ) ); switch ( session_->state ) { case GG_STATE_CONNECTING: kDebug( 14100 ) << "Recreating notifiers "; deleteNotifiers(); checkSocket( session_->fd, 0); break; case GG_STATE_ERROR: deleteNotifiers(); emit error( i18n( "Gadu-Gadu Registration Error" ), GaduSession::errorDescription( session_->error ) ); gg_free_register( session_ ); session_ = NULL; state = RegisterStateGotToken; return; break; case GG_STATE_DONE: deleteNotifiers(); if ( pubDir->success && pubDir->uin ) { uin= pubDir->uin; state = RegisterStateDone; emit done( i18n( "Registration Finished" ), i18n( "Registration has been completed successfully." ) ); } else { emit error( i18n( "Registration Error" ), i18n( "Incorrect data sent to server." ) ); state = RegisterStateGotToken; } gg_free_register( session_ ); session_ = NULL; disconnect( this, SLOT(watcher()) ); deleteLater(); return; break; } enableNotifiers( session_->check ); return; } }
int main() { struct gg_http *h; struct gg_pubdir *p; char email[100], password[100]; gg_debug_level = 255; printf("e-mail: "); fgets(email, 99, stdin); if (email[strlen(email)-1] == '\n') email[strlen(email)-1] = 0; printf("password: "******"b³±d\n"); return 1; } p = h->data; printf("success=%d, uin=%ld\n", p->success, p->uin); gg_free_register(h); #else signal(SIGCHLD, sigchld); if (!(h = gg_register(email, password, 1))) return 1; while (1) { fd_set rd, wr, ex; FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&ex); if ((h->check & GG_CHECK_READ)) FD_SET(h->fd, &rd); if ((h->check & GG_CHECK_WRITE)) FD_SET(h->fd, &wr); FD_SET(h->fd, &ex); if (select(h->fd + 1, &rd, &wr, &ex, NULL) == -1 || FD_ISSET(h->fd, &ex)) { if (errno == EINTR) continue; gg_free_register(h); perror("select"); return 1; } if (FD_ISSET(h->fd, &rd) || FD_ISSET(h->fd, &wr)) { if (gg_register_watch_fd(h) == -1) { gg_free_register(h); fprintf(stderr, "no b³±d jak b³±d\n"); return 1; } if (h->state == GG_STATE_ERROR) { gg_free_register(h); fprintf(stderr, "jaki¶tam b³±d\n"); return 1; } if (h->state == GG_STATE_DONE) { p = h->data; printf("success=%d, uin=%ld\n", p->success, p->uin); gg_free_register(h); break; } } } #endif return 0; }