std::vector<save_info> manager::get_saves_list(const std::string *dir, const std::string* filter) { // Don't use a reference, it seems to break on arklinux with GCC-4.3. std::string saves_dir = (dir) ? *dir : get_saves_dir(); #ifdef _WIN32 conv_ansi_utf8(saves_dir, false); #endif std::vector<std::string> saves; get_files_in_dir(saves_dir,&saves); std::vector<save_info> res; for(std::vector<std::string>::iterator i = saves.begin(); i != saves.end(); ++i) { if(filter && std::search(i->begin(), i->end(), filter->begin(), filter->end()) == i->end()) { continue; } const time_t modified = file_create_time(saves_dir + "/" + *i); // replace_underbar2space(*i); #ifdef _WIN32 res.push_back(save_info(conv_ansi_utf8_2(*i, true), modified)); #else res.push_back(save_info(*i, modified)); #endif } std::sort(res.begin(),res.end(),save_info_less_time()); return res; }
void inter_paraboloide(t_scene *sc) { t_dis dis; double k; t_info save; rotate(sc); translat(sc); dis.a = (sc->tmp_vec->x * sc->tmp_vec->x) + (sc->tmp_vec->y * sc->tmp_vec->y) - (sc->obj->cte * sc->tmp_vec->z); dis.b = 2.f * ((sc->tmp_oeil->x * sc->tmp_vec->x) + (sc->tmp_oeil->y * sc->tmp_vec->y) + (- sc->obj->cte * sc->tmp_oeil->z)); dis.c = (sc->tmp_oeil->x * sc->tmp_oeil->x) + (sc->tmp_oeil->y * sc->tmp_oeil->y) - (sc->obj->cte * sc->tmp_oeil->z); dis.dis = dis.b * dis.b - 4.f * dis.a * dis.c; k = calc_k(dis.a, dis.b, dis.dis); if (k <= 0) return ; if (k < sc->info->k || sc->info->k == -42) { save_info(sc->info, &save); sc->info->k = k; sc->info->x = sc->tmp_oeil->x + k * sc->tmp_vec->x; sc->info->y = sc->tmp_oeil->y + k * sc->tmp_vec->y; sc->info->z = sc->tmp_oeil->z + k * sc->tmp_vec->z; limit_object(sc); if (sc->info->k == -42) save_info(&save, sc->info); sc->info->obj = sc->obj; } }
int go_to_spot(t_scene *sc, t_object *obj, t_spot *spot) { double dlong; t_info save; sc->tmp_oeil->x = sc->info->x; sc->tmp_oeil->y = sc->info->y; sc->tmp_oeil->z = sc->info->z; save_info(sc->info, &save); sc->tmp_vec->x = spot->x - sc->info->x; sc->tmp_vec->y = spot->y - sc->info->y; sc->tmp_vec->z = spot->z - sc->info->z; dlong = sqrt((sc->tmp_vec->x * sc->tmp_vec->x) + (sc->tmp_vec->y * sc->tmp_vec->y) + (sc->tmp_vec->z * sc->tmp_vec->z)); sc->info->k = -42; spot_calc(sc, obj); if (sc->info->k > 0.00001 && sc->info->k < dlong) { save_info(&save, sc->info); return (1); } save_info(&save, sc->info); return (0); }
QString KSnapshot::getUnexistsFilePath(const QString &base) { QFileInfo save_info(base); QString basename = save_info.baseName(); QString suffix = save_info.suffix(); if ( !suffix.isEmpty() ) suffix = '.' + suffix; QString save_dir = QQGlobal::tempDir() +"/snapshot"; QDir snap_qdir(save_dir); if ( !snap_qdir.exists() ) snap_qdir.mkdir(save_dir); int i = 1; QString base_path = save_dir + '/' + basename; QString final_save_path = base_path + suffix; QDir save_qdir(save_dir); while ( save_qdir.exists(final_save_path) ) { final_save_path = base_path + QString::number(i) + suffix; ++i; } return final_save_path; }
int save_draw(ui_t *ui) { char field_value[80]; // Get panel information save_info_t *info = save_info(ui); // Get filter stats sip_stats_t stats = sip_calls_stats(); mvwprintw(ui->win, 7, 3, "( ) all dialogs "); mvwprintw(ui->win, 8, 3, "( ) selected dialogs [%d]", call_group_count(info->group)); mvwprintw(ui->win, 9, 3, "( ) filtered dialogs [%d]", stats.displayed); // Print 'current SIP message' field label if required if (info->msg != NULL) mvwprintw(ui->win, 10, 3, "( ) current SIP message"); mvwprintw(ui->win, 7, 35, "( ) .pcap (SIP)"); mvwprintw(ui->win, 8, 35, "( ) .pcap (SIP + RTP)"); mvwprintw(ui->win, 9, 35, "( ) .txt"); // Get filename field value. memset(field_value, 0, sizeof(field_value)); strcpy(field_value, field_buffer(info->fields[FLD_SAVE_FILE], 0)); strtrim(field_value); mvwprintw(ui->win, 4, 60, " "); if (strstr(field_value, ".pcap")) { info->saveformat = (setting_enabled(SETTING_CAPTURE_RTP))? SAVE_PCAP_RTP : SAVE_PCAP; } else if (strstr(field_value, ".txt")) { info->saveformat = SAVE_TXT; } else { if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) mvwprintw(ui->win, 4, 60, ".pcap"); else mvwprintw(ui->win, 4, 60, ".txt "); } set_field_buffer(info->fields[FLD_SAVE_ALL], 0, (info->savemode == SAVE_ALL) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_SELECTED], 0, (info->savemode == SAVE_SELECTED) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_DISPLAYED], 0, (info->savemode == SAVE_DISPLAYED) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_MESSAGE], 0, (info->savemode == SAVE_MESSAGE) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_PCAP], 0, (info->saveformat == SAVE_PCAP) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, (info->saveformat == SAVE_PCAP_RTP) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_TXT], 0, (info->saveformat == SAVE_TXT) ? "*" : " "); // Show disabled options with makers if (!setting_enabled(SETTING_CAPTURE_RTP)) set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, "-"); set_current_field(info->form, current_field(info->form)); form_driver(info->form, REQ_VALIDATION); return 0; }
void save_destroy(ui_t *ui) { save_info_t *info; int i; // Get panel information if ((info = save_info(ui))) { // Remove panel form and fields unpost_form(info->form); free_form(info->form); for (i = 0; i < FLD_SAVE_COUNT; i++) free_field(info->fields[i]); // Remove panel window and custom info sng_free(info); } // Delete panel ui_panel_destroy(ui); // Resume capture capture_set_paused(0); // Disable cursor position curs_set(0); }
void save_set_msg(ui_t *ui, sip_msg_t *msg) { // Get panel information save_info_t *info = save_info(ui); info->msg = msg; // make 'current SIP message' field visible field_opts_on(info->fields[FLD_SAVE_MESSAGE], O_VISIBLE); }
void save_set_group(ui_t *ui, sip_call_group_t *group) { // Get panel information save_info_t *info = save_info(ui); info->group = group; if (call_group_count(group)) { info->savemode = SAVE_SELECTED; } }
void ombre(t_scene *sc) { t_spot *spot; t_object *obj; t_info save; save_info(sc->info, &save); spot = sc->spot; sc->info->x = sc->info->x + sc->info->obj->x; sc->info->y = sc->info->y + sc->info->obj->y; sc->info->z = sc->info->z + sc->info->obj->z; while (spot) { obj = sc->obj; apply_shadow(sc, obj, spot, &save); spot = spot->next; } save_info(&save, sc->info); }
void inter_cone(t_scene *sc) { t_dis dis; double k; t_info save; rotate(sc); translat(sc); dis.a = (sc->tmp_vec->x * sc->tmp_vec->x) + (sc->tmp_vec->y * sc->tmp_vec->y) - (sc->obj->cte * (sc->tmp_vec->z * sc->tmp_vec->z)); dis.b = 2.f * ((sc->tmp_oeil->x * sc->tmp_vec->x) + (sc->tmp_oeil->y * sc->tmp_vec->y) + (- sc->obj->cte * (sc->tmp_oeil->z * sc->tmp_vec->z))); dis.c = (sc->tmp_oeil->x * sc->tmp_oeil->x) + (sc->tmp_oeil->y * sc->tmp_oeil->y) - (sc->obj->cte * (sc->tmp_oeil->z * sc->tmp_oeil->z)); dis.dis = dis.b * dis.b - 4.f * dis.a * dis.c; k = calc_k(dis.a, dis.b, dis.dis); if (sc->obj->neg) { statics_k(1, (-dis.b + sqrt(dis.dis)) / (2.f * dis.a), (-dis.b - sqrt(dis.dis)) / (2.f * dis.a)); return ; } if (statics_k(0, k, 0) || !k) return; if ((k < sc->info->k || sc->info->k == -42) && k) { save_info(&save, sc->info); sc->info->k = k; sc->info->x = sc->tmp_oeil->x + k * sc->tmp_vec->x; sc->info->y = sc->tmp_oeil->y + k * sc->tmp_vec->y; sc->info->z = sc->tmp_oeil->z + k * sc->tmp_vec->z; limit_object(sc); if (sc->info->k == -42) save_info(sc->info, &save); sc->info->obj = sc->obj; } }
bool CMovieCut::copyMovie(MI_MOVIE_INFO * minfo, bool onefile) { struct mybook books[MI_MOVIE_BOOK_USER_MAX+2]; struct stat64 s; char dpart[255]; unsigned char psi[PSI_SIZE]; int dstfd = -1, srcfd = -1; off64_t spos = 0, btotal = 0; time_t tt = time(0); bool need_gop = 0; bool dst_done = 0; bool was_cancel = false; bool retval = false; int bcount = 0; off64_t newsize = 0; off64_t secsize = getSecondSize(minfo); for (int book_nr = 0; book_nr < MI_MOVIE_BOOK_USER_MAX; book_nr++) { if (minfo->bookmarks.user[book_nr].pos != 0 && minfo->bookmarks.user[book_nr].length > 0) { books[bcount].pos = (minfo->bookmarks.user[book_nr].pos * secsize)/188 * 188; if (books[bcount].pos > SAFE_GOP) books[bcount].pos -= SAFE_GOP; books[bcount].len = (minfo->bookmarks.user[book_nr].length * secsize)/188 * 188; books[bcount].ok = 1; printf("copy: jump bookmark %d at %" PRId64 " len %" PRId64 "\n", bcount, books[bcount].pos, books[bcount].len); newsize += books[bcount].len; bcount++; } } if (!bcount) return false; unsigned char * buf = new unsigned char[BUF_SIZE]; if (buf == 0) { perror("new"); return false; } paintProgress(true); printf("********* %d boormarks, to %s file(s), expected size to copy %" PRId64 ", start time %s", bcount, onefile ? "one" : "many", newsize, ctime(&tt)); if (read_psi(minfo->file.Name.c_str(), &psi[0])) { perror(minfo->file.Name.c_str()); goto ret_err; } srcfd = open(minfo->file.Name.c_str(), O_RDONLY | O_LARGEFILE); if (srcfd < 0) { perror(minfo->file.Name.c_str()); goto ret_err; } stat64(minfo->file.Name.c_str(), &s); for (int i = 0; i < bcount; i++) { printf("\ncopy: processing bookmark %d at %" PRId64 " len %" PRId64 "\n", i, books[i].pos, books[i].len); if (!dst_done || !onefile) { findNewName(minfo->file.Name.c_str(), dpart, sizeof(dpart)); dstfd = open(dpart, O_CREAT|O_WRONLY|O_TRUNC| O_LARGEFILE, 0644); printf("copy: new file %s fd %d\n", dpart, dstfd); if (dstfd < 0) { printf("failed to open %s\n", dpart); goto ret_err; } dst_done = 1; spos = 0; write(dstfd, psi, PSI_SIZE); } need_gop = 1; off64_t offset = books[i].pos; lseek64(srcfd, offset, SEEK_SET); off64_t until = books[i].pos + books[i].len; printf("copy: read from %" PRId64 " to %" PRId64 " read size %d want gop %d\n", offset, until, BUF_SIZE, need_gop); while (offset < until) { size_t toread = (until-offset) > BUF_SIZE ? BUF_SIZE : until - offset; int msg = getInput(); was_cancel = msg & 2; if (msg & 4) { unlink(dpart); retval = true; goto ret_err; } size_t r = read(srcfd, buf, toread); if (r > 0) { int wptr = 0; if (r != toread) printf("****** short read ? %d\n", (int)r); if (buf[0] != 0x47) printf("copy: buffer not aligned at %" PRId64 "\n", offset); if (need_gop) { int gop = find_gop(buf, r); if (gop >= 0) { printf("cut: GOP found at %" PRId64 " offset %d\n", (off64_t)(offset+gop), gop); newsize -= gop; wptr = gop; } else printf("cut: GOP needed, but not found\n"); need_gop = 0; } offset += r; spos += r - wptr; btotal += r; percent = (int) ((float)(btotal)/(float)(newsize)*100.); paintProgress(msg != 0); size_t wr = write(dstfd, &buf[wptr], r-wptr); if (wr < (r-wptr)) { printf("write to %s failed\n", dpart); unlink(dpart); goto ret_err; } } else if (offset < s.st_size) { /* read error ? */ perror(minfo->file.Name.c_str()); break; } } /* while(offset < until) */ if (!onefile) { close(dstfd); dstfd = -1; save_info(minfo, dpart, spos, secsize); time_t tt1 = time(0); printf("copy: ********* %s: total written %" PRId64 " took %ld secs\n", dpart, spos, tt1-tt); } } /* for all books */ if (onefile) { save_info(minfo, dpart, spos, secsize); time_t tt1 = time(0); printf("copy: ********* %s: total written %" PRId64 " took %ld secs\n", dpart, spos, tt1-tt); } retval = true; ret_err: if (srcfd >= 0) close(srcfd); if (dstfd >= 0) close(dstfd); delete [] buf; if (was_cancel) g_RCInput->postMsg(CRCInput::RC_home, 0); frameBuffer->paintBoxRel(x + 40, y+12, 200, 15, COL_INFOBAR_PLUS_0);//TODO: remove unneeded box paints return retval; }
bool CMovieCut::cutMovie(MI_MOVIE_INFO * minfo) { struct mybook books[MI_MOVIE_BOOK_USER_MAX+2]; unsigned char psi[PSI_SIZE]; char dpart[255]; int bcount = 0; int dstfd = -1, srcfd = -1; struct stat64 s; off64_t spos = 0; bool need_gop = 0; int was_cancel = 0; bool retval = false; time_t tt = time(0); time_t tt1; off64_t size = minfo->file.Size; off64_t secsize = getSecondSize(minfo); off64_t newsize = size; if (minfo->bookmarks.start != 0) { books[bcount].pos = 0; books[bcount].len = (minfo->bookmarks.start * secsize)/188 * 188; if (books[bcount].len > SAFE_GOP) books[bcount].len -= SAFE_GOP; books[bcount].ok = 1; printf("CMovieCut::%s: start bookmark %d at %" PRId64 " len %" PRId64 "\n", __func__, bcount, books[bcount].pos, books[bcount].len); bcount++; } for (int book_nr = 0; book_nr < MI_MOVIE_BOOK_USER_MAX; book_nr++) { if (minfo->bookmarks.user[book_nr].pos != 0 && minfo->bookmarks.user[book_nr].length > 0) { books[bcount].pos = (minfo->bookmarks.user[book_nr].pos * secsize)/188 * 188; books[bcount].len = (minfo->bookmarks.user[book_nr].length * secsize)/188 * 188; if (books[bcount].len > SAFE_GOP) books[bcount].len -= SAFE_GOP; books[bcount].ok = 1; printf("CMovieCut::%s: jump bookmark %d at %" PRId64 " len %" PRId64 " -> skip to %" PRId64 "\n", __func__, bcount, books[bcount].pos, books[bcount].len, books[bcount].pos+books[bcount].len); bcount++; } } if (minfo->bookmarks.end != 0) { books[bcount].pos = ((off64_t) minfo->bookmarks.end * secsize)/188 * 188; books[bcount].len = size - books[bcount].pos; books[bcount].ok = 1; printf("CMovieCut::%s: end bookmark %d at %" PRId64 "\n", __func__, bcount, books[bcount].pos); bcount++; } if (!bcount) return false; unsigned char * buf = new unsigned char[BUF_SIZE]; if (buf == 0) { perror("new"); return false; } paintProgress(true); qsort(books, bcount, sizeof(struct mybook), compare_book); for (int i = 0; i < bcount; i++) { if (books[i].ok) { //printf("cut: bookmark %d at %" PRId64 " len %" PRId64 " -> skip to %" PRId64 "\n", i, books[i].pos, books[i].len, books[i].pos+books[i].len); newsize -= books[i].len; off64_t curend = books[i].pos + books[i].len; /* check for overlapping bookmarks */ for (int j = i + 1; j < bcount; j++) { if ((books[j].pos > books[i].pos) && (books[j].pos < curend)) { off64_t newend = books[j].pos + books[j].len; if (newend > curend) { printf("CMovieCut::%s: bad bookmark %d, position %" PRId64 " len %" PRId64 ", adjusting..\n", __func__, j, books[j].pos, books[j].len); books[j].pos = curend; books[j].len = newend - curend; } else { printf("CMovieCut::%s: bad bookmark %d, position %" PRId64 " len %" PRId64 ", skipping..\n", __func__, j, books[j].pos, books[j].len); books[j].ok = 0; } } } } } findNewName(minfo->file.Name.c_str(), dpart, sizeof(dpart)); int bindex = 0; off64_t bpos = books[bindex].pos; off64_t bskip = books[bindex].len; off64_t offset = 0; printf("CMovieCut::%s: new file %s, expected size %" PRId64 ", start time %s", __func__, dpart, newsize, ctime(&tt)); dstfd = open(dpart, O_CREAT|O_WRONLY|O_TRUNC| O_LARGEFILE, 0644); if (dstfd < 0) { perror(dpart); goto ret_err; } if (read_psi(minfo->file.Name.c_str(), &psi[0])) { perror(minfo->file.Name.c_str()); goto ret_err; } write(dstfd, psi, PSI_SIZE); stat64(minfo->file.Name.c_str(), &s); srcfd = open(minfo->file.Name.c_str(), O_RDONLY | O_LARGEFILE); if (srcfd < 0) { perror(minfo->file.Name.c_str()); goto ret_err; } lseek64(srcfd, offset, SEEK_SET); /* process all bookmarks */ while (true) { off64_t until = bpos; printf("CMovieCut::%s: bookmark #%d reading from %" PRId64 " to %" PRId64 " (%" PRId64 ") want gop %d\n", __func__, bindex, offset, until, until - offset, need_gop); /* read up to jump end */ while (offset < until) { int msg = getInput(); was_cancel = msg & 2; if (msg & 4) { unlink(dpart); retval = true; goto ret_err; } size_t toread = (until-offset) > BUF_SIZE ? BUF_SIZE : until - offset; size_t r = read(srcfd, buf, toread); if (r > 0) { int wptr = 0; if (r != toread) printf("CMovieCut::%s: short read at %" PRId64 ": %d\n", __func__, offset, (int)r); if (buf[0] != 0x47) printf("CMovieCut::%s: buffer not aligned at %" PRId64 "\n", __func__, offset); if (need_gop) { int gop = find_gop(buf, r); if (gop >= 0) { printf("CMovieCut::%s: GOP found at %" PRId64 " offset %d\n", __func__, (off64_t)(offset+gop), gop); newsize -= gop; wptr = gop; } else printf("CMovieCut::%s: GOP not found\n", __func__); need_gop = 0; } offset += r; spos += r - wptr; percent = (int) ((float)(spos)/(float)(newsize)*100.); paintProgress(msg != 0); size_t wr = write(dstfd, &buf[wptr], r-wptr); if (wr < (r-wptr)) { perror(dpart); goto ret_err; } } else if (offset < s.st_size) { /* read error ? */ perror(minfo->file.Name.c_str()); goto ret_err; } } printf("CMovieCut::%s: current file pos %" PRId64 " write pos %" PRId64 " book pos %" PRId64 " next offset %" PRId64 "\n", __func__, offset, spos, bpos, bpos + bskip); need_gop = 1; offset = bpos + bskip; bindex++; while(bindex < bcount) { if(books[bindex].ok) break; else bindex++; } if(bindex < bcount) { bpos = books[bindex].pos; bskip = books[bindex].len; } else bpos = size; if (offset >= s.st_size) { printf("CMovieCut::%s: offset behind EOF: %" PRId64 " from %" PRId64 "\n", __func__, offset, s.st_size); break; } lseek64(srcfd, offset, SEEK_SET); } tt1 = time(0); printf("CMovieCut::%s: total written %" PRId64 " tooks %ld secs end time %s", __func__, spos, tt1-tt, ctime(&tt1)); save_info(minfo, dpart, spos, secsize); retval = true; ret_err: if (srcfd >= 0) close(srcfd); if (dstfd >= 0) close(dstfd); delete [] buf; if (was_cancel) g_RCInput->postMsg(CRCInput::RC_home, 0); frameBuffer->paintBoxRel(x + 40, y+12, 200, 15, COL_INFOBAR_PLUS_0);//TODO: remove unneeded box paints return retval; }
void kcall(struct thread *image) { if (image->flags & TF_USER) { // perform syscall // save user state image->usr_eip = image->eip; image->usr_esp = image->useresp; // switch to system mode image->ss = 0x21; image->ds = 0x21; image->cs = 0x19; image->flags &= ~TF_USER; // restore system state image->eip = image->sys_eip; image->useresp = image->sys_esp; return; } switch (image->eax) { case KCALL_SPAWN: { int id = thread_new(); if (id == -1) { // failure to create new thread image->eax = -1; break; } struct thread *thread = thread_get(id); struct t_info *state = (void*) image->ebx; // initialize thread state thread->useresp = state->regs.esp; thread->esp = (uintptr_t) &thread->num; thread->ss = 0x21; thread->ds = 0x21; thread->cs = 0x19; thread->eflags = image->eflags; thread->eip = state->regs.eip; thread->ebp = state->regs.ebp; thread->esi = state->regs.esi; thread->edi = state->regs.edi; thread->edx = state->regs.edx; thread->ecx = state->regs.ecx; thread->ebx = state->regs.ebx; thread->eax = state->regs.eax; // add to scheduler queue thread->state = TS_QUEUED; schedule_push(thread); image->eax = id; break; } case KCALL_REAP: { struct thread *target = thread_get(image->ebx); if (target->state != TS_PAUSED) { image->eax = TE_STATE; } else { if (image->ecx) { save_info((void*) image->ecx, target); } image->eax = 0; thread_kill(target); } break; } case KCALL_GETTID: { image->eax = image->id; break; } case KCALL_YIELD: { thread_save(image); schedule_push(image); image->state = TS_QUEUED; break; } case KCALL_PAUSE: { struct thread *target = thread_get(image->ebx); if (image->ebx == (uint32_t) -1) target = image; if (!target) { image->eax = TE_EXIST; } else switch (target->state) { case TS_RUNNING: // pause (normal, from running) thread_save(target); target->state = TS_PAUSED; image->eax = 0; break; case TS_QUEUED: // pause (normal, from queued) schedule_remv(target); target->state = TS_PAUSED; image->eax = 0; break; case TS_WAITING: // pause (waiting) event_remv(target->id, target->event); target->state = TS_PAUSEDW; image->eax = 0; break; default: // invalid state transition image->eax = TE_STATE; break; } break; } case KCALL_RESUME: { struct thread *target = thread_get(image->ebx); if (!target) { image->eax = TE_EXIST; } else switch (target->state) { case TS_PAUSED: // resume thread by scheduling schedule_push(target); target->state = TS_QUEUED; image->eax = 0; break; case TS_PAUSEDW: // resume thread by entering wait queue event_wait(target->id, target->event); target->state = TS_WAITING; image->eax = 0; break; default: image->eax = TE_STATE; break; } break; } case KCALL_GETSTATE: { struct thread *target = thread_get(image->ebx); if (image->ebx == (uint32_t) -1) target = image; if (!target) { image->eax = TE_EXIST; } else if (target->state != TS_PAUSED && target->state != TS_PAUSEDW && target != image) { image->eax = TE_STATE; } else { save_info((void*) image->ecx, target); image->eax = 0; } break; } case KCALL_SETSTATE: { struct thread *target = thread_get(image->ebx); if (image->ebx == (uint32_t) -1) target = image; if (!target) { image->eax = TE_EXIST; } else switch (target->state) { case TS_PAUSED: case TS_PAUSEDW: case TS_RUNNING: { struct t_info *src = (void*) image->ecx; if (src->flags & TF_DEAD) { // kill thread if (target->state == TS_RUNNING) { thread_save(target); target->state = TS_PAUSED; } // notify reaper dead_push(target); } if (target->pctx != src->pctx) { // change paging contexts pctx_load(src->pctx); } // save thread state target->pctx = src->pctx; target->flags = src->flags; target->fault = src->fault; if (target->state != TS_RUNNING) { // save register state target->edi = src->regs.edi; target->esi = src->regs.esi; target->ebp = src->regs.ebp; target->useresp = src->regs.esp; target->ebx = src->regs.ebx; target->edx = src->regs.edx; target->ecx = src->regs.ecx; target->eax = src->regs.eax; target->eip = src->regs.eip; target->eflags = src->regs.eflags; // save MMX/SSE state if (!target->fxdata) target->fxdata = heap_alloc(512); memcpy(target->fxdata, &src->regs.fxdata[0], 512); } target->usr_eip = src->usr_ip; target->usr_esp = src->usr_sp; image->eax = 0; break; } default: image->eax = TE_STATE; break; } break; } case KCALL_GETDEAD: { if (dead_peek()) { struct thread *dead = dead_pull(); image->eax = dead->id; } else { thread_save(image); image->state = TS_PAUSED; dead_wait(image); } break; } case KCALL_GETFAULT: { if (fault_peek()) { struct thread *fault = fault_pull(); image->eax = fault->id; } else { thread_save(image); image->state = TS_PAUSED; fault_wait(image); } break; } case KCALL_WAIT: { image->eax = event_wait(image->id, image->ebx); break; } case KCALL_RESET: { if (image->ebx < 240) { extern int irqstate[EV_COUNT]; irqstate[image->ebx] = 0; irq_unmask(image->ebx); } image->eax = 0; break; } case KCALL_SYSRET: { // save system state image->sys_eip = image->eip; image->sys_esp = image->useresp; // perform return value swap-in image->eax = image->ebp; // switch to usermode image->ss = 0x33; image->ds = 0x33; image->cs = 0x2B; image->flags |= TF_USER; // restore user state image->eip = image->usr_eip; image->useresp = image->usr_esp; break; } case KCALL_NEWPCTX: { image->eax = pctx_new(); break; } case KCALL_FREEPCTX: { image->eax = pctx_free(image->ebx); break; } case KCALL_SETFRAME: { page_set(image->ebx, page_fmt(image->ecx, page_get(image->ebx))); image->eax = 0; break; } case KCALL_SETFLAGS: { page_set(image->ebx, page_fmt(page_ufmt(page_get(image->ebx)), image->ecx)); image->eax = 0; break; } case KCALL_GETFRAME: { uint32_t off = image->ebx & 0xFFF; uint32_t page = image->ebx & ~0xFFF; image->eax = page_ufmt(page_get(page)) | off; break; } case KCALL_GETFLAGS: { image->eax = page_get(image->ebx) & PF_MASK; break; } case KCALL_NEWFRAME: { uint64_t frame = frame_new(); image->eax = frame & 0xFFFFFFFF; image->ebx = frame >> 32ULL; break; } case KCALL_FREEFRAME: { frame_free(image->ebx); image->eax = 0; break; } case KCALL_TAKEFRAME: { image->eax = 1; break; } default: { debug_printf("warning: unimplemented kcall %d\n", image->eax); image->eax = -1; break; } } }
int login(fd_addr* const client_p) { char buf[BUFLEN]; int numbytes = 0; struct info* pnode; char tempname[NAMELEN]; char temppwd[PWDLEN]; int i; pnode = file_info; while(1) { write(client_p->fd, "\n\t*****************\n", BUFLEN); write(client_p->fd, "\t* (1) Login *\n", BUFLEN); write(client_p->fd, "\t* (2) Regist *\n", BUFLEN); write(client_p->fd, "\t* (3) Exit *\n", BUFLEN); write(client_p->fd, "\t*****************\n", BUFLEN); write(client_p->fd, "\n\tInput you chioce:", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in login"); pthread_exit(NULL); } buf[--numbytes] = '\0'; #ifdef DEBUG_VERSION printf("from:%s :%s\n", inet_ntoa(client_p->addr.sin_addr), buf); #endif if(strlen(buf) != 1) continue; //going to login if(buf[0] == '1') { write(client_p->fd, "\n\tinput you user name:\n", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in login"); pthread_exit(NULL); } buf[--numbytes] = '\0'; strcpy(tempname, buf); pnode = file_info; while(pnode) { if(!strcmp(buf, pnode->name)) { strncpy(tempname, buf, NAMELEN-1); break; } pnode = pnode->next; } if(!pnode) { write(client_p->fd, "user name not exist\n", BUFLEN); sleep(1); continue; } write(client_p->fd, "\n\tinput you password:\n", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in login"); pthread_exit(NULL); } buf[--numbytes] = '\0'; #ifdef DEBUG_VERSION_ printf("from:%s :%s\n", inet_ntoa(client_p->addr.sin_addr), buf); printf("node->name:%s\n", pnode->name); printf("client_p->user_name:%s///strlen:%d\n", client_p->user_name, strlen(client_p->user_name)); #endif if(!strcmp(buf, pnode->pwd)) { for(i=0; i<MAXPEOPLE; i++) { if((client[i].fd != -1) && !strcmp(tempname,client[i].user_name)) { break; } } //the user name already login if(i != MAXPEOPLE) { write(client_p->fd,"the user name have already login\n", BUFLEN); sleep(1); continue; } //if the user name not login then login else { strcpy(client_p->user_name, tempname); #ifdef DEBUG_VERSION printf("%s login success\n", client_p->user_name); #endif return 1; } } else { write(client_p->fd, "password not match!!!\n", BUFLEN); sleep(1); } } //going to regist else if(buf[0] == '2') { write(client_p->fd, "input you user name:\n", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in regist"); pthread_exit(NULL); } buf[--numbytes] = '\0'; strcpy(tempname, buf); pnode = file_info; //check if the user the already exist while(pnode) { if(!strcmp(buf, pnode->name)) { write(client_p->fd, "the user name already exist\n", BUFLEN); sleep(1); break; } pnode = pnode->next; } //if user name not exist if(!pnode) { write(client_p->fd, "input password:\n", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in regist"); pthread_exit(NULL); } buf[--numbytes] = '\0'; strcpy(temppwd, buf); write(client_p->fd, "input you password again:\n", BUFLEN); memset(buf, 0, BUFLEN); if((numbytes = recv(client_p->fd, buf, BUFLEN, 0)) == -1) { perror("recv in regist"); pthread_exit(NULL); } buf[--numbytes] = '\0'; //passwork correct if(!strcmp(temppwd, buf)) { pnode = malloc(sizeof(struct info)); pnode->next = NULL; strcpy(pnode->name, tempname); strcpy(pnode->pwd, temppwd); pnode->next = file_info; file_info = pnode; save_info(pnode); write(client_p->fd, "regist success!!!\n", BUFLEN); sleep(1); #ifdef DEBUG_VERSION printf("regist:%s:%s\n", pnode->name, pnode->pwd); #endif continue; } else { write(client_p->fd, "password not match!!!\n", BUFLEN); sleep(1); continue; } } } else if(buf[0] == '3') { write(client_p->fd, "EXIT", BUFLEN); close(client_p); pthread_mutex_lock(&client_mutex); FD_ADDR_CLR(client_p); pthread_mutex_unlock(&client_mutex); pthread_exit(NULL); } } }
int save_to_file(ui_t *ui) { char savepath[256]; char savefile[256]; char fullfile[512]; sip_call_t *call = NULL; sip_msg_t *msg = NULL; pcap_dumper_t *pd = NULL; FILE *f = NULL; int cur = 0, total = 0; WINDOW *progress; vector_iter_t calls, msgs, rtps, packets; packet_t *packet; vector_t *sorted; // Get panel information save_info_t *info = save_info(ui); // Get current path field value. memset(savepath, 0, sizeof(savepath)); strcpy(savepath, field_buffer(info->fields[FLD_SAVE_PATH], 0)); strtrim(savepath); if (strlen(savepath)) strcat(savepath, "/"); // Get current file field value. memset(savefile, 0, sizeof(savefile)); strcpy(savefile, field_buffer(info->fields[FLD_SAVE_FILE], 0)); strtrim(savefile); if (!strlen(savefile)) { dialog_run("Please enter a valid filename"); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { if (!strstr(savefile, ".pcap")) strcat(savefile, ".pcap"); } else { if (!strstr(savefile, ".txt")) strcat(savefile, ".txt"); } // Absolute filename sprintf(fullfile, "%s%s", savepath, savefile); if (access(fullfile, R_OK) == 0) { if (dialog_confirm("Overwrite confirmation", "Selected file already exits.\n Do you want to overwrite it?", "Yes,No") != 0) return 1; } // Don't allow to save no packets! if (info->savemode == SAVE_SELECTED && call_group_msg_count(info->group) == 0) { dialog_run("Unable to save: No selected dialogs."); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { // Open dump file pd = dump_open(fullfile); if (access(fullfile, W_OK) != 0) { dialog_run(capture_last_error()); return 1; } } else { // Open a text file if (!(f = fopen(fullfile, "w"))) { dialog_run("Error: %s", strerror(errno)); return 0; } } // Get calls iterator switch (info->savemode) { case SAVE_ALL: // Get calls iterator calls = sip_calls_iterator(); break; case SAVE_SELECTED: // Save selected packets to file calls = vector_iterator(info->group->calls); break; case SAVE_DISPLAYED: // Set filtering for this iterator calls = sip_calls_iterator(); vector_iterator_set_filter(&calls, filter_check_call); break; default: break; } if (info->savemode == SAVE_MESSAGE) { if (info->saveformat == SAVE_TXT) { // Save selected message to file save_msg_txt(f, info->msg); } else { // Save selected message packet to pcap dump_packet(pd, info->msg->packet); } } else if (info->saveformat == SAVE_TXT) { // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { save_msg_txt(f, msg); } } } else { // Store all messages in a time sorted vector sorted = vector_create(100, 50); vector_set_sorter(sorted, capture_packet_time_sorter); // Count packages for progress bar while ((call = vector_iterator_next(&calls))) { total += vector_count(call->msgs); if (info->saveformat == SAVE_PCAP_RTP) total += vector_count(call->rtp_packets); } vector_iterator_reset(&calls); progress = dialog_progress_run("Saving packets..."); dialog_progress_set_value(progress, 0); // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, msg->packet); } // Save RTP packets if (info->saveformat == SAVE_PCAP_RTP) { rtps = vector_iterator(call->rtp_packets); while ((packet = vector_iterator_next(&rtps))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, packet); } } } // Save sorted packets packets = vector_iterator(sorted); while ((packet = vector_iterator_next(&packets))) { dump_packet(pd, packet); } dialog_progress_destroy(progress); } // Close saved file if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { dump_close(pd); } else { fclose(f); } // Show success popup if (info->savemode == SAVE_MESSAGE) { dialog_run("Successfully saved selected SIP message to %s", savefile); } else { dialog_run("Successfully saved %d dialogs to %s", vector_iterator_count(&calls), savefile); } return 0; }
int save_handle_key(ui_t *ui, int key) { int field_idx; int action = -1; // Get panel information save_info_t *info = save_info(ui); // Get current field id field_idx = field_index(current_field(info->form)); // Check actions for this key while ((action = key_find_action(key, action)) != ERR) { // Check if we handle this action switch (action) { case ACTION_PRINTABLE: if (field_idx == FLD_SAVE_PATH || field_idx == FLD_SAVE_FILE) { form_driver(info->form, key); break; } continue; case ACTION_NEXT_FIELD: form_driver(info->form, REQ_NEXT_FIELD); form_driver(info->form, REQ_END_LINE); break; case ACTION_PREV_FIELD: form_driver(info->form, REQ_PREV_FIELD); form_driver(info->form, REQ_END_LINE); break; case ACTION_RIGHT: form_driver(info->form, REQ_RIGHT_CHAR); break; case ACTION_LEFT: form_driver(info->form, REQ_LEFT_CHAR); break; case ACTION_BEGIN: form_driver(info->form, REQ_BEG_LINE); break; case ACTION_END: form_driver(info->form, REQ_END_LINE); break; case ACTION_DELETE: form_driver(info->form, REQ_DEL_CHAR); break; case ACTION_BACKSPACE: form_driver(info->form, REQ_DEL_PREV); break; case ACTION_CLEAR: form_driver(info->form, REQ_CLR_FIELD); break; case ACTION_SELECT: switch (field_idx) { case FLD_SAVE_ALL: info->savemode = SAVE_ALL; break; case FLD_SAVE_SELECTED: info->savemode = SAVE_SELECTED; break; case FLD_SAVE_DISPLAYED: info->savemode = SAVE_DISPLAYED; break; case FLD_SAVE_MESSAGE: info->savemode = SAVE_MESSAGE; break; case FLD_SAVE_PCAP: info->saveformat = SAVE_PCAP; break; case FLD_SAVE_PCAP_RTP: info->saveformat = SAVE_PCAP_RTP; break; case FLD_SAVE_TXT: info->saveformat = SAVE_TXT; break; case FLD_SAVE_FILE: form_driver(info->form, key); break; default: break; } break; case ACTION_CONFIRM: if (field_idx != FLD_SAVE_CANCEL) { save_to_file(ui); } ui_destroy(ui); return KEY_HANDLED; default: // Parse next action continue; } // This panel has handled the key successfully break; } // Validate all input data form_driver(info->form, REQ_VALIDATION); // Change background and cursor of "button fields" set_field_back(info->fields[FLD_SAVE_SAVE], A_NORMAL); set_field_back(info->fields[FLD_SAVE_CANCEL], A_NORMAL); curs_set(1); // Change current field background field_idx = field_index(current_field(info->form)); if (field_idx == FLD_SAVE_SAVE || field_idx == FLD_SAVE_CANCEL) { set_field_back(info->fields[field_idx], A_REVERSE); curs_set(0); } // Return if this panel has handled or not the key return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED; }