bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer, bool& progress) { if (_ssl == nullptr || ! _isConnected) { return false; } progress = false; do { again: // reserve some memory for reading if (stringBuffer.reserve(READBUFFER_SIZE) == TRI_ERROR_OUT_OF_MEMORY) { // out of memory TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); return false; } int lenRead = SSL_read(_ssl, stringBuffer.end(), READBUFFER_SIZE - 1); switch (SSL_get_error(_ssl, lenRead)) { case SSL_ERROR_NONE: progress = true; stringBuffer.increaseLength(lenRead); break; case SSL_ERROR_ZERO_RETURN: SSL_shutdown(_ssl); _isConnected = false; return true; case SSL_ERROR_WANT_READ: goto again; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_CONNECT: case SSL_ERROR_SYSCALL: default: /* unexpected */ return false; } } while (readable()); return true; }
bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer, bool& connectionClosed) { #ifdef _WIN32 char windowsErrorBuf[256]; #endif connectionClosed = true; if (_ssl == nullptr) { return false; } if (! _isConnected) { return true; } connectionClosed = false; do { again: // reserve some memory for reading if (stringBuffer.reserve(READBUFFER_SIZE) == TRI_ERROR_OUT_OF_MEMORY) { // out of memory TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); return false; } ERR_clear_error(); int lenRead = SSL_read(_ssl, stringBuffer.end(), READBUFFER_SIZE - 1); switch (SSL_get_error(_ssl, lenRead)) { case SSL_ERROR_NONE: stringBuffer.increaseLength(lenRead); break; case SSL_ERROR_ZERO_RETURN: connectionClosed = true; SSL_shutdown(_ssl); _isConnected = false; return true; case SSL_ERROR_WANT_READ: goto again; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_CONNECT: case SSL_ERROR_SYSCALL: default: { char const* pErr = STR_ERROR(); int errorDetail = ERR_get_error(); char errorBuffer[256]; ERR_error_string_n(errorDetail, errorBuffer, sizeof(errorBuffer)); _errorDetails = std::string("SSL: while reading: error '") + std::to_string(errno) + std::string("' - ") + errorBuffer + std::string("' - ") + pErr; /* unexpected */ connectionClosed = true; return false; } } } while (readable()); return true; }
/* * Resolve the name of a function. If the function already has a name * listed, then it is skipped. Otherwise an intelligent name is guessed to * assign to the function's displayAtom field */ JSAtom *resolveFun(ParseNode *pn, HandleAtom prefix) { JS_ASSERT(pn != NULL && pn->isKind(PNK_FUNCTION)); RootedFunction fun(cx, pn->pn_funbox->function()); StringBuffer buf(cx); this->buf = &buf; /* If the function already has a name, use that */ if (fun->displayAtom() != NULL) { if (prefix == NULL) return fun->displayAtom(); if (!buf.append(prefix) || !buf.append("/") || !buf.append(fun->displayAtom())) return NULL; return buf.finishAtom(); } /* If a prefix is specified, then it is a form of namespace */ if (prefix != NULL && (!buf.append(prefix) || !buf.append("/"))) return NULL; /* Gather all nodes relevant to naming */ ParseNode *toName[MaxParents]; size_t size; ParseNode *assignment = gatherNameable(toName, &size); /* If the function is assigned to something, then that is very relevant */ if (assignment) { if (assignment->isAssignment()) assignment = assignment->pn_left; if (!nameExpression(assignment)) return NULL; } /* * Other than the actual assignment, other relevant nodes to naming are * those in object initializers and then particular nodes marking a * contribution. */ for (int pos = size - 1; pos >= 0; pos--) { ParseNode *node = toName[pos]; if (node->isKind(PNK_COLON)) { ParseNode *left = node->pn_left; if (left->isKind(PNK_NAME) || left->isKind(PNK_STRING)) { if (!appendPropertyReference(left->pn_atom)) return NULL; } else if (left->isKind(PNK_NUMBER)) { if (!appendNumericPropertyReference(left->pn_dval)) return NULL; } } else { /* * Don't have consecutive '<' characters, and also don't start * with a '<' character. */ if (!buf.empty() && *(buf.end() - 1) != '<' && !buf.append("<")) return NULL; } } /* * functions which are "genuinely anonymous" but are contained in some * other namespace are rather considered as "contributing" to the outer * function, so give them a contribution symbol here. */ if (!buf.empty() && *(buf.end() - 1) == '/' && !buf.append("<")) return NULL; if (buf.empty()) return NULL; JSAtom *atom = buf.finishAtom(); if (!atom) return NULL; fun->setGuessedAtom(atom); return atom; }
void Registry::getStringToBuffer(StringBuffer& buffer, StringRange valueName) const { assert("Empty Registry" && *this); DWORD type = REG_NONE; DWORD size = 0; LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size); if (result == ERROR_SUCCESS && 0 < size) { if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_MULTI_SZ) { throw ValueKindMismatchException(); } int length = size / sizeof(wchar_t); buffer.reserveAdditionally(length); result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, reinterpret_cast<LPBYTE>(buffer.end()), &size); buffer.expandLength(length - 1); } if (result == ERROR_FILE_NOT_FOUND) { throw ValueNotFoundException(); } checkResult(result); }