void client_writecb(event_loop_t *loop, int fd, void *data) { int rv; connection_t *conn; conn = data; rv = buffer_chain_send(conn->chain, fd); if (rv < 0) { printf("[w]send error, close......\n"); delete_event(loop, fd, EV_RDABLE|EV_WRABLE); close(fd); return; } conn->total -= conn->chain->sent; send_total += conn->chain->sent; if (conn->total == 0) { delete_event(loop, fd, EV_WRABLE); conn->writing = 0; if (conn->eof) { shutdown(fd, SHUT_WR); } } }
stf_status build_nonce(struct pluto_crypto_req_cont *cn , struct state *st , enum crypto_importance importance) { struct pluto_crypto_req rd; struct pluto_crypto_req *r = &rd; err_t e; bool toomuch = FALSE; pcr_init(r, pcr_build_nonce, importance); cn->pcrc_serialno = st->st_serialno; e = send_crypto_helper_request(r, cn, &toomuch); if(e != NULL) { loglog(RC_LOG_SERIOUS, "can not start crypto helper: %s", e); if(toomuch) { return STF_TOOMUCHCRYPTO; } else { return STF_FAIL; } } else if(!toomuch) { st->st_calculating = TRUE; delete_event(st); event_schedule(EVENT_CRYPTO_FAILED, EVENT_CRYPTO_FAILED_DELAY, st); return STF_SUSPEND; } else { /* we must have run the continuation directly, so * complete_v1_state_transition already got called. */ return STF_INLINE; } }
static void do_read(int epollfd,int fd,int sockfd,char *buf) { int nread; nread = read(fd,buf,MAXSIZE); if (nread == -1) { perror("read error:"); close(fd); } else if (nread == 0) { fprintf(stderr,"server close.\n"); close(fd); } else { if (fd == STDIN_FILENO) add_event(epollfd,sockfd,EPOLLOUT); else { delete_event(epollfd,sockfd,EPOLLIN); add_event(epollfd,STDOUT_FILENO,EPOLLOUT); } } }
void do_read(int epollfd, int fd, char* buf){ int nread; nread = read(fd, buf, MAXSIZE); if(nread == -1){ perror("read error:"); close(fd); delete_event(epollfd, fd, EPOLLIN); }else if(nread == 0){ fprintf(stderr, "client close.\n"); close(fd); delete_event(epollfd, fd, EPOLLIN); }else{ printf("read message is : %s", buf); modify_event(epollfd, fd, EPOLLOUT); } }
UINT MIDIFile::change_rpn_nrpn(UINT type, bool absolute, int id, int value, bool percent) { // id >= 0: change for one event only // value new value // percent = HP_PERCENT: change old value with percent-value, 150: +50%, 60: 60% // percent = HP_NO_PERCENT: new value gets value int read_time, read_chan, read_number, read_value, new_value; bool read_absolute; int result; if ((id < 0) || (id >= eventlist->get_length())) return HP_ERR_RANGE_EVENTLIST; result = read_rpn_nrpn(type,id,&read_time,&read_chan,&read_absolute,&read_number,&read_value); if (result != HP_ERR_NONE) return result; delete_event(id); if (absolute) { new_value = (percent==HP_PERCENT)?(read_value*value/100):value; } else { new_value = value; } return insert_rpn_nrpn(read_time,read_chan,type, read_number,new_value, read_absolute); }
static void do_read(int epollfd, int fd, char *buf) { int nread; nread = read(fd, buf, MAXSIZE); if (nread == -1) { perror("read error: "); close(fd); delete_event(epollfd, fd, EPOLLIN); } else if (nread == 0) { fprintf(stderr, "client close.\n"); close(fd); delete_event(epollfd, fd, EPOLLIN); } else { buf[strlen(buf)] = '\0'; printf("read message is : %s", buf); /* 修改描述符对应的事件,由读改为写 */ modify_event(epollfd, fd, EPOLLOUT); } }
void do_write(int epollfd, int fd, char* buf){ int nwrite; nwrite = write(fd, buf , strlen(buf)); if(nwrite == -1){ perror("write error:"); close(fd); delete_event(epollfd, fd, EPOLLOUT); }else modify_event(epollfd, fd, EPOLLIN); memset(buf, 0, MAXSIZE); }
static void do_read( int _epollfd, int _fd, char* _buf ) { int nread = ::read( _fd, _buf, MAXSIZE ); if( nread == -1 ) { perror( "read error:" ); ::close( _fd ); delete_event( _epollfd, _fd, EPOLLIN ); } else if( nread == 0 ) { fprintf( stderr, "client close.\n" ); ::close( _fd ); delete_event( _epollfd, _fd, EPOLLIN ); } else { printf( "read message is : %s", _buf ); modify_event( _epollfd, _fd, EPOLLIN ); } }
void client_readcb(event_loop_t *loop, int fd, void *data) { int rv; connection_t *conn; conn = data; rv = buffer_chain_recv(conn->chain, fd); if (rv < 0 || (rv == 0 && conn->total == 0)) { delete_event(loop, fd, EV_RDABLE|EV_WRABLE); close(fd); return; } if (rv == 0) { delete_event(loop, fd, EV_RDABLE); shutdown(fd, SHUT_RD); conn->eof = 1; return; } conn->total += conn->chain->recv; recv_total += conn->chain->recv; if (!conn->writing) { rv = buffer_chain_send(conn->chain, fd); if (rv < 0) { printf("[r]send error, close......\n"); delete_event(loop, fd, EV_RDABLE|EV_WRABLE); close(fd); return; } conn->total -= conn->chain->sent; send_total += conn->chain->sent; if (conn->total > 0) { create_event(loop, fd, EV_WRABLE, client_writecb, conn); conn->writing = 1; } } }
void editor_maybe_save_all(void) { GList *tmp, *tmp2; tmp = g_list_first(editors_all); while (tmp != NULL) { /* 2ndary list chaser: elements will be removed by the saver. */ tmp2 = g_list_next(tmp); delete_event(NULL, NULL, (EDITOR *)tmp->data); tmp = tmp2; } }
static void do_write(int epollfd, int fd, int sockfd, char *buf) { int nwrite; nwrite = write(fd, buf, strlen(buf)); if(nwrite == -1){ ERR_EXIT("write error"); }else{ if(fd == STDIN_FILENO){ delete_event(epollfd, sockfd, EPOLLOUT); }else{ modify_event(epollfd, fd, EPOLLIN); } } }
static void do_read(int epollfd,int fd,char *buf) { int nread; nread = read(fd,buf,MAXSIZE); if (nread == -1) { perror("read error:"); close(fd); delete_event(epollfd,fd,EPOLLIN); } else if (nread == 0) { fprintf(stderr,"client close, fd:%d\n", fd); close(fd); delete_event(epollfd,fd,EPOLLIN); } else { printf("read message is : %s",buf); //修改描述符对应的事件,由读改为写 fprintf(stdout, "do_read: modify_event(epollfd,fd,EPOLLOUT), fd:%d\n", fd); modify_event(epollfd,fd,EPOLLOUT); } }
static void do_write( int _epollfd, int _fd, char* _buf ) { int nwrite = ::write( _fd, _buf, strlen(_buf) ); if( nwrite == -1 ) { perror( "write error:" ); ::close( _fd ); delete_event( _epollfd, _fd, EPOLLOUT ); } else { modify_event( _epollfd, _fd, EPOLLOUT ); } ::memset( _buf, 0, MAXSIZE ); }
void do_read(int epollfd,int fd,char *buf) { int nread; int size; nread = read(fd,&size,4); if (nread == -1) { perror("read error:"); close(fd); delete_event(epollfd,fd,EPOLLIN); } else if (nread == 0) { fprintf(stderr,"client close.\n"); close(fd); delete_event(epollfd,fd,EPOLLIN); } else { recvFromClient(fd,size); //修改描述符对应的事件,由读改为写 modify_event(epollfd,fd,EPOLLOUT); } }
UINT MIDIFile::change_smpte_offset(int id , int hr, int mn, int se, int fr, int ff) { int result; int read_hr, read_mn, read_se, read_fr, read_ff; if ((id < 0) || (id >= eventlist->get_length())) return HP_ERR_RANGE_EVENTLIST; result = read_smpte_offset(id,&read_hr,&read_mn,&read_se,&read_fr,&read_ff); if (result != HP_ERR_NONE) return result; delete_event(id); return insert_smpte_offset(hr,mn,se,fr,ff); }
void finiThreadPool(struct ThreadPool *p) { p->fini_all = true; for (int i=0; i<p->num_thread; i++) { notify_event(p->threads[i].to_client); } for (int i=0; i<p->num_thread; i++) { p->threads[i].t.join(); } delete [] p->threads; delete_event(p->to_master); }
void remote_button_action(gint button_num) { switch(button_num) { case RC_0: case RC_1: case RC_2: case RC_3: case RC_4: case RC_5: case RC_6: case RC_7: case RC_8: case RC_9: set_timeout_goto_channel(button_num - RC_0); break; case RC_MUTE: toggle_audio(); break; case RC_CHAN_UP: increase_channel(1); break; case RC_CHAN_DOWN: increase_channel(-1); break; case RC_FULLSCREEN: toggle_fullscreen(); break; case RC_SCREENSHOT: create_screenshot(); break; case RC_QUIT: if (!delete_event(NULL, NULL, NULL)) destroy(NULL, NULL); break; #ifdef OSS case RC_VOLUME_UP: set_volume(volume + 2); break; case RC_VOLUME_DOWN: set_volume(volume - 2); break; #endif case RC_PREVIOUS_CHAN: goto_previous_channel(); break; } }
/** * DPD Timeout Function * * This function is called when a timeout DPD_EVENT occurs. We set clear/trap * both the SA and the eroutes, depending on what the connection definition * tells us (either 'hold' or 'clear') * * @param st A state structure that is fully negotiated * @return void */ void dpd_timeout(struct state *st) { int action; struct connection *c = st->st_connection; action = st->st_connection->dpd_action; /* probably wrong thing to assert here */ passert(action == DPD_ACTION_HOLD || action == DPD_ACTION_CLEAR || action == DPD_ACTION_RESTART); /** delete the state, which is probably in phase 2 */ set_cur_connection(c); log("DPD: No response from peer - declaring peer dead"); switch(action) { case DPD_ACTION_HOLD: /** dpdaction=hold - Wipe the SA's but %trap the eroute so we don't leak traffic. Also, being in %trap means new packets will force an initiation of the conn again. */ log("DPD: Putting connection into %%trap"); delete_states_by_connection(c); break; case DPD_ACTION_CLEAR: /** dpdaction=clear - Wipe the SA & eroute - everything */ log("DPD: Clearing Connection"); delete_states_by_connection(c); DBG(DBG_DPD, DBG_log("unrouting connection")); unroute_connection(c); /* --unroute */ break; case DPD_ACTION_RESTART: /** dpdaction=restart - immediate renegotiate the connection. */ log("DPD: Restarting Connection"); /* we replace the SA so that we do it in a rational place */ delete_event(st); event_schedule(EVENT_SA_REPLACE, 0, st); break; } reset_cur_connection(); }
static void do_write(int epollfd,int fd,char *buf) { int nwrite; nwrite = write(fd,buf,strlen(buf)); if (nwrite == -1) { perror("write error:"); close(fd); delete_event(epollfd,fd,EPOLLOUT); } else { fprintf(stdout, "do_write: modify_event(epollfd,fd,EPOLLIN), fd:%d\n", fd); modify_event(epollfd,fd,EPOLLIN); } memset(buf,0,MAXSIZE); }
UINT MIDIFile::change_texttype(int id, UINT type,char* new_text) { int read_time, read_chan; int result; char *read_text; if ((id < 0) || (id >= eventlist->get_length())) return HP_ERR_RANGE_EVENTLIST; result = read_text_from_meta(id,&read_time,type,&read_chan,&read_text); delete[] read_text; if (result != HP_ERR_NONE) return result; delete_event(id); return insert_texttype(read_time,type,new_text, read_chan); }
static void do_write(int epollfd,int fd,int sockfd,char *buf) { int nwrite; nwrite = write(fd,buf,strlen(buf)); if (nwrite == -1) { perror("write error:"); close(fd); } else { if (fd == STDOUT_FILENO) delete_event(epollfd,fd,EPOLLOUT); else modify_event(epollfd,fd,EPOLLIN); } memset(buf,0,MAXSIZE); }
static void do_read(int epollfd, int fd, int sockfd, char *buf) { int nread; nread = read(fd, buf, MAXSIZE); if(nread == -1){ ERR_EXIT("read error"); }else if(nread == 0){ cerr << "Server close" << endl; close(fd); }else{ if(fd == STDIN_FILENO){ add_event(epollfd, sockfd, EPOLLOUT); }else{ delete_event(epollfd, sockfd, EPOLLIN); add_event(epollfd, sockfd, EPOLLOUT); } } }
// leader/flower模式 static void *worker_main(void *arg) { pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); // struct timeval { // time_t tv_sec; /* seconds */ // suseconds_t tv_usec; /* microseconds */ // }; // tv_usec 的说明为时间的毫秒部分 struct timeval tv = {1, 0}; // daemon_quit 退出标识。 0 没有退出、1退出 while (!daemon_quit) { pthread_mutex_lock(&leader); AGAIN: while(loop.nready == 0 && daemon_quit == 0) // 取出事件 loop.nready = aeApiPoll(&loop, &tv); if (daemon_quit) { pthread_mutex_unlock(&leader); break; } // 遍历事件 loop.nready --; int fd = loop.fired[loop.nready]; conn *c = loop.conns[fd]; if (c == NULL){ fprintf(stderr, "Bug: conn %d should not be NULL\n", fd); delete_event(fd); close(fd); goto AGAIN; } //loop.conns[fd] = NULL; pthread_mutex_unlock(&leader); if (drive_machine(c)) { if (update_event(fd, c->ev_flags, c)) conn_close(c); } } return NULL; }
UINT MIDIFile::change_velocity_selected(int value, bool percent) { // percent = HP_PERCENT: change old velocity with percent-value, 150: +50%, 60: 60% // percent = HP_NO_PERCENT: new velocity gets value int old_vel, new_vel; MIDIEvent *mev; // look at all note_on int i; for (i=0; i < eventlist->get_length(); i++) { mev = eventlist->get(i); if ((mev->type != HP_NOTE_ON)||(mev->selected == 0)) { continue; } old_vel = ((NoteOnEvent*)mev)->vel(); new_vel = (percent==HP_PERCENT)?(old_vel*value/100):value; if (new_vel <= 0) { delete_event(i); // delete note i--; eventlist->sort(); } else { if (new_vel > 127) new_vel = 127; ((NoteOnEvent*)mev)->set_vel(new_vel); } } return HP_ERR_NONE; }
static gboolean on_vbox1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { /* these are the mods we actually use for global keys, we always only check for these set */ guint state = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_MOD4_MASK); switch (event->keyval) { case XK_Shift_L: /* shift keys - we need this for locking strongs (and */ case XK_Shift_R: /* other stuff) while moving mouse to previewer */ shift_key_pressed = TRUE; /* no break? hm... */ case XK_a: case XK_A: if (state == GDK_MOD1_MASK) { // Alt-A annotation gui_mark_verse_dialog(sM, sV); } else if (state == (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)) on_biblesync_kbd(3); // BSP audience break; case XK_b: case XK_B: if (state == GDK_MOD1_MASK) { // Alt-B bookmark gchar *label = g_strdup_printf("%s, %s", sV, sM); gui_bookmark_dialog(label, sM, sV); g_free(label); } break; case XK_c: case XK_C: if (state == GDK_MOD1_MASK) { // Alt-C commentary pane gtk_widget_grab_focus(navbar_versekey.lookup_entry); gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets.notebook_comm_book), 0); } break; case XK_d: case XK_D: if (state == GDK_MOD1_MASK) // Alt-D dictionary entry gtk_widget_grab_focus(widgets.entry_dict); break; case XK_f: case XK_F: if (state == GDK_CONTROL_MASK) { // Ctrl-F find text if (settings.showtexts) { gui_find_dlg(widgets.html_text, sM, FALSE, NULL); } else if (settings.showcomms) { if (settings.comm_showing) { gui_find_dlg(widgets.html_comm, sC, FALSE, NULL); } else { gui_find_dlg(widgets.html_book, sB, FALSE, NULL); } } else if (settings.showdicts) { gui_find_dlg(widgets.html_dict, sD, FALSE, NULL); } else gui_generic_warning(_("Xiphos: No windows.")); } break; case XK_g: case XK_G: if (state == GDK_MOD1_MASK) { // Alt-G genbook entry gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets.notebook_comm_book), 1); gtk_widget_grab_focus(navbar_book.lookup_entry); } break; case XK_j: if (state == 0) // J "next verse" access_on_down_eventbox_button_release_event(VERSE_BUTTON); break; case XK_k: if (state == 0) // K "previous verse" access_on_up_eventbox_button_release_event(VERSE_BUTTON); break; case XK_l: case XK_L: if (state == GDK_CONTROL_MASK) // Ctrl-L verse entry gtk_widget_grab_focus(navbar_versekey.lookup_entry); break; case XK_m: case XK_M: if (state == GDK_MOD1_MASK) // Alt-M morph { kbd_toggle_option((main_check_for_global_option(sM, "GBFMorph") || main_check_for_global_option(sM, "ThMLMorph") || main_check_for_global_option(sM, "OSISMorph")), "Morphological Tags"); } break; case XK_n: case XK_N: if (state == GDK_CONTROL_MASK) // Ctrl-N verse access_on_down_eventbox_button_release_event(VERSE_BUTTON); else if (state == 0) // n chapter access_on_down_eventbox_button_release_event(CHAPTER_BUTTON); else if (state == GDK_SHIFT_MASK) // N book access_on_down_eventbox_button_release_event(BOOK_BUTTON); else if (state == (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)) { // BSP transient navigate if (biblesync_active_xmit_allowed()) { biblesync_prep_and_xmit(sM, sV); gui_set_statusbar(_("BibleSync: Current navigation sent.")); } else { gui_generic_warning(_("BibleSync: Not speaking.")); } } break; case XK_o: case XK_O: if (state == (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)) on_biblesync_kbd(0); // BSP off break; case XK_p: case XK_P: if (state == GDK_CONTROL_MASK) // Ctrl-P verse access_on_up_eventbox_button_release_event(VERSE_BUTTON); else if (state == 0) // p chapter access_on_up_eventbox_button_release_event(CHAPTER_BUTTON); else if (state == GDK_SHIFT_MASK) // P book access_on_up_eventbox_button_release_event(BOOK_BUTTON); else if (state == GDK_MOD1_MASK) // Alt-P parallel detach on_undockInt_activate(NULL); else if (state == (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)) on_biblesync_kbd(1); // BSP personal break; case XK_q: case XK_Q: if (state == GDK_CONTROL_MASK) // Ctrl-Q quit delete_event(NULL, NULL, NULL); break; case XK_r: case XK_R: if (state == GDK_MOD1_MASK) // Alt-R red words { kbd_toggle_option(((main_check_for_global_option(sM, "GBFRedLetterWords")) || (main_check_for_global_option(sM, "OSISRedLetterWords"))), "Words of Christ in Red"); } break; case XK_s: case XK_S: if (state == GDK_MOD1_MASK) // Alt-S strong's { kbd_toggle_option(((main_check_for_global_option(sM, "GBFStrongs")) || (main_check_for_global_option(sM, "ThMLStrongs")) || (main_check_for_global_option(sM, "OSISStrongs"))), "Strong's Numbers"); } else if (state == (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)) on_biblesync_kbd(2); // BSP speaker break; case XK_t: case XK_T: if (state == GDK_CONTROL_MASK) // open a new tab on_notebook_main_new_tab_clicked(NULL, NULL); break; case XK_z: case XK_Z: if (state == GDK_MOD1_MASK) // Alt-Z open personal commentary access_to_edit_percomm(); break; case XK_plus: // Ctrl-Plus Increase base font size if (state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) new_base_font_size(TRUE); break; case XK_minus: // Ctrl-Minus Decrease base font size if (state == GDK_CONTROL_MASK) new_base_font_size(FALSE); break; case XK_0: // Ctrl-0 (zero) Neutralize base font size. if (state == GDK_CONTROL_MASK) { settings.base_font_size = 1; new_base_font_size(FALSE); } break; // ctrl-DIGIT [1-9] selects DIGIT-th tab. case XK_1: case XK_2: case XK_3: case XK_4: case XK_5: case XK_6: case XK_7: case XK_8: case XK_9: if (state == GDK_CONTROL_MASK) gui_select_nth_tab((event->keyval - XK_0) - 1); /* 0-based list */ case XK_F1: // F1 help if (state == 0) on_help_contents_activate(NULL, NULL); break; case XK_F2: // F2 preferences if (state == 0) on_preferences_activate(NULL, NULL); break; case XK_F3: // F3 search if (state == 0) main_open_search_dialog(); else if (state == GDK_CONTROL_MASK) gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets.notebook_sidebar), 2); break; case XK_F4: // F4 module manager if (state == 0) on_module_manager_activate(NULL, NULL); else if (state == GDK_CONTROL_MASK) gui_close_passage_tab(gtk_notebook_page_num(GTK_NOTEBOOK(widgets.notebook_main), ((PASSAGE_TAB_INFO *) cur_passage_tab)->page_widget)); break; case XK_F10: // Shift-F10 bible module right click if (state == GDK_SHIFT_MASK) gui_menu_popup(NULL, sM, NULL); /* FIXME: needs the html widget as first pram */ break; } XI_message(("on_vbox1_key_press_event\nkeycode: %d, keysym: %0x, state: %d", event->hardware_keycode, event->keyval, state)); return FALSE; }
int main() { vector<string> classes; //the first line of the ics7 file contains the elements of this icalproperty_set_x_name(ical_x_class_prop, "X-CLASS"); icalcomponent* calendar = NULL; struct icaltimetype atime; struct icalperiodtype rtime; //FIXME Later versions will try to load from the default file here //If we don't have a saved calendar, make a new one if (calendar == NULL) { atime = icaltime_from_timet( time(0),0); rtime.start = icaltime_from_timet( time(0),0); rtime.end = icaltime_from_timet( time(0),0); rtime.end.hour++; calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); } //FIXME Find all non-school days by prompt? //FIXME Ask for start/end of semester //Actually manipulating the calendar while (true) { //Prompt for user action cout << "What would you like to do?\n" << "1. Add a class\n" << "2. Add an event\n" << "3. Delete an event\n" << "4. Edit an event\n" << "5. Find an event\n" << "6. View an event\n" << "7. Delete a class\n" << "8. Exit the program\n" << endl; cout << "Enter the integer corresponding to your choice" << endl; string user_choice = ""; cin >> user_choice; bool user_choice_flag = true; //Check the string is all digits for (int i = 0; i < user_choice.size(); i++) { if (!isdigit(user_choice[i])) { cout << "Invalid selection (Not all digits)" << endl; user_choice_flag = false; break; } } if (!user_choice_flag) { continue; } //Given the choice, perform the desired action switch (atoi(user_choice.c_str())) { //ADD CLASS case 1: { add_class(calendar, classes); break; } //ADD EVENT (for a class or in general) case 2: { add_event(calendar); break; } //DELETE SINGLE EVENT case 3: { delete_event(calendar); break; } //EDIT EVENT (class or general) case 4: { edit_event(calendar); break; } //FIND EVENT case 5: { icalcomponent* event = find_event(calendar); if (event == NULL) { append_action_to_closed_log("Find event", false); }else { append_action_to_closed_log("Find event", true); } break; } //VIEW EVENT case 6: { view_event(calendar); break; } //DELETE CLASS //FIXME Not implemented in this sprint case 7: { //FIXME Ask for class name //FIXME Scan through first level of components for class //FIXME Print all matches and get the one to delete //FIXME Warn that all events for that class will be deleted //FIXME Delete class after user okay cout << "This feature is not implemented in this sprint." << endl; break; } //EXIT case 8: { //Prompt for okay if (yes_no_prompt("Your calendar data will not be saved. Continue? (y/n)")) { return 0; } break; } default: { cout << "Invalid selection (Not between 1 and 8 inclusive)" << endl; break; } } } return 0; }
/* delete a state object */ void delete_state(struct state *st) { struct connection *const c = st->st_connection; struct state *old_cur_state = cur_state == st? NULL : cur_state; openswan_log("deleting state #%lu (%s)", st->st_serialno, enum_show(&state_names, st->st_state)); /* * for most IKEv2 things, we may have further things to do after marking the state deleted, * so we do not actually free it here at all, but back in the main loop when all the work is done. */ if(st->st_ikev2) { /* child sa*/ if(st->st_clonedfrom != 0) { DBG(DBG_CONTROL, DBG_log("received request to delete child state")); if(st->st_state == STATE_CHILDSA_DEL) { DBG(DBG_CONTROL, DBG_log("now deleting the child state")); } else { /* Only send request if child sa is established * otherwise continue with deletion */ if(IS_CHILD_SA_ESTABLISHED(st)) { DBG(DBG_CONTROL, DBG_log("sending Child SA delete equest")); send_delete(st); change_state(st, STATE_CHILDSA_DEL); /* actual deletion when we receive peer response*/ return; } } } else { DBG(DBG_CONTROL, DBG_log("considering request to delete IKE parent state")); /* parent sa */ if(st->st_state == STATE_IKESA_DEL) { DBG(DBG_CONTROL, DBG_log("now deleting the IKE (or parent) state")); } else { /* Another check to verify if a secured * INFORMATIONAL exchange can be sent or not */ if(st->st_skey_ei.ptr && st->st_skey_ai.ptr && st->st_skey_er.ptr && st->st_skey_ar.ptr) { DBG(DBG_CONTROL, DBG_log("sending IKE SA delete request")); send_delete(st); change_state(st, STATE_IKESA_DEL); /* actual deletion when we receive peer response*/ return; } } } } /* If DPD is enabled on this state object, clear any pending events */ if(st->st_dpd_event != NULL) delete_dpd_event(st); /* if there is a suspended state transition, disconnect us */ if (st->st_suspended_md != NULL) { passert(st->st_suspended_md->st == st); DBG(DBG_CONTROL, DBG_log("disconnecting state #%lu from md", st->st_serialno)); st->st_suspended_md->st = NULL; } /* tell the other side of any IPSEC SAs that are going down */ if (IS_IPSEC_SA_ESTABLISHED(st->st_state) || IS_ISAKMP_SA_ESTABLISHED(st->st_state)) send_delete(st); delete_event(st); /* delete any pending timer event */ /* Ditch anything pending on ISAKMP SA being established. * Note: this must be done before the unhash_state to prevent * flush_pending_by_state inadvertently and prematurely * deleting our connection. */ flush_pending_by_state(st); /* if there is anything in the cryptographic queue, then remove this * state from it. */ delete_cryptographic_continuation(st); /* effectively, this deletes any ISAKMP SA that this state represents */ unhash_state(st); /* tell kernel to delete any IPSEC SA * ??? we ought to tell peer to delete IPSEC SAs */ if (IS_IPSEC_SA_ESTABLISHED(st->st_state) || IS_CHILD_SA_ESTABLISHED(st)) delete_ipsec_sa(st, FALSE); else if (IS_ONLY_INBOUND_IPSEC_SA_ESTABLISHED(st->st_state)) delete_ipsec_sa(st, TRUE); if (c->newest_ipsec_sa == st->st_serialno) c->newest_ipsec_sa = SOS_NOBODY; if (c->newest_isakmp_sa == st->st_serialno) c->newest_isakmp_sa = SOS_NOBODY; /* * fake a state change here while we are still associated with a * connection. Without this the state logging (when enabled) cannot * work out what happened. */ fake_state(st, STATE_UNDEFINED); st->st_connection = NULL; /* we might be about to free it */ cur_state = old_cur_state; /* without st_connection, st isn't complete */ connection_discard(c); change_state(st, STATE_UNDEFINED); release_whack(st); change_state(st, STATE_CHILDSA_DEL); }
/* here we are just freeing RAM */ void free_state(struct state *st) { delete_event(st); /* delete any pending timer event */ { struct msgid_list *p = st->st_used_msgids; while (p != NULL) { struct msgid_list *q = p; p = p->next; pfree(q); } } unreference_key(&st->st_peer_pubkey); free_sa(st->st_sadb); st->st_sadb=NULL; if (st->st_sec_in_use) { #ifdef HAVE_LIBNSS SECKEYPrivateKey *privk; SECKEYPublicKey *pubk; memcpy(&pubk,st->pubk.ptr,st->pubk.len); SECKEY_DestroyPublicKey(pubk); freeanychunk(st->pubk); memcpy(&privk,st->st_sec_chunk.ptr,st->st_sec_chunk.len); SECKEY_DestroyPrivateKey(privk); #else mpz_clear(&(st->st_sec)); #endif pfreeany(st->st_sec_chunk.ptr); } freeanychunk(st->st_firstpacket_me); freeanychunk(st->st_firstpacket_him); freeanychunk(st->st_tpacket); freeanychunk(st->st_rpacket); freeanychunk(st->st_p1isa); freeanychunk(st->st_gi); freeanychunk(st->st_gr); freeanychunk(st->st_shared); freeanychunk(st->st_ni); freeanychunk(st->st_nr); #ifdef HAVE_LIBNSS free_osw_nss_symkey(st->st_skeyid); free_osw_nss_symkey(st->st_skey_d); free_osw_nss_symkey(st->st_skey_ai); free_osw_nss_symkey(st->st_skey_ar); free_osw_nss_symkey(st->st_skey_ei); free_osw_nss_symkey(st->st_skey_er); free_osw_nss_symkey(st->st_skey_pi); free_osw_nss_symkey(st->st_skey_pr); free_osw_nss_symkey(st->st_enc_key); if(st->st_ah.our_keymat!=NULL) memset(st->st_ah.our_keymat, 0, st->st_ah.keymat_len); if(st->st_ah.peer_keymat!=NULL) memset(st->st_ah.peer_keymat, 0, st->st_ah.keymat_len); if(st->st_esp.our_keymat!=NULL) memset(st->st_esp.our_keymat, 0, st->st_esp.keymat_len); if(st->st_esp.peer_keymat!=NULL) memset(st->st_esp.peer_keymat, 0, st->st_esp.keymat_len); #endif freeanychunk(st->st_skeyid); freeanychunk(st->st_skey_d); freeanychunk(st->st_skey_ai); freeanychunk(st->st_skey_ar); freeanychunk(st->st_skey_ei); freeanychunk(st->st_skey_er); freeanychunk(st->st_skey_pi); freeanychunk(st->st_skey_pr); freeanychunk(st->st_enc_key); pfreeany(st->st_ah.our_keymat); pfreeany(st->st_ah.peer_keymat); pfreeany(st->st_esp.our_keymat); pfreeany(st->st_esp.peer_keymat); freeanychunk(st->st_xauth_password); #ifdef HAVE_LABELED_IPSEC pfreeany(st->sec_ctx); #endif pfree(st); }
/** * DPD Timeout Function * * This function is called when a timeout DPD_EVENT occurs. We set clear/trap * both the SA and the eroutes, depending on what the connection definition * tells us (either 'hold' or 'clear') * * @param st A state structure that is fully negotiated * @return void */ void dpd_timeout(struct state *st) { int action; struct connection *c = st->st_connection; action = st->st_connection->dpd_action; /* probably wrong thing to assert here */ passert(action == DPD_ACTION_HOLD || action == DPD_ACTION_CLEAR || action == DPD_ACTION_RESTART || action == DPD_ACTION_RESTART_BY_PEER ); /** delete the state, which is probably in phase 2 */ set_cur_connection(c); openswan_log("DPD: No response from peer - declaring peer dead"); switch(action) { case DPD_ACTION_HOLD: /** dpdaction=hold - Wipe the SA's but %trap the eroute so we don't leak traffic. Also, being in %trap means new packets will force an initiation of the conn again. */ openswan_log("DPD: Putting connection into %%trap"); delete_states_by_connection(c, TRUE); break; case DPD_ACTION_CLEAR: /** dpdaction=clear - Wipe the SA & eroute - everything */ openswan_log("DPD: Clearing Connection"); delete_states_by_connection(c, TRUE); DBG(DBG_DPD, DBG_log("unrouting connection")); unroute_connection(c); /* --unroute */ break; case DPD_ACTION_RESTART: /** dpdaction=restart - immediate renegotiate the connection. */ openswan_log("DPD: Restarting Connection"); /* * unlike the other kinds, we do not delete any states, * but rather, we arrange to replace all SAs involved. */ rekey_p2states_by_connection(c); if (c->kind == CK_INSTANCE) { /* If this is a template (eg: right=%any) we won't be able to * reinitiate, the peer has probably changed IP addresses, * or isn't available anymore. So remove the routes too */ unroute_connection(c); /* --unroute */ } /* we schedule the replace of the SA so that we do it * in a rational place and do it at a negative future time, * so it will occur before any of the phase 2 replacements. */ delete_event(st); delete_dpd_event(st); event_schedule(EVENT_SA_REPLACE, 0, st); case DPD_ACTION_RESTART_BY_PEER: /* dpdaction=restart_by_peer - immediately renegotiate connections to the same peer. */ openswan_log("DPD: Restarting all connections that share this peer"); restart_connections_by_peer(c); break; break; } reset_cur_connection(); }
G_MODULE_EXPORT void action_quit_activate_cb(GtkWidget *widget, EDITOR *e) { delete_event(NULL, NULL, e); }