Ejemplo n.º 1
0
/*
 * bind the given channel using info from netlist
 * returns not 0 if failed
 * note: replaces PrepareBind if no name service available
 */
static int DoBind(const struct ChannelDesc* channel)
{
  struct ChannelConnection *record;
  char buf[BIG_ENOUGH_STRING], *url = buf;

  record = GetChannelConnectionInfo(channel);
  assert(record != NULL);

  MakeURL(url, BIG_ENOUGH_STRING, channel, record);
  ZLOGS(LOG_DEBUG, "bind url %s", url);
  return zmq_bind(channel->socket, url);
}
Ejemplo n.º 2
0
	BrowserWidget* Core::NewURL (const QString& str, bool raise)
	{
		return NewURL (MakeURL (str), raise);
	}
Ejemplo n.º 3
0
status_t M3UParser::parse(const void *_data, size_t size) {
    int32_t lineNo = 0;

    sp<AMessage> itemMeta;

    const char *data = (const char *)_data;
    size_t offset = 0;
    while (offset < size) {
        size_t offsetLF = offset;
        while (offsetLF < size && data[offsetLF] != '\n') {
            ++offsetLF;
        }
        if (offsetLF >= size) {
            break;
        }

        AString line;
        if (offsetLF > offset && data[offsetLF - 1] == '\r') {
            line.setTo(&data[offset], offsetLF - offset - 1);
        } else {
            line.setTo(&data[offset], offsetLF - offset);
        }

        // LOGI("#%s#", line.c_str());

        if (line.empty()) {
            offset = offsetLF + 1;
            continue;
        }

        if (lineNo == 0 && line == "#EXTM3U") {
            mIsExtM3U = true;
        }

        if (mIsExtM3U) {
            status_t err = OK;

            if (line.startsWith("#EXT-X-TARGETDURATION")) {
                if (mIsVariantPlaylist) {
                    return ERROR_MALFORMED;
                }
                err = parseMetaData(line, &mMeta, "target-duration");
            } else if (line.startsWith("#EXT-X-MEDIA-SEQUENCE")) {
                if (mIsVariantPlaylist) {
                    return ERROR_MALFORMED;
                }
                err = parseMetaData(line, &mMeta, "media-sequence");
            } else if (line.startsWith("#EXT-X-ENDLIST")) {
                mIsComplete = true;
            } else if (line.startsWith("#EXTINF")) {
                if (mIsVariantPlaylist) {
                    return ERROR_MALFORMED;
                }
                err = parseMetaData(line, &itemMeta, "duration");
            } else if (line.startsWith("#EXT-X-DISCONTINUITY")) {
                if (mIsVariantPlaylist) {
                    return ERROR_MALFORMED;
                }
                if (itemMeta == NULL) {
                    itemMeta = new AMessage;
                }
                itemMeta->setInt32("discontinuity", true);
            } else if (line.startsWith("#EXT-X-STREAM-INF")) {
                if (mMeta != NULL) {
                    return ERROR_MALFORMED;
                }
                mIsVariantPlaylist = true;
                err = parseStreamInf(line, &itemMeta);
            }

            if (err != OK) {
                return err;
            }
        }

        if (!line.startsWith("#")) {
            if (!mIsVariantPlaylist) {
                int32_t durationSecs;
                if (itemMeta == NULL
                        || !itemMeta->findInt32("duration", &durationSecs)) {
                    return ERROR_MALFORMED;
                }
            }

            mItems.push();
            Item *item = &mItems.editItemAt(mItems.size() - 1);

            CHECK(MakeURL(mBaseURI.c_str(), line.c_str(), &item->mURI));

            item->mMeta = itemMeta;

            itemMeta.clear();
        }

        offset = offsetLF + 1;
        ++lineNo;
    }

    return OK;
}
Ejemplo n.º 4
0
// static
status_t M3UParser::parseCipherInfo(
        const AString &line, sp<AMessage> *meta, const AString &baseURI) {
    ssize_t colonPos = line.find(":");

    if (colonPos < 0) {
        return ERROR_MALFORMED;
    }

    size_t offset = colonPos + 1;

    while (offset < line.size()) {
        ssize_t end = FindNextUnquoted(line, ',', offset);
        if (end < 0) {
            end = line.size();
        }

        AString attr(line, offset, end - offset);
        attr.trim();

        offset = end + 1;

        ssize_t equalPos = attr.find("=");
        if (equalPos < 0) {
            continue;
        }

        AString key(attr, 0, equalPos);
        key.trim();

        AString val(attr, equalPos + 1, attr.size() - equalPos - 1);
        val.trim();

        LOGV("key=%s value=%s", key.c_str(), val.c_str());

        key.tolower();

        if (key == "method" || key == "uri" || key == "iv") {
            if (meta->get() == NULL) {
                *meta = new AMessage;
            }

            if (key == "uri") {
                if (val.size() >= 2
                        && val.c_str()[0] == '"'
                        && val.c_str()[val.size() - 1] == '"') {
                    // Remove surrounding quotes.
                    AString tmp(val, 1, val.size() - 2);
                    val = tmp;
                }

                AString absURI;
                if (MakeURL(baseURI.c_str(), val.c_str(), &absURI)) {
                    val = absURI;
                } else {
                    LOGE("failed to make absolute url for '%s'.",
                         val.c_str());
                }
            }

            key.insert(AString("cipher-"), 0);

            (*meta)->setString(key.c_str(), val.c_str(), val.size());
        }
    }

    return OK;
}
Ejemplo n.º 5
0
	void JobThreadFunc(void)
	{
		Lock();
		O2IMessages queue(Queue);
		Queue.clear();
		Unlock();

		if (queue.size() == 0)
			return;

		hashT myid;
		Profile->GetID(myid);

		O2IMessagesIt it;
		for (it = queue.begin(); it != queue.end() && IsActive(); it++) {
			O2IMessage &im = *it;

			TRACEA("[BroadcastJob]");
			TRACEW(it->msg.c_str());
			TRACEA("\n");

			O2NodeDB::NodeListT neighbors;
			if (NodeDB->neighbors(myid, neighbors, false, O2_BROADCAST_PATH_LIMIT+2) == 0)
				return;

			O2NodeDB::NodeListT::iterator nit = neighbors.begin();
			while (nit != neighbors.end()) {
				if (nit->id == im.id) {
					nit = neighbors.erase(nit);
					continue;
				}
				hashListT::iterator hit = std::find(im.paths.begin(), im.paths.end(), nit->id);
				if (hit != im.paths.end()) {
					nit = neighbors.erase(nit);
					continue;
				}
				nit++;
			}

			if (neighbors.empty())
				continue;

			hashT myid;
			Profile->GetID(myid);
			im.paths.push_back(myid);
			while (im.paths.size() > O2_BROADCAST_PATH_LIMIT)
				im.paths.pop_front();

			for (nit = neighbors.begin(); nit != neighbors.end() && IsActive(); nit++) {
				nit->lastlink = 0;
				nit->reset();

				// Broadcast発行
				O2SocketSession ss;
				ss.ip = nit->ip;
				ss.port = nit->port;

				string xml;
				BroadcastDB->MakeSendXML(im, xml);

				string url;
				MakeURL(ss.ip, ss.port, O2PROTOPATH_BROADCAST, url);

				HTTPHeader hdr(HTTPHEADERTYPE_REQUEST);
				hdr.method = "POST";
				hdr.SetURL(url.c_str());
				AddRequestHeaderFields(hdr, Profile);
				AddContentFields(hdr, xml.size(), "text/xml", DEFAULT_XML_CHARSET);
				hdr.Make(ss.sbuff);
				ss.sbuff += xml;

				Client->AddRequest(&ss);
				ss.Wait();

				HTTPHeader *header = (HTTPHeader*)ss.data;
				if (CheckResponse(&ss, header, NodeDB, *nit)) {
					;
				}

				if (header) delete header;
				Sleep(1000);
			}

			for (nit = neighbors.begin(); nit != neighbors.end() && IsActive(); nit++) {
				if (nit->lastlink) {
					// 成功したノードをtouch
					NodeDB->touch(*nit);
				}
				else {
					// 失敗したノードをremove
					NodeDB->remove(*nit);
					KeyDB->DeleteKeyByNodeID(nit->id);
				}
			}

			Sleep(IsActive() ? 1000 : 0);
		}
	}
