Esempio n. 1
0
uint8_t asfHeader::open(const char *name)
{
  _fd=ADM_fopen(name,"rb");
  if(!_fd)
  {
    GUI_Error_HIG("File Error.","Cannot open file\n");
    return 0; 
  }
  myName=ADM_strdup(name);
  if(!getHeaders())
  {
    return 0; 
  }
  ADM_info("Stream Video: index=%d, sid=%d\n",(int)_videoIndex,(int)_videoStreamId);
  for(int i=0;i<_nbAudioTrack;i++)
    ADM_info("Stream Audio: index=%d, sid=%d\n",
                (int)_allAudioTracks[i].streamIndex,(int)_allAudioTracks[i].streamIndex);
  buildIndex();
  fseeko(_fd,_dataStartOffset,SEEK_SET);
  _packet=new asfPacket(_fd,_nbPackets,_packetSize,&readQueue,&storageQueue,_dataStartOffset);
  curSeq=1;
  for(int i=0;i<_nbAudioTrack;i++)
  {
        _audioAccess[i]=new asfAudioAccess(this,i);
        _audioStreams[i]=ADM_audioCreateStream(&(_allAudioTracks[i].wavHeader), _audioAccess[i]);
  }
  if(!nbImage)
    {
        ADM_error("No image found \n");
        return 0;
    }
  return 1;
}
Esempio n. 2
0
EksponatMuzealny::r2f EStarodruk::saveElement(){
    r2f data;
    QStringList h = getHeaders();
    QStringList a = getAtrybuty();
    for (int i=0; i<h.size(); i++)
        data.append(qMakePair(h[i],a[i]));
    return data;
}
Esempio n. 3
0
void SpellList::populate()
{
    if (!complete() || level() < 0 || className().isEmpty()) {
        return;
    }

    int role = allSpells->getHeaders().key(className().toLatin1(), -1);
    if (role < 0) {
        qWarning() << className() << "is not a valid class name";
        return;
    }

    QList<Entry> available;
    int count = 0;
    for (QVariant spell : allSpells->getData()) {
        if (spell.toList().at(role) == level()) {
            available.push_back({{""}, level(), count});
        }
        count++;
    }
    model()->setSpells(available);
}
Esempio n. 4
0
uint8_t asfHeader::open(char *name)
{
  _fd=fopen(name,"rb");
  if(!_fd)
  {
    GUI_Error_HIG("File Error.","Cannot open file\n");
    return 0; 
  }
  myName=ADM_strdup(name);
  if(!getHeaders())
  {
    return 0; 
  }
  buildIndex();
  fseeko(_fd,_dataStartOffset,SEEK_SET);
  _packet=new asfPacket(_fd,_nbPackets,_packetSize,&readQueue,_dataStartOffset);
  curSeq=1;
  if(_nbAudioTrack)
  {
    _curAudio=new asfAudio(this,_currentAudioStream);
  }
  return 1;
}
Esempio n. 5
0
void ctkPlugin::uninstall()
{
  bool wasResolved = false;

  Q_D(ctkPlugin);
  if (d->archive)
  {
    try
    {
      d->archive->setStartLevel(-2); // Mark as uninstalled
    }
    catch (...)
    { }
  }

  d->cachedHeaders = getHeaders();

  switch (d->state)
  {
  case UNINSTALLED:
    throw std::logic_error("Plugin is in UNINSTALLED state");

  case STARTING: // Lazy start
  case ACTIVE:
  case STOPPING:
    try
    {
      //TODO: If activating or deactivating, wait a litle
      // we don't use mutliple threads to start plugins for now
      //d->waitOnActivation(fwCtx.packages, "Bundle.uninstall", false);
      if (d->state & (ACTIVE | STARTING))
      {
        try
        {
          d->stop0(d->state == ACTIVE);
        }
        catch (const std::exception& exception)
        {
          // NYI! not call inside lock
          d->fwCtx->listeners.frameworkError(this, exception);
        }
      }
    }
    catch (const std::exception& e)
    {
      d->deactivating = false;
      //fwCtx.packages.notifyAll();
      d->fwCtx->listeners.frameworkError(this, e);
    }
    // Fall through
  case RESOLVED:
    wasResolved = true;
    // Fall through
  case INSTALLED:
    d->fwCtx->plugins->remove(d->location);
    d->pluginActivator = 0;

    if (d->pluginDir.exists())
    {
      if (!ctkPluginFrameworkUtil::removeDir(d->pluginDir.absolutePath()))
      {
        // Plugin dir is not deleted completely, make sure we mark
        // it as uninstalled for next framework restart
        if (d->archive)
        {
          try
          {
            d->archive->setStartLevel(-2); // Mark as uninstalled
          }
          catch (const std::exception& e)
          {
            // NYI! Generate FrameworkError if dir still exists!?
            qDebug() << "Failed to mark plugin" <<  d->id
                     << "as uninstalled," << d->pluginDir.absoluteFilePath()
                     << "must be deleted manually:" << e.what();
          }
        }
      }
      d->pluginDir.setFile("");
    }
    if (d->archive)
    {
      d->archive->purge();
    }

    // id, location and headers survive after uninstall.
    // TODO: UNRESOLVED must be sent out during installed state
    // This needs to be reviewed. See OSGi bug #1374
    d->state = INSTALLED;
    d->modified();

    // Broadcast events
    if (wasResolved)
    {
      d->fwCtx->listeners.emitPluginChanged(ctkPluginEvent(ctkPluginEvent::UNRESOLVED, d->q_ptr));
    }

    d->state = UNINSTALLED;
    d->fwCtx->listeners.emitPluginChanged(ctkPluginEvent(ctkPluginEvent::UNINSTALLED, d->q_ptr));

    break;
  }
}
Esempio n. 6
0
void LocalForwarder::getHeadersHandle(const boost::system::error_code& e) {
    if (e) {
        LOG_ACPROXY_ERROR("get http request header error ", e.message());
        //conn_->close();
        return;
    }

    LOG_ACPROXY_INFO("start reading http request headers...");

    char buf[1024];  // XXX

    auto fd = socket_->native_handle();
    ssize_t sz = ::recv(fd, buf, sizeof(buf), MSG_PEEK);
    LOG_ACPROXY_DEBUG("sz of read http request header = ", sz);
    if (sz < 0) {
        const int err = errno;
        if (err == EAGAIN || err == EWOULDBLOCK) {
            LOG_ACPROXY_INFO("read http request header again...");
            getHeaders();
            return;
        }
        LOG_ACPROXY_INFO("read http request header error");
        //conn_->close();
        return;
    } else if (sz == 0) {
        LOG_ACPROXY_INFO("client close socket");
        //conn_->close();
        return;
    }
    const char* pos = (const char*)::memmem(buf, sz, "\r\n\r\n", 4);

    bool found = pos;
    ssize_t diff = (found ? pos - buf + 4 : sz);
    if (!found) {
        // \r | \n\r\n
        if (headers.size() >= 1 && headers.back() == '\r' && sz >= 3 &&
            buf[0] == '\n' && buf[1] == '\r' && buf[2] == '\n') {
            found = true;
            diff = 3;
        }

        // \r\n | \r\n
        if (headers.size() >= 2 && headers[headers.size() - 2] == '\r' &&
            headers[headers.size() - 1] == '\n' && sz >= 2 && buf[0] == '\r' &&
            buf[1] == '\n') {
            found = true;
            diff = 2;
        }

        // \r\n\r | \n
        if (headers.size() >= 3 && headers[headers.size() - 3] == '\r' &&
            headers[headers.size() - 2] == '\n' &&
            headers[headers.size() - 1] == '\r' && sz >= 1 && buf[0] == '\n') {
            found = true;
            diff = 1;
        }
    }

    // consume
    ::recv(fd, buf, diff, 0);
    headers.insert(headers.end(), buf, buf + diff);
    if (found) {
        Http::RequestHeaderGrammar<decltype(headers)::iterator> grammar;
        bool res = phrase_parse(headers.begin(), headers.end(), grammar,
                                boost::spirit::qi::ascii::blank, request_);
        if (!res) {
            LOG_ACPROXY_ERROR("parse http request header error");
            //conn_->close();
            return;
        }

        request_.rewrite();
        request_.setKeepAlive(false);

        // cache layer
        if (request_.method == "GET" || request_.method == "HEAD") {
            std::string key = keygen(request_.getHost(), request_.getPort(),
                                     request_.uri, request_.method);
            auto& cache = getGlobalCache();
            if (boost::optional<std::string> resp = cache.get(key)) {
                LOG_ACPROXY_INFO("hit, found in cache!");
                finish(resp.value());
                return;
            }
            if (auto c = conn_.lock()) {
                c->getRemoteForwarder()->setCacheKey(key);
            } else {
                LOG_ACPROXY_WARNING("connection object is freed");
                return;
            }
        }

        // LOG_ACPROXY_DEBUG("request = \n", request_.toBuffer());

        if (!request_.hasResponseBody()) {
            if (auto c = conn_.lock()) {
                c->getRemoteForwarder()->setResponseBody(false);
            } else {
                LOG_ACPROXY_WARNING("connection object is freed");
                return;
            }
        }

        std::string host = request_.getHost();
        int port = request_.getPort();
        if (auto c = conn_.lock()) {
            res = c->getRemoteForwarder()->connect(host, port);
        } else {
            LOG_ACPROXY_WARNING("connection object is freed");
            return;
        }
        if (!res) {
            if (auto c = conn_.lock()) {
                c->report("failure", {{"host", boost::asio::ip::host_name()}},
                          std::time(0));
            }
            // XXX Maybe shutdowning socket is better
            LOG_ACPROXY_INFO("connection timeout, close it");
            //send("HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n");
            //conn_->close();
            return;
        }
        LOG_ACPROXY_DEBUG("connection complete");

        if (!request_.isConnectMethod()) {
            // forward header to server
            if (auto c = conn_.lock()) {
                c->getRemoteForwarder()->send(request_.toBuffer());
            } else {
                LOG_ACPROXY_WARNING("connection object is freed");
                return;
            }
        } else {
            // no parse response header, get rawdata and forward instead
            if (auto c = conn_.lock()) {
                c->getRemoteForwarder()->setParseResponseHeader(false);
            } else {
                LOG_ACPROXY_WARNING("connection object is freed");
                return;
            }
            // send a fake 200 response in tunnel mode
            send("HTTP/1.1 200 Connection Established\r\n\r\n");
        }

        if (request_.hasContentBody()) {
            getBody();
        }
    } else {
        // request header is incomplete, read again
        LOG_ACPROXY_INFO("http request header incomplete, read again");
        getHeaders();
    }
    if (auto c = conn_.lock()) {
        c->update();
    } else {
        LOG_ACPROXY_WARNING("connection object is freed");
        return;
    }
}
Esempio n. 7
0
void LocalForwarder::start() {
    getHeaders();
}
Esempio n. 8
0
		lseek(fd, atoi(cur_hdr.ar_size) + (atoi(cur_hdr.ar_size)%2), SEEK_CUR);
	}

	/* We're done. Seek once again to first header. */
	lseek(fd, SARMAG, SEEK_SET);

	return numFound;
}

