Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Custom server URL #2

Open
Brawl345 opened this issue Nov 17, 2019 · 1 comment
Open

Custom server URL #2

Brawl345 opened this issue Nov 17, 2019 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Brawl345
Copy link
Member

Brawl345 commented Nov 17, 2019

Using a custom server URL without recompiling should be possible. It should be read from the feeds.xml from the <url> attribute of the <rss> tag (like this: <rss url="http://u.wiidb.de/rssmii/rss_test_displayer.php">

The code already has the basics, but I suck at C and mxmlElementGetAttr wants a const char * 🤔

@Brawl345 Brawl345 added enhancement New feature or request help wanted Extra attention is needed labels Nov 17, 2019
@GaryOderNichts
Copy link

GaryOderNichts commented Apr 8, 2020

I guess you mean this compiler warning: warning: assignment discards ‘const’ qualifier from pointer target type
A const pointer means that the memory this pointer is pointing to should not be modified once assigned.
You have two options to get rid of this warning:

  1. Ignore the warning by just casting it to a char*implicitly
    server_url = (char*) mxmlElementGetAttr(rss, "url");
  2. Copy the contents of the result into you server_url pointer
    char* server_url;
    const char* tmp_server_url = mxmlElementGetAttr(rss, "url");
    if (tmp_server_url != NULL) 
    {
        size_t url_lenght = strlen(tmp_server_url);
        server_url = malloc(url_lenght + 1); // allocate memory for the string and the null terminator
        strcpy(server_url, tmp_server_url);
    }
    else
    {
        server_url = "http://u.wiidb.de/rssmii/rss_displayer.php";
    }

Edit: this is better or else you cannot free your server url:

    const char* default_server_url = "http://u.wiidb.de/rssmii/rss_displayer.php";
    char* server_url;
    const char* tmp_server_url = mxmlElementGetAttr(rss, "url");
    if (tmp_server_url != NULL) 
    {
        size_t url_lenght = strlen(tmp_server_url);
        server_url = malloc(url_lenght + 1); // allocate memory for the string and the null terminator
        strcpy(server_url, tmp_server_url);
    }
    else
    {
        size_t url_lenght = strlen(default_server_url);
        server_url = malloc(url_lenght + 1); // allocate memory for the string and the null terminator
        strcpy(server_url, default_server_url);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants