/* this is the main function with the loops and modes */ void shoot(char *buf, int buff_size) { struct timespec sleep_ms_s, sleep_rem; int ret, cseqtmp, rand_tmp; char buf2[BUFSIZE], buf3[BUFSIZE], lport_str[LPORT_STR_LEN]; /* delays.retryAfter = DEFAULT_TIMEOUT; */ if (transport == SIP_UDP_TRANSPORT) { delays.retryAfter = timer_t1; } else { delays.retryAfter = timer_final; } inv_trans = 0; cseq_counter = 1; usrlocstep = REG_REP; /* initalize local vars */ cdata.dontsend=cdata.dontrecv=counters.retrans_r_c=counters.retrans_s_c= 0; delays.big_delay=counters.send_counter=counters.run= 0; timers.delaytime.tv_sec = 0; timers.delaytime.tv_usec = 0; usern = NULL; /* initialize local arrays */ memset(buf2, 0, BUFSIZE); memset(buf3, 0, BUFSIZE); memset(lport_str, 0, LPORT_STR_LEN); cdata.csock = cdata.usock = -1; cdata.connected = 0; cdata.buf_tmp = NULL; cdata.buf_tmp_size = 0; memset(&(timers.sendtime), 0, sizeof(timers.sendtime)); memset(&(timers.recvtime), 0, sizeof(timers.recvtime)); memset(&(timers.firstsendt), 0, sizeof(timers.firstsendt)); memset(&(timers.starttime), 0, sizeof(timers.starttime)); memset(&(timers.delaytime), 0, sizeof(timers.delaytime)); req = buf; rep = buf2; rec = buf3; create_sockets(&cdata); if (sleep_ms != 0) { if (sleep_ms == -2) { rand_tmp = rand(); sleep_ms_s.tv_sec = rand_tmp / 1000; sleep_ms_s.tv_nsec = (rand_tmp % 1000) * 1000000; } else { sleep_ms_s.tv_sec = sleep_ms / 1000; sleep_ms_s.tv_nsec = (sleep_ms % 1000) * 1000000; } } if (replace_b == 1){ replace_string(req, "$dsthost$", domainname); replace_string(req, "$srchost$", fqdn); sprintf(lport_str, "%i", lport); replace_string(req, "$port$", lport_str); if (username) replace_string(req, "$user$", username); } if (replace_str) replace_strings(req, replace_str); /* set all regular expression to simplfy the result code indetification */ regcomp(&(regexps.replyexp), "^SIP/[0-9]\\.[0-9] [1-6][0-9][0-9]", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.proexp), "^SIP/[0-9]\\.[0-9] 1[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.okexp), "^SIP/[0-9]\\.[0-9] 2[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.redexp), "^SIP/[0-9]\\.[0-9] 3[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.authexp), "^SIP/[0-9]\\.[0-9] 40[17] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.errexp), "^SIP/[0-9]\\.[0-9] 4[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); regcomp(&(regexps.tmhexp), "^SIP/[0-9]\\.[0-9] 483 ", REG_EXTENDED|REG_NOSUB|REG_ICASE); if (username) { if (nameend > 0) { usern = str_alloc(strlen(username) + 12); create_usern(usern, username, namebeg); } else { if (*(username + strlen(username) - 1) != '@') { usern = str_alloc(strlen(username) + 2); create_usern(usern, username, -1); } else { usern = username; } } } if (usrloc == 1||invite == 1||message == 1){ /* calculate the number of required steps and create initial mes */ if (usrloc == 1) { create_msg(REQ_REG, req, NULL, usern, cseq_counter); usrlocstep=REG_REP; } else if (invite == 1) { create_msg(REQ_INV, req, rep, usern, cseq_counter); inv_trans = 1; usrlocstep=INV_RECV; } else { create_msg(REQ_MES, req, rep, usern, cseq_counter); if (mes_body) usrlocstep=MES_OK_RECV; else usrlocstep=MES_RECV; } } else if (trace == 1){ /* for trace we need some spezial initis */ namebeg=0; create_msg(REQ_OPT, req, NULL, usern, cseq_counter); set_maxforw(req, namebeg); } else if (flood == 1){ if (nameend<=0) nameend=INT_MAX; namebeg=1; create_msg(REQ_FLOOD, req, NULL, usern, cseq_counter); } else if (randtrash == 1){ counters.randretrys=0; namebeg=1; create_msg(REQ_RAND, req, NULL, usern, cseq_counter); nameend=(int)strlen(req); if (trashchar == 1){ if (trashchar < nameend) nameend=trashchar; else fprintf(stderr, "warning: number of trashed chars to big. setting to " "request length\n"); } trash_random(req); } else { /* for none of the modes we also need some inits */ if (file_b == 0) { namebeg=1; create_msg(REQ_OPT, req, NULL, usern, cseq_counter); } else { if (STRNCASECMP(req, INV_STR, INV_STR_LEN) == 0) { inv_trans = 1; } if(via_ins == 1) add_via(req); } /* delays.retryAfter = delays.retryAfter / 10; */ if(maxforw!=-1) set_maxforw(req, maxforw); } cdata.connected = set_target(&(cdata.adr), address, rport, cdata.csock, cdata.connected); /* here we go until someone decides to exit */ while(1) { before_sending(); if (sleep_ms == -2) { rand_tmp = rand(); sleep_ms_s.tv_sec = rand_tmp / 1000; sleep_ms_s.tv_nsec = (rand_tmp % 1000) * 1000; } if (sleep_ms != 0) { dbg("sleeping for %li s + %li ns\n", sleep_ms_s.tv_sec, sleep_ms_s.tv_nsec); nanosleep(&sleep_ms_s, &sleep_rem); } send_message(req, &cdata, &counters, &timers); /* in flood we are only interested in sending so skip the rest */ if (flood == 0) { ret = recv_message(rec, BUFSIZE, inv_trans, &delays, &timers, &counters, &cdata, ®exps); if(ret > 0) { if (usrlocstep == INV_OK_RECV) { swap_ptr(&rep, &req); } /* send ACK for non-provisional reply on INVITE */ if ((STRNCASECMP(req, "INVITE", 6)==0) && (regexec(&(regexps.replyexp), rec, 0, 0, 0) == REG_NOERROR) && (regexec(&(regexps.proexp), rec, 0, 0, 0) == REG_NOMATCH)) { build_ack(req, rec, rep, ®exps); cdata.dontsend = 0; inv_trans = 0; /* lets fire the ACK to the server */ send_message(rep, &cdata, &counters, &timers); inv_trans = 1; } /* check for old CSeq => ignore retransmission */ cseqtmp = cseq(rec); if ((0 < cseqtmp) && (cseqtmp < cseq_counter)) { if (verbose>0) { printf("ignoring retransmission\n"); } counters.retrans_r_c++; cdata.dontsend = 1; continue; } else if (regexec(&(regexps.authexp), rec, 0, 0, 0) == REG_NOERROR) { if (!username && !auth_username) { if (timing > 0) { timing--; if (timing == 0) { if (counters.run == 0) { counters.run++; } printf("%.3f/%.3f/%.3f ms\n", delays.small_delay, delays.all_delay / counters.run, delays.big_delay); exit_code(0, __PRETTY_FUNCTION__, NULL); } counters.run++; new_transaction(req, rep); delays.retryAfter = timer_t1; continue; } fprintf(stderr, "%s\nerror: received 40[17] but cannot " "authentication without a username or auth username\n", rec); log_message(req); exit_code(2, __PRETTY_FUNCTION__, "missing username for authentication"); } /* prevents a strange error */ regcomp(&(regexps.authexp), "^SIP/[0-9]\\.[0-9] 40[17] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); insert_auth(req, rec); if (verbose > 2) printf("\nreceived:\n%s\n", rec); new_transaction(req, rep); continue; } /* if auth...*/ /* lets see if received a redirect */ if (redirects == 1 && regexec(&(regexps.redexp), rec, 0, 0, 0) == REG_NOERROR) { handle_3xx(&(cdata.adr)); } /* if redircts... */ else if (trace == 1) { trace_reply(); } /* if trace ... */ else if (usrloc == 1||invite == 1||message == 1) { handle_usrloc(); } else if (randtrash == 1) { handle_randtrash(); } else { handle_default(); } /* redirect, auth, and modes */ } /* ret > 0 */ else if (ret == -1) { // we did not got anything back, send again /* no re-transmission on reliable transports */ if (transport != SIP_UDP_TRANSPORT) { cdata.dontsend = 1; } continue; } else if (ret == -2) { // we received non-matching ICMP cdata.dontsend = 1; continue; } else { if (usrloc == 1) { printf("failed\n"); } perror("socket error"); exit_code(3, __PRETTY_FUNCTION__, "internal socket error"); } } /* !flood */ else { if (counters.send_counter == 1) { memcpy(&(timers.firstsendt), &(timers.sendtime), sizeof(struct timeval)); } if (namebeg==nameend) { printf("flood end reached\n"); printf("it took %.3f ms seconds to send %i request.\n", deltaT(&(timers.firstsendt), &(timers.sendtime)), namebeg); printf("we sent %f requests per second.\n", (namebeg/(deltaT(&(timers.firstsendt), &(timers.sendtime)))*1000)); exit_code(0, __PRETTY_FUNCTION__, NULL); } namebeg++; cseq_counter++; create_msg(REQ_FLOOD, req, NULL, usern, cseq_counter); } } /* while 1 */ /* this should never happen any more... */ if (randtrash == 1) { exit_code(0, __PRETTY_FUNCTION__, NULL); } printf("** give up retransmissioning....\n"); if (counters.retrans_r_c>0 && (verbose > 1)) { printf("%i retransmissions received during test\n", counters.retrans_r_c); } if (counters.retrans_s_c>0 && (verbose > 1)) { printf("sent %i retransmissions during test\n", counters.retrans_s_c); } exit_code(3, __PRETTY_FUNCTION__, "got outside of endless messaging loop"); }
// handler for all incoming connections static int ev_handler(struct mg_connection *conn, enum mg_event ev) { if (ev == MG_REQUEST) { QString canonical_path = "/"; QStringList pathParts = QString(conn->uri).split("/", QString::SkipEmptyParts); if ( pathParts.size() ) { canonical_path = pathParts.last(); } if ( canonical_path == "health" ) { return handle_health(conn); } QString format = get_var(conn, "format"); QString html = get_var(conn, "html"); QString js = get_var(conn, "js"); QString rasterizer = get_var(conn, "rasterizer"); QString output = get_var(conn, "output"); QString url = get_var(conn, "url"); bool transparent = get_var(conn, "transparent", "1").toInt(); int width = get_var(conn, "width").toInt(); int height = get_var(conn, "height", "-1").toInt(); int crop_x = get_var(conn, "crop_x", "0").toInt(); int crop_y = get_var(conn, "crop_y", "0").toInt(); int crop_w = get_var(conn, "crop_w", "0").toInt(); int crop_h = get_var(conn, "crop_h", "0").toInt(); int smart_width = get_var(conn, "smart_width", "1").toInt(); QString css = get_var(conn, "css"); QString selector = get_var(conn, "selector"); int load_timeout_msec = get_var(conn, "load_timeout", "0").toInt(); int enable_statsd = get_var(conn, "enable_statsd", "0").toInt(); std::string statsd_ns(get_var(conn, "statsd_ns").toLocal8Bit().constData()); QRect crop_rect; if ( crop_x || crop_y || crop_w || crop_h ) { crop_rect = QRect(crop_x, crop_y, crop_w, crop_h); } if ( !rasterizer.length() ) { rasterizer = ICHABOD_NAME; } if ( !output.length() ) { return send_error(conn, "No output specified"); } if ( width < 1 ) { return send_error(conn, "Bad dimensions"); } if ( !html.length() && !url.length() ) { return send_error(conn, "Empty document and no URL specified"); } QString input; QTemporaryFile file(output + QString("_XXXXXX.html")); if ( html.length() ) { if ( !file.open() ) { return send_error(conn, (QString("Unable to open:") + output + QString("_XXXXXX.html")).toLocal8Bit().constData() ); } QTextStream out(&file); out << html; out.flush(); input = file.fileName(); } else { input = url; } if ( format.startsWith(".") ) { format = format.mid(1); } if ( format.isEmpty() ) { format = "png"; } Settings settings; settings.verbosity = g_verbosity; settings.engine_verbosity = g_engine_verbosity; settings.convert_verbosity = g_convert_verbosity; settings.slow_response_ms = g_slow_response_ms; settings.rasterizer = rasterizer; settings.fmt = format; settings.in = input; settings.quality = 50; // reasonable size/speed tradeoff by default settings.out = output; settings.screen_width = width; settings.virtual_width = width; settings.screen_height = height; settings.transparent = transparent; settings.looping = false; settings.quantize_method = toQuantizeMethod( g_quantize ); settings.smart_width = smart_width; settings.crop_rect = crop_rect; settings.css = css; settings.selector = selector; settings.selector = selector; settings.load_timeout_msec = load_timeout_msec; QList<QString> scripts; scripts.append(js); settings.run_scripts = scripts; settings.statsd = 0; if ( enable_statsd ) { settings.statsd_ns = statsd_ns + (statsd_ns.length() ? "." : ""); settings.statsd = &g_statsd; } return handle_default(conn, settings); } else if (ev == MG_AUTH) { return MG_TRUE; } return MG_FALSE; }
MppShortcutTab :: MppShortcutTab(MppMainWindow *_mw) { uint32_t x; uint32_t xr = 0; uint32_t y = 0; mw = _mw; gb_jump = new MppGroupBox(tr("Label Jump MIDI shortcuts")); gb_mode = new MppGroupBox(tr("View Mode MIDI shortcuts")); gb_ops = new MppGroupBox(tr("Operation MIDI shortcuts")); gl = new MppGridLayout(); gl->addWidget(gb_jump, 0,0,2,4); gl->addWidget(gb_mode, 0,4,1,4); gl->addWidget(gb_ops, 1,4,1,4); gl->setRowStretch(3, 1); gl->setColumnStretch(8, 1); watchdog = new QTimer(this); watchdog->setSingleShot(1); connect(watchdog, SIGNAL(timeout()), this, SLOT(handle_watchdog())); memset(filter, 0, sizeof(filter)); memset(shortcut_desc, 0, sizeof(shortcut_desc)); shortcut_desc[MPP_SHORTCUT_J0] = "J0"; shortcut_desc[MPP_SHORTCUT_J1] = "J1"; shortcut_desc[MPP_SHORTCUT_J2] = "J2"; shortcut_desc[MPP_SHORTCUT_J3] = "J3"; shortcut_desc[MPP_SHORTCUT_J4] = "J4"; shortcut_desc[MPP_SHORTCUT_J5] = "J5"; shortcut_desc[MPP_SHORTCUT_J6] = "J6"; shortcut_desc[MPP_SHORTCUT_J7] = "J7"; shortcut_desc[MPP_SHORTCUT_J8] = "J8"; shortcut_desc[MPP_SHORTCUT_J9] = "J9"; shortcut_desc[MPP_SHORTCUT_J10] = "J10"; shortcut_desc[MPP_SHORTCUT_J11] = "J11"; shortcut_desc[MPP_SHORTCUT_J12] = "J12"; shortcut_desc[MPP_SHORTCUT_J13] = "J13"; shortcut_desc[MPP_SHORTCUT_J14] = "J14"; shortcut_desc[MPP_SHORTCUT_J15] = "J15"; shortcut_desc[MPP_SHORTCUT_ALL] = "ALL"; shortcut_desc[MPP_SHORTCUT_TRANS] = "TRANS"; shortcut_desc[MPP_SHORTCUT_FIXED] = "FIXED"; shortcut_desc[MPP_SHORTCUT_MIXED] = "MIXED"; shortcut_desc[MPP_SHORTCUT_CHORD_PIANO] = "CHORD-PIANO"; shortcut_desc[MPP_SHORTCUT_CHORD_GUITAR] = "CHORD-GUITAR"; shortcut_desc[MPP_SHORTCUT_TRIGGER] = "TRIGGER"; shortcut_desc[MPP_SHORTCUT_PAUSE] = "PAUSE"; shortcut_desc[MPP_SHORTCUT_REWIND] = "REWIND"; shortcut_desc[MPP_SHORTCUT_BPM_TOGGLE] = "BPMTOG"; but_set_all = new QPushButton("Record All"); connect(but_set_all, SIGNAL(released()), this, SLOT(handle_set_all_flat())); but_clr_all = new QPushButton("Record None"); connect(but_clr_all, SIGNAL(released()), this, SLOT(handle_clr_all_flat())); but_reset = new QPushButton("Clear Selected"); connect(but_reset, SIGNAL(released()), this, SLOT(handle_reset_all_flat())); but_default = new QPushButton("Set Defaults"); connect(but_default, SIGNAL(released()), this, SLOT(handle_default())); gl->addWidget(but_set_all, 2, 0, 1, 1); gl->addWidget(but_clr_all, 2, 1, 1, 1); gl->addWidget(but_reset, 2, 2, 1, 1); gl->addWidget(but_default, 2, 3, 1, 1); for (x = 0; x != MPP_SHORTCUT_MAX; x++) { MppGroupBox *gb; if (x == MPP_SHORTCUT_LABEL_MAX || x == MPP_SHORTCUT_MODE_MAX) { xr = 0; y = 0; } but_rec[x] = new MppButton(tr("REC"), x); connect(but_rec[x], SIGNAL(released(int)), this, SLOT(handle_record(int))); led_cmd[x] = new QLineEdit(); led_cmd[x]->setMaxLength(32); connect(led_cmd[x], SIGNAL(textChanged(const QString &)), this, SLOT(handle_text_changed(const QString &))); if (x < MPP_SHORTCUT_LABEL_MAX) { gb = gb_jump; } else if (x < MPP_SHORTCUT_MODE_MAX) { gb = gb_mode; } else { gb = gb_ops; } gb->addWidget(new QLabel(tr(shortcut_desc[x])), xr, y, 1, 1); gb->addWidget(led_cmd[x], xr, y + 1, 1, 1); gb->addWidget(but_rec[x], xr, y + 2, 1, 1); xr++; if (xr == 8) { xr = 0; y += 3; } } handle_default(); }
void foo(void) { switch(ch) { // handle 'a' case 'a': { handle_a(); multiline(123, 345); break; } // handle 'b' case 'b': handle_b(); multiline(123, 345); break; // handle 'c' and 'd' case 'c': case 'd': // c and d are really the same thing handle_cd(); multiline(123, 345); break; case 'e': { handle_a(); multiline(123, 345); } break; // case1 case (case1): { //do stuff break; } case (case2): { //do stuff break; } case (case3): /*do stuff*/ break; case (case3): statement(); { another_statement(); } break; // really should not get here default: handle_default(); multiline(123, 345); break; } multiline(123, 345); }