Github User Fetcher 1.0.0
C Application with Server and GUI
|
#include "user.h"
#include <curl/curl.h>
#include <jansson.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | Buffer |
Buffer structure to hold incoming HTTP response data. More... | |
Functions | |
void | buffer_init (Buffer *buf) |
Initialize a Buffer structure. | |
void | buffer_cleanup (Buffer *buf) |
Free the memory held by a Buffer. | |
int | buffer_ensure_capacity (Buffer *buf, size_t required_size) |
Ensure that a Buffer has enough capacity for new data. | |
static size_t | write_callback (const void *contents, size_t size, size_t nmemb, void *userp) |
Callback for libcurl to write response data into a Buffer. | |
User | fetch_github_user (const char *username) |
Fetch a GitHub user's information via the GitHub API. | |
void | print_github_user (const User *user) |
Print a User's information to the console. | |
void buffer_cleanup | ( | Buffer * | buf | ) |
Free the memory held by a Buffer.
buf | Pointer to Buffer to clean up. |
Definition at line 36 of file user.c.
References Buffer::capacity, Buffer::data, free, NULL, and Buffer::size.
Referenced by fetch_github_user().
int buffer_ensure_capacity | ( | Buffer * | buf, |
size_t | required_size ) |
Ensure that a Buffer has enough capacity for new data.
buf | Pointer to Buffer. |
required_size | Size needed. |
Definition at line 52 of file user.c.
References Buffer::capacity, Buffer::data, and realloc.
Referenced by write_callback().
void buffer_init | ( | Buffer * | buf | ) |
Initialize a Buffer structure.
buf | Pointer to Buffer to initialize. |
Definition at line 22 of file user.c.
References Buffer::capacity, Buffer::data, malloc, and Buffer::size.
Referenced by fetch_github_user().
User fetch_github_user | ( | const char * | username | ) |
Fetch a GitHub user's information via the GitHub API.
Fetch GitHub user information for a given username.
username | GitHub username. |
The returned User must be freed using user_free().
Definition at line 130 of file user.c.
References buffer_cleanup(), buffer_init(), User::company, curl_easy_cleanup(), curl_easy_init(), curl_easy_perform(), curl_easy_setopt, curl_easy_strerror(), CURLE_OK, Buffer::data, error(), free, json_decref(), json_is_string, json_loads(), json_object_get(), json_string_value(), User::location, User::login, malloc, User::name, name, snprintf, and write_callback().
Referenced by main(), Test(), and user_handler().
void print_github_user | ( | const User * | user | ) |
Print a User's information to the console.
Print GitHub user information to standard output.
user | Pointer to the User structure. |
Definition at line 230 of file user.c.
References User::company, User::location, User::login, User::name, and printf.
Referenced by BM_PrintUser(), and main().
|
static |
Callback for libcurl to write response data into a Buffer.
contents | Pointer to incoming data. |
size | Size of a single item. |
nmemb | Number of items. |
userp | Pointer to Buffer structure. |
Definition at line 89 of file user.c.
References buffer_ensure_capacity(), Buffer::data, Buffer::size, and SIZE_MAX.
Referenced by fetch_github_user().