/*************************************************************************** * Function: write_private_profile_string() * Arguments: <char *> section - the name of the section to search for * <char *> entry - the name of the entry to find the value of * <char *> buffer - pointer to the buffer that holds the string * <char *> file_name - the name of the .ini file to read from * Returns: TRUE if successful, otherwise FALSE ***************************************************************************/ int write_private_profile_string(char *section, char *entry, char *buffer, char *file_name) { char * content = read_file(file_name); FILE * fd = fopen(file_name,"w"); char t_section[MAX_LINE_LENGTH], *ptr; int ret = 0; if (!fd) goto end; if (!content) { fprintf (fd, "[%s]\n%s = %s\n", section, entry, buffer); ret = 1; goto end; } sprintf(t_section,"[%s]",section); /* Format the section name */ ptr = str_search (content, t_section, 0); /* look for the section start */ if (!ptr) { /* no such section: add the new section at end of file */ fprintf (fd, "%s\n[%s]\n%s = %s\n", content, section, entry, buffer); } else { char * eptr; eptr = str_search (ptr, entry, '['); if (!eptr) { /* no such entry: looks for next section */ eptr = str_search (++ptr, "[", 0); if (!eptr) { /* section is the last one */ fprintf (fd, "%s\n%s = %s\n", content, entry, buffer); } else { while (*ptr && (*ptr != '\n')) ptr++; *ptr = 0; fprintf (fd, "%s\n%s = %s", content, entry, buffer); *ptr = '\n'; fprintf (fd, "%s", ptr); } } else { *eptr++ = 0; fprintf (fd, "%s%s = %s", content, entry, buffer); while (*eptr && (*eptr != '\n')) eptr++; if (eptr) fprintf (fd, "%s", eptr); } } ret = 1; end: if (content) free(content); if (fd) fclose(fd); return 0; }
/* * Returns the group of the dir 'path'. */ char * group_find_by_dir(strlist_t *grps, char *path) { strlist_iterator_t *iter; char *tmpgroup, *tmpdir, buf[300]; strlist_t *grpdirs = 0; int found = 0; // only look through the groups of the user. for (iter = str_iterator(grps); str_iterator_hasnext(iter); ) { tmpgroup = str_iterator_next(iter); // get groupdirs as a list. sprintf(buf, "group.%s.%s", tmpgroup, PROPERTY_GROUP_DIR); grpdirs = config_get_split_property(buf); if (grpdirs && str_search(grpdirs, path, 0)) { free(iter); str_close(grpdirs); return strdup(tmpgroup); } } str_close(grpdirs); free(iter); return 0; }
strlist_t *str_op_and(strlist_t *p, strlist_t *q) { strlist_t *r = 0, *t; // add items in both p and q. for (t = p; t; t = t->next) if (str_search(q, t->data, 0)) r = str_add(r, t->data); return r; }
int main( int argc, char** argv){ if(3 != argc){ printf("Nombre de paramètres insuffisants\n"); return 1; } char* chaine = argv[1]; char* pattern = argv[2]; printf( "%d \n", str_search(chaine, pattern) ); return 0; }
strlist_t *str_op_or(strlist_t *p, strlist_t *q) { strlist_t *r = 0, *t; // add contents of p for (t = p; t; t = t->next) r = str_add(r, t->data); // add contents of q for (t = q; t; t = t->next) if (!str_search(r, t->data, 0)) r = str_add(r, t->data); return r; }
/* * Returns the list of pre groups from config. * */ strlist_t * groups_find_all() { strlist_t * l = 0; char *tmp, buf[300], *grp; hashtable_t *cfg = get_config(); hashtable_t *env = get_context(); hashtable_item_t *htn; // check if we have made it already. if (ht_get(env, "ALLGROUPS")) return (strlist_t*)ht_get(env, "ALLGROUPS"); ht_reset(cfg); // look through all properties in config. while (htn = ht_next(cfg)) { tmp = htn->key; if (strcmp(tmp, "group.")) continue; grp = strdup(tmp + 6); tmp = strchr(grp, '.'); if (!tmp) { free(grp); continue; } *tmp = 0; if (!str_search(l, grp, 0)) { l = str_add(l, grp); } } ht_put_obj(env, "ALLGROUPS", l); return l; }
int ws_handle_handshake(struct sip_msg *msg) { str key = {0, 0}, headers = {0, 0}, reply_key = {0, 0}, origin = {0, 0}; unsigned char sha1[SHA_DIGEST_LENGTH]; unsigned int hdr_flags = 0, sub_protocol = 0; int version = 0; struct hdr_field *hdr = msg->headers; struct tcp_connection *con; ws_connection_t *wsc; /* Make sure that the connection is closed after the response _and_ the existing connection (from the request) is reused for the response. The close flag will be unset later if the handshake is successful. */ msg->rpl_send_flags.f |= SND_F_CON_CLOSE; msg->rpl_send_flags.f |= SND_F_FORCE_CON_REUSE; if (cfg_get(websocket, ws_cfg, enabled) == 0) { LM_INFO("disabled: bouncing handshake\n"); ws_send_reply(msg, 503, &str_status_service_unavailable, NULL); return 0; } /* Retrieve TCP/TLS connection */ if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) == NULL) { LM_ERR("retrieving connection\n"); ws_send_reply(msg, 500, &str_status_internal_server_error, NULL); return 0; } if (con->type != PROTO_TCP && con->type != PROTO_TLS) { LM_ERR("unsupported transport: %d", con->type); goto end; } if (parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("error parsing headers\n"); ws_send_reply(msg, 500, &str_status_internal_server_error, NULL); goto end; } /* Process HTTP headers */ while (hdr != NULL) { /* Decode and validate Connection */ if (cmp_hdrname_strzn(&hdr->name, str_hdr_connection.s, str_hdr_connection.len) == 0) { strlower(&hdr->body); if (str_search(&hdr->body, &str_upgrade) != NULL) { LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); hdr_flags |= CONNECTION; } } /* Decode and validate Upgrade */ else if (cmp_hdrname_strzn(&hdr->name, str_hdr_upgrade.s, str_hdr_upgrade.len) == 0) { strlower(&hdr->body); if (str_search(&hdr->body, &str_websocket) != NULL) { LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); hdr_flags |= UPGRADE; } } /* Decode and validate Sec-WebSocket-Key */ else if (cmp_hdrname_strzn(&hdr->name, str_hdr_sec_websocket_key.s, str_hdr_sec_websocket_key.len) == 0) { if (hdr_flags & SEC_WEBSOCKET_KEY) { LM_WARN("%.*s found multiple times\n", hdr->name.len, hdr->name.s); ws_send_reply(msg, 400, &str_status_bad_request, NULL); goto end; } LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); key = hdr->body; hdr_flags |= SEC_WEBSOCKET_KEY; } /* Decode and validate Sec-WebSocket-Protocol */ else if (cmp_hdrname_strzn(&hdr->name, str_hdr_sec_websocket_protocol.s, str_hdr_sec_websocket_protocol.len) == 0) { strlower(&hdr->body); if (str_search(&hdr->body, &str_sip) != NULL) { LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); hdr_flags |= SEC_WEBSOCKET_PROTOCOL; sub_protocol |= SUB_PROTOCOL_SIP; } if (str_search(&hdr->body, &str_msrp) != NULL) { LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); hdr_flags |= SEC_WEBSOCKET_PROTOCOL; sub_protocol |= SUB_PROTOCOL_MSRP; } } /* Decode and validate Sec-WebSocket-Version */ else if (cmp_hdrname_strzn(&hdr->name, str_hdr_sec_websocket_version.s, str_hdr_sec_websocket_version.len) == 0) { if (hdr_flags & SEC_WEBSOCKET_VERSION) { LM_WARN("%.*s found multiple times\n", hdr->name.len, hdr->name.s); ws_send_reply(msg, 400, &str_status_bad_request, NULL); goto end; } str2sint(&hdr->body, &version); if (version != WS_VERSION) { LM_WARN("Unsupported protocol version %.*s\n", hdr->body.len, hdr->body.s); headers.s = headers_buf; headers.len = snprintf(headers.s, HDR_BUF_LEN, "%.*s: %d\r\n", str_hdr_sec_websocket_version.len, str_hdr_sec_websocket_version.s, WS_VERSION); ws_send_reply(msg, 426, &str_status_upgrade_required, &headers); goto end; } LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); hdr_flags |= SEC_WEBSOCKET_VERSION; } /* Decode Origin */ else if (cmp_hdrname_strzn(&hdr->name, str_hdr_origin.s, str_hdr_origin.len) == 0) { if (hdr_flags & ORIGIN) { LM_WARN("%.*s found multiple times\n", hdr->name.len, hdr->name.s); ws_send_reply(msg, 400, &str_status_bad_request, NULL); goto end; } LM_DBG("found %.*s: %.*s\n", hdr->name.len, hdr->name.s, hdr->body.len, hdr->body.s); origin = hdr->body; hdr_flags |= ORIGIN; } hdr = hdr->next; } /* Final check that all required headers/values were found */ sub_protocol &= ws_sub_protocols; if ((hdr_flags & REQUIRED_HEADERS) != REQUIRED_HEADERS || sub_protocol == 0) { LM_WARN("required headers not present\n"); headers.s = headers_buf; headers.len = 0; if (ws_sub_protocols & SUB_PROTOCOL_SIP) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n", str_hdr_sec_websocket_protocol.len, str_hdr_sec_websocket_protocol.s, str_sip.len, str_sip.s); if (ws_sub_protocols & SUB_PROTOCOL_MSRP) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n", str_hdr_sec_websocket_protocol.len, str_hdr_sec_websocket_protocol.s, str_msrp.len, str_msrp.s); headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %d\r\n", str_hdr_sec_websocket_version.len, str_hdr_sec_websocket_version.s, WS_VERSION); ws_send_reply(msg, 400, &str_status_bad_request, &headers); goto end; } /* Construct reply_key */ reply_key.s = (char *) pkg_malloc( (key.len + str_ws_guid.len) * sizeof(char)); if (reply_key.s == NULL) { LM_ERR("allocating pkg memory\n"); ws_send_reply(msg, 500, &str_status_internal_server_error, NULL); goto end; } memcpy(reply_key.s, key.s, key.len); memcpy(reply_key.s + key.len, str_ws_guid.s, str_ws_guid.len); reply_key.len = key.len + str_ws_guid.len; SHA1((const unsigned char *) reply_key.s, reply_key.len, sha1); pkg_free(reply_key.s); reply_key.s = key_buf; reply_key.len = base64_enc(sha1, SHA_DIGEST_LENGTH, (unsigned char *) reply_key.s, base64_enc_len(SHA_DIGEST_LENGTH)); /* Add the connection to the WebSocket connection table */ wsconn_add(msg->rcv, sub_protocol); /* Make sure Kamailio core sends future messages on this connection directly to this module */ if (con->type == PROTO_TLS) con->type = con->rcv.proto = PROTO_WSS; else con->type = con->rcv.proto = PROTO_WS; /* Now Kamailio is ready to receive WebSocket frames build and send a 101 reply */ headers.s = headers_buf; headers.len = 0; if (ws_cors_mode == CORS_MODE_ANY) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: *\r\n", str_hdr_access_control_allow_origin.len, str_hdr_access_control_allow_origin.s); else if (ws_cors_mode == CORS_MODE_ORIGIN && origin.len > 0) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n", str_hdr_access_control_allow_origin.len, str_hdr_access_control_allow_origin.s, origin.len, origin.s); if (sub_protocol & SUB_PROTOCOL_SIP) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n", str_hdr_sec_websocket_protocol.len, str_hdr_sec_websocket_protocol.s, str_sip.len, str_sip.s); else if (sub_protocol & SUB_PROTOCOL_MSRP) headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n", str_hdr_sec_websocket_protocol.len, str_hdr_sec_websocket_protocol.s, str_msrp.len, str_msrp.s); headers.len += snprintf(headers.s + headers.len, HDR_BUF_LEN - headers.len, "%.*s: %.*s\r\n" "%.*s: %.*s\r\n" "%.*s: %.*s\r\n", str_hdr_upgrade.len, str_hdr_upgrade.s, str_websocket.len, str_websocket.s, str_hdr_connection.len, str_hdr_connection.s, str_upgrade.len, str_upgrade.s, str_hdr_sec_websocket_accept.len, str_hdr_sec_websocket_accept.s, reply_key.len, reply_key.s); msg->rpl_send_flags.f &= ~SND_F_CON_CLOSE; if (ws_send_reply(msg, 101, &str_status_switching_protocols, &headers) < 0) { if ((wsc = wsconn_get(msg->rcv.proto_reserved1)) != NULL) wsconn_rm(wsc, WSCONN_EVENTROUTE_NO); goto end; } else { if (sub_protocol & SUB_PROTOCOL_SIP) update_stat(ws_sip_successful_handshakes, 1); else if (sub_protocol & SUB_PROTOCOL_MSRP) update_stat(ws_msrp_successful_handshakes, 1); } tcpconn_put(con); return 1; end: if (con) tcpconn_put(con); return 0; }
void m_keyb(int ch,int bank,int prg,int velo) { int bnk_m,bnk_l,pm,ch2; int a,i; unsigned char onkey[32],onnote[32]; unsigned char s[16],ke[128]; char obuf[64]; msg("Music KeyBoard Emulater"); if(rcd->act==0){all_note_off(0);} bnk_l=bank>>8;bnk_m=bank&0xff;ch=(ch-1)&31;ch2=ch&15; pm=rcd->put_mode;rcd->put_mode=rcd->ch_port[ch]; twait(5); if(bank>=0 && tim_asin[ch+1]>=7 && tim_asin[ch+1]<=14){ obuf[0]=0xb0+ch2;obuf[1]=0;obuf[2]=bnk_m; obuf[3]=32;obuf[4]=bnk_l;obuf[5]=255; (*rcd->mix_out)(obuf); } if(prg>=0){ obuf[0]=0xc0+ch2;obuf[1]=prg;obuf[2]=255; (*rcd->mix_out)(obuf); } twait(8); strcpy(onkey," "); while (1){ int ln,sh; if(INPOUT(0xff)==27){break;} sh=B_SFTSNS(); ln=0; for(i=0;i<=6;i++){ a=BITSNS(i); if( a & 1 ){ke[ln++]=bitkey[i][0];} if( a & 2 ){ke[ln++]=bitkey[i][1];} if( a & 4 ){ke[ln++]=bitkey[i][2];} if( a & 8 ){ke[ln++]=bitkey[i][3];} if( a & 16 ){ke[ln++]=bitkey[i][4];} if( a & 32 ){ke[ln++]=bitkey[i][5];} if( a & 64 ){ke[ln++]=bitkey[i][6];} if( a & 128 ){ke[ln++]=bitkey[i][7];} } ke[ln]=0; for (i=0;i<16;i++){ if ( onkey[i]>32 ) { int a; s[0]=onkey[i];s[1]=0; a=str_search(ke,s); if( a==0 ){ int note; onkey[i]=32;note=onnote[i]; /* note off */ obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=0; obuf[3]=255;(*rcd->mix_out)(obuf); } } } ln=0; for (i=0;i<16;i++){ if(ke[ln]==0){break;} if(onkey[i]==32){ s[0]=ke[ln++];s[1]=0; if(str_search(onkey,s)==0){ int a; a=str_search(keytable,s); if(a!=0){ int note; onkey[i]=s[0];note=keycode[a]; if(sh&1){note+=12;}/*shift*/ if(sh&2){note-=12;}/*ctrl*/ if(sh&128){note+=12;}/*caps*/ if(sh&256){note-=12;}/*かな*/ onnote[i]=note; /* note on */ obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=velo; obuf[3]=255;(*rcd->mix_out)(obuf); } } } } } /* 97-10-24 key.emu.で発音したままになるかもしれないのを修正した for (i=0;i<16;i++){ if ( onkey[i]>32 ) { int note; note=onnote[i]; *//* note off *//* obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=0; obuf[3]=255;(*rcd->mix_out)(obuf); } } */ snsclr();rcd->put_mode=pm;msg_clr(); }
/********** program start **********/ void main(int argc,char *argv[]) { int i,f=0,convmode; char cmd[128]; def_file[0]=0; work_size=64*1024; /*cmdflag=0;cnfflag=0;*/mdlflag=0; B_PRINT("X68k STed def<->dfb file converter STdef.x v0.12 Copyright 1996,97 TURBO\r\n"); if( argc>1 ){ for(i=1;i<argc;i++){ strcpy(cmd,argv[i]); if( cmd[0]=='-' ){ switch(cmd[1]){ case 'C': case 'c':convmode=0;break; case 'R': case 'r':convmode=1;break; default:f=1; } }else{ strcpy(def_file,cmd); } } } if( f!=0 || argc<2){ /* B_PRINT( "usage: STdef [option...] [file name] (.DEF/.DFB)\r\n" "options\r\n" "\t-C<file>\t音源定義ファイルをバイナリに変換する\r\n\n" */ B_PRINT("usage: STdef <file name> (.DEF/.DFB)\r\n\n"); exit(1); } dat=(unsigned char *)MALLOC(work_size); if((int)dat>=0x81000000){ B_PRINT("バッファが確保出来ません。\r\n");exit(1);} if( def_file[0]==0 ){ B_PRINT("ファイルを指定して下さい。\r\n");exit(1); } definit(); if(str_search(def_file,".")==0){ strmfe(def_file,def_file,"def"); i=defload(def_file,2); if(i!=0){ if(i==-2){exit(1);} strmfe(def_file,def_file,"dfb"); i=def_bload(def_file,2); if(i!=0){ if(i==-1){B_PRINT("ファイルが見付かりません。\r\n");} exit(1); } } }else{ i=defload(def_file,2); if(i!=0){ if(i==-1){B_PRINT("ファイルが見付かりません。\r\n");} exit(1); } } exit(1); }
unsigned char easyUtils::str_match (const char *search, const std::string &subject) { std::string str_search (search); return str_match (str_search, subject); }
UtfIterator<C> str_search(const basic_string<C>& str, const C* target) { return str_search(utf_begin(str), utf_end(str), cstr(target)); }
UtfIterator<C> str_search(const Irange<UtfIterator<C>>& range, const C* target) { return str_search(range.begin(), range.end(), cstr(target)); }
UtfIterator<C> str_search(const UtfIterator<C>& b, const UtfIterator<C>& e, const C* target) { return str_search(b, e, cstr(target)); }
UtfIterator<C> str_search(const Irange<UtfIterator<C>>& range, const basic_string<C>& target) { return str_search(range.begin(), range.end(), target); }