-
Notifications
You must be signed in to change notification settings - Fork 16
/
solr_functions_params.c
executable file
·1230 lines (839 loc) · 36.5 KB
/
solr_functions_params.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Israel Ekpo <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: solr_functions_params.c 289604 2009-10-13 04:32:39Z iekpo $ */
#include "php_solr.h"
/* {{{ PHP_SOLR_API void solr_destroy_params(void *solr_params) */
PHP_SOLR_API void solr_destroy_params(void *solr_params)
{
solr_params_t *params = (solr_params_t *) solr_params;
zend_hash_destroy(params->params);
pefree(params->params, SOLR_PARAMS_PERSISTENT);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_destroy_param(solr_param_t **param) */
PHP_SOLR_API void solr_destroy_param(solr_param_t **param)
{
solr_param_value_t *temp_ptr = NULL;
solr_param_value_t *current_ptr = (*param)->head;
while(current_ptr != NULL) {
temp_ptr = current_ptr->next;
(*param)->value_free_func(current_ptr);
current_ptr = temp_ptr;
}
(*param)->head = NULL;
(*param)->last = NULL;
pefree((*param)->param_name, SOLR_PARAMS_PERSISTENT);
(*param)->param_name = NULL;
pefree((*param), SOLR_PARAMS_PERSISTENT);
(*param) = NULL;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_params_delete_param_value(solr_param_t *param, const solr_param_value_t *target_value TSRMLS_DC) */
PHP_SOLR_API int solr_params_delete_param_value(solr_param_t *param, const solr_param_value_t *target_value TSRMLS_DC)
{
solr_param_value_t *curr_value = param->head;
int match_found = 0;
if (!target_value)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid pointer. Submitted target cannot be used for the delete search\n");
return FAILURE;
}
while(!match_found && curr_value != NULL)
{
match_found = param->value_equal_func(curr_value, target_value);
/* If the target was found */
if (match_found)
{
/* If the target is not the head */
if (curr_value->prev)
{
curr_value->prev->next = curr_value->next;
} else {
param->head = curr_value->next;
}
/* If the target is not the tail */
if (curr_value->next)
{
curr_value->next->prev = curr_value->prev;
} else {
param->last = curr_value->prev;
}
/* Destroy target value */
param->value_free_func(curr_value);
goto dpv_end;
}
curr_value = curr_value->next;
}
dpv_end :
if (!match_found)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Target parameter value could not be found in '%s'. No value was deleted ", param->param_name);
return FAILURE;
}
param->count--; /* Reduce the value count by one */
return SUCCESS;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_params_insert_param_value(solr_param_t *param, solr_param_value_t *param_value) */
PHP_SOLR_API int solr_params_insert_param_value(solr_param_t *param, solr_param_value_t *param_value)
{
if (!param_value)
{
return FAILURE;
}
param_value->next = param_value->prev = NULL;
if (!param->allow_multiple)
{
param->value_free_func(param->head);
param->head = param_value;
param->last = param_value;
param->count = 1U;
return SUCCESS;
}
if (param->head == NULL) {
param->head = param_value;
param->last = param_value;
} else {
param_value->prev = param->last;
param->last->next = param_value;
param->last = param_value;
}
param->count++;
return SUCCESS;
}
/* }}} */
/* {{{ PHP_SOLR_API solr_param_t *solr_create_new_param(const solr_char_t *param_name, size_t param_name_len, solr_param_type_t param_type, solr_bool allow_multiple, solr_param_value_equal_func_t value_equal_func, solr_param_fetch_func_t param_fetch_func, solr_param_value_free_func_t value_free_func, solr_char_t delimiter, solr_char_t arg_separator TSRMLS_DC) */
PHP_SOLR_API solr_param_t *solr_create_new_param(const solr_char_t *param_name, size_t param_name_len, solr_param_type_t param_type, solr_bool allow_multiple, solr_param_value_equal_func_t value_equal_func, solr_param_fetch_func_t param_fetch_func, solr_param_value_free_func_t value_free_func, solr_char_t delimiter, solr_char_t arg_separator TSRMLS_DC)
{
solr_param_t *query_param = (solr_param_t *) pemalloc(sizeof(solr_param_t), SOLR_PARAMS_PERSISTENT);
/* Always initialize linked list containers to NULL. */
/* Member pointers may contain unallocated addresses */
/* This notice applies to all solr_param_t member pointers here */
memset(query_param, 0, sizeof(solr_param_t));
query_param->type = param_type;
query_param->count = 0L;
query_param->param_name = solr_strndup(param_name, param_name_len);
query_param->param_name_length = param_name_len;
query_param->allow_multiple = allow_multiple;
query_param->head = query_param->last = NULL;
query_param->value_equal_func = value_equal_func;
query_param->fetch_func = param_fetch_func;
query_param->value_free_func = value_free_func;
query_param->delimiter = delimiter;
query_param->arg_separator = arg_separator;
return query_param;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_add_or_set_normal_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length, zend_bool allow_multiple TSRMLS_DC)
parameter value addition functions */
PHP_SOLR_API int solr_add_or_set_normal_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length, zend_bool allow_multiple TSRMLS_DC)
{
solr_params_t *solr_params = NULL;
solr_param_t **param_ptr = NULL;
HashTable *params = NULL;
solr_param_type_t param_type = SOLR_PARAM_TYPE_NORMAL;
solr_param_t *param = NULL;
solr_param_value_t *parameter_value = NULL;
if (!pname_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter name");
return FAILURE;
}
if (!pvalue_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter value");
return FAILURE;
}
if (solr_fetch_params_entry(objptr, &solr_params TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SolrParams instance could not be retrieved from HashTable");
return FAILURE;
}
params = solr_params->params;
if (zend_hash_find(params, (char *) pname, pname_length, (void **) ¶m_ptr) == SUCCESS)
{
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.normal), pvalue, pvalue_length);
solr_params_insert_param_value((*param_ptr), parameter_value);
return SUCCESS;
}
param = solr_create_new_param(pname, pname_length, param_type, allow_multiple, solr_normal_param_value_equal, (solr_param_fetch_func_t) solr_normal_param_value_fetch, solr_normal_param_value_free, '&', 0 TSRMLS_CC);
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.normal), pvalue, pvalue_length);
solr_params_insert_param_value(param, parameter_value);
if (zend_hash_add(params, pname, pname_length, (void *) ¶m, sizeof(solr_param_t *), (void **) NULL) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error from %s %s=%s", __func__, (char *) pname, pvalue);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_add_simple_list_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length TSRMLS_DC) */
PHP_SOLR_API int solr_add_simple_list_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length TSRMLS_DC)
{
zend_bool allow_multiple = 1; /* This value type by definition allows multiple. add parameters can be added more than once */
solr_params_t *solr_params = NULL;
solr_param_t **param_ptr = NULL;
HashTable *params = NULL;
solr_param_type_t param_type = SOLR_PARAM_TYPE_SIMPLE_LIST;
solr_param_t *param = NULL;
solr_param_value_t *parameter_value = NULL;
if (!pname_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter name");
return FAILURE;
}
if (!pvalue_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter value");
return FAILURE;
}
if (solr_fetch_params_entry(objptr, &solr_params TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "SolrParams instance could not be retrieved from HashTable");
return FAILURE;
}
params = solr_params->params;
if (zend_hash_find(params, pname, pname_length, (void **) ¶m_ptr) == SUCCESS)
{
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.simple_list), pvalue, pvalue_length);
solr_params_insert_param_value((*param_ptr), parameter_value);
return SUCCESS;
}
param = solr_create_new_param(pname, pname_length, param_type, allow_multiple, solr_simple_list_param_value_equal, (solr_param_fetch_func_t) solr_simple_list_param_value_fetch, solr_simple_list_param_value_free, ',', 0 TSRMLS_CC);
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.simple_list), pvalue, pvalue_length);
solr_params_insert_param_value(param, parameter_value);
if (zend_hash_add(params, pname, pname_length, (void *) ¶m, sizeof(solr_param_t *), (void **) NULL) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error from %s %s=%s", __func__, (char *) pname, pvalue);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_add_arg_list_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length, solr_char_t *avalue, int avalue_length, solr_char_t delimiter, solr_char_t arg_separator TSRMLS_DC) */
PHP_SOLR_API int solr_add_arg_list_param(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length, solr_char_t *avalue, int avalue_length, solr_char_t delimiter, solr_char_t arg_separator TSRMLS_DC)
{
zend_bool allow_multiple = 1; /* This value type by definition allows multiple */
solr_params_t *solr_params = NULL;
solr_param_type_t param_type = SOLR_PARAM_TYPE_ARG_LIST;
solr_param_t *param = NULL;
solr_param_value_t *parameter_value = NULL;
HashTable *params = NULL;
solr_param_t **param_ptr = NULL;
if (!pname_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter name");
return FAILURE;
}
if (!pvalue_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameter value");
return FAILURE;
}
if (!avalue_length)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid argument value");
return FAILURE;
}
if (solr_fetch_params_entry(objptr, &solr_params TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SolrParams instance could not be retrieved from HashTable");
return FAILURE;
}
params = solr_params->params;
if (zend_hash_find(params, pname, pname_length, (void **) ¶m_ptr) == SUCCESS)
{
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.arg_list.value), pvalue, pvalue_length);
solr_string_appends(&(parameter_value->contents.arg_list.arg), avalue, avalue_length);
solr_params_insert_param_value((*param_ptr), parameter_value);
return SUCCESS;
}
param = solr_create_new_param(pname, pname_length, param_type, allow_multiple, solr_arg_list_param_value_equal, (solr_param_fetch_func_t) solr_arg_list_param_value_fetch, solr_arg_list_param_value_free, delimiter, arg_separator TSRMLS_CC);
parameter_value = (solr_param_value_t *) pemalloc(sizeof(solr_param_value_t), SOLR_PARAMS_PERSISTENT);
memset(parameter_value, 0, sizeof(solr_param_value_t));
solr_string_appends(&(parameter_value->contents.arg_list.value), pvalue, pvalue_length);
solr_string_appends(&(parameter_value->contents.arg_list.arg), avalue, avalue_length);
solr_params_insert_param_value(param, parameter_value);
if (zend_hash_add(params, pname, pname_length, (void *) ¶m, sizeof(solr_param_t *), (void **) NULL) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error from %s %s=%s", __func__, (char *) pname, pvalue);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
/* {{{ Parameter value EQUALITY FUNCTIONS */
/* {{{ PHP_SOLR_API int solr_normal_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b) */
PHP_SOLR_API int solr_normal_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b)
{
return solr_string_equal(&(a->contents.normal), &(b->contents.normal));
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_simple_list_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b) */
PHP_SOLR_API int solr_simple_list_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b)
{
return solr_string_equal(&(a->contents.simple_list), &(b->contents.simple_list));
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_arg_list_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b) */
PHP_SOLR_API int solr_arg_list_param_value_equal(const solr_param_value_t *a, const solr_param_value_t *b)
{
return solr_string_equal(&(a->contents.arg_list.value), &(b->contents.arg_list.value));
}
/* }}} */
/* }}} */
/* {{{ Parameter values retrieval functions */
/* {{{ PHP_SOLR_API void solr_normal_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer) */
PHP_SOLR_API void solr_normal_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t glue = '&';
if (!solr_param->allow_multiple)
{
auto int new_pv_length = 0;
solr_char_t *url_encoded_param_value = (solr_char_t *) php_raw_url_encode((char *) current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
} else {
ulong n_loops = solr_param->count - 1;
auto int new_pv_length = 0;
solr_char_t *url_encoded_param_value = NULL;
while(n_loops)
{
new_pv_length = 0;
url_encoded_param_value = php_raw_url_encode(current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
url_encoded_param_value = NULL;
solr_string_appendc(buffer, glue);
n_loops--;
current_ptr = current_ptr->next;
}
url_encoded_param_value = php_raw_url_encode(current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
url_encoded_param_value = NULL;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_simple_list_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer) */
PHP_SOLR_API void solr_simple_list_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t list_delimiter = ','; /* Comma 0x2C */
ulong n_loops = solr_param->count - 1;
auto solr_string_t tmp_buffer;
auto int new_pv_length = 0;
solr_char_t *url_encoded_list = NULL;
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
memset(&tmp_buffer, 0, sizeof(solr_string_t));
while(n_loops)
{
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.simple_list));
solr_string_appendc(&tmp_buffer, list_delimiter);
n_loops--;
current_ptr = current_ptr->next;
}
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.simple_list));
url_encoded_list = php_raw_url_encode(tmp_buffer.str, tmp_buffer.len, &new_pv_length);
solr_string_appends(buffer, url_encoded_list, new_pv_length);
efree(url_encoded_list);
url_encoded_list = NULL;
solr_string_free(&tmp_buffer);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_arg_list_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer) */
PHP_SOLR_API void solr_arg_list_param_value_fetch(solr_param_t *solr_param, solr_string_t *buffer)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t list_delimiter = solr_param->delimiter;
solr_char_t separator = solr_param->arg_separator;
ulong n_loops = solr_param->count - 1;
solr_string_t tmp_buffer;
int new_pv_length = 0;
solr_char_t *url_encoded_list = NULL;
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
memset(&tmp_buffer, 0, sizeof(solr_string_t));
while(n_loops)
{
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.value));
solr_string_appendc(&tmp_buffer, separator);
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.arg));
solr_string_appendc(&tmp_buffer, list_delimiter);
n_loops--;
current_ptr = current_ptr->next;
}
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.value));
solr_string_appendc(&tmp_buffer, separator);
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.arg));
url_encoded_list = php_raw_url_encode(tmp_buffer.str, tmp_buffer.len, &new_pv_length);
solr_string_appends(buffer, url_encoded_list, new_pv_length);
efree(url_encoded_list);
url_encoded_list = NULL;
solr_string_free(&tmp_buffer);
}
/* }}} */
/* }}} */
/* {{{ Parameter retrieval functions. Only used for display. */
/* {{{ PHP_SOLR_API void solr_normal_param_value_display_string(solr_param_t *solr_param, zval *param_value) */
PHP_SOLR_API void solr_normal_param_value_display_string(solr_param_t *solr_param, zval *param_value)
{
solr_param_value_t *current_ptr = solr_param->head;
ZVAL_STRINGL(param_value, current_ptr->contents.normal.str, current_ptr->contents.normal.len, 1);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_normal_param_value_display_integer(solr_param_t *solr_param, zval *param_value) */
PHP_SOLR_API void solr_normal_param_value_display_integer(solr_param_t *solr_param, zval *param_value)
{
solr_param_value_t *current_ptr = solr_param->head;
long int return_value = atol(current_ptr->contents.normal.str);
ZVAL_LONG(param_value, return_value);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_normal_param_value_display_double(solr_param_t *solr_param, zval *param_value) */
PHP_SOLR_API void solr_normal_param_value_display_double(solr_param_t *solr_param, zval *param_value)
{
solr_param_value_t *current_ptr = solr_param->head;
double return_value = atof(current_ptr->contents.normal.str);
ZVAL_DOUBLE(param_value, return_value);
}
/* }}} */
/* Checks if current_ptr->contents.normal.str matches str_const */
#define solr_npvdb_strcmp(str_const) (0 == strcmp(str_const, current_ptr->contents.normal.str))
/* {{{ PHP_SOLR_API void solr_normal_param_value_display_boolean(solr_param_t *solr_param, zval *param_value) */
PHP_SOLR_API void solr_normal_param_value_display_boolean(solr_param_t *solr_param, zval *param_value)
{
solr_param_value_t *current_ptr = solr_param->head;
zend_bool return_value = (zend_bool) (solr_npvdb_strcmp("true") || solr_npvdb_strcmp("on") );
ZVAL_BOOL(param_value, return_value);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_normal_param_value_display_sort_type(solr_param_t *solr_param, zval *param_value) */
PHP_SOLR_API void solr_normal_param_value_display_sort_type(solr_param_t *solr_param, zval *param_value)
{
solr_param_value_t *current_ptr = solr_param->head;
long int return_value = (long int) (solr_npvdb_strcmp("count"));
ZVAL_LONG(param_value, return_value);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_normal_param_value_display(solr_param_t *solr_param, zval *param_value_array) */
PHP_SOLR_API void solr_normal_param_value_display(solr_param_t *solr_param, zval *param_value_array)
{
solr_param_value_t *current_ptr = solr_param->head;
register int duplicate = 1;
while (current_ptr != NULL)
{
add_next_index_stringl(param_value_array, current_ptr->contents.normal.str, current_ptr->contents.normal.len, duplicate);
current_ptr = current_ptr->next;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_simple_list_param_value_display(solr_param_t *solr_param, zval *param_value_array) */
PHP_SOLR_API void solr_simple_list_param_value_display(solr_param_t *solr_param, zval *param_value_array)
{
solr_param_value_t *current_ptr = solr_param->head;
register int duplicate = 1;
while (current_ptr != NULL)
{
add_next_index_stringl(param_value_array, current_ptr->contents.simple_list.str, current_ptr->contents.simple_list.len, duplicate);
current_ptr = current_ptr->next;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_arg_list_param_value_display(solr_param_t *solr_param, zval *param_value_array) */
PHP_SOLR_API void solr_arg_list_param_value_display(solr_param_t *solr_param, zval *param_value_array)
{
solr_param_value_t *current_ptr = solr_param->head;
register int duplicate = 1;
while (current_ptr != NULL)
{
solr_string_t tmp_buffer;
memset(&tmp_buffer, 0, sizeof(solr_string_t));
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.value));
solr_string_appendc(&tmp_buffer, solr_param->arg_separator);
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.arg));
add_next_index_stringl(param_value_array, tmp_buffer.str, tmp_buffer.len, duplicate);
solr_string_free(&tmp_buffer);
current_ptr = current_ptr->next;
}
}
/* }}} */
/* }}} */
/* {{{ Parameter retrieval functions. Only used for toString() */
/* {{{ PHP_SOLR_API void solr_normal_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode) */
PHP_SOLR_API void solr_normal_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t glue = '&';
if (!solr_param->allow_multiple)
{
auto int new_pv_length = 0;
solr_char_t *url_encoded_param_value = NULL;
if (url_encode)
{
url_encoded_param_value = (solr_char_t *) php_raw_url_encode((char *) current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
} else {
new_pv_length = current_ptr->contents.normal.len;
url_encoded_param_value = solr_strndup(current_ptr->contents.normal.str, current_ptr->contents.normal.len);
}
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
} else {
ulong n_loops = solr_param->count - 1;
auto int new_pv_length = 0;
solr_char_t *url_encoded_param_value = NULL;
while(n_loops)
{
new_pv_length = 0;
if (url_encode)
{
url_encoded_param_value = php_raw_url_encode(current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
} else {
new_pv_length = current_ptr->contents.normal.len;
url_encoded_param_value = solr_strndup(current_ptr->contents.normal.str, current_ptr->contents.normal.len);
}
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
url_encoded_param_value = NULL;
solr_string_appendc(buffer, glue);
n_loops--;
current_ptr = current_ptr->next;
}
if (url_encode)
{
url_encoded_param_value = php_raw_url_encode(current_ptr->contents.normal.str, current_ptr->contents.normal.len, &new_pv_length);
} else {
new_pv_length = current_ptr->contents.normal.len;
url_encoded_param_value = solr_strndup(current_ptr->contents.normal.str, current_ptr->contents.normal.len);
}
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
solr_string_appends(buffer, url_encoded_param_value, new_pv_length);
efree(url_encoded_param_value);
url_encoded_param_value = NULL;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_simple_list_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode) */
PHP_SOLR_API void solr_simple_list_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t list_delimiter = ','; /* Comma 0x2C */
ulong n_loops = solr_param->count - 1;
auto solr_string_t tmp_buffer;
auto int new_pv_length = 0;
solr_char_t *url_encoded_list = NULL;
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
memset(&tmp_buffer, 0, sizeof(solr_string_t));
while(n_loops)
{
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.simple_list));
solr_string_appendc(&tmp_buffer, list_delimiter);
n_loops--;
current_ptr = current_ptr->next;
}
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.simple_list));
if (url_encode)
{
url_encoded_list = php_raw_url_encode(tmp_buffer.str, tmp_buffer.len, &new_pv_length);
} else {
new_pv_length = tmp_buffer.len;
url_encoded_list = solr_strndup(tmp_buffer.str, tmp_buffer.len);
}
solr_string_appends(buffer, url_encoded_list, new_pv_length);
efree(url_encoded_list);
url_encoded_list = NULL;
solr_string_free(&tmp_buffer);
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_arg_list_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode) */
PHP_SOLR_API void solr_arg_list_param_value_tostring(solr_param_t *solr_param, solr_string_t *buffer, zend_bool url_encode)
{
solr_param_value_t *current_ptr = solr_param->head;
solr_char_t list_delimiter = solr_param->delimiter;
solr_char_t separator = solr_param->arg_separator;
ulong n_loops = solr_param->count - 1;
solr_string_t tmp_buffer;
int new_pv_length = 0;
solr_char_t *url_encoded_list = NULL;
solr_string_appends(buffer, solr_param->param_name, solr_param->param_name_length);
solr_string_appendc(buffer, '=');
memset(&tmp_buffer, 0, sizeof(solr_string_t));
while(n_loops)
{
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.value));
solr_string_appendc(&tmp_buffer, separator);
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.arg));
solr_string_appendc(&tmp_buffer, list_delimiter);
n_loops--;
current_ptr = current_ptr->next;
}
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.value));
solr_string_appendc(&tmp_buffer, separator);
solr_string_append_solr_string(&tmp_buffer, &(current_ptr->contents.arg_list.arg));
if (url_encode)
{
url_encoded_list = php_raw_url_encode(tmp_buffer.str, tmp_buffer.len, &new_pv_length);
} else {
new_pv_length = tmp_buffer.len;
url_encoded_list = solr_strndup(tmp_buffer.str, tmp_buffer.len);
}
solr_string_appends(buffer, url_encoded_list, new_pv_length);
efree(url_encoded_list);
url_encoded_list = NULL;
solr_string_free(&tmp_buffer);
}
/* }}} */
/* }}} */
/* {{{ Memory deallocation functions for parameter values */
/* {{{ PHP_SOLR_API void solr_normal_param_value_free(solr_param_value_t *param_value) */
PHP_SOLR_API void solr_normal_param_value_free(solr_param_value_t *param_value)
{
if (param_value)
{
solr_string_free(&(param_value->contents.normal));
pefree(param_value, SOLR_PARAMS_PERSISTENT);
param_value = NULL;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_simple_list_param_value_free(solr_param_value_t *param_value) */
PHP_SOLR_API void solr_simple_list_param_value_free(solr_param_value_t *param_value)
{
if (param_value)
{
solr_string_free(&(param_value->contents.simple_list));
pefree(param_value, SOLR_PARAMS_PERSISTENT);
param_value = NULL;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_arg_list_param_value_free(solr_param_value_t *param_value) */
PHP_SOLR_API void solr_arg_list_param_value_free(solr_param_value_t *param_value)
{
if (param_value)
{
solr_string_free(&(param_value->contents.arg_list.value));
solr_string_free(&(param_value->contents.arg_list.arg));
pefree(param_value, SOLR_PARAMS_PERSISTENT);
param_value = NULL;
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_set_return_solr_params_object(zval **return_value_ptr, zval *current_objptr TSRMLS_DC) */
PHP_SOLR_API void solr_set_return_solr_params_object(zval **return_value_ptr, zval *current_objptr TSRMLS_DC)
{
zval_ptr_dtor(return_value_ptr);
Z_SET_ISREF_P(current_objptr);
Z_ADDREF_P(current_objptr);
*return_value_ptr = current_objptr;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_delete_solr_parameter(zval *objptr, solr_char_t *name, int name_length TSRMLS_DC) */
PHP_SOLR_API int solr_delete_solr_parameter(zval *objptr, solr_char_t *name, int name_length TSRMLS_DC)
{
solr_params_t *solr_params = NULL;
HashTable *params_ht = NULL;
if (solr_fetch_params_entry(objptr, &solr_params TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "SolrParams instance could not be retrieved from HashTable");
return FAILURE;
}
params_ht = solr_params->params;
if (zend_hash_del(params_ht, name, name_length) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "parameter '%s' was not set. Attempting to remove an undefined parameter.", name);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_SOLR_API int solr_delete_normal_param_value(zval *objptr, solr_char_t *pname, int pname_length, solr_char_t *pvalue, int pvalue_length TSRMLS_DC) */