Browse code

doc: rpc struct_scan and struct_add example fixes

Andrei Pelinescu-Onciul authored on 11/05/2009 15:12:16
Showing 2 changed files
... ...
@@ -303,7 +303,9 @@ static void rpc_delete_contact(rpc_t* rpc)
303 303
         return;
304 304
     }
305 305
 
306
-    if (rpc->struct_scan(handle, "Sdf", &contact, &expires, &q) < 0) {
306
+    if (rpc->struct_scan(handle, "Sdf", "Contact", &contact,
307
+                                        "Expires", &expires,
308
+                                        "Q",       &q        ) < 0) {
307 309
         /* Reply is set automatically by struct_scan upon failure,
308 310
          * no need to do anything here
309 311
          */
... ...
@@ -460,8 +462,9 @@ static void rpc_func(rpc_t* rpc)
460 460
         /* Create empty structure and obtain its handle */
461 461
     if (rpc->add("{", &handle) < 0) return;
462 462
         /* Fill-in the structure */
463
-    if (rpc->struct_add(handle, "sd", "attr1", str_val, "attr2", int_val) < 0) r
464
-eturn;
463
+    if (rpc->struct_add(handle, "sd", "attr1", str_val,
464
+                                      "attr2", int_val ) < 0)
465
+        return;
465 466
 }
466 467
 
467 468
    The function returns -1 on an error (and sets the status code and
... ...
@@ -483,8 +486,10 @@ static void rpc_register(rpc_t* rpc)
483 483
         /* Extract the domain, address of record from the request */
484 484
     if (rpc->scan("sS{", &domain, &aor, &handle) < 0) return;
485 485
         /* Extract the structure describing the contact to be processed */
486
-    if (rpc->struct_scan(handle, "Sdf", &contact.c, &contact.expires, &contact.q
487
-) < 0) return;
486
+    if (rpc->struct_scan(handle, "Sdf", "Contact", &contact.c,
487
+                                        "Expires", &contact.expires,
488
+                                        "Q",       &contact.q       ) < 0)
489
+        return;
488 490
 
489 491
         /* Process the contact, new_contact will contain updated value after pro
490 492
 cessing */
... ...
@@ -497,8 +502,9 @@ cessing */
497 497
         /* Return the domain and the address of record */
498 498
     rpc->add("sS{", &domain, &aor, &handle) < 0) return;
499 499
         /* And also add the new values for contact, q, and expires parameters */
500
-    rpc->struct_add(handle, "Sdf", &new_contact.c, &new_contact.expires, &new_co
501
-ntact.q);
500
+    rpc->struct_add(handle, "Sdf", "Contact", &new_contact.c,
501
+                                   "Expires", &new_contact.expires,
502
+                                   "Q",       &new_contact.q       );
502 503
 }
503 504
 
504 505
 1.3. Client Examples
... ...
@@ -405,7 +405,9 @@ static void rpc_delete_contact(rpc_t* rpc)
405 405
         return;
406 406
     }
407 407
 
408
-    if (rpc->struct_scan(handle, "Sdf", &contact, &expires, &q) < 0) {
408
+    if (rpc->struct_scan(handle, "Sdf", "Contact", &contact,
409
+                                        "Expires", &expires,
410
+                                        "Q",       &q        ) < 0) {
409 411
         /* Reply is set automatically by struct_scan upon failure,
410 412
          * no need to do anything here
411 413
          */
... ...
@@ -628,7 +630,9 @@ static void rpc_func(rpc_t* rpc)
628 628
         /* Create empty structure and obtain its handle */
629 629
     if (rpc->add("{", &handle) < 0) return;
630 630
         /* Fill-in the structure */
631
-    if (rpc->struct_add(handle, "sd", "attr1", str_val, "attr2", int_val) < 0) return;
631
+    if (rpc->struct_add(handle, "sd", "attr1", str_val,
632
+                                      "attr2", int_val ) < 0)
633
+        return;
632 634
 }
633 635
 ]]>
634 636
 		    </programlisting>
... ...
@@ -658,7 +662,10 @@ static void rpc_register(rpc_t* rpc)
658 658
         /* Extract the domain, address of record from the request */
659 659
     if (rpc->scan("sS{", &domain, &aor, &handle) < 0) return;
660 660
         /* Extract the structure describing the contact to be processed */
661
-    if (rpc->struct_scan(handle, "Sdf", &contact.c, &contact.expires, &contact.q) < 0) return;
661
+    if (rpc->struct_scan(handle, "Sdf", "Contact", &contact.c,
662
+                                        "Expires", &contact.expires,
663
+                                        "Q",       &contact.q       ) < 0)
664
+        return;
662 665
 
663 666
         /* Process the contact, new_contact will contain updated value after processing */
664 667
     if (process_contact(domain, &aor, &new_contact, &contact) < 0) {
... ...
@@ -670,7 +677,9 @@ static void rpc_register(rpc_t* rpc)
670 670
         /* Return the domain and the address of record */
671 671
     rpc->add("sS{", &domain, &aor, &handle) < 0) return;
672 672
         /* And also add the new values for contact, q, and expires parameters */
673
-    rpc->struct_add(handle, "Sdf", &new_contact.c, &new_contact.expires, &new_contact.q);
673
+    rpc->struct_add(handle, "Sdf", "Contact", &new_contact.c,
674
+                                   "Expires", &new_contact.expires,
675
+                                   "Q",       &new_contact.q       );
674 676
 }
675 677
 ]]>
676 678
 		</programlisting>