Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Macros | Functions
URLRequest.c File Reference
#include <assert.h>
#include "MutableDictionary.h"
#include "URLRequest.h"

Go to the source code of this file.

Macros

#define _Class   _URLRequest
 

Functions

Class_URLRequest (void)
 
static Objectcopy (const Object *self)
 
static void dealloc (Object *self)
 
static void initialize (Class *clazz)
 
static URLRequestinitWithURL (URLRequest *self, URL *url)
 
static void setValueForHTTPHeaderField (URLRequest *self, const char *value, const char *field)
 

Macro Definition Documentation

◆ _Class

#define _Class   _URLRequest

Definition at line 29 of file URLRequest.c.

Function Documentation

◆ _URLRequest()

Class * _URLRequest ( void  )

Definition at line 122 of file URLRequest.c.

122 {
123 static Class *clazz;
124 static Once once;
125
126 do_once(&once, {
127 clazz = _initialize(&(const ClassDef) {
128 .name = "URLRequest",
129 .superclass = _Object(),
130 .instanceSize = sizeof(URLRequest),
131 .interfaceOffset = offsetof(URLRequest, interface),
132 .interfaceSize = sizeof(URLRequestInterface),
134 });
135 });
136
137 return clazz;
138}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: URLRequest.c:109
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
A protocol-agnostic abstraction for requesting resources via URLs.
Definition: URLRequest.h:56

◆ copy()

static Object * copy ( const Object self)
static
See also
Object::copy(const Object *)

Definition at line 36 of file URLRequest.c.

36 {
37
38 URLRequest *this = (URLRequest *) self;
39
40 URLRequest *that = $(alloc(URLRequest), initWithURL, this->url);
41
42 if (this->httpBody) {
43 that->httpBody = (Data *) $((Object *) this->httpBody, copy);
44 }
45
46 if (this->httpHeaders) {
47 that->httpHeaders = (Dictionary *) $((Object *) this->httpHeaders, copy);
48 }
49
50 return (Object *) that;
51}
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
Immutable data buffers.
Definition: Data.h:50
Immutable key-value stores.
Definition: Dictionary.h:60
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Object * copy(const Object *self)
Creates a shallow copy of this Object.
Definition: Array.c:40
Dictionary * httpHeaders
The HTTP request headers.
Definition: URLRequest.h:77
URLRequest * initWithURL(URLRequest *self, URL *url)
Initializes this URLRequest with the specified URL.
Definition: URLRequest.c:73
Data * httpBody
The HTTP request body, sent as POST or PUT data.
Definition: URLRequest.h:72

◆ dealloc()

static void dealloc ( Object self)
static
See also
Object::dealloc(Object *)

Definition at line 56 of file URLRequest.c.

56 {
57
58 URLRequest *this = (URLRequest *) self;
59
60 release(this->httpBody);
61 release(this->httpHeaders);
62 release(this->url);
63
64 super(Object, self, dealloc);
65}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition: Class.c:196
#define super(type, obj, method,...)
void dealloc(Object *self)
Frees all resources held by this Object.
Definition: Array.c:50

◆ initialize()

static void initialize ( Class clazz)
static
See also
Class::initialize(Class *)

Definition at line 109 of file URLRequest.c.

109 {
110
111 ((ObjectInterface *) clazz->interface)->copy = copy;
112 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
113
114 ((URLRequestInterface *) clazz->interface)->initWithURL = initWithURL;
115 ((URLRequestInterface *) clazz->interface)->setValueForHTTPHeaderField = setValueForHTTPHeaderField;
116}
ident interface
The interface of the Class.
Definition: Class.h:105
void setValueForHTTPHeaderField(URLREquest *self, const char *value, const char *field)

◆ initWithURL()

static URLRequest * initWithURL ( URLRequest self,
URL url 
)
static

Definition at line 73 of file URLRequest.c.

73 {
74
75 assert(url);
76
77 self = (URLRequest *) super(Object, self, init);
78 if (self) {
79 self->url = retain(url);
80 }
81
82 return self;
83}
ident retain(ident obj)
Atomically increment the given Object's reference count.
Definition: Class.c:211
Condition * init(Condition *self)
Initializes this Condition.
Definition: Condition.c:67
URL * url
The URL.
Definition: URLRequest.h:87

◆ setValueForHTTPHeaderField()

static void setValueForHTTPHeaderField ( URLRequest self,
const char *  value,
const char *  field 
)
static

Definition at line 89 of file URLRequest.c.

89 {
90
91 if (self->httpHeaders == NULL) {
93 }
94
95 String *object = str(value);
96 String *key = str(field);
97
98 $((MutableDictionary *) self->httpHeaders, setObjectForKey, object, key);
99
100 release(object);
101 release(key);
102}
Mutable key-value stores.
void setObjectForKey(MutableDictionary *self, const ident obj, const ident key)
Sets a pair in this MutableDictionary.
Immutable UTF-8 strings.
Definition: String.h:69
OBJECTIVELY_EXPORT String * str(const char *fmt,...)
A convenience function for instantiating Strings.
Definition: String.c:739