Exemplo n.º 1
0
Arquivo: sax.c Projeto: actility/ong
/**
 * @brief Retrieve the text contained in a xml token, eg <tok>content</tok>
 * @param node The xml node
 * @return The contained text
 */
char *getContainedText(mxml_node_t *node) {
	char *content = NULL;
	if (node && node->type == MXML_OPAQUE) {
		content = (char *)mxmlGetOpaque (node);
		if (content && !strcmp(content, "\n")) {
			node	= mxmlWalkNext (node, NULL, MXML_DESCEND);
			content = (char *)mxmlGetCDATA(node);
		}
	}
	return content;
}
Exemplo n.º 2
0
Arquivo: Chess.c Projeto: ishefi/chess
int load_game(char * path, settings * game_settings){
	FILE * fp;
	mxml_node_t *xml_tree;
	mxml_node_t *xml_node;
	char row_node[17] = "game/board/row_x";
	char row[9] = { 0 };
	cord c;

	fp = fopen(path, "r");
	if (fp == NULL)
		return FALSE;
	xml_tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
	fclose(fp);

	xml_node = mxmlFindPath(xml_tree, "game/next_turn");
	game_settings->next = (xml_node == NULL) ? WHITE : string_to_color(mxmlGetOpaque(xml_node));

	xml_node = mxmlFindPath(xml_tree, "game/game_mode");
	game_settings->mode = (xml_node == NULL) ? PLAYER_VS_COMP : atoi(mxmlGetOpaque(xml_node));

	if (game_settings->mode == PLAYER_VS_COMP){
		xml_node = mxmlFindPath(xml_tree, "game/difficulty");
		game_settings->minimax_depth = (xml_node == NULL) ? 1 : atoi(mxmlGetOpaque(xml_node));

		xml_node = mxmlFindPath(xml_tree, "game/user_color");
		game_settings->color = (xml_node == NULL) ? WHITE : string_to_color(mxmlGetOpaque(xml_node));
	}

	for (int y = 8; y > 0; y--) {
		row_node[15] = '0' + y;
		xml_node = mxmlFindPath(xml_tree, row_node);
		strcpy(row, mxmlGetOpaque(xml_node));
		for (int x = 0; x < 8; x++) {
			c.x = x;
			c.y = y - 1;
			board_piece(game_settings->board, c) = (row[x] == '_') ? EMPTY : row[x];
		}
	}
	//mxmlDelete(xml_tree);
	return TRUE;
}
Exemplo n.º 3
0
static int l_get_value(lua_State *L)
{
	mxml_node_t *node = l_checkMXML(L, 1);

	lua_pushstring(L, mxmlGetOpaque(node));
	if (lua_isnumber(L, -1)) {
		double num;

		num = luaL_checknumber(L, -1);
		lua_pop(L, 1);
		lua_pushnumber(L, num);
	}

	return 1;
}
Exemplo n.º 4
0
static void
response_proces(struct https_client_ctx *ctx)
{
  mxml_node_t *tree;
  mxml_node_t *s_node;
  mxml_node_t *e_node;
  char *body;
  char *errmsg;
  char *sk;

  // NULL-terminate the buffer
  evbuffer_add(ctx->data, "", 1);

  body = (char *)evbuffer_pullup(ctx->data, -1);
  if (!body || (strlen(body) == 0))
    {
      DPRINTF(E_LOG, L_LASTFM, "Empty response\n");
      return;
    }

  DPRINTF(E_SPAM, L_LASTFM, "LastFM response:\n%s\n", body);

  tree = mxmlLoadString(NULL, body, MXML_OPAQUE_CALLBACK);
  if (!tree)
    return;

  // Look for errors
  e_node = mxmlFindElement(tree, tree, "error", NULL, NULL, MXML_DESCEND);
  if (e_node)
    {
      errmsg = trimwhitespace(mxmlGetOpaque(e_node));
      DPRINTF(E_LOG, L_LASTFM, "Request to LastFM failed: %s\n", errmsg);

      if (errmsg)
	free(errmsg);
      mxmlDelete(tree);
      return;
    }

  // Was it a scrobble request? Then do nothing. TODO: Check for error messages
  s_node = mxmlFindElement(tree, tree, "scrobbles", NULL, NULL, MXML_DESCEND);
  if (s_node)
    {
      DPRINTF(E_DBG, L_LASTFM, "Scrobble callback\n");
      mxmlDelete(tree);
      return;
    }

  // Otherwise an auth request, so get the session key
  s_node = mxmlFindElement(tree, tree, "key", NULL, NULL, MXML_DESCEND);
  if (!s_node)
    {
      DPRINTF(E_LOG, L_LASTFM, "Session key not found\n");
      mxmlDelete(tree);
      return;
    }

  sk = trimwhitespace(mxmlGetOpaque(s_node));
  if (sk)
    {
      DPRINTF(E_LOG, L_LASTFM, "Got session key from LastFM: %s\n", sk);
      db_admin_add("lastfm_sk", sk);

      if (lastfm_session_key)
	free(lastfm_session_key);

      lastfm_session_key = sk;
    }

  mxmlDelete(tree);
}