Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:32:07+00:00 2026-06-17T21:32:07+00:00

So far I have gotten my libev code to successfully return a static sting

  • 0

So far I have gotten my libev code to successfully return a static sting that says “OMP OMP”, however when I write a function that returns a “static” string it never seems to work. (Sidenote: the idea is to turn that same function into a dynamic response but just for agile testing purposes I need this to work first). My code for the libev read callback is as the following…

void p2pserver_network_buf_read_callback(struct bufferevent *incoming, void *arg){
    //Define function local variables
    struct evbuffer *evreturn;
    char *req;

    //Begin function local logic
    req = evbuffer_readline(incoming->input);
    if (req == NULL){
        return;    
    }


    char *response;
    parse_json_command(req, response);
    //response = "OMP OMP";
    g_print("PARSED");
    evreturn = evbuffer_new();
    evbuffer_add_printf(evreturn, "%s", response);

    bufferevent_write_buffer(incoming,evreturn);
    evbuffer_free(evreturn);
    free(req);

    g_print("%s", response);
}

The parse_json_command function is as the following…

void parse_json_command(char json_command, char *response){

    //Define Local Variables
    g_print("PARSING");

    response = "YOU KNOW";

    //Print out the recieved message....
    //g_message("%s", json_command);


    /** 
     * TODO: check if the JSON is valid before parsing 
     *          to prevent "Segmentation Defaults" 
     *          and its good sanity checks.
     **/

    //Parse JSON incomming
    /*json_object * jobj = json_tokener_parse(json_command);

    enum json_type type;
    json_object_object_foreach(jobj, key, val){
        g_print("%s\n", key);

        if(g_utf8_collate(key, "cmd") >= 0){
            //Looks like the user has sent a "cmd" (command), lets analyze the "val" (value) of that command to see what the caller/client needs to be attending to...

            //Is the client requesting an "Identity Update" (Pings server: if this is the first time ping, the server and client will exachange keys if the relationship exists the server just accepts the encrypted "ping" packet update)
            type = json_object_get_type(val);
            if(type == json_type_string){
                char* cmd_value;
                cmd_value = json_object_get_string(val);
                //g_print("VALUE:%d\n", g_utf8_collate(cmd_value, "identupdate"));
                if(g_utf8_collate(cmd_value, "identupdate") == 0){
                    //Call "Identity Update Response"
                        //char return_response = p2pserver_json_identupdate_response(json_command);

                }
            }
        }
    }
    */
    return;
}

If you want to see the complete code (only a couple of pages big at the time of this writing) you can go to the source code at the following link: https://github.com/Xenland/P2PCrypt-Server

Thanks for your time and help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:32:08+00:00Added an answer on June 17, 2026 at 9:32 pm

    c passes arguments by value, not by reference. You problem is here:

    void parse_json_command(char json_command, char *response){
        [...]
        response = "YOU KNOW";
        [...]
    }
    
    char *response;
    parse_json_command(req, response);
    

    response is a uninitialized pointer to a string. You are assigning a pointer to a static string to the response pointer in the function, but that does not modify response outside of the function, it just changes response within the function. There are different ways to fix this. Probably the easiest one for a quick fix would be to change the function’s prototype to return a char * instead of void:

    char * parse_json_command(char json_command){
        char *response;
        [...]
        response = "YOU KNOW";
        [...]
        return response;
    }
    
    char *response;
    response = parse_json_command(req);
    

    Also, the json_command argument should probably be a char * or const char *, not just a single char, if you want to pass more than a single byte there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I have managed to write some code that should print the source
I've programmed 2 rails apps so far that have definitely gotten me pretty comfortable
I have a code which has a start() function that executes every cycle. In
I'm playing around with the Facebook API, and have gotten far enough to get
So far i have an assembly script that lets you boot from it and
What I have so far: I have a form in PHP that contain the
I am experimenting with Blackberry's Persistent Store, but I have gotten nowhere so far,
so far i have gotten my login view to appear at the at the
Im trying to implement an activity that uses ExpandableListView and I have gotten so
This is how far I have gotten to. The form is just a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.