Example #1
0
void MythHttpHandler::RequestFinished(int id, bool error)
{
    QMutexLocker locker(&m_lock);

    LOG(VB_NETWORK, LOG_DEBUG, LOC + QString("RequestFinished(%1,%2) url: %3")
            .arg(id).arg(error).arg(m_cur_url.toString()));
    if (error && m_pool)
    {
        m_pool->Update(m_qhttp->error(), m_qhttp->errorString(),
                       m_cur_url,
                       m_cur_status_id, m_cur_status_str, QByteArray());
    }
    else if ((id == m_cur_get_id) && m_pool)
    {
        if ((307 == m_cur_status_id) || // temporary move..
            (303 == m_cur_status_id) || // move.. MUST use get
            (302 == m_cur_status_id) || // temporary move..
            (301 == m_cur_status_id))   // permanent move..
        {
            m_cur_status_id = 0;
            QString urlStr = extract_url(QString(m_qhttp->readAll()));
            if (!urlStr.isEmpty() && m_cur_redirect_cnt < kMaxRedirectCount)
            {
                m_cur_redirect_cnt++;
                QUrl url = QUrl(urlStr);
                m_qhttp->setHost(url.host());
                QString path = url.path().isEmpty() ? "/" : url.path();
                m_cur_get_id = m_qhttp->get(path);
                return;
            }
        }

        m_pool->Update(QHttp::NoError, QString::null,
                       m_cur_url,
                       m_cur_status_id, m_cur_status_str,
                       m_qhttp->readAll());
    }
    else
        return;

    if (!m_urls.empty())
    {
        Get(m_urls.front());
        m_urls.pop_front();
    }
}
Example #2
0
int main(void)
{
  CURL *curl;
  CURLcode res;
  struct MemoryStruct chunk;

  chunk.memory = malloc(1);  
  chunk.size = 0;    

  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  if(curl) {

    curl_easy_setopt(curl, CURLOPT_URL, "http://www.vulcan.com.br/Contato.aspx");

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

    curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");

    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK) {
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
    }
    else {
      	printf("%s\n",chunk.memory);
	extract_url(chunk.memory,"http://www.vulcan.com.br");
    }

    curl_easy_cleanup(curl);

    if(chunk.memory)
    {	
      free(chunk.memory);
      chunk.memory=NULL;
    }

    curl_global_cleanup();
  }
  return 0;
}
Example #3
0
File: api.c Project: lxsang/STRos
void publisherUpdate(rpc_value_t params, int n, int client)
{
	//LOG("Number params %d\n", n);
	//LOG("parms: %s\n",as_string(params));
	char* topic = list_at(params,1)->value.s;
	char* url;
	list l;
	if(topic == NULL)
	{
		rpc_bad_request(client);
		return;
	}
	subscriber* sub = (subscriber*)dvalue(xml_prc_server.node->subscribers,topic);
	if(sub == NULL)
	{
		rpc_bad_request(client);
		return;
	}
	l = list_at(params,2)->value.array;
	extract_url(sub, l);
	rpc_dummy_response(client);
}
int main(int argc, char *argv[]) {

  struct push_pack pc;

  int retval;

  char *publish_url = argc>1 ? argv[1] : "http://localhost/ajaxtime/publish";

  char *id_name = argc>2 ? argv[2] : "channel";

  char json_string[200];

  char *server_name;

  char port[6];

  unsigned short port_numeric;

  retval = prep_push(&pc, publish_url, id_name);

  if (retval==-1) {

    fprintf(stderr, "%s: Trouble with prep_push. What's up with that?\n", __FUNCTION__);
    
    return -1;

  }

  // extract server_name and port from publish_url

  retval = extract_url(&server_name, &port_numeric, publish_url, YES_MALLOC);

  if (retval==-1) {

    fprintf(stderr, "%s: Trouble extracting server_name and/or port with extract_url on url=%s.\n", __FUNCTION__, publish_url);

    return -1;

  }

  assert(server_name!=NULL);

  if (!port_numeric) port_numeric = 80;

  retval = sprintf(port, "%u", port_numeric);

  {

    struct time_pack w_time = { .min = 3, .sec = 20 }, b_time = { .min = 4, .sec = 47 };

    int move_number = 1;

    char *move_string = "e4";

    int white_move = 1;

    retval = reformulate_json(json_string, &w_time, &b_time, move_number, move_string, white_move);

    if (retval==-1) {
      printf("%s: Trouble preparing valid json_string.\n", __FUNCTION__);
      return -1;
    }

  }

  retval = push_submission(&pc, server_name, port, "7932221", 1, json_string);
  if (retval==-1) {

    printf("%s: Trouble with call to push_submission.\n", __FUNCTION__);
    return -1;

  }

  printf("%s: Sent %s\n", __FUNCTION__, json_string);

  return 0;

}