static void send_announcement(struct subnet_record *subrec, int announce_type, const char *from_name, const char *to_name, int to_type, struct in_addr to_ip, time_t announce_interval, const char *server_name, int server_type, const char *server_comment) { pstring outbuf; char *p; memset(outbuf,'\0',sizeof(outbuf)); p = outbuf+1; SCVAL(outbuf,0,announce_type); /* Announcement parameters. */ SCVAL(p,0,updatecount); SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); SCVAL(p,21,lp_major_announce_version()); /* Major version. */ SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ SSVAL(p,27,BROWSER_ELECTION_VERSION); SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, DGRAM_PORT); }
static void udpsvc_process(udpsvc_t *svc) { int addrlen, cc; struct sockaddr_in addr; struct gdexception exception_frame; update_udp_av(); exception_frame.e_exception = exception; exception_frame.e_catch = 0; exception = &exception_frame; if (setjmp(exception_frame.e_context) == 0) { push_string(inet_ntoa(addr.sin_addr), STRING_MSTRING); push_string((char *)nq_rptr(svc->nq), STRING_MSTRING); (void)apply_master_ob(M_INCOMING_UDP, 2); } exception = exception->e_exception; addrlen = sizeof (addr); if (!read_datagram(svc)) { nd_enable(svc->nd, ND_R); svc->task = 0; return; } reschedule_task(svc->task); }
/*! @decl void map(string map, function(string, string:void) fun) *! *! For each entry in @[map], call the function specified by @[fun]. *! *! @[fun] will get two arguments, the first being the key, and the *! second the value. *! *! @[map] is the YP-map to search in. This must be the full map name. *! eg @tt{passwd.byname@} instead of just @tt{passwd@}. */ static void f_map(INT32 args) { int err; char *retval, *retkey; int retlen, retkeylen; char *map; struct svalue *f = &sp[-1]; check_all_args(NULL, args, BIT_STRING, BIT_FUNCTION|BIT_ARRAY, 0 ); map = sp[-2].u.string->str; if(!(err = yp_first(this->domain,map, &retkey,&retkeylen, &retval, &retlen))) do { push_string(make_shared_binary_string(retkey, retkeylen)); push_string(make_shared_binary_string(retval, retlen)); apply_svalue( f, 2 ); err = yp_next(this->domain, map, retkey, retkeylen, &retkey, &retkeylen, &retval, &retlen); } while(!err); if(err != YPERR_NOMORE) YPERROR( err ); }
int main( int argc, char *argv[] ) { cexception_t inner; SLLIST * volatile string_list = NULL; char * curr = NULL; char * one = "one"; char * two = "two"; char * three = "three"; cexception_guard( inner ) { push_string( &string_list, &one, &inner ); push_string( &string_list, &two, &inner ); push_string( &string_list, &three, &inner ); } cexception_catch { fprintf( stderr, "%s: %s\n", argv[0], cexception_message( &inner )); } curr = sllist_pop_data( &string_list ); printf( "%s\n", curr ? curr : "(null)" ); curr = sllist_pop_data( &string_list ); printf( "%s\n", curr ? curr : "(null)" ); curr = sllist_pop_data( &string_list ); printf( "%s\n", curr ? curr : "(null)" ); curr = sllist_pop_data( &string_list ); printf( "%s\n", curr ? curr : "(null)" ); dispose_sllist( &string_list ); return 0; }
/* ioctl - used for job query */ static NTSTATUS print_ioctl(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_ioctl *io) { char *p; if (io->generic.level != RAW_IOCTL_IOCTL) { return NT_STATUS_NOT_IMPLEMENTED; } if (io->ioctl.in.request == IOCTL_QUERY_JOB_INFO) { /* a request for the print job id of an open print job */ io->ioctl.out.blob = data_blob_talloc(req, NULL, 32); data_blob_clear(&io->ioctl.out.blob); p = (char *)io->ioctl.out.blob.data; SSVAL(p,0, 1 /* REWRITE: fsp->rap_print_jobid */); push_string(p+2, lpcfg_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII); push_string(p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII); return NT_STATUS_OK; } return NT_STATUS_INVALID_PARAMETER; }
/*! @decl mapping(string:string) all(string map) *! *! Returns the whole map as a mapping. *! *! @[map] is the YP-map to search in. This must be the full map name, *! you have to use @tt{passwd.byname@} instead of just @tt{passwd@}. */ static void f_all(INT32 args) { int err, num=0; char *retval, *retkey; int retlen, retkeylen; char *map; struct mapping *res_map; check_all_args(NULL, args, BIT_STRING, 0); map = sp[-1].u.string->str; res_map = allocate_mapping( (this->last_size?this->last_size+2:40) ); if(!(err = yp_first(this->domain, map, &retkey,&retkeylen, &retval,&retlen))) do { push_string(make_shared_binary_string(retkey, retkeylen)); push_string(make_shared_binary_string(retval, retlen)); mapping_insert( res_map, sp-2, sp-1 ); pop_stack(); pop_stack(); err = yp_next(this->domain, map, retkey, retkeylen, &retkey, &retkeylen, &retval, &retlen); num++; } while(!err); if(err != YPERR_NOMORE) { free_mapping( res_map ); YPERROR( err ); } this->last_size = num; pop_n_elems(args); push_mapping( res_map ); }
static int cpio_mkslink(const char *name, const char *target, unsigned int mode, uid_t uid, gid_t gid) { char s[256]; if (name[0] == '/') name++; sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" "%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ ino++, /* ino */ S_IFLNK | mode, /* mode */ (long) uid, /* uid */ (long) gid, /* gid */ 1, /* nlink */ (long) default_mtime, /* mtime */ (unsigned)strlen(target)+1, /* filesize */ 3, /* major */ 1, /* minor */ 0, /* rmajor */ 0, /* rminor */ (unsigned)strlen(name) + 1,/* namesize */ 0); /* chksum */ push_hdr(s); push_string(name); push_pad(); push_string(target); push_pad(); return 0; }
/** * @brief Implementation of game:get_starting_location(). * @param l The Lua context that is calling this function. * @return Number of values to return to Lua. */ int LuaContext::game_api_get_starting_location(lua_State* l) { Savegame& savegame = check_game(l, 1); push_string(l, savegame.get_string(Savegame::KEY_STARTING_MAP)); push_string(l, savegame.get_string(Savegame::KEY_STARTING_POINT)); return 2; }
/* Prints the stack in the inverse order */ void print_inverse_order(StringStack *stack) { StringStack *aux = initialize_string_stack(); while (stack->size > 0) push_string(aux,pop_string(stack)); while (aux->size > 0) { printf("%stack",top_string(aux)); push_string(stack,pop_string(aux)); } }
/* pmfileconflicttype_t alpm_fileconflict_get_type(pmfileconflict_t *conflict); */ static int lalpm_fileconflict_get_type(lua_State *L) { pmfileconflict_t *conflict = check_pmfileconflict(L, 1); pmfileconflicttype_t type = alpm_fileconflict_get_type(conflict); switch(type) { case PM_FILECONFLICT_TARGET: return push_string(L, "FILECONFLICT_TARGET"); case PM_FILECONFLICT_FILESYSTEM: return push_string(L, "FILECONFLICT_FILESYSTEM"); } return 1; }
/*Get qgram distances * Input * s: a string * t: a string * x: length of s * y: length of t * q: the 'q' in q-gram * Q: a qtree * int: distance distance function to compute: * 0 : q-gram distance * 1 : cosine distance * 2 : jaccard distance * * * Return values: * >=0 : qgram distance * -1 : infinite distance * -2 : Not enough memory */ static double qgram_tree( unsigned int *s, unsigned int *t, unsigned int x, unsigned int y, unsigned int q, qtree *Q, int distance ){ // return -1 when q is larger than the length of the shortest string. if ( q > (x <= y ? x : y) ) return -1.0; // rare edge cases. if ( q == 0 ){ if ( x + y > 0 ){ // distance undefined return -1.0; } else { // x == y == 0. return 0.0; } } double dist[3] = {0,0,0}; Q = push_string(s, x, q, Q, 0, 2); if (Q == NULL) return -2.0; Q = push_string(t, y, q, Q, 1, 2); if (Q == NULL) return -2.0; switch ( distance ){ case 0: getdist(Q,dist); break; case 1: getcosine(Q, dist); if (dist[0]==dist[1] && dist[0]==dist[2]){ // strings are equal. Prevent machine rounding about 0.0 dist[0] = 0.0; } else { // there are several ways to express the rhs (including ones that give 0L // at equal strings) but this has least chance of overflow. dist[0] = 1.0 - dist[0]/(sqrt(dist[1]) * sqrt(dist[2])); } break; case 2: getjaccard(Q,dist); dist[0] = 1.0 - dist[0]/dist[1]; break; default: break; } return dist[0]; }
/*Get qgram distances * Input * s: a string * t: a string * x: length of s * y: length of t * q: the 'q' in q-gram * Q: a qtree * int: distance distance function to compute: * 0 : q-gram distance * 1 : cosine distance * 2 : jaccard distance * * * Return values: * >=0 : qgram distance * -1 : infinite distance * -2 : Not enough memory */ double qgram_dist( unsigned int *s, int x, unsigned int *t, int y, unsigned int q, qtree **Qp, int distance ){ // rare edge case: q==0. Note that we return 0 for all cases where // q equals zero. In the R journal paper we used Inf for cases where // q=0 and |s| or |t| > 0 if ( q == 0 ) return 0.0; double dist[3] = {0,0,0}; *Qp = push_string(s, x, q, *Qp, 0, 2); *Qp = push_string(t, y, q, *Qp, 1, 2); if (*Qp == NULL) return 0; qtree *Q = *Qp; switch ( distance ){ case 0: getdist(Q,dist); break; case 1: getcosine(Q, dist); if (dist[0]==dist[1] && dist[0]==dist[2]){ // strings are equal. Prevent machine rounding about 0.0 dist[0] = 0.0; } else { // there are several ways to express the rhs (including ones that give 0L // at equal strings) but this has least chance of overflow // fabs is taken to avoid numerical -0. dist[0] = fabs(1.0 - dist[0]/(sqrt(dist[1]) * sqrt(dist[2]))); } break; case 2: getjaccard(*Qp,dist); dist[0] = 1.0 - dist[0]/dist[1]; break; default: break; } return dist[0]; }
std::vector<unsigned char> CEntityWriter::SaveMatrices(long rate, std::map<std::string, std::vector<float> >& animations) { std::vector<unsigned char> out; push_long(out, rate); push_long(out, 1); // 1 - matrix animation std::map<std::string, std::vector<float> >::iterator it = animations.begin(); CAnimationTransformer trans; while (it != animations.end() ) { char buffer[200]; memset(buffer, 0, 200); std::string component_name = it->first; int pos= component_name.find("/"); strncpy(buffer, component_name.c_str(), pos); component_name = buffer; push_string(out,buffer); std::vector<float>& next = it->second; std::vector<CKeyFrame> frames = trans.GetFrames(next); //out.resize(sizeof(long) + pos + sizeof(float)*next.size()); push_long(out,frames.size()); for (int i= 0 ; i < frames.size() ; i ++ ) { std::vector<unsigned char> frame; frame.resize(sizeof(CKeyFrame)); memcpy(&frame[0], & frames[i] , sizeof(CKeyFrame)); out.insert(out.end(),frame.begin(), frame.end()); } it++; } return out; }
/*! @decl array(string) split(string s) *! Works as @[match], but returns an array of the strings that *! matched the subregexps. Subregexps are those contained in "( )" in *! the regexp. Subregexps that were not matched will contain zero. *! If the total regexp didn't match, zero is returned. *! *! @bugs *! You can currently only have 39 subregexps. *! *! @bugs *! The current implementation doesn't support searching *! in strings containing the NUL character or any *! wide character. *! *! @seealso *! @[match] */ static void regexp_split(INT32 args) { struct pike_string *s; struct regexp *r; get_all_args("Regexp.SimpleRegexp->split", args, "%S", &s); if(pike_regexec(r=THIS->regexp, s->str)) { int i,j; add_ref(s); pop_n_elems(args); for(j=i=1;i<NSUBEXP;i++) { if(!r->startp[i] || !r->endp[i]) { push_int(0); }else{ push_string(make_shared_binary_string(r->startp[i], r->endp[i]-r->startp[i])); j=i; } } if(j<i-1) pop_n_elems(i-j-1); push_array(aggregate_array(j)); free_string(s); }else{ pop_n_elems(args); push_int(0); } }
/** * @brief Implementation of sol.menu.stop(). * @param l the Lua context that is calling this function * @return number of values to return to Lua */ int LuaContext::menu_api_stop(lua_State* l) { LuaContext& lua_context = get_lua_context(l); luaL_checktype(l, 1, LUA_TTABLE); int menu_ref = LUA_REFNIL; std::list<LuaMenuData>& menus = lua_context.menus; std::list<LuaMenuData>::iterator it; for (it = menus.begin(); it != menus.end(); it++) { int ref = it->ref; push_ref(l, ref); if (lua_equal(l, 1, -1)) { menu_ref = ref; lua_context.menu_on_finished(menu_ref); menus.erase(it); lua_context.destroy_ref(menu_ref); break; } } if (menu_ref == LUA_REFNIL) { push_string(l, "Unknown menu."); lua_error(l); } return 0; }
static void image_ttf_face__names(INT32 args) { int ns,res; TT_UShort i; TT_Face face=THISf->face; pop_n_elems(args); if ((ns=TT_Get_Name_Count(face))==-1) Pike_error("Image.TTF.Face->names(): Illegal face handler\n"); for (i=0; i<ns; i++) { unsigned short platformID,encodingID,languageID,nameID; TT_UShort length; char *stringPtr; if ((res=TT_Get_Name_ID(face,i, &platformID,&encodingID,&languageID,&nameID))) my_tt_error("Image.TTF.Face->names()","TT_Get_Name_ID: ",res); push_int(platformID); push_int(encodingID); push_int(languageID); push_int(nameID); if ((res=TT_Get_Name_String(face,i,&stringPtr,&length))) my_tt_error("Image.TTF.Face->names()","TT_Get_Name_String: ",res); push_string(make_shared_binary_string(stringPtr,length)); f_aggregate(5); } f_aggregate(ns); }
static void f_crypt_md5(INT32 args) { char salt[8]; char *ret, *saltp =""; char *choice = "cbhisjKlm4k65p7qrJfLMNQOPxwzyAaBDFgnoWXYCZ0123tvdHueEGISRTUV89./"; if (args < 1) SIMPLE_TOO_FEW_ARGS_ERROR("crypt_md5", 1); if (Pike_sp[-args].type != T_STRING) SIMPLE_BAD_ARG_ERROR("crypt_md5", 1, "string"); if (args > 1) { if (Pike_sp[1-args].type != T_STRING) SIMPLE_BAD_ARG_ERROR("crypt_md5", 2, "string"); saltp = Pike_sp[1-args].u.string->str; } else { unsigned int i, r; for (i = 0; i < sizeof(salt); i++) { r = my_rand(); salt[i] = choice[r % (size_t) strlen(choice)]; } saltp = salt; } ret = (char *)crypt_md5(Pike_sp[-args].u.string->str, saltp); pop_n_elems(args); push_string(make_shared_string(ret)); }
/** * \brief Implementation of item:get_name(). * \param l The Lua context that is calling this function. * \return Number of values to return to Lua. */ int LuaContext::item_api_get_name(lua_State* l) { EquipmentItem& item = check_item(l, 1); push_string(l, item.get_name()); return 1; }
//-------------------------------------------------------- // moduleInit //-------------------------------------------------------- void MsgBase::packMsg(NetMsgBody &netMsg) { netMsg.msgType = m_pMsgInfo->msgType; push_u16((uint16_t)m_pMsgInfo->info.size()); for(map<string,string>::const_iterator it = m_pMsgInfo->info.begin();it!= m_pMsgInfo->info.end();it++) { push_string(it->first); push_string(it->second); } netMsg.msgHead.length = netMsg.msgData.length() + HEAD_SIZE; }
static int global_current_dir (lua_State *L) { check_args(L, 0); std::string dir = lua_current_dir(L); push_string(L, dir); return 1; }
static void to_ascii(void) { struct number *n; struct value *value; char str[2]; value = pop(); if (value != NULL) { str[1] = '\0'; switch (value->type) { case BCODE_NONE: return; case BCODE_NUMBER: n = value->u.num; normalize(n, 0); if (BN_num_bits(n->number) > 8) bn_check(BN_mask_bits(n->number, 8)); str[0] = (char)BN_get_word(n->number); break; case BCODE_STRING: str[0] = value->u.string[0]; break; } stack_free_value(value); push_string(bstrdup(str)); } }
static void f_extension( INT32 args ) { int i, found=0; struct pike_string *src; char *orig, *ptr; if(Pike_sp[-1].type != T_STRING) SIMPLE_BAD_ARG_ERROR("Caudium.extension", 1, "string"); src = Pike_sp[-1].u.string; if(src->size_shift) { Pike_error("Caudium.extension(): Only 8-bit strings allowed.\n"); } orig = src->str; for(i = src->len-1; i >= 0; i--) { if(orig[i] == 0x2E) { found = 1; i++; break; } } if(found) { int len = src->len - i; switch(orig[src->len-1]) { case '#': case '~': /* Remove unix backup extension */ len--; } pop_n_elems(args); push_string(make_shared_binary_string(orig+i, len)); } else { pop_n_elems(args); push_text(""); } }
/* append a string into a blob */ size_t smbcli_blob_append_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *str, unsigned int flags) { size_t max_len; int len; if (!str) return 0; /* determine string type to use */ if (!(flags & (STR_ASCII|STR_UNICODE))) { flags |= (session->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII; } max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len); if (!blob->data) { return 0; } len = push_string(blob->data + blob->length, str, max_len, flags); blob->length += len; return len; }
/*********************************************************** encode a password buffer with a unicode password. The buffer is filled with random data to make it harder to attack. ************************************************************/ bool encode_pw_buffer(uint8_t buffer[516], const char *password, int string_flags) { uint8_t new_pw[512]; ssize_t new_pw_len; /* the incoming buffer can be any alignment. */ string_flags |= STR_NOALIGN; new_pw_len = push_string(new_pw, password, sizeof(new_pw), string_flags); if (new_pw_len == -1) { return false; } memcpy(&buffer[512 - new_pw_len], new_pw, new_pw_len); generate_random_buffer(buffer, 512 - new_pw_len); /* * The length of the new password is in the last 4 bytes of * the data buffer. */ SIVAL(buffer, 512, new_pw_len); ZERO_STRUCT(new_pw); return true; }
/* **| method: string dn2ufn ( string dn ); **| Convert the given DN to an user friendly form thereof. This will **| strip the type names from the passed dn. See RFC 1781 for more **| details. ** **| arg: string dn **| an UTF-8 string with the dn to convert. ** **| returns: the user friendly form of the DN. */ static void f_ldap_dn2ufn(INT32 args) { struct pike_string *dn = NULL; char *ufn; if (args != 1) Pike_error("OpenLDAP.Client->dn2ufn(): requires exactly one 8-bit string argument\n"); get_all_args("OpenLDAP.Client->dn2ufn()", args, "%S", &dn); pop_n_elems(args); if (!dn) { push_int(0); return; } ufn = ldap_dn2ufn(dn->str); if (!ufn) { push_int(0); } else { push_string(make_shared_string(ufn)); ldap_memfree(ufn); } }
static int php_roxen_low_ub_write(const char *str, uint str_length TSRMLS_DC) { int sent_bytes = 0; struct pike_string *to_write = NULL; #ifdef ROXEN_USE_ZTS GET_THIS(); #endif if(!MY_FD_OBJ->prog) { PG(connection_status) = PHP_CONNECTION_ABORTED; zend_bailout(); return -1; } to_write = make_shared_binary_string(str, str_length); push_string(to_write); safe_apply(MY_FD_OBJ, "write", 1); if(Pike_sp[-1].type == PIKE_T_INT) sent_bytes = Pike_sp[-1].u.integer; pop_stack(); if(sent_bytes != str_length) { /* This means the connection is closed. Dead. Gone. *sniff* */ php_handle_aborted_connection(); } return sent_bytes; }
void bquote(fcode_env_t *env) { char stringbuff[256]; int len, count; char *strptr; count = len = next_bytecode(env); if (env->state) { COMPILE_TOKEN("e_ptr); strptr = (char *)HERE; *strptr++ = len; while (count--) *strptr++ = next_bytecode(env); *strptr++ = 0; set_here(env, (uchar_t *)strptr, "bquote"); token_roundup(env, "bquote"); } else { strptr = stringbuff; while (count--) *strptr++ = next_bytecode(env); *strptr = 0; push_string(env, stringbuff, len); } }
static void smb2srv_notify_send(struct ntvfs_request *ntvfs) { struct smb2srv_request *req; union smb_notify *io; size_t size = 0; int i; uint8_t *p; DATA_BLOB blob = data_blob(NULL, 0); SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_notify); SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x08, True, 0)); #define MAX_BYTES_PER_CHAR 3 /* work out how big the reply buffer could be */ for (i=0;i<io->smb2.out.num_changes;i++) { size += 12 + 3 + (1+strlen(io->smb2.out.changes[i].name.s)) * MAX_BYTES_PER_CHAR; } blob = data_blob_talloc(req, NULL, size); if (size > 0 && !blob.data) { SMB2SRV_CHECK(NT_STATUS_NO_MEMORY); } p = blob.data; /* construct the changes buffer */ for (i=0;i<io->smb2.out.num_changes;i++) { uint32_t ofs; ssize_t len; SIVAL(p, 4, io->smb2.out.changes[i].action); len = push_string(p + 12, io->smb2.out.changes[i].name.s, blob.length - (p+12 - blob.data), STR_UNICODE); SIVAL(p, 8, len); ofs = len + 12; if (ofs & 3) { int pad = 4 - (ofs & 3); memset(p+ofs, 0, pad); ofs += pad; } if (i == io->smb2.out.num_changes-1) { SIVAL(p, 0, 0); } else { SIVAL(p, 0, ofs); } p += ofs; } blob.length = p - blob.data; SMB2SRV_CHECK(smb2_push_o16s32_blob(&req->out, 0x02, blob)); smb2srv_send_reply(req); }
/** * \brief Implementation of sol.video.get_window_title(). * \param l the Lua context that is calling this function * \return number of values to return to Lua */ int LuaContext::video_api_get_window_title(lua_State *l) { const std::string& window_title = VideoManager::get_instance()->get_window_title(); push_string(l, window_title); return 1; }
/** * \brief Implementation of sol.video.get_mode(). * \param l the Lua context that is calling this function * \return number of values to return to Lua */ int LuaContext::video_api_get_mode(lua_State *l) { VideoManager::VideoMode mode = VideoManager::get_instance()->get_video_mode(); push_string(l, VideoManager::video_mode_names[mode]); return 1; }