/** Delete file from archive.
 */
void delete(int fd, char* arName, int nNum, char** names)
{
	/* Get headers of the files we are looking for, if they exist. */
	struct ar_hdr headers[nNum];
	int hNum = getHeaders(fd, nNum, names, headers);

	/* If no files were found, quit. */
	if (hNum == 0) {
		printf("None of the requested files were found! Exiting.\n");
		exit(0);
	}

	/* Create new file. */
	char newName[strlen(arName)+10];
	sprintf(newName, "%s.tmp", arName);
	int new_fd = creat(newName, 0666);
	if (new_fd == -1) {
		perror("Could not create temporary file!");
		exit(-1);
	}
Esempio n. 9
0
std::tuple<std::unique_ptr<HTTPMessage>, std::unique_ptr<folly::IOBuf> >
makeResponse(uint16_t statusCode, size_t len) {
  auto resp = makeResponse(statusCode);
  resp->getHeaders().set(HTTP_HEADER_CONTENT_LENGTH, folly::to<string>(len));
  return std::make_pair(std::move(resp), makeBuf(len));
}
Esempio n. 10
0
void HttpSocket<isServer>::onData(uS::Socket s, char *data, int length) {
    HttpSocket httpSocket(s);
    HttpSocket::Data *httpData = httpSocket.getData();

    httpSocket.cork(true);

    if (httpData->contentLength) {
        httpData->missedDeadline = false;
        if (httpData->contentLength >= length) {
            getGroup<isServer>(s)->httpDataHandler(httpData->outstandingResponsesTail, data, length, httpData->contentLength -= length);
            return;
        } else {
            getGroup<isServer>(s)->httpDataHandler(httpData->outstandingResponsesTail, data, httpData->contentLength, 0);
            data += httpData->contentLength;
            length -= httpData->contentLength;
            httpData->contentLength = 0;
        }
    }

    if (FORCE_SLOW_PATH || httpData->httpBuffer.length()) {
        if (httpData->httpBuffer.length() + length > MAX_HEADER_BUFFER_SIZE) {
            httpSocket.onEnd(s);
            return;
        }

        httpData->httpBuffer.reserve(httpData->httpBuffer.length() + length + WebSocketProtocol<uWS::CLIENT>::CONSUME_POST_PADDING);
        httpData->httpBuffer.append(data, length);
        data = (char *) httpData->httpBuffer.data();
        length = httpData->httpBuffer.length();
    }

    char *end = data + length;
    char *cursor = data;
    *end = '\r';
    Header headers[MAX_HEADERS];
    do {
        char *lastCursor = cursor;
        if ((cursor = getHeaders(cursor, end, headers, MAX_HEADERS))) {
            HttpRequest req(headers);

            if (isServer) {
                headers->valueLength = std::max<int>(0, headers->valueLength - 9);
                httpData->missedDeadline = false;
                if (req.getHeader("upgrade", 7)) {
                    if (getGroup<SERVER>(s)->httpUpgradeHandler) {
                        getGroup<SERVER>(s)->httpUpgradeHandler(HttpSocket<isServer>(s), req);
                    } else {
                        Header secKey = req.getHeader("sec-websocket-key", 17);
                        Header extensions = req.getHeader("sec-websocket-extensions", 24);
                        Header subprotocol = req.getHeader("sec-websocket-protocol", 22);
                        if (secKey.valueLength == 24) {
                            bool perMessageDeflate;
                            httpSocket.upgrade(secKey.value, extensions.value, extensions.valueLength,
                                               subprotocol.value, subprotocol.valueLength, &perMessageDeflate);
                            getGroup<SERVER>(s)->removeHttpSocket(s);
                            s.enterState<WebSocket<SERVER>>(new WebSocket<SERVER>::Data(perMessageDeflate, httpData));
                            getGroup<SERVER>(s)->addWebSocket(s);
                            s.cork(true);
                            getGroup<SERVER>(s)->connectionHandler(WebSocket<SERVER>(s), req);
                            s.cork(false);
                            delete httpData;
                        } else {
                            httpSocket.onEnd(s);
                        }
                    }
                    return;
                } else {
                    if (getGroup<SERVER>(s)->httpRequestHandler) {

                        HttpResponse *res = HttpResponse::allocateResponse(httpSocket, httpData);
                        if (httpData->outstandingResponsesTail) {
                            httpData->outstandingResponsesTail->next = res;
                        } else {
                            httpData->outstandingResponsesHead = res;
                        }
                        httpData->outstandingResponsesTail = res;

                        Header contentLength;
                        if (req.getMethod() != HttpMethod::METHOD_GET && (contentLength = req.getHeader("content-length", 14))) {
                            httpData->contentLength = atoi(contentLength.value);
                            size_t bytesToRead = std::min<int>(httpData->contentLength, end - cursor);
                            getGroup<SERVER>(s)->httpRequestHandler(res, req, cursor, bytesToRead, httpData->contentLength -= bytesToRead);
                            cursor += bytesToRead;
                        } else {
                            getGroup<SERVER>(s)->httpRequestHandler(res, req, nullptr, 0, 0);
                        }

                        if (s.isClosed() || s.isShuttingDown()) {
                            return;
                        }
                    } else {
                        httpSocket.onEnd(s);
                        return;
                    }
                }
            } else {
                if (req.getHeader("upgrade", 7)) {
                    s.enterState<WebSocket<CLIENT>>(new WebSocket<CLIENT>::Data(false, httpData));

                    httpSocket.cancelTimeout();
                    httpSocket.setUserData(httpData->httpUser);
                    getGroup<CLIENT>(s)->addWebSocket(s);
                    s.cork(true);
                    getGroup<CLIENT>(s)->connectionHandler(WebSocket<CLIENT>(s), req);
                    s.cork(false);

                    if (!(s.isClosed() || s.isShuttingDown())) {
                        WebSocketProtocol<CLIENT> *kws = (WebSocketProtocol<CLIENT> *) ((WebSocket<CLIENT>::Data *) s.getSocketData());
                        kws->consume(cursor, end - cursor, s);
                    }

                    delete httpData;
                } else {
                    httpSocket.onEnd(s);
                }
                return;
            }
        } else {
            if (!httpData->httpBuffer.length()) {
                if (length > MAX_HEADER_BUFFER_SIZE) {
                    httpSocket.onEnd(s);
                } else {
                    httpData->httpBuffer.append(lastCursor, end - lastCursor);
                }
            }
            return;
        }
    } while(cursor != end);

    httpSocket.cork(false);
    httpData->httpBuffer.clear();
}
Esempio n. 11
0
File: mynet.c Progetto: zehome/cpige
/* Cette fonction se reconnecte au server servername,
 * port serverport, toute les time secondes, avec un
 * maximum de _nb_tentatives.
 *
 * Si _nb_tentatives est NULL, ou égal a -1, alors il n'y 
 * a aucune limite.
 *
 * Retourne la chausette créée
 */
int reconnect(int time, int _nb_tentatives, int _get_headers, icyHeaders *out_icy)
{
  int tentatives = 0;
  int server_socket;
  serverSettings_t *settings;
  icyHeaders *icy;
  
  if (!time) time = 2;
  
  if (serversPool == NULL)
  {
    _ERROR("Error: not any server defined.\n");
    exit(1);
  }
  
  /* Get an entry in the pool */
  settings = getSettings(serversPool, &poolPosition);
  if (settings == NULL)
  {
    _ERROR("No valid settings in urlPool.\n");
    exit(1);
  }

RECO:
  sleep(time);

  while ( (server_socket = server_connect(settings->serverAddr, settings->port)) < 0)
  {
    /* Get an entry in the pool */
    settings = getSettings(serversPool, &poolPosition);
    if (settings == NULL)
    {
      _ERROR("No valid settings in urlPool.\n");
      exit(1);
    }

    tentatives++;
    if ((tentatives > _nb_tentatives) && (_nb_tentatives != -1))
    {
      MESSAGE("Too many tentatives. Exiting program.\n");
      exit(-2);
    }
    MESSAGE("Reconnecting to http://%s:%d%s [try %d] in %d sec.\n", settings->serverAddr, settings->port, settings->mountpoint, tentatives, time);
    sleep(time);
  }

  VERBOSE("Time spent to reconnect: %d seconds, %d tentatives.\n", (tentatives * time), tentatives);

  if (sendHeaders(server_socket, settings->mountpoint, 1) <= 0)
  {
    _ERROR("Error sending headers: 0 byte sent.\n");
    goto RECO;
  }
  
  if (_get_headers)
  {
    if ( (icy = readicyheaders(getHeaders(server_socket))) == NULL)
      goto RECO;
    else
      out_icy = icy;
  }
  
  cPigeStats->reconnections++;
  
  return server_socket;
}
Esempio n. 12
0
std::string HttpHeaders::RequestHeaders()
{
	return getAction() + "\r\n" + getHeaders();
}
Esempio n. 13
0
std::string HttpHeaders::ResponseHeaders()
{
	return getProto() + " " + getCode() + " " + getStatus() + "\r\n" + getHeaders();
}