Пример #1
0
struct PP_Var
ppb_url_util_dev_resolve_relative_to_url(struct PP_Var base_url, struct PP_Var relative_string,
                                         struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    struct PP_Var var = PP_MakeNull();

    if (base_url.type != PP_VARTYPE_STRING) {
        trace_warning("%s, base_url is not a string\n", __func__);
        return PP_MakeNull();
    }

    if (relative_string.type != PP_VARTYPE_STRING) {
        trace_warning("%s, relative_string is not a string\n", __func__);
        return PP_MakeNull();
    }

    const char *s_base_url = ppb_var_var_to_utf8(base_url, NULL);
    const char *s_relative_string = ppb_var_var_to_utf8(relative_string, NULL);

    UriParserStateA ups;
    UriUriA uri_base, uri_rel, uri_result;

    ups.uri = &uri_base;
    if (uriParseUriA(&ups, s_base_url) != URI_SUCCESS) {
        trace_warning("%s, can't parse s_base_url\n", __func__);
        goto err_1;
    }

    ups.uri = &uri_rel;
    if (uriParseUriA(&ups, s_relative_string) != URI_SUCCESS) {
        trace_warning("%s, can't parse s_relative_string\n", __func__);
        goto err_2;
    }

    if (uriAddBaseUriA(&uri_result, &uri_rel, &uri_base) != URI_SUCCESS) {
        trace_warning("%s, can't merge base and rel\n", __func__);
        goto err_3;
    }

    int len;
    uriToStringCharsRequiredA(&uri_result, &len);
    len++;
    char *str = malloc(len);
    uriToStringA(str, &uri_result, len, NULL);
    var = ppb_var_var_from_utf8_z(str);
    free(str);

    if (components)
        parse_url_string(str, components);

err_3:  uriFreeUriMembersA(&uri_result);
err_2:  uriFreeUriMembersA(&uri_rel);
err_1:  uriFreeUriMembersA(&uri_base);
    return var;
}
Пример #2
0
struct PP_Var nspawn_send_request(struct PP_Var req_var) {
  /*
   * naclprocess.js is required in order send requests to JavaScript.
   * If NACL_PROCESS is not set in the environment then we assume it is
   * not present and exit early. Without this check we would block forever
   * waiting for a response for the JavaScript side.
   *
   * Only check this once per process, as some programs (emacs)
   * engage in manipulation of the environment that may not be safely
   * read at all times.
   */
  static int checked_for_nacl_process = 0;
  if (!checked_for_nacl_process) {
    const char* naclprocess = getenv("NACL_PROCESS");
    if (naclprocess == NULL) {
      fprintf(stderr, "nspawn_send_request called without NACL_PROCESS set\n");
      return PP_MakeNull();
    }
    checked_for_nacl_process = 1;
  }

  int64_t id = get_request_id();
  char req_id[64];
  sprintf(req_id, "%lld", id);
  nspawn_dict_setstring(req_var, "id", req_id);

  struct NaClSpawnReply reply;
  pthread_mutex_init(&reply.mu, NULL);
  pthread_cond_init(&reply.cond, NULL);
  PSEventRegisterMessageHandler(req_id, &handle_reply, &reply);

  PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), req_var);
  nspawn_var_release(req_var);

  pthread_mutex_lock(&reply.mu);
  /*
   * Wait for response for JavaScript.  This can block for an unbounded amount
   * of time (e.g. waiting for a response to waitpid).
   */
  int error = pthread_cond_wait(&reply.cond, &reply.mu);
  pthread_mutex_unlock(&reply.mu);

  pthread_cond_destroy(&reply.cond);
  pthread_mutex_destroy(&reply.mu);

  PSEventRegisterMessageHandler(req_id, NULL, &reply);

  if (error != 0) {
    fprintf(stderr, "nspawn_send_request: pthread_cond_timedwait: %s\n",
          strerror(error));
    return PP_MakeNull();
  }

  return reply.result_var;
}
struct PP_Var
read_from_sq_to_browser(struct PP_Var (*func)(const char* str, int32_t size))
{
  int err = 0;
  int32_t size;

  pthread_mutex_lock(&s2b.mutex);
  if (!s2b.is_full && s2b.free_end == s2b.free_start) {
    err = 1;
  }

  if (!err) {
    int first_part_size, second_part_size;
    size = s2b.buffer[s2b.free_end/4];

    s2b.free_end += 4;
    if (s2b.free_end == s2b.capacity) {
      s2b.free_end = 0;
    }
    
    first_part_size = (size < s2b.capacity - s2b.free_end)
      ? size : s2b.capacity - s2b.free_end;
    second_part_size = size - first_part_size > 0 ? size - first_part_size : 0;

    memcpy(tmp_buffer, &s2b.buffer[s2b.free_end/4], size);
    s2b.free_end += CEIL4(first_part_size);
    if (second_part_size > 0) {
      s2b.free_end = 0;
      memcpy(tmp_buffer + first_part_size, &s2b.buffer[s2b.free_end/4], second_part_size);
      s2b.free_end += CEIL4(second_part_size);
    }
    
    s2b.is_full = 0;
    if (s2b.free_end == s2b.capacity) {
      s2b.free_end = 0;
    }
  }
  pthread_mutex_unlock(&s2b.mutex);
  if (!err)
    return func(tmp_buffer, size);

  return PP_MakeNull();
}
Пример #4
0
static struct PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) {
  return PP_MakeNull();
}