summaryrefslogtreecommitdiff
path: root/toxav/msi.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-12 21:37:58 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-13 01:07:02 +0100
commita8823830d39bdbde8d4f4f34bfcb26dc4bf79741 (patch)
tree086d51b0db42c8fdbef669d002739f607db52f01 /toxav/msi.c
parent0aa2840164fc782f150cd45f8668ca623e6002cf (diff)
Add some astyle options to make it do more.
It now enforces a bit more formatting. In particular, padding inside parentheses is removed. I would like it to remove padding after unary operators, but there seems to be no option for that.
Diffstat (limited to 'toxav/msi.c')
-rw-r--r--toxav/msi.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index cb92525a..d80d7c76 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -64,9 +64,9 @@ typedef struct { \
64} MSIHeader##header 64} MSIHeader##header
65 65
66 66
67GENERIC_HEADER (Request, MSIRequest); 67GENERIC_HEADER(Request, MSIRequest);
68GENERIC_HEADER (Error, MSIError); 68GENERIC_HEADER(Error, MSIError);
69GENERIC_HEADER (Capabilities, uint8_t); 69GENERIC_HEADER(Capabilities, uint8_t);
70 70
71 71
72typedef struct { 72typedef struct {
@@ -76,26 +76,26 @@ typedef struct {
76} MSIMessage; 76} MSIMessage;
77 77
78 78
79void msg_init (MSIMessage *dest, MSIRequest request); 79void msg_init(MSIMessage *dest, MSIRequest request);
80int msg_parse_in (Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length); 80int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length);
81uint8_t *msg_parse_header_out (MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length); 81uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length);
82static int send_message (Messenger *m, uint32_t friend_number, const MSIMessage *msg); 82static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg);
83int send_error (Messenger *m, uint32_t friend_number, MSIError error); 83int send_error(Messenger *m, uint32_t friend_number, MSIError error);
84static int invoke_callback(MSICall *call, MSICallbackID cb); 84static int invoke_callback(MSICall *call, MSICallbackID cb);
85static MSICall *get_call (MSISession *session, uint32_t friend_number); 85static MSICall *get_call(MSISession *session, uint32_t friend_number);
86MSICall *new_call (MSISession *session, uint32_t friend_number); 86MSICall *new_call(MSISession *session, uint32_t friend_number);
87void kill_call (MSICall *call); 87void kill_call(MSICall *call);
88void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data); 88void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data);
89void handle_init (MSICall *call, const MSIMessage *msg); 89void handle_init(MSICall *call, const MSIMessage *msg);
90void handle_push (MSICall *call, const MSIMessage *msg); 90void handle_push(MSICall *call, const MSIMessage *msg);
91void handle_pop (MSICall *call, const MSIMessage *msg); 91void handle_pop(MSICall *call, const MSIMessage *msg);
92void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object); 92void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object);
93 93
94 94
95/** 95/**
96 * Public functions 96 * Public functions
97 */ 97 */
98void msi_register_callback (MSISession *session, msi_action_cb *callback, MSICallbackID id) 98void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id)
99{ 99{
100 if (!session) { 100 if (!session) {
101 return; 101 return;
@@ -105,13 +105,13 @@ void msi_register_callback (MSISession *session, msi_action_cb *callback, MSICal
105 session->callbacks[id] = callback; 105 session->callbacks[id] = callback;
106 pthread_mutex_unlock(session->mutex); 106 pthread_mutex_unlock(session->mutex);
107} 107}
108MSISession *msi_new (Messenger *m) 108MSISession *msi_new(Messenger *m)
109{ 109{
110 if (m == NULL) { 110 if (m == NULL) {
111 return NULL; 111 return NULL;
112 } 112 }
113 113
114 MSISession *retu = calloc (sizeof (MSISession), 1); 114 MSISession *retu = calloc(sizeof(MSISession), 1);
115 115
116 if (retu == NULL) { 116 if (retu == NULL) {
117 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); 117 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!");
@@ -134,7 +134,7 @@ MSISession *msi_new (Messenger *m)
134 LOGGER_DEBUG(m->log, "New msi session: %p ", retu); 134 LOGGER_DEBUG(m->log, "New msi session: %p ", retu);
135 return retu; 135 return retu;
136} 136}
137int msi_kill (MSISession *session) 137int msi_kill(MSISession *session)
138{ 138{
139 if (session == NULL) { 139 if (session == NULL) {
140 LOGGER_ERROR(session->messenger->log, "Tried to terminate non-existing session"); 140 LOGGER_ERROR(session->messenger->log, "Tried to terminate non-existing session");
@@ -166,10 +166,10 @@ int msi_kill (MSISession *session)
166 pthread_mutex_destroy(session->mutex); 166 pthread_mutex_destroy(session->mutex);
167 167
168 LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", session); 168 LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", session);
169 free (session); 169 free(session);
170 return 0; 170 return 0;
171} 171}
172int msi_invite (MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities) 172int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities)
173{ 173{
174 if (!session) { 174 if (!session) {
175 return -1; 175 return -1;
@@ -188,7 +188,7 @@ int msi_invite (MSISession *session, MSICall **call, uint32_t friend_number, uin
188 return -1; 188 return -1;
189 } 189 }
190 190
191 (*call) = new_call (session, friend_number); 191 (*call) = new_call(session, friend_number);
192 192
193 if (*call == NULL) { 193 if (*call == NULL) {
194 pthread_mutex_unlock(session->mutex); 194 pthread_mutex_unlock(session->mutex);
@@ -203,7 +203,7 @@ int msi_invite (MSISession *session, MSICall **call, uint32_t friend_number, uin
203 msg.capabilities.exists = true; 203 msg.capabilities.exists = true;
204 msg.capabilities.value = capabilities; 204 msg.capabilities.value = capabilities;
205 205
206 send_message ((*call)->session->messenger, (*call)->friend_number, &msg); 206 send_message((*call)->session->messenger, (*call)->friend_number, &msg);
207 207
208 (*call)->state = msi_CallRequesting; 208 (*call)->state = msi_CallRequesting;
209 209
@@ -211,7 +211,7 @@ int msi_invite (MSISession *session, MSICall **call, uint32_t friend_number, uin
211 pthread_mutex_unlock(session->mutex); 211 pthread_mutex_unlock(session->mutex);
212 return 0; 212 return 0;
213} 213}
214int msi_hangup (MSICall *call) 214int msi_hangup(MSICall *call)
215{ 215{
216 if (!call || !call->session) { 216 if (!call || !call->session) {
217 return -1; 217 return -1;
@@ -236,13 +236,13 @@ int msi_hangup (MSICall *call)
236 MSIMessage msg; 236 MSIMessage msg;
237 msg_init(&msg, requ_pop); 237 msg_init(&msg, requ_pop);
238 238
239 send_message (session->messenger, call->friend_number, &msg); 239 send_message(session->messenger, call->friend_number, &msg);
240 240
241 kill_call(call); 241 kill_call(call);
242 pthread_mutex_unlock(session->mutex); 242 pthread_mutex_unlock(session->mutex);
243 return 0; 243 return 0;
244} 244}
245int msi_answer (MSICall *call, uint8_t capabilities) 245int msi_answer(MSICall *call, uint8_t capabilities)
246{ 246{
247 if (!call || !call->session) { 247 if (!call || !call->session) {
248 return -1; 248 return -1;
@@ -273,7 +273,7 @@ int msi_answer (MSICall *call, uint8_t capabilities)
273 msg.capabilities.exists = true; 273 msg.capabilities.exists = true;
274 msg.capabilities.value = capabilities; 274 msg.capabilities.value = capabilities;
275 275
276 send_message (session->messenger, call->friend_number, &msg); 276 send_message(session->messenger, call->friend_number, &msg);
277 277
278 call->state = msi_CallActive; 278 call->state = msi_CallActive;
279 pthread_mutex_unlock(session->mutex); 279 pthread_mutex_unlock(session->mutex);
@@ -310,7 +310,7 @@ int msi_change_capabilities(MSICall *call, uint8_t capabilities)
310 msg.capabilities.exists = true; 310 msg.capabilities.exists = true;
311 msg.capabilities.value = capabilities; 311 msg.capabilities.value = capabilities;
312 312
313 send_message (call->session->messenger, call->friend_number, &msg); 313 send_message(call->session->messenger, call->friend_number, &msg);
314 314
315 pthread_mutex_unlock(session->mutex); 315 pthread_mutex_unlock(session->mutex);
316 return 0; 316 return 0;
@@ -326,7 +326,7 @@ void msg_init(MSIMessage *dest, MSIRequest request)
326 dest->request.exists = true; 326 dest->request.exists = true;
327 dest->request.value = request; 327 dest->request.value = request;
328} 328}
329int msg_parse_in (Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length) 329int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length)
330{ 330{
331 /* Parse raw data received from socket into MSIMessage struct */ 331 /* Parse raw data received from socket into MSIMessage struct */
332 332
@@ -400,7 +400,7 @@ int msg_parse_in (Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t l
400#undef SET_UINT8 400#undef SET_UINT8
401#undef SET_UINT16 401#undef SET_UINT16
402} 402}
403uint8_t *msg_parse_header_out (MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length) 403uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length)
404{ 404{
405 /* Parse a single header for sending */ 405 /* Parse a single header for sending */
406 assert(dest); 406 assert(dest);
@@ -418,7 +418,7 @@ uint8_t *msg_parse_header_out (MSIHeaderID id, uint8_t *dest, const void *value,
418 418
419 return dest + value_len; /* Set to next position ready to be written */ 419 return dest + value_len; /* Set to next position ready to be written */
420} 420}
421int send_message (Messenger *m, uint32_t friend_number, const MSIMessage *msg) 421int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg)
422{ 422{
423 /* Parse and send message */ 423 /* Parse and send message */
424 assert(m); 424 assert(m);
@@ -463,7 +463,7 @@ int send_message (Messenger *m, uint32_t friend_number, const MSIMessage *msg)
463 463
464 return -1; 464 return -1;
465} 465}
466int send_error (Messenger *m, uint32_t friend_number, MSIError error) 466int send_error(Messenger *m, uint32_t friend_number, MSIError error)
467{ 467{
468 /* Send error message */ 468 /* Send error message */
469 assert(m); 469 assert(m);
@@ -476,7 +476,7 @@ int send_error (Messenger *m, uint32_t friend_number, MSIError error)
476 msg.error.exists = true; 476 msg.error.exists = true;
477 msg.error.value = error; 477 msg.error.value = error;
478 478
479 send_message (m, friend_number, &msg); 479 send_message(m, friend_number, &msg);
480 return 0; 480 return 0;
481} 481}
482int invoke_callback(MSICall *call, MSICallbackID cb) 482int invoke_callback(MSICall *call, MSICallbackID cb)
@@ -486,7 +486,7 @@ int invoke_callback(MSICall *call, MSICallbackID cb)
486 if (call->session->callbacks[cb]) { 486 if (call->session->callbacks[cb]) {
487 LOGGER_DEBUG(call->session->messenger->log, "Invoking callback function: %d", cb); 487 LOGGER_DEBUG(call->session->messenger->log, "Invoking callback function: %d", cb);
488 488
489 if (call->session->callbacks[cb] (call->session->av, call) != 0) { 489 if (call->session->callbacks[cb](call->session->av, call) != 0) {
490 LOGGER_WARNING(call->session->messenger->log, 490 LOGGER_WARNING(call->session->messenger->log,
491 "Callback state handling failed, sending error"); 491 "Callback state handling failed, sending error");
492 goto FAILURE; 492 goto FAILURE;
@@ -506,7 +506,7 @@ FAILURE:
506 506
507 return -1; 507 return -1;
508} 508}
509static MSICall *get_call (MSISession *session, uint32_t friend_number) 509static MSICall *get_call(MSISession *session, uint32_t friend_number)
510{ 510{
511 assert(session); 511 assert(session);
512 512
@@ -516,7 +516,7 @@ static MSICall *get_call (MSISession *session, uint32_t friend_number)
516 516
517 return session->calls[friend_number]; 517 return session->calls[friend_number];
518} 518}
519MSICall *new_call (MSISession *session, uint32_t friend_number) 519MSICall *new_call(MSISession *session, uint32_t friend_number)
520{ 520{
521 assert(session); 521 assert(session);
522 522
@@ -530,7 +530,7 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
530 rc->friend_number = friend_number; 530 rc->friend_number = friend_number;
531 531
532 if (session->calls == NULL) { /* Creating */ 532 if (session->calls == NULL) { /* Creating */
533 session->calls = calloc (sizeof(MSICall *), friend_number + 1); 533 session->calls = calloc(sizeof(MSICall *), friend_number + 1);
534 534
535 if (session->calls == NULL) { 535 if (session->calls == NULL) {
536 free(rc); 536 free(rc);
@@ -568,7 +568,7 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
568 session->calls[friend_number] = rc; 568 session->calls[friend_number] = rc;
569 return rc; 569 return rc;
570} 570}
571void kill_call (MSICall *call) 571void kill_call(MSICall *call)
572{ 572{
573 /* Assume that session mutex is locked */ 573 /* Assume that session mutex is locked */
574 if (call == NULL) { 574 if (call == NULL) {
@@ -635,7 +635,7 @@ void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *
635 break; 635 break;
636 } 636 }
637} 637}
638void handle_init (MSICall *call, const MSIMessage *msg) 638void handle_init(MSICall *call, const MSIMessage *msg)
639{ 639{
640 assert(call); 640 assert(call);
641 LOGGER_DEBUG(call->session->messenger->log, 641 LOGGER_DEBUG(call->session->messenger->log,
@@ -675,7 +675,7 @@ void handle_init (MSICall *call, const MSIMessage *msg)
675 msg.capabilities.exists = true; 675 msg.capabilities.exists = true;
676 msg.capabilities.value = call->self_capabilities; 676 msg.capabilities.value = call->self_capabilities;
677 677
678 send_message (call->session->messenger, call->friend_number, &msg); 678 send_message(call->session->messenger, call->friend_number, &msg);
679 679
680 /* If peer changed capabilities during re-call they will 680 /* If peer changed capabilities during re-call they will
681 * be handled accordingly during the next step 681 * be handled accordingly during the next step
@@ -697,7 +697,7 @@ FAILURE:
697 send_error(call->session->messenger, call->friend_number, call->error); 697 send_error(call->session->messenger, call->friend_number, call->error);
698 kill_call(call); 698 kill_call(call);
699} 699}
700void handle_push (MSICall *call, const MSIMessage *msg) 700void handle_push(MSICall *call, const MSIMessage *msg)
701{ 701{
702 assert(call); 702 assert(call);
703 703
@@ -752,7 +752,7 @@ FAILURE:
752 send_error(call->session->messenger, call->friend_number, call->error); 752 send_error(call->session->messenger, call->friend_number, call->error);
753 kill_call(call); 753 kill_call(call);
754} 754}
755void handle_pop (MSICall *call, const MSIMessage *msg) 755void handle_pop(MSICall *call, const MSIMessage *msg)
756{ 756{
757 assert(call); 757 assert(call);
758 758
@@ -796,16 +796,16 @@ void handle_pop (MSICall *call, const MSIMessage *msg)
796 } 796 }
797 } 797 }
798 798
799 kill_call (call); 799 kill_call(call);
800} 800}
801void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object) 801void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object)
802{ 802{
803 LOGGER_DEBUG(m->log, "Got msi message"); 803 LOGGER_DEBUG(m->log, "Got msi message");
804 804
805 MSISession *session = object; 805 MSISession *session = object;
806 MSIMessage msg; 806 MSIMessage msg;
807 807
808 if (msg_parse_in (m->log, &msg, data, length) == -1) { 808 if (msg_parse_in(m->log, &msg, data, length) == -1) {
809 LOGGER_WARNING(m->log, "Error parsing message"); 809 LOGGER_WARNING(m->log, "Error parsing message");
810 send_error(m, friend_number, msi_EInvalidMessage); 810 send_error(m, friend_number, msi_EInvalidMessage);
811 return; 811 return;