Ejemplo n.º 6
0
int PrefetchChannelDtor(struct ChannelDesc *channel)
{
  char url[BIG_ENOUGH_STRING];  /* debug purposes only */

  assert(channel != NULL);
  assert(channel->socket != NULL);

  /* log parameters and channel internals */
  MakeURL(url, BIG_ENOUGH_STRING, channel, GetChannelConnectionInfo(channel));
  ZLOGS(LOG_DEBUG, "%s has url %s", channel->alias, url);

  /* close "PUT" channel */
  if(channel->limits[PutsLimit] && channel->limits[PutSizeLimit])
  {
    int size = CHANNELS_ETAG_ENABLED ? TAG_DIGEST_SIZE - 1 : 0;

    /* prepare digest */
    if(TagEngineEnabled())
    {
      TagDigest(channel->tag, channel->digest);
      TagDtor(channel->tag);
    }

    /* send eof */
    channel->eof = 1;
    SendMessage(channel, channel->digest, size);
    ZLOGS(LOG_DEBUG, "%s closed with tag %s, putsize %ld",
        channel->alias, channel->digest, channel->counters[PutSizeLimit]);
  }

  /* close "GET" channel */
  if(channel->limits[GetsLimit] && channel->limits[GetSizeLimit])
  {
    /* wind the channel to the end */
    while(channel->eof == 0)
    {
      char buf[NET_BUFFER_SIZE];
      int32_t size = FetchMessage(channel, buf, NET_BUFFER_SIZE);
      ++channel->counters[GetsLimit];
      channel->counters[GetSizeLimit] += size;

      /* update tag if enabled */
      if(TagEngineEnabled())
        TagUpdate(channel->tag, buf, size);
    }

    /* test integrity (if etag enabled) */
    if(TagEngineEnabled())
    {
      /* prepare digest */
      TagDigest(channel->tag, channel->digest);
      TagDtor(channel->tag);

      /* raise the error if the data corrupted */
      if(memcmp(channel->control, channel->digest, TAG_DIGEST_SIZE) != 0)
      {
        ZLOG(LOG_ERROR, "%s corrupted, control: %s, local: %s",
            channel->alias, channel->control, channel->digest);
        SetExitState("data corrupted");
        SetExitCode(EPIPE);
      }

      ZLOGS(LOG_DEBUG, "%s closed with tag %s, getsize %ld",
          channel->alias, channel->digest, channel->counters[GetSizeLimit]);
    }

    zmq_msg_close(&channel->msg);
    zmq_close(channel->socket);
  }

  /* will destroy context and netlist after all network channels closed */
  NetDtor();

  return 0;
}