static void createNewHeap_numberOfProcessLessThanNull_status(void ** state){ heap_t * heap1 = heap_new(-5); assert_int_equal(heap_getStatus(heap1), HEAP_INRORRECTNUMBER); heap_free(heap1); }
static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blocking, SIZE_T *ret_size, BOOL *eof) { const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer; SecBuffer bufs[4]; SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs}; SSIZE_T size, buf_len = 0; int i; SECURITY_STATUS res; assert(conn->extra_len < ssl_buf_size); if(conn->extra_len) { memcpy(conn->ssl_buf, conn->extra_buf, conn->extra_len); buf_len = conn->extra_len; conn->extra_len = 0; heap_free(conn->extra_buf); conn->extra_buf = NULL; } set_socket_blocking(conn, blocking && !buf_len); size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0); if(size < 0) { if(!buf_len) { if(WSAGetLastError() == WSAEWOULDBLOCK) { TRACE("would block\n"); return WSAEWOULDBLOCK; } WARN("recv failed\n"); return ERROR_INTERNET_CONNECTION_ABORTED; } }else { buf_len += size; } if(!buf_len) { TRACE("EOF\n"); *eof = TRUE; *ret_size = 0; return ERROR_SUCCESS; } *eof = FALSE; do { memset(bufs, 0, sizeof(bufs)); bufs[0].BufferType = SECBUFFER_DATA; bufs[0].cbBuffer = buf_len; bufs[0].pvBuffer = conn->ssl_buf; res = DecryptMessage(&conn->ssl_ctx, &buf_desc, 0, NULL); switch(res) { case SEC_E_OK: break; case SEC_I_CONTEXT_EXPIRED: TRACE("context expired\n"); *eof = TRUE; return ERROR_SUCCESS; case SEC_E_INCOMPLETE_MESSAGE: assert(buf_len < ssl_buf_size); set_socket_blocking(conn, blocking); size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0); if(size < 1) { if(size < 0 && WSAGetLastError() == WSAEWOULDBLOCK) { TRACE("would block\n"); /* FIXME: Optimize extra_buf usage. */ conn->extra_buf = heap_alloc(buf_len); if(!conn->extra_buf) return ERROR_NOT_ENOUGH_MEMORY; conn->extra_len = buf_len; memcpy(conn->extra_buf, conn->ssl_buf, conn->extra_len); return WSAEWOULDBLOCK; } return ERROR_INTERNET_CONNECTION_ABORTED; } buf_len += size; continue; default: WARN("failed: %08x\n", res); return ERROR_INTERNET_CONNECTION_ABORTED; } } while(res != SEC_E_OK); for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { if(bufs[i].BufferType == SECBUFFER_DATA) { size = min(buf_size, bufs[i].cbBuffer); memcpy(buf, bufs[i].pvBuffer, size); if(size < bufs[i].cbBuffer) { assert(!conn->peek_len); conn->peek_msg_mem = conn->peek_msg = heap_alloc(bufs[i].cbBuffer - size); if(!conn->peek_msg) return ERROR_NOT_ENOUGH_MEMORY; conn->peek_len = bufs[i].cbBuffer-size; memcpy(conn->peek_msg, (char*)bufs[i].pvBuffer+size, conn->peek_len); } *ret_size = size; } } for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { if(bufs[i].BufferType == SECBUFFER_EXTRA) { conn->extra_buf = heap_alloc(bufs[i].cbBuffer); if(!conn->extra_buf) return ERROR_NOT_ENOUGH_MEMORY; conn->extra_len = bufs[i].cbBuffer; memcpy(conn->extra_buf, bufs[i].pvBuffer, conn->extra_len); } } return ERROR_SUCCESS; }
void free(void *ptr) { return heap_free(ptr); }
static GpStatus read_element(struct memory_buffer *mbuf, GpRegion *region, region_element *node, INT *count) { GpStatus status; const DWORD *type; type = buffer_read(mbuf, sizeof(*type)); if (!type) return Ok; TRACE("type %#x\n", *type); node->type = *type; switch (node->type) { case CombineModeReplace: case CombineModeIntersect: case CombineModeUnion: case CombineModeXor: case CombineModeExclude: case CombineModeComplement: { region_element *left, *right; left = heap_alloc_zero(sizeof(region_element)); if (!left) return OutOfMemory; right = heap_alloc_zero(sizeof(region_element)); if (!right) { heap_free(left); return OutOfMemory; } status = read_element(mbuf, region, left, count); if (status == Ok) { status = read_element(mbuf, region, right, count); if (status == Ok) { node->elementdata.combine.left = left; node->elementdata.combine.right = right; region->num_children += 2; return Ok; } } heap_free(left); heap_free(right); return status; } case RegionDataRect: { const GpRectF *rc; rc = buffer_read(mbuf, sizeof(*rc)); if (!rc) { ERR("failed to read rect data\n"); return InvalidParameter; } node->elementdata.rect = *rc; *count += 1; return Ok; } case RegionDataPath: { GpPath *path; const struct path_header *path_header; const BYTE *types; path_header = buffer_read(mbuf, sizeof(*path_header)); if (!path_header) { ERR("failed to read path header\n"); return InvalidParameter; } if (path_header->magic != VERSION_MAGIC) { ERR("invalid path header magic %#x\n", path_header->magic); return InvalidParameter; } /* Windows always fails to create an empty path in a region */ if (!path_header->count) { TRACE("refusing to create an empty path in a region\n"); return GenericError; } status = GdipCreatePath(FillModeAlternate, &path); if (status) return status; node->elementdata.path = path; if (!lengthen_path(path, path_header->count)) return OutOfMemory; path->pathdata.Count = path_header->count; if (path_header->flags & ~FLAGS_INTPATH) FIXME("unhandled path flags %#x\n", path_header->flags); if (path_header->flags & FLAGS_INTPATH) { const packed_point *pt; DWORD i; pt = buffer_read(mbuf, sizeof(*pt) * path_header->count); if (!pt) { ERR("failed to read packed %u path points\n", path_header->count); return InvalidParameter; } for (i = 0; i < path_header->count; i++) { path->pathdata.Points[i].X = (REAL)pt[i].X; path->pathdata.Points[i].Y = (REAL)pt[i].Y; } } else { const GpPointF *ptf; ptf = buffer_read(mbuf, sizeof(*ptf) * path_header->count); if (!ptf) { ERR("failed to read %u path points\n", path_header->count); return InvalidParameter; } memcpy(path->pathdata.Points, ptf, sizeof(*ptf) * path_header->count); } types = buffer_read(mbuf, path_header->count); if (!types) { ERR("failed to read %u path types\n", path_header->count); return InvalidParameter; } memcpy(path->pathdata.Types, types, path_header->count); if (path_header->count & 3) { if (!buffer_read(mbuf, 4 - (path_header->count & 3))) { ERR("failed to read rounding %u bytes\n", 4 - (path_header->count & 3)); return InvalidParameter; } } *count += 1; return Ok; } case RegionDataEmptyRect: case RegionDataInfiniteRect: *count += 1; return Ok; default: FIXME("element type %#x is not supported\n", *type); break; } return InvalidParameter; }
static HRESULT HttpProtocol_start_downloading(Protocol *prot) { HttpProtocol *This = impl_from_Protocol(prot); LPWSTR content_type, content_length, ranges; DWORD len = sizeof(DWORD); DWORD status_code; BOOL res; HRESULT hres; static const WCHAR wszDefaultContentType[] = {'t','e','x','t','/','h','t','m','l',0}; if(!This->http_negotiate) { WARN("Expected IHttpNegotiate pointer to be non-NULL\n"); return S_OK; } res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status_code, &len, NULL); if(res) { WCHAR *response_headers; if((This->base.bind_info.dwOptions & BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS) && is_redirect_response(status_code)) { WCHAR *location; TRACE("Got redirect with disabled auto redirects\n"); location = query_http_info(This, HTTP_QUERY_LOCATION); This->base.flags |= FLAG_RESULT_REPORTED | FLAG_LAST_DATA_REPORTED; IInternetProtocolSink_ReportResult(This->base.protocol_sink, INET_E_REDIRECT_FAILED, 0, location); heap_free(location); return INET_E_REDIRECT_FAILED; } response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF); if(response_headers) { hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers, NULL, NULL); heap_free(response_headers); if (hres != S_OK) { WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres); return S_OK; } } }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); } ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES); if(ranges) { IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL); heap_free(ranges); } content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE); if(content_type) { /* remove the charset, if present */ LPWSTR p = strchrW(content_type, ';'); if (p) *p = '\0'; IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, content_type); heap_free(content_type); }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, wszDefaultContentType); } content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH); if(content_length) { This->base.content_length = atoiW(content_length); heap_free(content_length); } return S_OK; }
static HRESULT WINAPI ProtocolSinkHandler_ReportData(IInternetProtocolSink *iface, DWORD bscf, ULONG progress, ULONG progress_max) { BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface); TRACE("(%p)->(%x %u %u)\n", This, bscf, progress, progress_max); This->bscf = bscf; This->progress = progress; This->progress_max = progress_max; if(!This->protocol_sink) return S_OK; if((This->pi & PI_MIMEVERIFICATION) && !This->reported_mime) { BYTE buf[BUFFER_SIZE]; DWORD read = 0; LPWSTR mime; HRESULT hres; do { read = 0; if(is_apartment_thread(This)) This->continue_call++; hres = IInternetProtocol_Read(This->protocol, buf, sizeof(buf)-This->buf_size, &read); if(is_apartment_thread(This)) This->continue_call--; if(FAILED(hres) && hres != E_PENDING) return hres; if(!This->buf) { This->buf = heap_alloc(BUFFER_SIZE); if(!This->buf) return E_OUTOFMEMORY; }else if(read + This->buf_size > BUFFER_SIZE) { BYTE *tmp; tmp = heap_realloc(This->buf, read+This->buf_size); if(!tmp) return E_OUTOFMEMORY; This->buf = tmp; } memcpy(This->buf+This->buf_size, buf, read); This->buf_size += read; }while(This->buf_size < MIME_TEST_SIZE && hres == S_OK); if(This->buf_size < MIME_TEST_SIZE && hres != S_FALSE) return S_OK; bscf = BSCF_FIRSTDATANOTIFICATION; if(hres == S_FALSE) bscf |= BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE; if(!This->reported_mime) { BSTR raw_uri; hres = IUri_GetRawUri(This->uri, &raw_uri); if(FAILED(hres)) return hres; hres = FindMimeFromData(NULL, raw_uri, This->buf, min(This->buf_size, MIME_TEST_SIZE), This->mime, 0, &mime, 0); SysFreeString(raw_uri); if(FAILED(hres)) return hres; heap_free(This->mime); This->mime = heap_strdupW(mime); CoTaskMemFree(mime); This->reported_mime = TRUE; if(This->protocol_sink) IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_MIMETYPEAVAILABLE, This->mime); } } if(!This->protocol_sink) return S_OK; return IInternetProtocolSink_ReportData(This->protocol_sink, bscf, progress, progress_max); }
void filter_postproc_relsets(msieve_obj *obj, merge_t *merge) { /* external interface to the postprocessing phase */ uint32 i, j; uint32 cycle_bins[NUM_CYCLE_BINS + 2] = {0}; uint32 max_ideal_list_size; uint32 num_relations; relation_set_t *relset_array = merge->relset_array; uint32 num_relsets = merge->num_relsets; uint32 num_ideals; hashtable_t h; ideal_list_t ideal_list; heap_t active_heap; heap_t inactive_heap; merge_aux_t *aux; logprintf(obj, "commencing cycle optimization\n"); /* we will call the relation sets 'cycles' here, but they are treated the same as in the merge phase. Instead of a list of ideals, each cycle has a list of relations that occur in that cycle. We assign one 'ideal' to each relation that appears in the collection of cycles, and minimize that. Note that we assume that the merge phase has already cancelled out any relations that appear more than once in a cycle */ hashtable_init(&h, 1, 0); max_ideal_list_size = 0; for (i = num_relations = 0; i < num_relsets; i++) { relation_set_t *r = relset_array + i; uint32 curr_num_relations = r->num_relations; max_ideal_list_size = MAX(max_ideal_list_size, curr_num_relations); num_relations += curr_num_relations; /* initialize the cycle. There are no small ideals, and cycles that have only one relation will never be optimized to have zero relations, so skip those */ r->num_small_ideals = 0; r->num_large_ideals = 0; r->num_active_ideals = 0; if (curr_num_relations == 1) continue; r->num_large_ideals = curr_num_relations; r->num_active_ideals = curr_num_relations; r->data = (uint32 *)xrealloc(r->data, 2 * curr_num_relations * sizeof(uint32)); /* every unique relation is assigned a number */ for (j = 0; j < curr_num_relations; j++) { hashtable_find(&h, r->data + j, r->data + curr_num_relations + j, NULL); } /* relation lists occur in sorted order */ qsort(r->data + curr_num_relations, (size_t)curr_num_relations, sizeof(uint32), compare_uint32); } num_ideals = merge->num_ideals = hashtable_get_num(&h); hashtable_free(&h); logprintf(obj, "start with %u relations\n", num_relations); /* initialize the heaps for tracking cycles; all cycles start out active. Then add each cycle to the heaps; each relation that occurs in more than one cycle is heapified */ aux = (merge_aux_t *)xmalloc(sizeof(merge_aux_t)); heap_init(&active_heap); heap_init(&inactive_heap); ideal_list_init(&ideal_list, num_ideals, 1); for (i = 0; i < num_relsets; i++) { relation_set_t *r = relset_array + i; if (r->num_large_ideals > 1) { heap_add_relset(&active_heap, &inactive_heap, &ideal_list, r, i, 1); } } /* for each relation, starting with the relations that occur in the fewst cycles, - remove all the cycles containing that relation - optimize the collection of cycles - put the cycles back into the heap - make the relation inactive */ num_relations = 0; while (active_heap.num_ideals > 0) { uint32 ideal = heap_remove_best(&active_heap, &ideal_list); load_next_relset_group(aux, &active_heap, &inactive_heap, &ideal_list, relset_array, ideal, 1); num_relations += do_merges_core(aux); ideal_list.list[ideal].active = 0; store_next_relset_group(aux, &active_heap, &inactive_heap, &ideal_list, relset_array); } logprintf(obj, "pruned %u relations\n", num_relations); logprintf(obj, "memory use: %.1f MB\n", (double) get_merge_memuse(relset_array, num_relsets, &ideal_list) / 1048576); /* print statistics on the final collection of cycles */ for (i = j = 0; i < num_relsets; i++) { relation_set_t *r = relset_array + i; j = MAX(j, r->num_relations); if (r->num_relations > NUM_CYCLE_BINS) cycle_bins[NUM_CYCLE_BINS+1]++; else cycle_bins[r->num_relations]++; r->num_small_ideals = 0; r->num_large_ideals = 0; } logprintf(obj, "distribution of cycle lengths:\n"); for (i = 1; i < NUM_CYCLE_BINS + 1; i++) logprintf(obj, "%u relations: %u\n", i, cycle_bins[i]); logprintf(obj, "%u+ relations: %u\n", i, cycle_bins[i]); logprintf(obj, "heaviest cycle: %u relations\n", j); heap_free(&active_heap); heap_free(&inactive_heap); ideal_list_free(&ideal_list); free(aux); }
static nsresult run_insert_script(HTMLDocumentNode *doc, nsISupports *script_iface, nsISupports *parser_iface) { nsIDOMHTMLScriptElement *nsscript; HTMLScriptElement *script_elem; nsIParser *nsparser = NULL; script_queue_entry_t *iter; HTMLInnerWindow *window; nsresult nsres; HRESULT hres; TRACE("(%p)->(%p)\n", doc, script_iface); window = doc->window; if(!window) return NS_OK; nsres = nsISupports_QueryInterface(script_iface, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript); if(NS_FAILED(nsres)) { ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres); return nsres; } if(parser_iface) { nsres = nsISupports_QueryInterface(parser_iface, &IID_nsIParser, (void**)&nsparser); if(NS_FAILED(nsres)) { ERR("Could not get nsIParser iface: %08x\n", nsres); nsparser = NULL; } } hres = script_elem_from_nsscript(doc, nsscript, &script_elem); nsIDOMHTMLScriptElement_Release(nsscript); if(FAILED(hres)) return NS_ERROR_FAILURE; if(nsparser) { nsIParser_BeginEvaluatingParserInsertedScript(nsparser); window->parser_callback_cnt++; } IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface); doc_insert_script(window, script_elem); while(!list_empty(&window->script_queue)) { iter = LIST_ENTRY(list_head(&window->script_queue), script_queue_entry_t, entry); list_remove(&iter->entry); if(!iter->script->parsed) doc_insert_script(window, iter->script); IHTMLScriptElement_Release(&iter->script->IHTMLScriptElement_iface); heap_free(iter); } IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface); if(nsparser) { window->parser_callback_cnt--; nsIParser_EndEvaluatingParserInsertedScript(nsparser); nsIParser_Release(nsparser); } IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface); return NS_OK; }
static HRESULT regexp_match(script_ctx_t *ctx, jsdisp_t *dispex, jsstr_t *jsstr, BOOL gflag, match_result_t **match_result, DWORD *result_cnt) { RegExpInstance *This = (RegExpInstance*)dispex; match_result_t *ret = NULL; match_state_t *result; DWORD i=0, ret_size = 0; heap_pool_t *mark; const WCHAR *str; HRESULT hres; mark = heap_pool_mark(&ctx->tmp_heap); str = jsstr_flatten(jsstr); if(!str) return E_OUTOFMEMORY; result = alloc_match_state(This->jsregexp, &ctx->tmp_heap, str); if(!result) { heap_pool_clear(mark); return E_OUTOFMEMORY; } while(1) { hres = do_regexp_match_next(ctx, This, 0, jsstr, str, result); if(hres == S_FALSE) { hres = S_OK; break; } if(FAILED(hres)) break; if(ret_size == i) { if(ret) { match_result_t *old_ret = ret; ret = heap_realloc(old_ret, (ret_size <<= 1) * sizeof(match_result_t)); if(!ret) heap_free(old_ret); }else { ret = heap_alloc((ret_size=4) * sizeof(match_result_t)); } if(!ret) { hres = E_OUTOFMEMORY; break; } } ret[i].index = result->cp - str - result->match_len; ret[i++].length = result->match_len; if(!gflag && !(This->jsregexp->flags & REG_GLOB)) { hres = S_OK; break; } } heap_pool_clear(mark); if(FAILED(hres)) { heap_free(ret); return hres; } *match_result = ret; *result_cnt = i; return S_OK; }
static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp) { HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface); HRESULT hres = S_OK; TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp); *pdisp = NULL; switch(V_VT(&name)) { case VT_I4: if(V_I4(&name) < 0) return E_INVALIDARG; hres = get_item_idx(This, V_I4(&name), pdisp); break; case VT_UINT: hres = get_item_idx(This, V_UINT(&name), pdisp); break; case VT_BSTR: { DWORD i; if(V_VT(&index) == VT_I4) { LONG idx = V_I4(&index); if(idx < 0) return E_INVALIDARG; for(i=0; i<This->len; i++) { if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--) break; } if(i != This->len) { *pdisp = (IDispatch*)&This->elems[i]->IHTMLElement_iface; IDispatch_AddRef(*pdisp); } }else { elem_vector_t buf = {NULL, 0, 8}; buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*)); for(i=0; i<This->len; i++) { if(is_elem_name(This->elems[i], V_BSTR(&name))) { node_addref(&This->elems[i]->node); elem_vector_add(&buf, This->elems[i]); } } if(buf.len > 1) { elem_vector_normalize(&buf); *pdisp = (IDispatch*)HTMLElementCollection_Create(buf.buf, buf.len); }else { if(buf.len == 1) { /* Already AddRef-ed */ *pdisp = (IDispatch*)&buf.buf[0]->IHTMLElement_iface; } heap_free(buf.buf); } } break; } default: FIXME("Unsupported name %s\n", debugstr_variant(&name)); hres = E_NOTIMPL; } if(SUCCEEDED(hres)) TRACE("returning %p\n", *pdisp); return hres; }
HRESULT get_elem_source_index(HTMLElement *elem, LONG *ret) { elem_vector_t buf = {NULL, 0, 8}; nsIDOMNode *parent_node, *iter; UINT16 parent_type; HTMLDOMNode *node; int i; nsresult nsres; HRESULT hres; iter = elem->node.nsnode; nsIDOMNode_AddRef(iter); /* Find document or document fragment parent. */ while(1) { nsres = nsIDOMNode_GetParentNode(iter, &parent_node); nsIDOMNode_Release(iter); assert(nsres == NS_OK); if(!parent_node) break; nsres = nsIDOMNode_GetNodeType(parent_node, &parent_type); assert(nsres == NS_OK); if(parent_type != ELEMENT_NODE) { if(parent_type != DOCUMENT_NODE && parent_type != DOCUMENT_FRAGMENT_NODE) FIXME("Unexpected parent_type %d\n", parent_type); break; } iter = parent_node; } if(!parent_node) { *ret = -1; return S_OK; } hres = get_node(elem->node.doc, parent_node, TRUE, &node); nsIDOMNode_Release(parent_node); if(FAILED(hres)) return hres; /* Create all children collection and find the element in it. * This could be optimized if we ever find the reason. */ buf.buf = heap_alloc(buf.size*sizeof(*buf.buf)); if(!buf.buf) { IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface); return E_OUTOFMEMORY; } create_all_list(elem->node.doc, node, &buf); for(i=0; i < buf.len; i++) { if(buf.buf[i] == elem) break; } IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface); heap_free(buf.buf); if(i == buf.len) { FIXME("The element is not in parent's child list?\n"); return E_UNEXPECTED; } *ret = i; return S_OK; }
static HRESULT register_server(BOOL do_register) { HRESULT hres; HMODULE hAdvpack; HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable); STRTABLEA strtable; STRENTRYA pse[35]; static CLSID const *clsids[35]; unsigned int i = 0; static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0}; TRACE("(%x)\n", do_register); INF_SET_CLSID(AboutProtocol); INF_SET_CLSID(CAnchorBrowsePropertyPage); INF_SET_CLSID(CBackgroundPropertyPage); INF_SET_CLSID(CCDAnchorPropertyPage); INF_SET_CLSID(CCDGenericPropertyPage); INF_SET_CLSID(CDocBrowsePropertyPage); INF_SET_CLSID(CDwnBindInfo); INF_SET_CLSID(CHiFiUses); INF_SET_CLSID(CHtmlComponentConstructor); INF_SET_CLSID(CImageBrowsePropertyPage); INF_SET_CLSID(CInlineStylePropertyPage); INF_SET_CLSID(CPeerHandler); INF_SET_CLSID(CRecalcEngine); INF_SET_CLSID(CSvrOMUses); INF_SET_CLSID(CrSource); INF_SET_CLSID(ExternalFrameworkSite); INF_SET_CLSID(HTADocument); INF_SET_CLSID(HTMLDocument); INF_SET_CLSID(HTMLLoadOptions); INF_SET_CLSID(HTMLPluginDocument); INF_SET_CLSID(HTMLPopup); INF_SET_CLSID(HTMLPopupDoc); INF_SET_CLSID(HTMLServerDoc); INF_SET_CLSID(HTMLWindowProxy); INF_SET_CLSID(IImageDecodeFilter); INF_SET_CLSID(IImgCtx); INF_SET_CLSID(IntDitherer); INF_SET_CLSID(JSProtocol); INF_SET_CLSID(MHTMLDocument); INF_SET_CLSID(MailtoProtocol); INF_SET_CLSID(ResProtocol); INF_SET_CLSID(Scriptlet); INF_SET_CLSID(SysimageProtocol); INF_SET_CLSID(TridentAPI); INF_SET_ID(LIBID_MSHTML); for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) { pse[i].pszValue = heap_alloc(39); sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0], clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4], clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]); } strtable.cEntries = sizeof(pse)/sizeof(pse[0]); strtable.pse = pse; hAdvpack = LoadLibraryW(wszAdvpack); pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall"); hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable); FreeLibrary(hAdvpack); for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) heap_free(pse[i].pszValue); if(FAILED(hres)) ERR("RegInstall failed: %08x\n", hres); return hres; }
static void free_strings(void) { unsigned int i; for(i = 0; i < sizeof(status_strings)/sizeof(*status_strings); i++) heap_free(status_strings[i]); }
static void freeMemory_deleteFromEmptyMemory_status(void ** state){ heap_t * heap1 = heap_new(5); heap_freeMemory(heap1, 0); assert_int_equal(heap_getStatus(heap1), MEMORY_EMPTY); heap_free(heap1); }
void vmm_free(void *ptr) { heap_free(&normal_heap, ptr); }
HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, jsstr_t *jsstr, jsval_t *r) { static const WCHAR indexW[] = {'i','n','d','e','x',0}; static const WCHAR inputW[] = {'i','n','p','u','t',0}; static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0}; RegExpInstance *regexp = (RegExpInstance*)re; match_result_t *match_result; unsigned match_cnt, i; const WCHAR *str; jsdisp_t *array; HRESULT hres; str = jsstr_flatten(jsstr); if(!str) return E_OUTOFMEMORY; if(!(regexp->jsregexp->flags & REG_GLOB)) { match_state_t *match; heap_pool_t *mark; mark = heap_pool_mark(&ctx->tmp_heap); match = alloc_match_state(regexp->jsregexp, &ctx->tmp_heap, str); if(!match) { heap_pool_clear(mark); return E_OUTOFMEMORY; } hres = regexp_match_next(ctx, ®exp->dispex, 0, jsstr, &match); if(FAILED(hres)) { heap_pool_clear(mark); return hres; } if(r) { if(hres == S_OK) { IDispatch *ret; hres = create_match_array(ctx, jsstr, match, &ret); if(SUCCEEDED(hres)) *r = jsval_disp(ret); }else { *r = jsval_null(); } } heap_pool_clear(mark); return S_OK; } hres = regexp_match(ctx, ®exp->dispex, jsstr, FALSE, &match_result, &match_cnt); if(FAILED(hres)) return hres; if(!match_cnt) { TRACE("no match\n"); if(r) *r = jsval_null(); return S_OK; } hres = create_array(ctx, match_cnt, &array); if(FAILED(hres)) return hres; for(i=0; i < match_cnt; i++) { jsstr_t *tmp_str; tmp_str = jsstr_substr(jsstr, match_result[i].index, match_result[i].length); if(!tmp_str) { hres = E_OUTOFMEMORY; break; } hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str)); jsstr_release(tmp_str); if(FAILED(hres)) break; } while(SUCCEEDED(hres)) { hres = jsdisp_propput_name(array, indexW, jsval_number(match_result[match_cnt-1].index)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, lastIndexW, jsval_number(match_result[match_cnt-1].index + match_result[match_cnt-1].length)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, inputW, jsval_string(jsstr)); break; } heap_free(match_result); if(SUCCEEDED(hres) && r) *r = jsval_obj(array); else jsdisp_release(array); return hres; }
void vmm_dma_free(void *ptr) { heap_free(&dma_heap, ptr); }
HRESULT opentype_get_font_strings_from_id(const void *table_data, DWRITE_INFORMATIONAL_STRING_ID id, IDWriteLocalizedStrings **strings) { const TT_NAME_V0 *header; BYTE *storage_area = 0; USHORT count = 0; UINT16 name_id; BOOL exists; HRESULT hr; int i; if (!table_data) return E_FAIL; hr = create_localizedstrings(strings); if (FAILED(hr)) return hr; header = table_data; switch (header->format) { case 0: break; default: FIXME("unsupported NAME format %d\n", header->format); } storage_area = (LPBYTE)table_data + GET_BE_WORD(header->stringOffset); count = GET_BE_WORD(header->count); name_id = dwriteid_to_opentypeid[id]; exists = FALSE; for (i = 0; i < count; i++) { const TT_NameRecord *record = &header->nameRecord[i]; USHORT lang_id, length, offset, encoding, platform; if (GET_BE_WORD(record->nameID) != name_id) continue; exists = TRUE; /* Right now only accept unicode and windows encoded fonts */ platform = GET_BE_WORD(record->platformID); if (platform != OPENTYPE_PLATFORM_UNICODE && platform != OPENTYPE_PLATFORM_MAC && platform != OPENTYPE_PLATFORM_WIN) { FIXME("platform %i not supported\n", platform); continue; } /* Skip such entries for now, as it's not clear which locale is implied when unicode platform is used. Also fonts tend to duplicate those strings as WIN platform entries. */ if (platform == OPENTYPE_PLATFORM_UNICODE) continue; lang_id = GET_BE_WORD(record->languageID); length = GET_BE_WORD(record->length); offset = GET_BE_WORD(record->offset); encoding = GET_BE_WORD(record->encodingID); if (lang_id < 0x8000) { WCHAR locale[LOCALE_NAME_MAX_LENGTH]; WCHAR *name_string; UINT codepage; codepage = get_name_record_codepage(platform, encoding); get_name_record_locale(platform, lang_id, locale, sizeof(locale)/sizeof(WCHAR)); if (codepage) { DWORD len = MultiByteToWideChar(codepage, 0, (LPSTR)(storage_area + offset), length, NULL, 0); name_string = heap_alloc(sizeof(WCHAR) * (len+1)); MultiByteToWideChar(codepage, 0, (LPSTR)(storage_area + offset), length, name_string, len); name_string[len] = 0; } else { int i; length /= sizeof(WCHAR); name_string = heap_strdupnW((LPWSTR)(storage_area + offset), length); for (i = 0; i < length; i++) name_string[i] = GET_BE_WORD(name_string[i]); } TRACE("string %s for locale %s found\n", debugstr_w(name_string), debugstr_w(locale)); add_localizedstring(*strings, locale, name_string); heap_free(name_string); } else { FIXME("handle NAME format 1\n"); continue; } } if (!exists) { IDWriteLocalizedStrings_Release(*strings); *strings = NULL; } return hr; }
static HRESULT HttpProtocol_start_downloading(Protocol *prot) { HttpProtocol *This = impl_from_Protocol(prot); LPWSTR content_type, content_length, ranges; DWORD len = sizeof(DWORD); DWORD status_code; BOOL res; HRESULT hres; static const WCHAR wszDefaultContentType[] = {'t','e','x','t','/','h','t','m','l',0}; if(!This->http_negotiate) { WARN("Expected IHttpNegotiate pointer to be non-NULL\n"); return S_OK; } res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status_code, &len, NULL); if(res) { LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF); if(response_headers) { hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers, NULL, NULL); heap_free(response_headers); if (hres != S_OK) { WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres); return S_OK; } } }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); } ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES); if(ranges) { IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL); heap_free(ranges); } content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE); if(content_type) { /* remove the charset, if present */ LPWSTR p = strchrW(content_type, ';'); if (p) *p = '\0'; IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, content_type); heap_free(content_type); }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, wszDefaultContentType); } content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH); if(content_length) { This->base.content_length = atoiW(content_length); heap_free(content_length); } return S_OK; }
HRESULT RegisteredTask_create(const WCHAR *path, const WCHAR *name, ITaskDefinition *definition, LONG flags, TASK_LOGON_TYPE logon, IRegisteredTask **obj, BOOL create) { WCHAR *full_name; RegisteredTask *regtask; HRESULT hr; if (!name) { if (!create) return E_INVALIDARG; /* NULL task name is allowed only in the root folder */ if (path[0] != '\\' || path[1]) return E_INVALIDARG; full_name = NULL; } else { full_name = get_full_path(path, name); if (!full_name) return E_OUTOFMEMORY; } regtask = heap_alloc(sizeof(*regtask)); if (!regtask) { heap_free(full_name); return E_OUTOFMEMORY; } if (create) { WCHAR *actual_path = NULL; TASK_XML_ERROR_INFO *error_info = NULL; BSTR xml = NULL; hr = ITaskDefinition_get_XmlText(definition, &xml); if (hr != S_OK || (hr = SchRpcRegisterTask(full_name, xml, flags, NULL, logon, 0, NULL, &actual_path, &error_info)) != S_OK) { heap_free(full_name); heap_free(regtask); SysFreeString(xml); return hr; } heap_free(full_name); full_name = heap_strdupW(actual_path); MIDL_user_free(actual_path); } else { static const WCHAR languages[] = { 0 }; DWORD count = 0; WCHAR *xml = NULL; hr = SchRpcRetrieveTask(full_name, languages, &count, &xml); if (hr != S_OK || (hr = ITaskDefinition_put_XmlText(definition, xml)) != S_OK) { heap_free(full_name); heap_free(regtask); return hr; } MIDL_user_free(xml); } regtask->IRegisteredTask_iface.lpVtbl = &RegisteredTask_vtbl; regtask->path = full_name; regtask->ref = 1; regtask->taskdef = definition; *obj = ®task->IRegisteredTask_iface; TRACE("created %p\n", *obj); return S_OK; }
/****************************************************************************** * GdipCreateRegionHrgn [GDIPLUS.@] */ GpStatus WINGDIPAPI GdipCreateRegionHrgn(HRGN hrgn, GpRegion **region) { DWORD size; LPRGNDATA buf; LPRECT rect; GpStatus stat; GpPath* path; GpRegion* local; DWORD i; TRACE("(%p, %p)\n", hrgn, region); if(!region || !(size = GetRegionData(hrgn, 0, NULL))) return InvalidParameter; buf = heap_alloc_zero(size); if(!buf) return OutOfMemory; if(!GetRegionData(hrgn, size, buf)){ heap_free(buf); return GenericError; } if(buf->rdh.nCount == 0){ if((stat = GdipCreateRegion(&local)) != Ok){ heap_free(buf); return stat; } if((stat = GdipSetEmpty(local)) != Ok){ heap_free(buf); GdipDeleteRegion(local); return stat; } *region = local; heap_free(buf); return Ok; } if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok){ heap_free(buf); return stat; } rect = (LPRECT)buf->Buffer; for(i = 0; i < buf->rdh.nCount; i++){ if((stat = GdipAddPathRectangle(path, (REAL)rect->left, (REAL)rect->top, (REAL)(rect->right - rect->left), (REAL)(rect->bottom - rect->top))) != Ok){ heap_free(buf); GdipDeletePath(path); return stat; } rect++; } stat = GdipCreateRegionPath(path, region); heap_free(buf); GdipDeletePath(path); return stat; }
static void Array_destructor(jsdisp_t *dispex) { heap_free(dispex); }
static HRESULT WINAPI schema_cache_add(IXMLDOMSchemaCollection2* iface, BSTR uri, VARIANT var) { schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface); xmlChar* name = xmlChar_from_wchar(uri); TRACE("(%p)->(%s, var(vt %x))\n", This, debugstr_w(uri), V_VT(&var)); switch (V_VT(&var)) { case VT_NULL: { xmlHashRemoveEntry(This->cache, name, cache_free); } break; case VT_BSTR: { cache_entry* entry = cache_entry_from_url(var, name, This->version); if (entry) { cache_entry_add_ref(entry); } else { heap_free(name); return E_FAIL; } xmlHashRemoveEntry(This->cache, name, cache_free); xmlHashAddEntry(This->cache, name, entry); } break; case VT_DISPATCH: { xmlDocPtr doc = NULL; cache_entry* entry; SCHEMA_TYPE type; IXMLDOMNode* domnode = NULL; IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IXMLDOMNode, (void**)&domnode); if (domnode) doc = xmlNodePtr_from_domnode(domnode, XML_DOCUMENT_NODE)->doc; if (!doc) { IXMLDOMNode_Release(domnode); heap_free(name); return E_INVALIDARG; } type = schema_type_from_xmlDocPtr(doc); if (type == SCHEMA_TYPE_XSD) { entry = cache_entry_from_xsd_doc(doc, name, This->version); } else if (type == SCHEMA_TYPE_XDR) { entry = cache_entry_from_xdr_doc(doc, name, This->version); } else { WARN("invalid schema!\n"); entry = NULL; } IXMLDOMNode_Release(domnode); if (entry) { cache_entry_add_ref(entry); } else { heap_free(name); return E_FAIL; } xmlHashRemoveEntry(This->cache, name, cache_free); xmlHashAddEntry(This->cache, name, entry); } break; default: { heap_free(name); return E_INVALIDARG; } } heap_free(name); return S_OK; }
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, unsigned seplen, jsval_t *r) { jsstr_t **str_tab, *ret = NULL; jsval_t val; DWORD i; HRESULT hres = E_FAIL; if(!length) { if(r) *r = jsval_string(jsstr_empty()); return S_OK; } str_tab = heap_alloc_zero(length * sizeof(*str_tab)); if(!str_tab) return E_OUTOFMEMORY; for(i=0; i < length; i++) { hres = jsdisp_get_idx(array, i, &val); if(hres == DISP_E_UNKNOWNNAME) { hres = S_OK; continue; } else if(FAILED(hres)) break; if(!is_undefined(val) && !is_null(val)) { hres = to_string(ctx, val, str_tab+i); jsval_release(val); if(FAILED(hres)) break; } } if(SUCCEEDED(hres)) { DWORD len = 0; if(str_tab[0]) len = jsstr_length(str_tab[0]); for(i=1; i < length; i++) { len += seplen; if(str_tab[i]) len += jsstr_length(str_tab[i]); if(len > JSSTR_MAX_LENGTH) { hres = E_OUTOFMEMORY; break; } } if(SUCCEEDED(hres)) { WCHAR *ptr = NULL; ret = jsstr_alloc_buf(len, &ptr); if(ret) { if(str_tab[0]) ptr += jsstr_flush(str_tab[0], ptr); for(i=1; i < length; i++) { if(seplen) { memcpy(ptr, sep, seplen*sizeof(WCHAR)); ptr += seplen; } if(str_tab[i]) ptr += jsstr_flush(str_tab[i], ptr); } }else { hres = E_OUTOFMEMORY; } } } for(i=0; i < length; i++) { if(str_tab[i]) jsstr_release(str_tab[i]); } heap_free(str_tab); if(FAILED(hres)) return hres; TRACE("= %s\n", debugstr_jsstr(ret)); if(r) *r = jsval_string(ret); else jsstr_release(ret); return S_OK; }
static DWORD netcon_secure_connect_setup(netconn_t *connection, BOOL compat_mode) { SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}}; SecBufferDesc out_desc = {SECBUFFER_VERSION, 1, &out_buf}, in_desc = {SECBUFFER_VERSION, 2, in_bufs}; SecHandle *cred = &cred_handle; BYTE *read_buf; SIZE_T read_buf_size = 2048; ULONG attrs = 0; CtxtHandle ctx; SSIZE_T size; int bits; const CERT_CONTEXT *cert; SECURITY_STATUS status; DWORD res = ERROR_SUCCESS; const DWORD isc_req_flags = ISC_REQ_ALLOCATE_MEMORY|ISC_REQ_USE_SESSION_KEY|ISC_REQ_CONFIDENTIALITY |ISC_REQ_SEQUENCE_DETECT|ISC_REQ_REPLAY_DETECT|ISC_REQ_MANUAL_CRED_VALIDATION; if(!ensure_cred_handle()) return ERROR_INTERNET_SECURITY_CHANNEL_ERROR; if(compat_mode) { if(!have_compat_cred_handle) return ERROR_INTERNET_SECURITY_CHANNEL_ERROR; cred = &compat_cred_handle; } read_buf = heap_alloc(read_buf_size); if(!read_buf) return ERROR_OUTOFMEMORY; status = InitializeSecurityContextW(cred, NULL, connection->server->name, isc_req_flags, 0, 0, NULL, 0, &ctx, &out_desc, &attrs, NULL); assert(status != SEC_E_OK); set_socket_blocking(connection, TRUE); while(status == SEC_I_CONTINUE_NEEDED || status == SEC_E_INCOMPLETE_MESSAGE) { if(out_buf.cbBuffer) { assert(status == SEC_I_CONTINUE_NEEDED); TRACE("sending %u bytes\n", out_buf.cbBuffer); size = sock_send(connection->socket, out_buf.pvBuffer, out_buf.cbBuffer, 0); if(size != out_buf.cbBuffer) { ERR("send failed\n"); status = ERROR_INTERNET_SECURITY_CHANNEL_ERROR; break; } FreeContextBuffer(out_buf.pvBuffer); out_buf.pvBuffer = NULL; out_buf.cbBuffer = 0; } if(status == SEC_I_CONTINUE_NEEDED) { assert(in_bufs[1].cbBuffer < read_buf_size); memmove(read_buf, (BYTE*)in_bufs[0].pvBuffer+in_bufs[0].cbBuffer-in_bufs[1].cbBuffer, in_bufs[1].cbBuffer); in_bufs[0].cbBuffer = in_bufs[1].cbBuffer; in_bufs[1].BufferType = SECBUFFER_EMPTY; in_bufs[1].cbBuffer = 0; in_bufs[1].pvBuffer = NULL; } assert(in_bufs[0].BufferType == SECBUFFER_TOKEN); assert(in_bufs[1].BufferType == SECBUFFER_EMPTY); if(in_bufs[0].cbBuffer + 1024 > read_buf_size) { BYTE *new_read_buf; new_read_buf = heap_realloc(read_buf, read_buf_size + 1024); if(!new_read_buf) { status = E_OUTOFMEMORY; break; } in_bufs[0].pvBuffer = read_buf = new_read_buf; read_buf_size += 1024; } size = sock_recv(connection->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0); if(size < 1) { WARN("recv error\n"); res = ERROR_INTERNET_SECURITY_CHANNEL_ERROR; break; } TRACE("recv %lu bytes\n", size); in_bufs[0].cbBuffer += size; in_bufs[0].pvBuffer = read_buf; status = InitializeSecurityContextW(cred, &ctx, connection->server->name, isc_req_flags, 0, 0, &in_desc, 0, NULL, &out_desc, &attrs, NULL); TRACE("InitializeSecurityContext ret %08x\n", status); if(status == SEC_E_OK) { if(SecIsValidHandle(&connection->ssl_ctx)) DeleteSecurityContext(&connection->ssl_ctx); connection->ssl_ctx = ctx; if(in_bufs[1].BufferType == SECBUFFER_EXTRA) FIXME("SECBUFFER_EXTRA not supported\n"); status = QueryContextAttributesW(&ctx, SECPKG_ATTR_STREAM_SIZES, &connection->ssl_sizes); if(status != SEC_E_OK) { WARN("Could not get sizes\n"); break; } status = QueryContextAttributesW(&ctx, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (void*)&cert); if(status == SEC_E_OK) { res = netconn_verify_cert(connection, cert, cert->hCertStore); CertFreeCertificateContext(cert); if(res != ERROR_SUCCESS) { WARN("cert verify failed: %u\n", res); break; } }else { WARN("Could not get cert\n"); break; } connection->ssl_buf = heap_alloc(connection->ssl_sizes.cbHeader + connection->ssl_sizes.cbMaximumMessage + connection->ssl_sizes.cbTrailer); if(!connection->ssl_buf) { res = GetLastError(); break; } } } heap_free(read_buf); if(status != SEC_E_OK || res != ERROR_SUCCESS) { WARN("Failed to establish SSL connection: %08x (%u)\n", status, res); heap_free(connection->ssl_buf); connection->ssl_buf = NULL; return res ? res : ERROR_INTERNET_SECURITY_CHANNEL_ERROR; } TRACE("established SSL connection\n"); connection->secure = TRUE; connection->security_flags |= SECURITY_FLAG_SECURE; bits = NETCON_GetCipherStrength(connection); if (bits >= 128) connection->security_flags |= SECURITY_FLAG_STRENGTH_STRONG; else if (bits >= 56) connection->security_flags |= SECURITY_FLAG_STRENGTH_MEDIUM; else connection->security_flags |= SECURITY_FLAG_STRENGTH_WEAK; if(connection->mask_errors) connection->server->security_flags = connection->security_flags; return ERROR_SUCCESS; }
/* ECMA-262 3rd Edition 15.4.4.11 */ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *jsthis, *cmp_func = NULL; jsval_t *vtab, **sorttab = NULL; DWORD length; DWORD i; HRESULT hres = S_OK; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(argc > 1) { WARN("invalid arg_cnt %d\n", argc); return E_FAIL; } if(argc == 1) { if(!is_object_instance(argv[0])) { WARN("arg is not dispatch\n"); return E_FAIL; } cmp_func = iface_to_jsdisp(get_object(argv[0])); if(!cmp_func || !is_class(cmp_func, JSCLASS_FUNCTION)) { WARN("cmp_func is not a function\n"); if(cmp_func) jsdisp_release(cmp_func); return E_FAIL; } } if(!length) { if(cmp_func) jsdisp_release(cmp_func); if(r) *r = jsval_obj(jsdisp_addref(jsthis)); return S_OK; } vtab = heap_alloc_zero(length * sizeof(*vtab)); if(vtab) { for(i=0; i<length; i++) { hres = jsdisp_get_idx(jsthis, i, vtab+i); if(hres == DISP_E_UNKNOWNNAME) { vtab[i] = jsval_undefined(); hres = S_OK; } else if(FAILED(hres)) { WARN("Could not get elem %d: %08x\n", i, hres); break; } } }else { hres = E_OUTOFMEMORY; } if(SUCCEEDED(hres)) { sorttab = heap_alloc(length*2*sizeof(*sorttab)); if(!sorttab) hres = E_OUTOFMEMORY; } /* merge-sort */ if(SUCCEEDED(hres)) { jsval_t *tmpv, **tmpbuf; INT cmp; tmpbuf = sorttab + length; for(i=0; i < length; i++) sorttab[i] = vtab+i; for(i=0; i < length/2; i++) { hres = sort_cmp(ctx, cmp_func, *sorttab[2*i+1], *sorttab[2*i], &cmp); if(FAILED(hres)) break; if(cmp < 0) { tmpv = sorttab[2*i]; sorttab[2*i] = sorttab[2*i+1]; sorttab[2*i+1] = tmpv; } } if(SUCCEEDED(hres)) { DWORD k, a, b, bend; for(k=2; k < length; k *= 2) { for(i=0; i+k < length; i += 2*k) { a = b = 0; if(i+2*k <= length) bend = k; else bend = length - (i+k); memcpy(tmpbuf, sorttab+i, k*sizeof(jsval_t*)); while(a < k && b < bend) { hres = sort_cmp(ctx, cmp_func, *tmpbuf[a], *sorttab[i+k+b], &cmp); if(FAILED(hres)) break; if(cmp < 0) { sorttab[i+a+b] = tmpbuf[a]; a++; }else { sorttab[i+a+b] = sorttab[i+k+b]; b++; } } if(FAILED(hres)) break; if(a < k) memcpy(sorttab+i+a+b, tmpbuf+a, (k-a)*sizeof(jsval_t*)); } if(FAILED(hres)) break; } } for(i=0; SUCCEEDED(hres) && i < length; i++) hres = jsdisp_propput_idx(jsthis, i, *sorttab[i]); } if(vtab) { for(i=0; i < length; i++) jsval_release(vtab[i]); heap_free(vtab); } heap_free(sorttab); if(cmp_func) jsdisp_release(cmp_func); if(FAILED(hres)) return hres; if(r) *r = jsval_obj(jsdisp_addref(jsthis)); return S_OK; }
/* Search the CHM storage stream (an HTML file) for the requested text. * * Before searching the HTML file all HTML tags are removed so that only * the content of the document is scanned. If the search string is found * then the title of the document is returned. */ static WCHAR *SearchCHM_File(IStorage *pStorage, const WCHAR *file, const char *needle) { char *buffer = heap_alloc(BLOCK_SIZE); strbuf_t content, node, node_name; IStream *temp_stream = NULL; DWORD i, buffer_size = 0; WCHAR *title = NULL; BOOL found = FALSE; stream_t stream; HRESULT hres; hres = IStorage_OpenStream(pStorage, file, NULL, STGM_READ, 0, &temp_stream); if(FAILED(hres)) { FIXME("Could not open '%s' stream: %08x\n", debugstr_w(file), hres); goto cleanup; } strbuf_init(&node); strbuf_init(&content); strbuf_init(&node_name); stream_init(&stream, temp_stream); /* Remove all HTML formatting and record the title */ while(next_node(&stream, &node)) { get_node_name(&node, &node_name); if(next_content(&stream, &content) && content.len > 1) { char *text = &content.buf[1]; int textlen = content.len-1; if(!strcasecmp(node_name.buf, "title")) { int wlen = MultiByteToWideChar(CP_ACP, 0, text, textlen, NULL, 0); title = heap_alloc((wlen+1)*sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, text, textlen, title, wlen); title[wlen] = 0; } buffer = heap_realloc(buffer, buffer_size + textlen + 1); memcpy(&buffer[buffer_size], text, textlen); buffer[buffer_size + textlen] = '\0'; buffer_size += textlen; } strbuf_zero(&node); strbuf_zero(&content); } /* Convert the buffer to lower case for comparison against the * requested text (already in lower case). */ for(i=0;i<buffer_size;i++) buffer[i] = tolower(buffer[i]); /* Search the decoded buffer for the requested text */ if(strstr(buffer, needle)) found = TRUE; strbuf_free(&node); strbuf_free(&content); strbuf_free(&node_name); cleanup: heap_free(buffer); if(temp_stream) IStream_Release(temp_stream); if(!found) { heap_free(title); return NULL; } return title; }
static void ClassFactory_Destructor(ClassFactory *This) { TRACE("Destroying class factory %p\n", This); heap_free(This); BROWSEUI_refCount--; }
HRESULT create_selection(xmlNodePtr node, xmlChar* query, IXMLDOMNodeList **out) { domselection *This = heap_alloc(sizeof(domselection)); xmlXPathContextPtr ctxt = xmlXPathNewContext(node->doc); HRESULT hr; TRACE("(%p, %s, %p)\n", node, debugstr_a((char const*)query), out); *out = NULL; if (!This || !ctxt || !query) { xmlXPathFreeContext(ctxt); heap_free(This); return E_OUTOFMEMORY; } This->IXMLDOMSelection_iface.lpVtbl = &domselection_vtbl; This->ref = 1; This->resultPos = 0; This->node = node; This->enumvariant = NULL; init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMSelection_iface, &domselection_dispex); xmldoc_add_ref(This->node->doc); ctxt->error = query_serror; ctxt->node = node; registerNamespaces(ctxt); if (is_xpathmode(This->node->doc)) { xmlXPathRegisterAllFunctions(ctxt); This->result = xmlXPathEvalExpression(query, ctxt); } else { xmlChar* pattern_query = XSLPattern_to_XPath(ctxt, query); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"not", xmlXPathNotFunction); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"boolean", xmlXPathBooleanFunction); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"index", XSLPattern_index); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"end", XSLPattern_end); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"nodeType", XSLPattern_nodeType); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IEq", XSLPattern_OP_IEq); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_INEq", XSLPattern_OP_INEq); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILt", XSLPattern_OP_ILt); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILEq", XSLPattern_OP_ILEq); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGt", XSLPattern_OP_IGt); xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGEq", XSLPattern_OP_IGEq); This->result = xmlXPathEvalExpression(pattern_query, ctxt); xmlFree(pattern_query); } if (!This->result || This->result->type != XPATH_NODESET) { hr = E_FAIL; goto cleanup; } *out = (IXMLDOMNodeList*)&This->IXMLDOMSelection_iface; hr = S_OK; TRACE("found %d matches\n", xmlXPathNodeSetGetLength(This->result->nodesetval)); cleanup: if (This && FAILED(hr)) IXMLDOMSelection_Release( &This->IXMLDOMSelection_iface ); xmlXPathFreeContext(ctxt); return hr; }
static void createNewHeap_emptyHeap_zeroCount(void ** state){ heap_t * heap1 = heap_new(5); assert_null(heap_amountOfObjects(heap1)); heap_free(heap1); }