~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/api2/INKMgmtAPI.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/*****************************************************************************
 
25
 * Filename: InkMgmtAPI.cc
 
26
 * Purpose: This file implements all traffic server management functions.
 
27
 * Created: 9/11/00
 
28
 * Created by: Lan Tran
 
29
 *
 
30
 *
 
31
 ***************************************************************************/
 
32
#include "libts.h"
 
33
#include <limits.h>
 
34
#include "I_Layout.h"
 
35
 
 
36
#include "INKMgmtAPI.h"
 
37
#include "CfgContextManager.h"
 
38
#include "CfgContextImpl.h"
 
39
#include "CfgContextUtils.h"
 
40
#include "CoreAPI.h"
 
41
#include "CoreAPIShared.h"
 
42
 
 
43
#include "TextBuffer.h"
 
44
 
 
45
// forward declarations
 
46
void init_pdss_format(INKPdSsFormat * info);
 
47
 
 
48
 
 
49
/***************************************************************************
 
50
 * API Memory Management
 
51
 ***************************************************************************/
 
52
void *
 
53
_INKmalloc(unsigned int size, const char *path)
 
54
{
 
55
#ifdef PURIFY
 
56
  return xmalloc(size);
 
57
#else
 
58
  return _xmalloc(size, path);
 
59
#endif
 
60
}
 
61
 
 
62
void *
 
63
_INKrealloc(void *ptr, unsigned int size, const char *path)
 
64
{
 
65
#ifdef PURIFY
 
66
  return xrealloc(ptr, size);
 
67
#else
 
68
  return _xrealloc(ptr, size, path);
 
69
#endif
 
70
}
 
71
 
 
72
char *
 
73
_INKstrdup(const char *str, int length, const char *path)
 
74
{
 
75
#ifdef PURIFY
 
76
  return xstrndup(str, length);
 
77
#else
 
78
  return _xstrdup(str, length, path);
 
79
#endif
 
80
}
 
81
 
 
82
void
 
83
_INKfree(void *ptr)
 
84
{
 
85
#ifdef PURIFY
 
86
  xfree(ptr);
 
87
#else
 
88
  _xfree(ptr);
 
89
#endif
 
90
}
 
91
 
 
92
 
 
93
/***************************************************************************
 
94
 * API Helper Functions for Data Carrier Structures
 
95
 ***************************************************************************/
 
96
 
 
97
/*--- INKList operations -------------------------------------------------*/
 
98
inkapi INKList
 
99
INKListCreate(void)
 
100
{
 
101
  return (void *) create_queue();
 
102
}
 
103
 
 
104
/* NOTE: The List must be EMPTY */
 
105
inkapi void
 
106
INKListDestroy(INKList l)
 
107
{
 
108
  if (!l)
 
109
    return;
 
110
 
 
111
  delete_queue((LLQ *) l);
 
112
  return;
 
113
}
 
114
 
 
115
inkapi INKError
 
116
INKListEnqueue(INKList l, void *data)
 
117
{
 
118
  int ret;
 
119
 
 
120
  ink_assert(l && data);
 
121
  if (!l || !data)
 
122
    return INK_ERR_PARAMS;
 
123
 
 
124
  ret = enqueue((LLQ *) l, data);       /* returns TRUE=1 or FALSE=0 */
 
125
  if (ret == 0) {
 
126
    return INK_ERR_FAIL;
 
127
  } else {
 
128
    return INK_ERR_OKAY;
 
129
  }
 
130
}
 
131
 
 
132
inkapi void *
 
133
INKListDequeue(INKList l)
 
134
{
 
135
  ink_assert(l);
 
136
  if (!l || queue_is_empty((LLQ *) l))
 
137
    return NULL;
 
138
 
 
139
  return dequeue((LLQ *) l);
 
140
}
 
141
 
 
142
inkapi bool
 
143
INKListIsEmpty(INKList l)
 
144
{
 
145
  int ret;
 
146
 
 
147
  ink_assert(l);
 
148
  if (!l)
 
149
    return true;                // list doesn't exist, so it's empty
 
150
 
 
151
  ret = queue_is_empty((LLQ *) l);      /* returns 0 if empty, non-zero if not empty */
 
152
  if (ret == 0) {               /* empty */
 
153
    return true;
 
154
  } else {
 
155
    return false;
 
156
  }
 
157
}
 
158
 
 
159
inkapi int
 
160
INKListLen(INKList l)
 
161
{
 
162
  ink_assert(l);
 
163
  if (!l)
 
164
    return -1;
 
165
 
 
166
  return queue_len((LLQ *) l);
 
167
}
 
168
 
 
169
inkapi bool
 
170
INKListIsValid(INKList l)
 
171
{
 
172
  int i, len;
 
173
  void *ele;
 
174
 
 
175
  if (!l)
 
176
    return false;
 
177
 
 
178
  len = queue_len((LLQ *) l);
 
179
  for (i = 0; i < len; i++) {
 
180
    ele = (void *) dequeue((LLQ *) l);
 
181
    if (!ele)
 
182
      return false;
 
183
    enqueue((LLQ *) l, ele);
 
184
  }
 
185
  return true;
 
186
}
 
187
 
 
188
/*--- INKIpAddrList operations -------------------------------------------------*/
 
189
inkapi INKIpAddrList
 
190
INKIpAddrListCreate(void)
 
191
{
 
192
  return (void *) create_queue();       /* this queue will be a list of IpAddrEle* */
 
193
}
 
194
 
 
195
inkapi void
 
196
INKIpAddrListDestroy(INKIpAddrList ip_addrl)
 
197
{
 
198
  INKIpAddrEle *ipaddr_ele;
 
199
 
 
200
  if (!ip_addrl) {
 
201
    return;
 
202
  }
 
203
 
 
204
  /* dequeue each element and free it;
 
205
     currently, an element can only be an INKIpAddrEle
 
206
     or it can be an INKIpAddr ?? */
 
207
  while (!queue_is_empty((LLQ *) ip_addrl)) {
 
208
    ipaddr_ele = (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
 
209
 
 
210
    if (!ipaddr_ele)
 
211
      continue;
 
212
 
 
213
    INKIpAddrEleDestroy(ipaddr_ele);
 
214
  }
 
215
 
 
216
  /* we have removed everything on the list so free list */
 
217
  delete_queue((LLQ *) ip_addrl);
 
218
  return;
 
219
}
 
220
 
 
221
inkapi INKError
 
222
INKIpAddrListEnqueue(INKIpAddrList ip_addrl, INKIpAddrEle * ip_addr)
 
223
{
 
224
  int ret;
 
225
 
 
226
  ink_assert(ip_addrl && ip_addr);
 
227
  if (!ip_addrl || !ip_addr)
 
228
    return INK_ERR_PARAMS;
 
229
 
 
230
  ret = enqueue((LLQ *) ip_addrl, ip_addr);
 
231
  if (ret == 0) {
 
232
    return INK_ERR_FAIL;
 
233
  } else {
 
234
    return INK_ERR_OKAY;
 
235
  }
 
236
}
 
237
 
 
238
 
 
239
/* The the INKIpAddrEle returned is actually removed from the end of list */
 
240
inkapi INKIpAddrEle *
 
241
INKIpAddrListDequeue(INKIpAddrList ip_addrl)
 
242
{
 
243
  ink_assert(ip_addrl);
 
244
  if (!ip_addrl || queue_is_empty((LLQ *) ip_addrl))
 
245
    return NULL;
 
246
 
 
247
  return (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
 
248
}
 
249
 
 
250
 
 
251
inkapi int
 
252
INKIpAddrListLen(INKIpAddrList ip_addrl)
 
253
{
 
254
  ink_assert(ip_addrl);
 
255
  if (!ip_addrl)
 
256
    return -1;
 
257
 
 
258
  return queue_len((LLQ *) ip_addrl);
 
259
}
 
260
 
 
261
inkapi bool
 
262
INKIpAddrListIsEmpty(INKIpAddrList ip_addrl)
 
263
{
 
264
  ink_assert(ip_addrl);
 
265
  if (!ip_addrl)
 
266
    return true;
 
267
 
 
268
  return queue_is_empty((LLQ *) ip_addrl);
 
269
}
 
270
 
 
271
// returns false if any of the IpAddrEle is not an valid IP address by making
 
272
// use of ccu_checkIpAddrEle; if return false, the ip's may be reordered
 
273
// from the original list
 
274
inkapi bool
 
275
INKIpAddrListIsValid(INKIpAddrList ip_addrl)
 
276
{
 
277
  int i, len;
 
278
  INKIpAddrEle *ele;
 
279
 
 
280
  if (!ip_addrl)
 
281
    return false;
 
282
 
 
283
  len = queue_len((LLQ *) ip_addrl);
 
284
  for (i = 0; i < len; i++) {
 
285
    ele = (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
 
286
    if (!ccu_checkIpAddrEle(ele)) {
 
287
      enqueue((LLQ *) ip_addrl, ele);
 
288
      return false;
 
289
    }
 
290
    enqueue((LLQ *) ip_addrl, ele);
 
291
  }
 
292
  return true;
 
293
}
 
294
 
 
295
/*--- INKPortList operations ----------------------------------------------*/
 
296
inkapi INKPortList
 
297
INKPortListCreate()
 
298
{
 
299
  return (void *) create_queue();       /* this queue will be a list of INKPortEle* */
 
300
}
 
301
 
 
302
inkapi void
 
303
INKPortListDestroy(INKPortList portl)
 
304
{
 
305
  INKPortEle *port_ele;
 
306
 
 
307
  if (!portl) {
 
308
    return;
 
309
  }
 
310
  // dequeue each element and free it
 
311
  while (!queue_is_empty((LLQ *) portl)) {
 
312
    port_ele = (INKPortEle *) dequeue((LLQ *) portl);
 
313
 
 
314
    if (!port_ele)
 
315
      continue;
 
316
 
 
317
    INKPortEleDestroy(port_ele);
 
318
  }
 
319
 
 
320
  /* we have removed everything on the list so free list */
 
321
  delete_queue((LLQ *) portl);
 
322
  return;
 
323
}
 
324
 
 
325
inkapi INKError
 
326
INKPortListEnqueue(INKPortList portl, INKPortEle * port)
 
327
{
 
328
  int ret;
 
329
 
 
330
  ink_assert(portl && port);
 
331
  if (!portl || !port)
 
332
    return INK_ERR_PARAMS;
 
333
 
 
334
  ret = enqueue((LLQ *) portl, port);   /* returns TRUE=1 or FALSE=0 */
 
335
  if (ret == 0) {
 
336
    return INK_ERR_FAIL;
 
337
  } else {
 
338
    return INK_ERR_OKAY;
 
339
  }
 
340
}
 
341
 
 
342
inkapi INKPortEle *
 
343
INKPortListDequeue(INKPortList portl)
 
344
{
 
345
  ink_assert(portl);
 
346
  if (!portl || queue_is_empty((LLQ *) portl))
 
347
    return NULL;
 
348
 
 
349
  return (INKPortEle *) dequeue((LLQ *) portl);
 
350
}
 
351
 
 
352
inkapi int
 
353
INKPortListLen(INKPortList portl)
 
354
{
 
355
  ink_assert(portl);
 
356
  if (!portl)
 
357
    return -1;
 
358
 
 
359
  return queue_len((LLQ *) portl);
 
360
}
 
361
 
 
362
inkapi bool
 
363
INKPortListIsEmpty(INKPortList portl)
 
364
{
 
365
  ink_assert(portl);
 
366
  if (!portl)
 
367
    return true;
 
368
 
 
369
  return queue_is_empty((LLQ *) portl);
 
370
}
 
371
 
 
372
// returns false if any of the PortEle's has a port_a <= 0;
 
373
// if returns false, then will return the entire port list
 
374
// intact, although the ports may not be ordered in the same way
 
375
inkapi bool
 
376
INKPortListIsValid(INKPortList portl)
 
377
{
 
378
  int i, len;
 
379
  INKPortEle *ele;
 
380
 
 
381
  if (!portl)
 
382
    return false;
 
383
 
 
384
  len = queue_len((LLQ *) portl);
 
385
  for (i = 0; i < len; i++) {
 
386
    ele = (INKPortEle *) dequeue((LLQ *) portl);
 
387
    if (!ccu_checkPortEle(ele)) {
 
388
      enqueue((LLQ *) portl, ele);
 
389
      return false;
 
390
    }
 
391
    enqueue((LLQ *) portl, ele);
 
392
  }
 
393
  return true;
 
394
}
 
395
 
 
396
 
 
397
/*--- INKDomainList operations -----------------------------------------*/
 
398
inkapi INKDomainList
 
399
INKDomainListCreate()
 
400
{
 
401
  return (void *) create_queue();       /* this queue will be a list of char* */
 
402
}
 
403
 
 
404
inkapi void
 
405
INKDomainListDestroy(INKDomainList domainl)
 
406
{
 
407
  INKDomain *domain;
 
408
 
 
409
  if (!domainl) {
 
410
    return;
 
411
  }
 
412
 
 
413
  /* dequeue each element and free it */
 
414
  while (!queue_is_empty((LLQ *) domainl)) {
 
415
    domain = (INKDomain *) dequeue((LLQ *) domainl);
 
416
 
 
417
    if (!domain)
 
418
      continue;
 
419
 
 
420
    INKDomainDestroy(domain);
 
421
  }
 
422
 
 
423
  delete_queue((LLQ *) domainl);
 
424
}
 
425
 
 
426
inkapi INKError
 
427
INKDomainListEnqueue(INKDomainList domainl, INKDomain * domain)
 
428
{
 
429
  int ret;
 
430
 
 
431
  ink_assert(domainl && domain);
 
432
  if (!domainl || !domain)
 
433
    return INK_ERR_PARAMS;
 
434
 
 
435
  ret = enqueue((LLQ *) domainl, domain);       /* returns TRUE=1 or FALSE=0 */
 
436
  if (ret == 0) {
 
437
    return INK_ERR_FAIL;
 
438
  } else {
 
439
    return INK_ERR_OKAY;
 
440
  }
 
441
}
 
442
 
 
443
inkapi INKDomain *
 
444
INKDomainListDequeue(INKDomainList domainl)
 
445
{
 
446
  ink_assert(domainl);
 
447
  if (!domainl || queue_is_empty((LLQ *) domainl))
 
448
    return NULL;
 
449
 
 
450
  return (INKDomain *) dequeue((LLQ *) domainl);
 
451
}
 
452
 
 
453
inkapi bool
 
454
INKDomainListIsEmpty(INKDomainList domainl)
 
455
{
 
456
  ink_assert(domainl);
 
457
  if (!domainl)
 
458
    return true;
 
459
 
 
460
  return queue_is_empty((LLQ *) domainl);
 
461
}
 
462
 
 
463
inkapi int
 
464
INKDomainListLen(INKDomainList domainl)
 
465
{
 
466
  ink_assert(domainl);
 
467
  if (!domainl)
 
468
    return -1;
 
469
 
 
470
  return queue_len((LLQ *) domainl);
 
471
}
 
472
 
 
473
// returns false if encounter a NULL hostname and ip
 
474
inkapi bool
 
475
INKDomainListIsValid(INKDomainList domainl)
 
476
{
 
477
  int i, len;
 
478
  INKDomain *dom;
 
479
 
 
480
  if (!domainl)
 
481
    return false;
 
482
 
 
483
  len = queue_len((LLQ *) domainl);
 
484
  for (i = 0; i < len; i++) {
 
485
    dom = (INKDomain *) dequeue((LLQ *) domainl);
 
486
    if (!dom) {
 
487
      return false;
 
488
    }
 
489
    if (!dom->domain_val) {
 
490
      return false;
 
491
    }
 
492
    enqueue((LLQ *) domainl, dom);
 
493
  }
 
494
  return true;
 
495
 
 
496
}
 
497
 
 
498
/*--- INKStringList operations --------------------------------------*/
 
499
inkapi INKStringList
 
500
INKStringListCreate()
 
501
{
 
502
  return (void *) create_queue();       /* this queue will be a list of char* */
 
503
}
 
504
 
 
505
/* usually, must be an empty list before destroying*/
 
506
inkapi void
 
507
INKStringListDestroy(INKStringList strl)
 
508
{
 
509
  char *str;
 
510
 
 
511
  if (!strl) {
 
512
    return;
 
513
  }
 
514
 
 
515
  /* dequeue each element and free it */
 
516
  while (!queue_is_empty((LLQ *) strl)) {
 
517
    str = (char *) dequeue((LLQ *) strl);
 
518
 
 
519
    if (!str)
 
520
      continue;
 
521
 
 
522
    xfree(str);
 
523
  }
 
524
 
 
525
  delete_queue((LLQ *) strl);
 
526
}
 
527
 
 
528
inkapi INKError
 
529
INKStringListEnqueue(INKStringList strl, char *str)
 
530
{
 
531
  int ret;
 
532
 
 
533
  ink_assert(strl && str);
 
534
  if (!strl || !str)
 
535
    return INK_ERR_PARAMS;
 
536
 
 
537
  ret = enqueue((LLQ *) strl, str);     /* returns TRUE=1 or FALSE=0 */
 
538
  if (ret == 0) {
 
539
    return INK_ERR_FAIL;
 
540
  } else {
 
541
    return INK_ERR_OKAY;
 
542
  }
 
543
}
 
544
 
 
545
inkapi char *
 
546
INKStringListDequeue(INKStringList strl)
 
547
{
 
548
  ink_assert(strl);
 
549
  if (!strl || queue_is_empty((LLQ *) strl))
 
550
    return NULL;
 
551
 
 
552
  return (char *) dequeue((LLQ *) strl);
 
553
}
 
554
 
 
555
inkapi bool
 
556
INKStringListIsEmpty(INKStringList strl)
 
557
{
 
558
  ink_assert(strl);
 
559
  if (!strl)
 
560
    return true;
 
561
 
 
562
  return queue_is_empty((LLQ *) strl);
 
563
}
 
564
 
 
565
inkapi int
 
566
INKStringListLen(INKStringList strl)
 
567
{
 
568
  ink_assert(strl);
 
569
  if (!strl)
 
570
    return -1;
 
571
 
 
572
  return queue_len((LLQ *) strl);
 
573
}
 
574
 
 
575
// returns false if any element is NULL string
 
576
inkapi bool
 
577
INKStringListIsValid(INKStringList strl)
 
578
{
 
579
  int i, len;
 
580
  char *str;
 
581
 
 
582
  if (!strl)
 
583
    return false;
 
584
 
 
585
  len = queue_len((LLQ *) strl);
 
586
  for (i = 0; i < len; i++) {
 
587
    str = (char *) dequeue((LLQ *) strl);
 
588
    if (!str)
 
589
      return false;
 
590
    enqueue((LLQ *) strl, str);
 
591
  }
 
592
  return true;
 
593
}
 
594
 
 
595
/*--- INKIntList operations --------------------------------------*/
 
596
inkapi INKIntList
 
597
INKIntListCreate()
 
598
{
 
599
  return (void *) create_queue();       /* this queue will be a list of int* */
 
600
}
 
601
 
 
602
/* usually, must be an empty list before destroying*/
 
603
inkapi void
 
604
INKIntListDestroy(INKIntList intl)
 
605
{
 
606
  int *iPtr;
 
607
 
 
608
  if (!intl)
 
609
    return;
 
610
 
 
611
  /* dequeue each element and free it */
 
612
  while (!queue_is_empty((LLQ *) intl)) {
 
613
    iPtr = (int *) dequeue((LLQ *) intl);
 
614
 
 
615
    if (!iPtr)
 
616
      continue;
 
617
 
 
618
    xfree(iPtr);
 
619
  }
 
620
 
 
621
  delete_queue((LLQ *) intl);
 
622
  return;
 
623
}
 
624
 
 
625
inkapi INKError
 
626
INKIntListEnqueue(INKIntList intl, int *elem)
 
627
{
 
628
  int ret;
 
629
 
 
630
  ink_assert(intl && elem);
 
631
  if (!intl || !elem)
 
632
    return INK_ERR_PARAMS;
 
633
 
 
634
  ret = enqueue((LLQ *) intl, elem);    /* returns TRUE=1 or FALSE=0 */
 
635
  if (ret == 0) {
 
636
    return INK_ERR_FAIL;
 
637
  } else {
 
638
    return INK_ERR_OKAY;
 
639
  }
 
640
}
 
641
 
 
642
inkapi int *
 
643
INKIntListDequeue(INKIntList intl)
 
644
{
 
645
  ink_assert(intl);
 
646
  if (!intl || queue_is_empty((LLQ *) intl))
 
647
    return NULL;
 
648
 
 
649
  return (int *) dequeue((LLQ *) intl);
 
650
}
 
651
 
 
652
inkapi bool
 
653
INKIntListIsEmpty(INKIntList intl)
 
654
{
 
655
  ink_assert(intl);
 
656
  if (!intl)
 
657
    return true;
 
658
 
 
659
  return queue_is_empty((LLQ *) intl);
 
660
}
 
661
 
 
662
inkapi int
 
663
INKIntListLen(INKIntList intl)
 
664
{
 
665
  ink_assert(intl);
 
666
  if (!intl)
 
667
    return -1;
 
668
 
 
669
  return queue_len((LLQ *) intl);
 
670
}
 
671
 
 
672
inkapi bool
 
673
INKIntListIsValid(INKIntList intl, int min, int max)
 
674
{
 
675
  if (!intl)
 
676
    return false;
 
677
 
 
678
  for (unsigned long i = 0; i < queue_len((LLQ *) intl); i++) {
 
679
    int *item = (int *) dequeue((LLQ *) intl);
 
680
    if (*item < min) {
 
681
      return false;
 
682
    }
 
683
    if (*item > max) {
 
684
      return false;
 
685
    }
 
686
    enqueue((LLQ *) intl, item);
 
687
  }
 
688
  return true;
 
689
}
 
690
 
 
691
 
 
692
// helper fn that sets default values for the info passed in
 
693
void
 
694
init_pdss_format(INKPdSsFormat * info)
 
695
{
 
696
  info->pd_type = INK_PD_UNDEFINED;
 
697
  info->pd_val = NULL;
 
698
  info->sec_spec.active = 0;
 
699
  info->sec_spec.time.hour_a = 0;
 
700
  info->sec_spec.time.min_a = 0;
 
701
  info->sec_spec.time.hour_b = 0;
 
702
  info->sec_spec.time.min_b = 0;
 
703
  info->sec_spec.src_ip = INK_INVALID_IP_ADDR;
 
704
  info->sec_spec.prefix = NULL;
 
705
  info->sec_spec.suffix = NULL;
 
706
  info->sec_spec.port = INK_INVALID_PORT;
 
707
  info->sec_spec.method = INK_METHOD_UNDEFINED;
 
708
  info->sec_spec.scheme = INK_SCHEME_UNDEFINED;
 
709
}
 
710
 
 
711
/*--- allocate/deallocate operations --------------------------------------*/
 
712
inkapi INKEvent *
 
713
INKEventCreate(void)
 
714
{
 
715
  INKEvent *event;
 
716
  event = (INKEvent *) xmalloc(sizeof(INKEvent));
 
717
  if (!event)
 
718
    return NULL;
 
719
 
 
720
  event->id = -1;
 
721
  event->name = NULL;
 
722
  event->description = NULL;
 
723
  event->priority = INK_EVENT_PRIORITY_UNDEFINED;
 
724
 
 
725
  return event;
 
726
}
 
727
 
 
728
inkapi void
 
729
INKEventDestroy(INKEvent * event)
 
730
{
 
731
  if (event) {
 
732
    if (event->name)
 
733
      xfree(event->name);
 
734
    if (event->description)
 
735
      xfree(event->description);
 
736
    xfree(event);
 
737
  }
 
738
  return;
 
739
}
 
740
 
 
741
inkapi INKRecordEle *
 
742
INKRecordEleCreate(void)
 
743
{
 
744
  INKRecordEle *ele;
 
745
  ele = (INKRecordEle *) xmalloc(sizeof(INKRecordEle));
 
746
  if (!ele)
 
747
    return NULL;
 
748
 
 
749
  ele->rec_name = NULL;
 
750
  ele->rec_type = INK_REC_UNDEFINED;
 
751
 
 
752
  //ele->int_val = -1;
 
753
  //ele->counter_val = -1;
 
754
  //ele->float_val = -1;
 
755
  //ele->string_val = NULL;
 
756
 
 
757
  return ele;
 
758
}
 
759
 
 
760
inkapi void
 
761
INKRecordEleDestroy(INKRecordEle * ele)
 
762
{
 
763
  if (ele) {
 
764
    if (ele->rec_name)
 
765
      xfree(ele->rec_name);
 
766
    if (ele->rec_type == INK_REC_STRING && ele->string_val)
 
767
      xfree(ele->string_val);
 
768
    xfree(ele);
 
769
  }
 
770
  return;
 
771
}
 
772
 
 
773
inkapi INKIpAddrEle *
 
774
INKIpAddrEleCreate(void)
 
775
{
 
776
  INKIpAddrEle *ele;
 
777
 
 
778
  ele = (INKIpAddrEle *) xmalloc(sizeof(INKIpAddrEle));
 
779
  if (!ele)
 
780
    return NULL;
 
781
 
 
782
  /* set default values */
 
783
  ele->type = INK_IP_UNDEFINED;
 
784
  ele->ip_a = INK_INVALID_IP_ADDR;
 
785
  ele->cidr_a = INK_INVALID_IP_CIDR;
 
786
  ele->port_a = INK_INVALID_PORT;
 
787
  ele->ip_b = INK_INVALID_IP_ADDR;
 
788
  ele->cidr_b = INK_INVALID_IP_CIDR;
 
789
  ele->port_b = INK_INVALID_PORT;
 
790
  return ele;
 
791
}
 
792
 
 
793
inkapi void
 
794
INKIpAddrEleDestroy(INKIpAddrEle * ele)
 
795
{
 
796
  if (ele) {
 
797
    if (ele->ip_a)
 
798
      xfree(ele->ip_a);
 
799
    if (ele->ip_b)
 
800
      xfree(ele->ip_b);
 
801
    xfree(ele);
 
802
  }
 
803
 
 
804
  return;
 
805
}
 
806
 
 
807
inkapi INKPortEle *
 
808
INKPortEleCreate(void)
 
809
{
 
810
  INKPortEle *ele;
 
811
 
 
812
  ele = (INKPortEle *) xmalloc(sizeof(INKPortEle));
 
813
  if (!ele)
 
814
    return NULL;
 
815
 
 
816
  ele->port_a = INK_INVALID_PORT;
 
817
  ele->port_b = INK_INVALID_PORT;
 
818
 
 
819
  return ele;
 
820
}
 
821
 
 
822
inkapi void
 
823
INKPortEleDestroy(INKPortEle * ele)
 
824
{
 
825
  if (ele)
 
826
    xfree(ele);
 
827
  return;
 
828
}
 
829
 
 
830
inkapi INKDomain *
 
831
INKDomainCreate()
 
832
{
 
833
  INKDomain *ele;
 
834
 
 
835
  ele = (INKDomain *) xmalloc(sizeof(INKDomain));
 
836
  if (!ele)
 
837
    return NULL;
 
838
 
 
839
  ele->domain_val = NULL;
 
840
  ele->port = INK_INVALID_PORT;
 
841
 
 
842
  return ele;
 
843
}
 
844
 
 
845
inkapi void
 
846
INKDomainDestroy(INKDomain * ele)
 
847
{
 
848
  if (ele) {
 
849
    // this is okay because INKIpAddr is also a char*
 
850
    if (ele->domain_val)
 
851
      xfree(ele->domain_val);
 
852
    xfree(ele);
 
853
  }
 
854
}
 
855
 
 
856
inkapi INKSspec *
 
857
INKSspecCreate(void)
 
858
{
 
859
  INKSspec *sec_spec;
 
860
 
 
861
  sec_spec = (INKSspec *) xmalloc(sizeof(INKSspec));
 
862
  if (!sec_spec)
 
863
    return NULL;
 
864
 
 
865
  /* set defaults */
 
866
  sec_spec->active = 0;
 
867
  (sec_spec->time).hour_a = 0;
 
868
  (sec_spec->time).min_a = 0;
 
869
  (sec_spec->time).hour_b = 0;
 
870
  (sec_spec->time).min_b = 0;
 
871
  sec_spec->src_ip = INK_INVALID_IP_ADDR;
 
872
  sec_spec->prefix = NULL;
 
873
  sec_spec->suffix = NULL;
 
874
  sec_spec->port = NULL;
 
875
  sec_spec->method = INK_METHOD_UNDEFINED;
 
876
  sec_spec->scheme = INK_SCHEME_UNDEFINED;
 
877
  return sec_spec;
 
878
}
 
879
 
 
880
inkapi void
 
881
INKSspecDestroy(INKSspec * ele)
 
882
{
 
883
  if (ele) {
 
884
    if (ele->prefix)
 
885
      xfree(ele->prefix);
 
886
    if (ele->suffix)
 
887
      xfree(ele->suffix);
 
888
    if (ele->port)
 
889
      INKPortEleDestroy(ele->port);
 
890
    xfree(ele);
 
891
  }
 
892
  return;
 
893
}
 
894
 
 
895
inkapi INKPdSsFormat *
 
896
INKPdSsFormatCreate(void)
 
897
{
 
898
  INKPdSsFormat *ele;
 
899
 
 
900
  ele = (INKPdSsFormat *) xmalloc(sizeof(INKPdSsFormat));
 
901
  if (!ele)
 
902
    return NULL;
 
903
 
 
904
  /* should set default values here */
 
905
  ele->pd_type = INK_PD_UNDEFINED;
 
906
  ele->pd_val = NULL;
 
907
 
 
908
  ele->sec_spec.active = 0;
 
909
  (ele->sec_spec.time).hour_a = -1;
 
910
  (ele->sec_spec.time).min_a = -1;
 
911
  (ele->sec_spec.time).hour_b = -1;
 
912
  (ele->sec_spec.time).min_b = -1;
 
913
  ele->sec_spec.src_ip = INK_INVALID_IP_ADDR;
 
914
  ele->sec_spec.prefix = NULL;
 
915
  ele->sec_spec.suffix = NULL;
 
916
  ele->sec_spec.port = NULL;
 
917
  ele->sec_spec.method = INK_METHOD_UNDEFINED;
 
918
  ele->sec_spec.scheme = INK_SCHEME_UNDEFINED;
 
919
 
 
920
  return ele;
 
921
}
 
922
 
 
923
inkapi void
 
924
INKPdSsFormatDestroy(INKPdSsFormat * ele)
 
925
{
 
926
  if (ele) {
 
927
    if (ele->pd_val)
 
928
      xfree(ele->pd_val);
 
929
    if (ele->sec_spec.src_ip)
 
930
      xfree(ele->sec_spec.src_ip);
 
931
    if (ele->sec_spec.prefix)
 
932
      xfree(ele->sec_spec.prefix);
 
933
    if (ele->sec_spec.suffix)
 
934
      xfree(ele->sec_spec.suffix);
 
935
    if (ele->sec_spec.port)
 
936
      INKPortEleDestroy(ele->sec_spec.port);
 
937
  }
 
938
  return;
 
939
}
 
940
 
 
941
/*-------------------------------------------------------------
 
942
 * INKAdminAccessEle
 
943
 *-------------------------------------------------------------*/
 
944
inkapi INKAdminAccessEle *
 
945
INKAdminAccessEleCreate()
 
946
{
 
947
  INKAdminAccessEle *ele;
 
948
 
 
949
  ele = (INKAdminAccessEle *) xmalloc(sizeof(INKAdminAccessEle));
 
950
  if (!ele)
 
951
    return NULL;
 
952
 
 
953
  ele->cfg_ele.type = INK_ADMIN_ACCESS;
 
954
  ele->cfg_ele.error = INK_ERR_OKAY;
 
955
  ele->user = NULL;
 
956
  ele->password = NULL;
 
957
  ele->access = INK_ACCESS_UNDEFINED;
 
958
 
 
959
  return ele;
 
960
}
 
961
 
 
962
inkapi void
 
963
INKAdminAccessEleDestroy(INKAdminAccessEle * ele)
 
964
{
 
965
  if (ele) {
 
966
    if (ele->user)
 
967
      xfree(ele->user);
 
968
    if (ele->password)
 
969
      xfree(ele->password);
 
970
    xfree(ele);
 
971
  }
 
972
  return;
 
973
}
 
974
 
 
975
 
 
976
/*-------------------------------------------------------------
 
977
 * CacheObj
 
978
 *-------------------------------------------------------------*/
 
979
inkapi INKCacheEle *
 
980
INKCacheEleCreate(INKRuleTypeT type)
 
981
{
 
982
  INKCacheEle *ele;
 
983
 
 
984
  if (type != INK_CACHE_NEVER &&
 
985
      type != INK_CACHE_IGNORE_NO_CACHE &&
 
986
      type != INK_CACHE_IGNORE_CLIENT_NO_CACHE &&
 
987
      type != INK_CACHE_IGNORE_SERVER_NO_CACHE &&
 
988
      type != INK_CACHE_PIN_IN_CACHE &&
 
989
      type != INK_CACHE_REVALIDATE &&
 
990
      type != INK_CACHE_TTL_IN_CACHE && type != INK_CACHE_AUTH_CONTENT && type != INK_TYPE_UNDEFINED)
 
991
    return NULL;                // invalid type
 
992
 
 
993
  ele = (INKCacheEle *) xmalloc(sizeof(INKCacheEle));
 
994
  if (!ele)
 
995
    return NULL;
 
996
 
 
997
  /* set defaults */
 
998
  ele->cfg_ele.type = type;
 
999
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1000
  init_pdss_format(&(ele->cache_info));
 
1001
  ele->time_period.d = 0;
 
1002
  ele->time_period.h = 0;
 
1003
  ele->time_period.m = 0;
 
1004
  ele->time_period.s = 0;
 
1005
 
 
1006
  return ele;
 
1007
}
 
1008
 
 
1009
inkapi void
 
1010
INKCacheEleDestroy(INKCacheEle * ele)
 
1011
{
 
1012
  if (ele) {
 
1013
    INKPdSsFormatDestroy(&(ele->cache_info));
 
1014
    xfree(ele);
 
1015
  }
 
1016
  return;
 
1017
}
 
1018
 
 
1019
/*-------------------------------------------------------------
 
1020
 * CongestionObj
 
1021
 *-------------------------------------------------------------*/
 
1022
// FIXME: for now use defaults specified in feature spec; the
 
1023
// defaults though are configurable as records, so should use
 
1024
// records values instead
 
1025
inkapi INKCongestionEle *
 
1026
INKCongestionEleCreate()
 
1027
{
 
1028
  INKCongestionEle *ele;
 
1029
 
 
1030
  ele = (INKCongestionEle *) xmalloc(sizeof(INKCongestionEle));
 
1031
  if (!ele)
 
1032
    return NULL;
 
1033
 
 
1034
  /* set defaults */
 
1035
  ele->cfg_ele.type = INK_CONGESTION;
 
1036
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1037
  //init_pdss_format(&(ele->congestion_info));
 
1038
  ele->pd_type = INK_PD_UNDEFINED;
 
1039
  ele->pd_val = NULL;
 
1040
  ele->prefix = NULL;
 
1041
  ele->port = INK_INVALID_PORT;
 
1042
  ele->scheme = INK_HTTP_CONGEST_PER_IP;
 
1043
  ele->max_connection_failures = 5;
 
1044
  ele->fail_window = 120;
 
1045
  ele->proxy_retry_interval = 10;
 
1046
  ele->client_wait_interval = 300;
 
1047
  ele->wait_interval_alpha = 30;
 
1048
  ele->live_os_conn_timeout = 60;
 
1049
  ele->live_os_conn_retries = 2;
 
1050
  ele->dead_os_conn_timeout = 15;
 
1051
  ele->dead_os_conn_retries = 1;
 
1052
  ele->max_connection = -1;
 
1053
  ele->error_page_uri = xstrdup("congestion#retryAfter");
 
1054
 
 
1055
  return ele;
 
1056
}
 
1057
 
 
1058
inkapi void
 
1059
INKCongestionEleDestroy(INKCongestionEle * ele)
 
1060
{
 
1061
  if (ele) {
 
1062
    if (ele->pd_val)
 
1063
      xfree(ele->pd_val);
 
1064
    if (ele->prefix)
 
1065
      xfree(ele->prefix);
 
1066
    if (ele->error_page_uri)
 
1067
      xfree(ele->error_page_uri);
 
1068
    xfree(ele);
 
1069
  }
 
1070
  return;
 
1071
}
 
1072
 
 
1073
 
 
1074
/*-------------------------------------------------------------
 
1075
 * HostingObj
 
1076
 *-------------------------------------------------------------*/
 
1077
inkapi INKHostingEle *
 
1078
INKHostingEleCreate()
 
1079
{
 
1080
  INKHostingEle *ele;
 
1081
 
 
1082
  ele = (INKHostingEle *) xmalloc(sizeof(INKHostingEle));
 
1083
  if (!ele)
 
1084
    return NULL;
 
1085
 
 
1086
  ele->cfg_ele.type = INK_HOSTING;
 
1087
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1088
  ele->pd_type = INK_PD_UNDEFINED;
 
1089
  ele->pd_val = NULL;
 
1090
  ele->partitions = INK_INVALID_LIST;
 
1091
 
 
1092
  return ele;
 
1093
}
 
1094
 
 
1095
inkapi void
 
1096
INKHostingEleDestroy(INKHostingEle * ele)
 
1097
{
 
1098
  if (ele) {
 
1099
    if (ele->pd_val)
 
1100
      xfree(ele->pd_val);
 
1101
    if (ele->partitions)
 
1102
      INKIntListDestroy(ele->partitions);
 
1103
    xfree(ele);
 
1104
  }
 
1105
  return;
 
1106
}
 
1107
 
 
1108
/*-------------------------------------------------------------
 
1109
 * IcpObject
 
1110
 *-------------------------------------------------------------*/
 
1111
inkapi INKIcpEle *
 
1112
INKIcpEleCreate()
 
1113
{
 
1114
  INKIcpEle *ele;
 
1115
 
 
1116
  ele = (INKIcpEle *) xmalloc(sizeof(INKIcpEle));
 
1117
  if (!ele)
 
1118
    return NULL;
 
1119
 
 
1120
  /* set defaults */
 
1121
  ele->cfg_ele.type = INK_ICP;
 
1122
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1123
  ele->peer_hostname = NULL;
 
1124
  ele->peer_host_ip_addr = INK_INVALID_IP_ADDR;
 
1125
  ele->peer_type = INK_ICP_UNDEFINED;
 
1126
  ele->peer_proxy_port = INK_INVALID_PORT;
 
1127
  ele->peer_icp_port = INK_INVALID_PORT;
 
1128
  ele->is_multicast = FALSE;
 
1129
  ele->mc_ip_addr = INK_INVALID_IP_ADDR;
 
1130
  ele->mc_ttl = INK_MC_TTL_SINGLE_SUBNET;       // default value
 
1131
 
 
1132
  return ele;
 
1133
 
 
1134
}
 
1135
 
 
1136
inkapi void
 
1137
INKIcpEleDestroy(INKIcpEle * ele)
 
1138
{
 
1139
  if (ele) {
 
1140
    if (ele->peer_hostname)
 
1141
      xfree(ele->peer_hostname);
 
1142
    if (ele->peer_host_ip_addr)
 
1143
      xfree(ele->peer_host_ip_addr);
 
1144
    if (ele->mc_ip_addr)
 
1145
      xfree(ele->mc_ip_addr);
 
1146
    xfree(ele);
 
1147
  }
 
1148
  return;
 
1149
}
 
1150
 
 
1151
/*-------------------------------------------------------------
 
1152
 * INKIpAllowEle
 
1153
 *-------------------------------------------------------------*/
 
1154
inkapi INKIpAllowEle *
 
1155
INKIpAllowEleCreate()
 
1156
{
 
1157
 
 
1158
  INKIpAllowEle *ele;
 
1159
 
 
1160
  ele = (INKIpAllowEle *) xmalloc(sizeof(INKIpAllowEle));
 
1161
  if (!ele)
 
1162
    return NULL;
 
1163
 
 
1164
  ele->cfg_ele.type = INK_IP_ALLOW;
 
1165
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1166
  ele->src_ip_addr = INK_INVALID_IP_ADDR;
 
1167
  ele->action = INK_IP_ALLOW_UNDEFINED;
 
1168
 
 
1169
  return ele;
 
1170
}
 
1171
 
 
1172
inkapi void
 
1173
INKIpAllowEleDestroy(INKIpAllowEle * ele)
 
1174
{
 
1175
  if (ele) {
 
1176
    if (ele->src_ip_addr)
 
1177
      INKIpAddrEleDestroy(ele->src_ip_addr);
 
1178
    xfree(ele);
 
1179
  }
 
1180
  return;
 
1181
 
 
1182
}
 
1183
 
 
1184
 
 
1185
/*-------------------------------------------------------------
 
1186
 * INKLogFilterEle
 
1187
 *-------------------------------------------------------------*/
 
1188
inkapi INKLogFilterEle *
 
1189
INKLogFilterEleCreate()
 
1190
{
 
1191
  INKLogFilterEle *ele;
 
1192
 
 
1193
  ele = (INKLogFilterEle *) xmalloc(sizeof(INKLogFilterEle));
 
1194
  if (!ele)
 
1195
    return NULL;
 
1196
 
 
1197
  ele->cfg_ele.type = INK_LOG_FILTER;
 
1198
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1199
  ele->action = INK_LOG_FILT_UNDEFINED;
 
1200
  ele->filter_name = NULL;
 
1201
  ele->log_field = NULL;
 
1202
  ele->compare_op = INK_LOG_COND_UNDEFINED;
 
1203
  ele->compare_str = NULL;
 
1204
  ele->compare_int = -1;
 
1205
  return ele;
 
1206
}
 
1207
 
 
1208
inkapi void
 
1209
INKLogFilterEleDestroy(INKLogFilterEle * ele)
 
1210
{
 
1211
  if (ele) {
 
1212
    if (ele->filter_name)
 
1213
      xfree(ele->filter_name);
 
1214
    if (ele->log_field)
 
1215
      xfree(ele->log_field);
 
1216
    if (ele->compare_str)
 
1217
      xfree(ele->compare_str);
 
1218
    xfree(ele);
 
1219
  }
 
1220
  return;
 
1221
}
 
1222
 
 
1223
/*-------------------------------------------------------------
 
1224
 * INKLogFormatEle
 
1225
 *-------------------------------------------------------------*/
 
1226
inkapi INKLogFormatEle *
 
1227
INKLogFormatEleCreate()
 
1228
{
 
1229
  INKLogFormatEle *ele;
 
1230
 
 
1231
  ele = (INKLogFormatEle *) xmalloc(sizeof(INKLogFormatEle));
 
1232
  if (!ele)
 
1233
    return NULL;
 
1234
 
 
1235
  ele->cfg_ele.type = INK_LOG_FORMAT;
 
1236
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1237
  ele->name = NULL;
 
1238
  ele->format = NULL;
 
1239
  ele->aggregate_interval_secs = 0;
 
1240
 
 
1241
  return ele;
 
1242
}
 
1243
 
 
1244
inkapi void
 
1245
INKLogFormatEleDestroy(INKLogFormatEle * ele)
 
1246
{
 
1247
  if (ele) {
 
1248
    if (ele->name)
 
1249
      xfree(ele->name);
 
1250
    if (ele->format)
 
1251
      xfree(ele->format);
 
1252
    xfree(ele);
 
1253
  }
 
1254
  return;
 
1255
}
 
1256
 
 
1257
/*-------------------------------------------------------------
 
1258
 * INKLogObjectEle
 
1259
 *-------------------------------------------------------------*/
 
1260
inkapi INKLogObjectEle *
 
1261
INKLogObjectEleCreate()
 
1262
{
 
1263
  INKLogObjectEle *ele;
 
1264
 
 
1265
  ele = (INKLogObjectEle *) xmalloc(sizeof(INKLogObjectEle));
 
1266
  if (!ele)
 
1267
    return NULL;
 
1268
 
 
1269
  ele->cfg_ele.type = INK_LOG_OBJECT;
 
1270
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1271
  ele->format_name = NULL;
 
1272
  ele->file_name = NULL;
 
1273
  ele->log_mode = INK_LOG_MODE_UNDEFINED;
 
1274
  ele->collation_hosts = INK_INVALID_LIST;
 
1275
  ele->filters = INK_INVALID_LIST;
 
1276
  ele->protocols = INK_INVALID_LIST;
 
1277
  ele->server_hosts = INK_INVALID_LIST;
 
1278
 
 
1279
  return ele;
 
1280
}
 
1281
 
 
1282
inkapi void
 
1283
INKLogObjectEleDestroy(INKLogObjectEle * ele)
 
1284
{
 
1285
  if (ele) {
 
1286
    if (ele->format_name)
 
1287
      xfree(ele->format_name);
 
1288
    if (ele->file_name)
 
1289
      xfree(ele->file_name);
 
1290
    if (ele->collation_hosts)
 
1291
      INKDomainListDestroy(ele->collation_hosts);
 
1292
    if (ele->filters)
 
1293
      INKStringListDestroy(ele->filters);
 
1294
    if (ele->protocols)
 
1295
      INKStringListDestroy(ele->protocols);
 
1296
    if (ele->server_hosts)
 
1297
      INKStringListDestroy(ele->server_hosts);
 
1298
    xfree(ele);
 
1299
  }
 
1300
  return;
 
1301
}
 
1302
 
 
1303
/*-------------------------------------------------------------
 
1304
 * INKMgmtAllowEle
 
1305
 *-------------------------------------------------------------*/
 
1306
inkapi INKMgmtAllowEle *
 
1307
INKMgmtAllowEleCreate()
 
1308
{
 
1309
 
 
1310
  INKMgmtAllowEle *ele;
 
1311
 
 
1312
  ele = (INKMgmtAllowEle *) xmalloc(sizeof(INKMgmtAllowEle));
 
1313
  if (!ele)
 
1314
    return NULL;
 
1315
 
 
1316
  ele->cfg_ele.type = INK_MGMT_ALLOW;
 
1317
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1318
  ele->src_ip_addr = INK_INVALID_IP_ADDR;
 
1319
  ele->action = INK_MGMT_ALLOW_UNDEFINED;
 
1320
 
 
1321
  return ele;
 
1322
}
 
1323
 
 
1324
inkapi void
 
1325
INKMgmtAllowEleDestroy(INKMgmtAllowEle * ele)
 
1326
{
 
1327
  if (ele) {
 
1328
    if (ele->src_ip_addr)
 
1329
      INKIpAddrEleDestroy(ele->src_ip_addr);
 
1330
    xfree(ele);
 
1331
  }
 
1332
  return;
 
1333
 
 
1334
}
 
1335
 
 
1336
 
 
1337
/*-------------------------------------------------------------
 
1338
 * INKParentProxyEleCreate
 
1339
 *-------------------------------------------------------------*/
 
1340
inkapi INKParentProxyEle *
 
1341
INKParentProxyEleCreate(INKRuleTypeT type)
 
1342
{
 
1343
  INKParentProxyEle *ele;
 
1344
 
 
1345
  if (type != INK_PP_PARENT && type != INK_PP_GO_DIRECT && type != INK_TYPE_UNDEFINED)
 
1346
    return NULL;
 
1347
 
 
1348
  ele = (INKParentProxyEle *) xmalloc(sizeof(INKParentProxyEle));
 
1349
  if (!ele)
 
1350
    return NULL;
 
1351
 
 
1352
  ele->cfg_ele.type = type;
 
1353
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1354
  init_pdss_format(&(ele->parent_info));
 
1355
  ele->rr = INK_RR_NONE;
 
1356
  ele->proxy_list = INK_INVALID_LIST;
 
1357
  ele->direct = false;
 
1358
 
 
1359
  return ele;
 
1360
}
 
1361
 
 
1362
inkapi void
 
1363
INKParentProxyEleDestroy(INKParentProxyEle * ele)
 
1364
{
 
1365
  if (ele) {
 
1366
    INKPdSsFormatDestroy(&(ele->parent_info));
 
1367
    if (ele->proxy_list)
 
1368
      INKDomainListDestroy(ele->proxy_list);
 
1369
    xfree(ele);
 
1370
  }
 
1371
 
 
1372
  return;
 
1373
}
 
1374
 
 
1375
/*-------------------------------------------------------------
 
1376
 * INKPartitionEle
 
1377
 *-------------------------------------------------------------*/
 
1378
inkapi INKPartitionEle *
 
1379
INKPartitionEleCreate()
 
1380
{
 
1381
  INKPartitionEle *ele;
 
1382
 
 
1383
  ele = (INKPartitionEle *) xmalloc(sizeof(INKPartitionEle));
 
1384
  if (!ele)
 
1385
    return NULL;
 
1386
 
 
1387
  ele->cfg_ele.type = INK_PARTITION;
 
1388
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1389
  ele->partition_num = 0;
 
1390
  ele->scheme = INK_PARTITION_UNDEFINED;
 
1391
  ele->partition_size = 0;
 
1392
  ele->size_format = INK_SIZE_FMT_UNDEFINED;
 
1393
 
 
1394
  return ele;
 
1395
}
 
1396
 
 
1397
inkapi void
 
1398
INKPartitionEleDestroy(INKPartitionEle * ele)
 
1399
{
 
1400
  if (ele) {
 
1401
    xfree(ele);
 
1402
  }
 
1403
  return;
 
1404
}
 
1405
 
 
1406
/*-------------------------------------------------------------
 
1407
 * INKPluginEle
 
1408
 *-------------------------------------------------------------*/
 
1409
inkapi INKPluginEle *
 
1410
INKPluginEleCreate()
 
1411
{
 
1412
  INKPluginEle *ele;
 
1413
 
 
1414
  ele = (INKPluginEle *) xmalloc(sizeof(INKPluginEle));
 
1415
  if (!ele)
 
1416
    return NULL;
 
1417
 
 
1418
  ele->cfg_ele.type = INK_PLUGIN;
 
1419
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1420
  ele->name = NULL;
 
1421
  ele->args = INK_INVALID_LIST;
 
1422
 
 
1423
  return ele;
 
1424
}
 
1425
 
 
1426
inkapi void
 
1427
INKPluginEleDestroy(INKPluginEle * ele)
 
1428
{
 
1429
  if (ele) {
 
1430
    if (ele->name)
 
1431
      xfree(ele->name);
 
1432
    if (ele->args)
 
1433
      INKStringListDestroy(ele->args);
 
1434
    xfree(ele);
 
1435
  }
 
1436
  return;
 
1437
}
 
1438
 
 
1439
/*-------------------------------------------------------------
 
1440
 * INKRemapEle
 
1441
 *-------------------------------------------------------------*/
 
1442
INKRemapEle *
 
1443
INKRemapEleCreate(INKRuleTypeT type)
 
1444
{
 
1445
  INKRemapEle *ele;
 
1446
 
 
1447
  if (type != INK_REMAP_MAP &&
 
1448
      type != INK_REMAP_REVERSE_MAP &&
 
1449
      type != INK_REMAP_REDIRECT && type != INK_REMAP_REDIRECT_TEMP && type != INK_TYPE_UNDEFINED)
 
1450
    return NULL;
 
1451
 
 
1452
  ele = (INKRemapEle *) xmalloc(sizeof(INKRemapEle));
 
1453
  if (!ele)
 
1454
    return NULL;
 
1455
 
 
1456
  ele->cfg_ele.type = type;
 
1457
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1458
  ele->map = true;
 
1459
  ele->from_scheme = INK_SCHEME_UNDEFINED;
 
1460
  ele->from_host = NULL;
 
1461
  ele->from_port = INK_INVALID_PORT;
 
1462
  ele->from_path_prefix = NULL;
 
1463
  ele->to_scheme = INK_SCHEME_UNDEFINED;
 
1464
  ele->to_host = NULL;
 
1465
  ele->to_port = INK_INVALID_PORT;
 
1466
  ele->to_path_prefix = NULL;
 
1467
 
 
1468
  return ele;
 
1469
}
 
1470
 
 
1471
void
 
1472
INKRemapEleDestroy(INKRemapEle * ele)
 
1473
{
 
1474
  if (ele) {
 
1475
    if (ele->from_host)
 
1476
      xfree(ele->from_host);
 
1477
    if (ele->from_path_prefix)
 
1478
      xfree(ele->from_path_prefix);
 
1479
    if (ele->to_host)
 
1480
      xfree(ele->to_host);
 
1481
    if (ele->to_path_prefix)
 
1482
      xfree(ele->to_path_prefix);
 
1483
    xfree(ele);
 
1484
  }
 
1485
}
 
1486
 
 
1487
/*-------------------------------------------------------------
 
1488
 * INKSocksEle
 
1489
 *-------------------------------------------------------------*/
 
1490
INKSocksEle *
 
1491
INKSocksEleCreate(INKRuleTypeT type)
 
1492
{
 
1493
  INKSocksEle *ele;
 
1494
  ele = (INKSocksEle *) xmalloc(sizeof(INKSocksEle));
 
1495
  if (!ele)
 
1496
    return NULL;
 
1497
 
 
1498
  ele->cfg_ele.type = type;
 
1499
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1500
  ele->ip_addrs = INK_INVALID_LIST;
 
1501
  ele->dest_ip_addr = INK_INVALID_IP_ADDR;
 
1502
  ele->socks_servers = INK_INVALID_LIST;
 
1503
  ele->rr = INK_RR_NONE;
 
1504
  ele->username = NULL;
 
1505
  ele->password = NULL;
 
1506
 
 
1507
  return ele;
 
1508
}
 
1509
 
 
1510
void
 
1511
INKSocksEleDestroy(INKSocksEle * ele)
 
1512
{
 
1513
  if (ele) {
 
1514
    if (ele->ip_addrs)
 
1515
      INKIpAddrListDestroy(ele->ip_addrs);
 
1516
    if (ele->dest_ip_addr)
 
1517
      INKIpAddrEleDestroy(ele->dest_ip_addr);
 
1518
    if (ele->socks_servers)
 
1519
      INKDomainListDestroy(ele->socks_servers);
 
1520
    if (ele->username)
 
1521
      xfree(ele->username);
 
1522
    if (ele->password)
 
1523
      xfree(ele->password);
 
1524
    xfree(ele);
 
1525
  }
 
1526
}
 
1527
 
 
1528
/*-------------------------------------------------------------
 
1529
 * INKSplitDnsEle
 
1530
 *-------------------------------------------------------------*/
 
1531
INKSplitDnsEle *
 
1532
INKSplitDnsEleCreate()
 
1533
{
 
1534
  INKSplitDnsEle *ele;
 
1535
  ele = (INKSplitDnsEle *) xmalloc(sizeof(INKSplitDnsEle));
 
1536
  if (!ele)
 
1537
    return NULL;
 
1538
 
 
1539
  ele->cfg_ele.type = INK_SPLIT_DNS;
 
1540
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1541
  ele->pd_type = INK_PD_UNDEFINED;
 
1542
  ele->pd_val = NULL;
 
1543
  ele->dns_servers_addrs = INK_INVALID_LIST;
 
1544
  ele->def_domain = NULL;
 
1545
  ele->search_list = INK_INVALID_LIST;
 
1546
 
 
1547
  return ele;
 
1548
}
 
1549
 
 
1550
void
 
1551
INKSplitDnsEleDestroy(INKSplitDnsEle * ele)
 
1552
{
 
1553
  if (ele) {
 
1554
    if (ele->pd_val)
 
1555
      xfree(ele->pd_val);
 
1556
    if (ele->dns_servers_addrs)
 
1557
      INKDomainListDestroy(ele->dns_servers_addrs);
 
1558
    if (ele->def_domain)
 
1559
      xfree(ele->def_domain);
 
1560
    if (ele->search_list)
 
1561
      INKDomainListDestroy(ele->search_list);
 
1562
    xfree(ele);
 
1563
  }
 
1564
  return;
 
1565
}
 
1566
 
 
1567
/*-------------------------------------------------------------
 
1568
 * INKStorageEle
 
1569
 *-------------------------------------------------------------*/
 
1570
INKStorageEle *
 
1571
INKStorageEleCreate()
 
1572
{
 
1573
  INKStorageEle *ele;
 
1574
  ele = (INKStorageEle *) xmalloc(sizeof(INKStorageEle));
 
1575
  if (!ele)
 
1576
    return NULL;
 
1577
 
 
1578
  ele->cfg_ele.type = INK_STORAGE;
 
1579
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1580
  ele->pathname = NULL;
 
1581
  ele->size = -1;
 
1582
 
 
1583
  return ele;
 
1584
}
 
1585
 
 
1586
void
 
1587
INKStorageEleDestroy(INKStorageEle * ele)
 
1588
{
 
1589
  if (ele) {
 
1590
    if (ele->pathname)
 
1591
      xfree(ele->pathname);
 
1592
    xfree(ele);
 
1593
  }
 
1594
  return;
 
1595
}
 
1596
 
 
1597
/*-------------------------------------------------------------
 
1598
 * INKUpdateEle
 
1599
 *-------------------------------------------------------------*/
 
1600
INKUpdateEle *
 
1601
INKUpdateEleCreate()
 
1602
{
 
1603
  INKUpdateEle *ele;
 
1604
  ele = (INKUpdateEle *) xmalloc(sizeof(INKUpdateEle));
 
1605
  if (!ele)
 
1606
    return NULL;
 
1607
 
 
1608
  ele->cfg_ele.type = INK_UPDATE_URL;
 
1609
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1610
  ele->url = NULL;
 
1611
  ele->headers = INK_INVALID_LIST;
 
1612
  ele->offset_hour = -1;
 
1613
  ele->interval = -1;
 
1614
  ele->recursion_depth = 0;
 
1615
 
 
1616
  return ele;
 
1617
}
 
1618
 
 
1619
void
 
1620
INKUpdateEleDestroy(INKUpdateEle * ele)
 
1621
{
 
1622
  if (ele) {
 
1623
    if (ele->url)
 
1624
      xfree(ele->url);
 
1625
    if (ele->headers)
 
1626
      INKStringListDestroy(ele->headers);
 
1627
    xfree(ele);
 
1628
  }
 
1629
  return;
 
1630
}
 
1631
 
 
1632
/*-------------------------------------------------------------
 
1633
 * INKVirtIpAddrEle
 
1634
 *-------------------------------------------------------------*/
 
1635
INKVirtIpAddrEle *
 
1636
INKVirtIpAddrEleCreate()
 
1637
{
 
1638
  INKVirtIpAddrEle *ele;
 
1639
  ele = (INKVirtIpAddrEle *) xmalloc(sizeof(INKVirtIpAddrEle));
 
1640
  if (!ele)
 
1641
    return NULL;
 
1642
 
 
1643
  ele->cfg_ele.type = INK_VADDRS;
 
1644
  ele->cfg_ele.error = INK_ERR_OKAY;
 
1645
  ele->intr = NULL;
 
1646
  ele->sub_intr = -1;
 
1647
  ele->ip_addr = INK_INVALID_IP_ADDR;
 
1648
 
 
1649
  return ele;
 
1650
}
 
1651
 
 
1652
void
 
1653
INKVirtIpAddrEleDestroy(INKVirtIpAddrEle * ele)
 
1654
{
 
1655
  if (ele) {
 
1656
    if (ele->intr)
 
1657
      xfree(ele->intr);
 
1658
    if (ele->ip_addr)
 
1659
      xfree(ele->ip_addr);
 
1660
    xfree(ele);
 
1661
  }
 
1662
}
 
1663
 
 
1664
/***************************************************************************
 
1665
 * API Core
 
1666
 ***************************************************************************/
 
1667
 
 
1668
/*--- statistics operations ----------------------------------------------- */
 
1669
inkapi INKError
 
1670
INKStatsReset()
 
1671
{
 
1672
  return StatsReset();
 
1673
}
 
1674
 
 
1675
/*--- variable operations ------------------------------------------------- */
 
1676
/* Call the CfgFileIO variable operations */
 
1677
 
 
1678
inkapi INKError
 
1679
INKRecordGet(char *rec_name, INKRecordEle * rec_val)
 
1680
{
 
1681
  return MgmtRecordGet(rec_name, rec_val);
 
1682
}
 
1683
 
 
1684
INKError
 
1685
INKRecordGetInt(const char *rec_name, INKInt * int_val)
 
1686
{
 
1687
  INKError ret = INK_ERR_OKAY;
 
1688
 
 
1689
  INKRecordEle *ele = INKRecordEleCreate();
 
1690
  ret = MgmtRecordGet(rec_name, ele);
 
1691
  if (ret != INK_ERR_OKAY)
 
1692
    goto END;
 
1693
 
 
1694
  *int_val = ele->int_val;
 
1695
 
 
1696
END:
 
1697
  INKRecordEleDestroy(ele);
 
1698
  return ret;
 
1699
}
 
1700
 
 
1701
INKError
 
1702
INKRecordGetCounter(const char *rec_name, INKCounter * counter_val)
 
1703
{
 
1704
  INKError ret;
 
1705
 
 
1706
  INKRecordEle *ele = INKRecordEleCreate();
 
1707
  ret = MgmtRecordGet(rec_name, ele);
 
1708
  if (ret != INK_ERR_OKAY)
 
1709
    goto END;
 
1710
  *counter_val = ele->counter_val;
 
1711
 
 
1712
END:
 
1713
  INKRecordEleDestroy(ele);
 
1714
  return ret;
 
1715
}
 
1716
 
 
1717
INKError
 
1718
INKRecordGetFloat(const char *rec_name, INKFloat * float_val)
 
1719
{
 
1720
  INKError ret;
 
1721
 
 
1722
  INKRecordEle *ele = INKRecordEleCreate();
 
1723
  ret = MgmtRecordGet(rec_name, ele);
 
1724
  if (ret != INK_ERR_OKAY)
 
1725
    goto END;
 
1726
  *float_val = ele->float_val;
 
1727
 
 
1728
END:
 
1729
  INKRecordEleDestroy(ele);
 
1730
  return ret;
 
1731
}
 
1732
 
 
1733
INKError
 
1734
INKRecordGetString(const char *rec_name, INKString *string_val)
 
1735
{
 
1736
  INKError ret;
 
1737
  char *str;
 
1738
  size_t str_size = 0;
 
1739
 
 
1740
  INKRecordEle *ele = INKRecordEleCreate();
 
1741
  ret = MgmtRecordGet(rec_name, ele);
 
1742
  if (ret != INK_ERR_OKAY)
 
1743
    goto END;
 
1744
 
 
1745
  str_size = strlen(ele->string_val) + 1;
 
1746
  str = (char *) xmalloc(sizeof(char) * str_size);
 
1747
  if (!str)
 
1748
    return INK_ERR_SYS_CALL;
 
1749
  ink_strncpy(str, ele->string_val, str_size);
 
1750
  *string_val = str;
 
1751
 
 
1752
END:
 
1753
  INKRecordEleDestroy(ele);
 
1754
  return ret;
 
1755
}
 
1756
 
 
1757
 
 
1758
/*-------------------------------------------------------------------------
 
1759
 * INKRecordGetMlt
 
1760
 *-------------------------------------------------------------------------
 
1761
 * Purpose: Retrieves list of record values specified in the rec_names list
 
1762
 * Input: rec_names - list of record names to retrieve
 
1763
 *        rec_vals  - queue of INKRecordEle* that correspons to rec_names
 
1764
 * Output: If at any point, while retrieving one of the records there's a
 
1765
 *         a failure then the entire process is aborted, all the allocated
 
1766
 *         INKRecordEle's are deallocated and INK_ERR_FAIL is returned.
 
1767
 * Note: rec_names is not freed; if function is successful, the rec_names
 
1768
 *       list is unchanged!
 
1769
 *
 
1770
 * IS THIS FUNCTION AN ATOMIC TRANSACTION? Technically, all the variables
 
1771
 * requested should refer to the same config file. But a lock is only
 
1772
 * put on each variable it is looked up. Need to be able to lock
 
1773
 * a file while retrieving all the requested records!
 
1774
 */
 
1775
 
 
1776
inkapi INKError
 
1777
INKRecordGetMlt(INKStringList rec_names, INKList rec_vals)
 
1778
{
 
1779
  INKRecordEle *ele;
 
1780
  char *rec_name;
 
1781
  int num_recs, i, j;
 
1782
  INKError ret;
 
1783
 
 
1784
  if (!rec_names || !rec_vals)
 
1785
    return INK_ERR_PARAMS;
 
1786
 
 
1787
  num_recs = queue_len((LLQ *) rec_names);
 
1788
  for (i = 0; i < num_recs; i++) {
 
1789
    rec_name = (char *) dequeue((LLQ *) rec_names);     // remove name from list
 
1790
    if (!rec_name)
 
1791
      return INK_ERR_PARAMS;    // NULL is invalid record name
 
1792
 
 
1793
    ele = INKRecordEleCreate();
 
1794
 
 
1795
    ret = MgmtRecordGet(rec_name, ele);
 
1796
    enqueue((LLQ *) rec_names, rec_name);       // return name to list
 
1797
 
 
1798
    if (ret != INK_ERR_OKAY) {  // RecordGet failed
 
1799
      // need to free all the ele's allocated by MgmtRecordGet so far
 
1800
      INKRecordEleDestroy(ele);
 
1801
      for (j = 0; j < i; j++) {
 
1802
        ele = (INKRecordEle *) dequeue((LLQ *) rec_vals);
 
1803
        if (ele)
 
1804
          INKRecordEleDestroy(ele);
 
1805
      }
 
1806
      return ret;
 
1807
    }
 
1808
    enqueue((LLQ *) rec_vals, ele);     // all is good; add ele to end of list
 
1809
  }
 
1810
 
 
1811
  return INK_ERR_OKAY;
 
1812
}
 
1813
 
 
1814
 
 
1815
inkapi INKError
 
1816
INKRecordSet(const char *rec_name, const char *val, INKActionNeedT * action_need)
 
1817
{
 
1818
  return MgmtRecordSet(rec_name, val, action_need);
 
1819
}
 
1820
 
 
1821
 
 
1822
inkapi INKError
 
1823
INKRecordSetInt(const char *rec_name, INKInt int_val, INKActionNeedT * action_need)
 
1824
{
 
1825
  return MgmtRecordSetInt(rec_name, int_val, action_need);
 
1826
}
 
1827
 
 
1828
inkapi INKError
 
1829
INKRecordSetCounter(const char *rec_name, INKCounter counter_val, INKActionNeedT * action_need)
 
1830
{
 
1831
  return MgmtRecordSetCounter(rec_name, counter_val, action_need);
 
1832
}
 
1833
 
 
1834
inkapi INKError
 
1835
INKRecordSetFloat(const char *rec_name, INKFloat float_val, INKActionNeedT * action_need)
 
1836
{
 
1837
  return MgmtRecordSetFloat(rec_name, float_val, action_need);
 
1838
}
 
1839
 
 
1840
inkapi INKError
 
1841
INKRecordSetString(const char *rec_name, const char *str_val, INKActionNeedT * action_need)
 
1842
{
 
1843
  return MgmtRecordSetString(rec_name, str_val, action_need);
 
1844
}
 
1845
 
 
1846
 
 
1847
/*-------------------------------------------------------------------------
 
1848
 * INKRecordSetMlt
 
1849
 *-------------------------------------------------------------------------
 
1850
 * Basically iterates through each RecordEle in rec_list and calls the
 
1851
 * appropriate "MgmtRecordSetxx" function for that record
 
1852
 * Input: rec_list - queue of INKRecordEle*; each INKRecordEle* must have
 
1853
 *        a valid record name (remains unchanged on return)
 
1854
 * Output: if there is an error during the setting of one of the variables then
 
1855
 *         will continue to try to set the other variables. Error response will
 
1856
 *         indicate though that not all set operations were successful.
 
1857
 *         INK_ERR_OKAY is returned if all the records are set successfully
 
1858
 * Note: Determining the action needed is more complex b/c need to keep
 
1859
 * track of which record change is the most drastic out of the group of
 
1860
 * records; action_need will be set to the most severe action needed of
 
1861
 * all the "Set" calls
 
1862
 */
 
1863
inkapi INKError
 
1864
INKRecordSetMlt(INKList rec_list, INKActionNeedT * action_need)
 
1865
{
 
1866
  int num_recs, ret, i;
 
1867
  INKRecordEle *ele;
 
1868
  INKError status = INK_ERR_OKAY;
 
1869
  INKActionNeedT top_action_req = INK_ACTION_UNDEFINED;
 
1870
 
 
1871
  if (!rec_list || !action_need)
 
1872
    return INK_ERR_PARAMS;
 
1873
 
 
1874
  num_recs = queue_len((LLQ *) rec_list);
 
1875
 
 
1876
  for (i = 0; i < num_recs; i++) {
 
1877
    ele = (INKRecordEle *) dequeue((LLQ *) rec_list);
 
1878
    if (ele) {
 
1879
      switch (ele->rec_type) {
 
1880
      case INK_REC_INT:
 
1881
        ret = MgmtRecordSetInt(ele->rec_name, ele->int_val, action_need);
 
1882
        break;
 
1883
      case INK_REC_COUNTER:
 
1884
        ret = MgmtRecordSetCounter(ele->rec_name, ele->counter_val, action_need);
 
1885
        break;
 
1886
      case INK_REC_FLOAT:
 
1887
        ret = MgmtRecordSetFloat(ele->rec_name, ele->float_val, action_need);
 
1888
        break;
 
1889
      case INK_REC_STRING:
 
1890
        ret = MgmtRecordSetString(ele->rec_name, ele->string_val, action_need);
 
1891
        break;
 
1892
      default:
 
1893
        ret = INK_ERR_FAIL;
 
1894
        break;
 
1895
      };                        /* end of switch (ele->rec_type) */
 
1896
      if (ret != INK_ERR_OKAY)
 
1897
        status = INK_ERR_FAIL;
 
1898
 
 
1899
      // keep track of most severe action; reset if needed
 
1900
      // the INKACtionNeedT should be listed such that most severe actions have
 
1901
      // a lower number (so most severe action == 0)
 
1902
      if (*action_need < top_action_req)        // a more severe action
 
1903
        top_action_req = *action_need;
 
1904
    }
 
1905
    enqueue((LLQ *) rec_list, ele);
 
1906
  }
 
1907
 
 
1908
  // set the action_need to be the most sever action needed of all the "set" calls
 
1909
  *action_need = top_action_req;
 
1910
 
 
1911
  return status;
 
1912
}
 
1913
 
 
1914
/*--- api initialization and shutdown -------------------------------------*/
 
1915
inkapi INKError
 
1916
INKInit(const char *socket_path)
 
1917
{
 
1918
  return Init(socket_path);
 
1919
}
 
1920
 
 
1921
inkapi INKError
 
1922
INKTerminate()
 
1923
{
 
1924
  return Terminate();
 
1925
}
 
1926
 
 
1927
/*--- plugin initialization -----------------------------------------------*/
 
1928
inkexp extern void
 
1929
INKPluginInit(int argc, const char *argv[])
 
1930
{
 
1931
  NOWARN_UNUSED(argc);
 
1932
  NOWARN_UNUSED(argv);
 
1933
}
 
1934
 
 
1935
/*--- network operations --------------------------------------------------*/
 
1936
inkapi INKError
 
1937
INKConnect(INKIpAddr ip_addr, int port)
 
1938
{
 
1939
  NOWARN_UNUSED(ip_addr);
 
1940
  NOWARN_UNUSED(port);
 
1941
  return INK_ERR_OKAY;
 
1942
}
 
1943
inkapi INKError
 
1944
INKDisconnectCbRegister(INKDisconnectFunc * func, void *data)
 
1945
{
 
1946
  NOWARN_UNUSED(func);
 
1947
  NOWARN_UNUSED(data);
 
1948
  return INK_ERR_OKAY;
 
1949
}
 
1950
inkapi INKError
 
1951
INKDisconnectRetrySet(int retries, int retry_sleep_msec)
 
1952
{
 
1953
  NOWARN_UNUSED(retries);
 
1954
  NOWARN_UNUSED(retry_sleep_msec);
 
1955
  return INK_ERR_OKAY;
 
1956
}
 
1957
inkapi INKError
 
1958
INKDisconnect()
 
1959
{
 
1960
  return INK_ERR_OKAY;
 
1961
}
 
1962
 
 
1963
/*--- control operations --------------------------------------------------*/
 
1964
/* NOTE: these operations are wrappers that make direct calls to the CoreAPI */
 
1965
 
 
1966
/* INKProxyStateGet: get the proxy state (on/off)
 
1967
 * Input:  <none>
 
1968
 * Output: proxy state (on/off)
 
1969
 */
 
1970
inkapi INKProxyStateT
 
1971
INKProxyStateGet()
 
1972
{
 
1973
  return ProxyStateGet();
 
1974
}
 
1975
 
 
1976
/* INKProxyStateSet: set the proxy state (on/off)
 
1977
 * Input:  proxy_state - set to on/off
 
1978
 *         clear - start TS with cache clearing option,
 
1979
 *                 when stopping TS should always be INK_CACHE_CLEAR_OFF
 
1980
 * Output: INKError
 
1981
 */
 
1982
inkapi INKError
 
1983
INKProxyStateSet(INKProxyStateT proxy_state, INKCacheClearT clear)
 
1984
{
 
1985
  return ProxyStateSet(proxy_state, clear);
 
1986
}
 
1987
 
 
1988
/* INKReconfigure: tell traffic_server to re-read its configuration files
 
1989
 * Input:  <none>
 
1990
 * Output: INKError
 
1991
 */
 
1992
inkapi INKError
 
1993
INKReconfigure()
 
1994
{
 
1995
  return Reconfigure();
 
1996
}
 
1997
 
 
1998
/* INKRestart: restarts Traffic Server
 
1999
 * Input:  cluster - local or cluster-wide
 
2000
 * Output: INKError
 
2001
 */
 
2002
inkapi INKError
 
2003
INKRestart(bool cluster)
 
2004
{
 
2005
  return Restart(cluster);
 
2006
}
 
2007
 
 
2008
/* INKHardRestart: a traffic_cop restart (restarts TM and TS),
 
2009
 * essentially does a "start_traffic_server"/"stop_traffic_server" sequence
 
2010
 * Input:  <none>
 
2011
 * Output: INKError
 
2012
 * Note: only for remote API clients
 
2013
 */
 
2014
/* CAN ONLY BE IMPLEMENTED ON THE REMOTE SIDE !!! */
 
2015
inkapi INKError
 
2016
INKHardRestart()
 
2017
{
 
2018
  return HardRestart();         // should return INK_ERR_FAIL
 
2019
}
 
2020
 
 
2021
/* INKActionDo: based on INKActionNeedT, will take appropriate action
 
2022
 * Input: action - action that needs to be taken
 
2023
 * Output: INKError
 
2024
 */
 
2025
inkapi INKError
 
2026
INKActionDo(INKActionNeedT action)
 
2027
{
 
2028
  INKError ret;
 
2029
 
 
2030
  switch (action) {
 
2031
  case INK_ACTION_SHUTDOWN:
 
2032
    ret = HardRestart();
 
2033
    break;
 
2034
  case INK_ACTION_RESTART:
 
2035
    ret = Restart(true);        // cluster wide by default?
 
2036
    break;
 
2037
  case INK_ACTION_RECONFIGURE:
 
2038
    ret = Reconfigure();
 
2039
    break;
 
2040
  case INK_ACTION_DYNAMIC:
 
2041
    /* do nothing - change takes effect immediately */
 
2042
    return INK_ERR_OKAY;
 
2043
  default:
 
2044
    return INK_ERR_FAIL;
 
2045
  }
 
2046
 
 
2047
  return ret;
 
2048
}
 
2049
 
 
2050
 
 
2051
/*--- diags output operations ---------------------------------------------*/
 
2052
inkapi void
 
2053
INKDiags(INKDiagsT mode, const char *fmt, ...)
 
2054
{
 
2055
  // need to find way to pass arguments to the function
 
2056
  va_list ap;
 
2057
 
 
2058
  va_start(ap, fmt);            // initialize the argument pointer ap
 
2059
  Diags(mode, fmt, ap);
 
2060
  va_end(ap);
 
2061
 
 
2062
  return;
 
2063
}
 
2064
 
 
2065
/* NOTE: user must deallocate the memory for the string returned */
 
2066
char *
 
2067
INKGetErrorMessage(INKError err_id)
 
2068
{
 
2069
  char msg[1024];               // need to define a MAX_ERR_MSG_SIZE???
 
2070
  char *err_msg = NULL;
 
2071
 
 
2072
  switch (err_id) {
 
2073
  case INK_ERR_OKAY:
 
2074
    snprintf(msg, sizeof(msg), "[%d] Everything's looking good.", err_id);
 
2075
    break;
 
2076
  case INK_ERR_READ_FILE:      /* Error occur in reading file */
 
2077
    snprintf(msg, sizeof(msg), "[%d] Unable to find/open file for reading.", err_id);
 
2078
    break;
 
2079
  case INK_ERR_WRITE_FILE:     /* Error occur in writing file */
 
2080
    snprintf(msg, sizeof(msg), "[%d] Unable to find/open file for writing.", err_id);
 
2081
    break;
 
2082
  case INK_ERR_PARSE_CONFIG_RULE:      /* Error in parsing configuration file */
 
2083
    snprintf(msg, sizeof(msg), "[%d] Error parsing configuration file.", err_id);
 
2084
    break;
 
2085
  case INK_ERR_INVALID_CONFIG_RULE:    /* Invalid Configuration Rule */
 
2086
    snprintf(msg, sizeof(msg), "[%d] Invalid configuration rule reached.", err_id);
 
2087
    break;
 
2088
  case INK_ERR_NET_ESTABLISH:
 
2089
    snprintf(msg, sizeof(msg), "[%d] Error establishing socket conenction.", err_id);
 
2090
    break;
 
2091
  case INK_ERR_NET_READ:       /* Error reading from socket */
 
2092
    snprintf(msg, sizeof(msg), "[%d] Error reading from socket.", err_id);
 
2093
    break;
 
2094
  case INK_ERR_NET_WRITE:      /* Error writing to socket */
 
2095
    snprintf(msg, sizeof(msg), "[%d] Error writing to socket.", err_id);
 
2096
    break;
 
2097
  case INK_ERR_NET_EOF:        /* Hit socket EOF */
 
2098
    snprintf(msg, sizeof(msg), "[%d] Reached socket EOF.", err_id);
 
2099
    break;
 
2100
  case INK_ERR_NET_TIMEOUT:    /* Timed out waiting for socket read */
 
2101
    snprintf(msg, sizeof(msg), "[%d] Timed out waiting for socket read.", err_id);
 
2102
    break;
 
2103
  case INK_ERR_SYS_CALL:       /* Error in sys/utility call, eg.malloc */
 
2104
    snprintf(msg, sizeof(msg), "[%d] Error in basic system/utility call.", err_id);
 
2105
    break;
 
2106
  case INK_ERR_PARAMS:         /* Invalid parameters for a fn */
 
2107
    snprintf(msg, sizeof(msg), "[%d] Invalid parameters passed into function call.", err_id);
 
2108
    break;
 
2109
  case INK_ERR_FAIL:
 
2110
    snprintf(msg, sizeof(msg), "[%d] Generic Fail message (ie. CoreAPI call).", err_id);
 
2111
    break;
 
2112
 
 
2113
  default:
 
2114
    snprintf(msg, sizeof(msg), "[%d] Invalid error type.", err_id);
 
2115
    break;
 
2116
  }
 
2117
 
 
2118
  err_msg = xstrdup(msg);
 
2119
  return err_msg;
 
2120
}
 
2121
 
 
2122
 
 
2123
/*--- password operations -------------------------------------------------*/
 
2124
inkapi INKError
 
2125
INKEncryptPassword(char *passwd, char **e_passwd)
 
2126
{
 
2127
 
 
2128
  INK_DIGEST_CTX md5_context;
 
2129
  char passwd_md5[16];
 
2130
  char *passwd_md5_str;
 
2131
  int passwd_md5_str_len = 32;
 
2132
 
 
2133
  ink_debug_assert(passwd);
 
2134
  ink_debug_assert(INK_ENCRYPT_PASSWD_LEN <= passwd_md5_str_len);
 
2135
 
 
2136
  const size_t md5StringSize = (passwd_md5_str_len + 1) * sizeof(char);
 
2137
  passwd_md5_str = (char *) xmalloc(md5StringSize);
 
2138
  if (!passwd_md5_str)
 
2139
    return INK_ERR_FAIL;
 
2140
 
 
2141
  ink_code_incr_md5_init(&md5_context);
 
2142
  ink_code_incr_md5_update(&md5_context, passwd, strlen(passwd));
 
2143
  ink_code_incr_md5_final(passwd_md5, &md5_context);
 
2144
  ink_code_md5_stringify(passwd_md5_str, md5StringSize, passwd_md5);
 
2145
 
 
2146
  // use only a subset of the MD5 string
 
2147
  passwd_md5_str[INK_ENCRYPT_PASSWD_LEN] = '\0';
 
2148
  *e_passwd = passwd_md5_str;
 
2149
 
 
2150
  return INK_ERR_OKAY;
 
2151
}
 
2152
 
 
2153
inkapi INKError
 
2154
INKEncryptToFile(const char *passwd, const char *filepath)
 
2155
{
 
2156
  return EncryptToFile(passwd, filepath);
 
2157
}
 
2158
 
 
2159
/*--- direct file operations ----------------------------------------------*/
 
2160
inkapi INKError
 
2161
INKConfigFileRead(INKFileNameT file, char **text, int *size, int *version)
 
2162
{
 
2163
  return ReadFile(file, text, size, version);
 
2164
}
 
2165
 
 
2166
inkapi INKError
 
2167
INKConfigFileWrite(INKFileNameT file, char *text, int size, int version)
 
2168
{
 
2169
  return WriteFile(file, text, size, version);
 
2170
}
 
2171
 
 
2172
 
 
2173
/* ReadFromUrl: reads a remotely located config file into a buffer
 
2174
 * Input:  url        - remote location of the file
 
2175
 *         header     - a buffer is allocated on the header char* pointer
 
2176
 *         headerSize - the size of the header buffer is returned
 
2177
 *         body       - a buffer is allocated on the body char* pointer
 
2178
 *         bodySize   - the size of the body buffer is returned
 
2179
 * Output: INKError   - INK_ERR_OKAY if succeed, INK_ERR_FAIL otherwise
 
2180
 * Obsolete:  inkapi INKError INKReadFromUrl (char *url, char **text, int *size);
 
2181
 * NOTE: The URL can be expressed in the following forms:
 
2182
 *       - http://www.inktomi.com:80/products/network/index.html
 
2183
 *       - http://www.inktomi.com/products/network/index.html
 
2184
 *       - http://www.inktomi.com/products/network/
 
2185
 *       - http://www.inktomi.com/
 
2186
 *       - http://www.inktomi.com
 
2187
 *       - www.inktomi.com
 
2188
 * NOTE: header and headerSize can be NULL
 
2189
 */
 
2190
inkapi INKError
 
2191
INKReadFromUrl(char *url, char **header, int *headerSize, char **body, int *bodySize)
 
2192
{
 
2193
  //return ReadFromUrl(url, header, headerSize, body, bodySize);
 
2194
  return INKReadFromUrlEx(url, header, headerSize, body, bodySize, URL_TIMEOUT);
 
2195
 
 
2196
}
 
2197
 
 
2198
inkapi INKError
 
2199
INKReadFromUrlEx(const char *url, char **header, int *headerSize, char **body, int *bodySize, int timeout)
 
2200
{
 
2201
  int hFD = -1;
 
2202
  char *httpHost = NULL;
 
2203
  char *httpPath = NULL;
 
2204
  int httpPort = HTTP_PORT;
 
2205
  int bufsize = URL_BUFSIZE;
 
2206
  char buffer[URL_BUFSIZE];
 
2207
  char request[BUFSIZE];
 
2208
  char *hdr_temp;
 
2209
  char *bdy_temp;
 
2210
  INKError status = INK_ERR_OKAY;
 
2211
 
 
2212
  // Sanity check
 
2213
  if (!url)
 
2214
    return INK_ERR_FAIL;
 
2215
  if (timeout < 0) {
 
2216
    timeout = URL_TIMEOUT;
 
2217
  }
 
2218
  // Chop the protocol part, if it exists
 
2219
  const char *doubleSlash = strstr(url, "//");
 
2220
  if (doubleSlash) {
 
2221
    url = doubleSlash + 2;      // advance two positions to get rid of leading '//'
 
2222
  }
 
2223
  // the path starts after the first occurrence of '/'
 
2224
  const char *tempPath = strstr(url, "/");
 
2225
  char *host_and_port;
 
2226
  if (tempPath) {
 
2227
    host_and_port = xstrndup(url, strlen(url) - strlen(tempPath));
 
2228
    tempPath += 1;              // advance one position to get rid of leading '/'
 
2229
    httpPath = xstrdup(tempPath);
 
2230
  } else {
 
2231
    host_and_port = xstrdup(url);
 
2232
    httpPath = xstrdup("");
 
2233
  }
 
2234
 
 
2235
  // the port proceed by a ":", if it exists
 
2236
  char *colon = strstr(host_and_port, ":");
 
2237
  if (colon) {
 
2238
    httpHost = xstrndup(host_and_port, strlen(host_and_port) - strlen(colon));
 
2239
    colon += 1;                 // advance one position to get rid of leading ':'
 
2240
    httpPort = ink_atoi(colon);
 
2241
    if (httpPort <= 0)
 
2242
      httpPort = HTTP_PORT;
 
2243
  } else {
 
2244
    httpHost = xstrdup(host_and_port);
 
2245
  }
 
2246
  xfree(host_and_port);
 
2247
 
 
2248
  hFD = connectDirect(httpHost, httpPort, timeout);
 
2249
  if (hFD == -1) {
 
2250
    status = INK_ERR_NET_ESTABLISH;
 
2251
    goto END;
 
2252
  }
 
2253
 
 
2254
  /* sending the HTTP request via the established socket */
 
2255
  snprintf(request, BUFSIZE, "http://%s:%d/%s", httpHost, httpPort, httpPath);
 
2256
  if ((status = sendHTTPRequest(hFD, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2257
    goto END;
 
2258
 
 
2259
  memset(buffer, 0, bufsize);   /* empty the buffer */
 
2260
  if ((status = readHTTPResponse(hFD, buffer, bufsize, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2261
    goto END;
 
2262
 
 
2263
  if ((status = parseHTTPResponse(buffer, &hdr_temp, headerSize, &bdy_temp, bodySize))
 
2264
      != INK_ERR_OKAY)
 
2265
    goto END;
 
2266
 
 
2267
  if (header && headerSize)
 
2268
    *header = xstrndup(hdr_temp, *headerSize);
 
2269
  *body = xstrndup(bdy_temp, *bodySize);
 
2270
 
 
2271
END:
 
2272
  if (httpHost)
 
2273
    xfree(httpHost);
 
2274
  if (httpPath)
 
2275
    xfree(httpPath);
 
2276
  return status;
 
2277
}
 
2278
 
 
2279
/*--- cache inspector operations -------------------------------------------*/
 
2280
 
 
2281
inkapi INKError
 
2282
INKLookupFromCacheUrl(INKString url, INKString * info)
 
2283
{
 
2284
  INKError err = INK_ERR_OKAY;
 
2285
  int fd;
 
2286
  char request[BUFSIZE];
 
2287
  char response[URL_BUFSIZE];
 
2288
  char *header;
 
2289
  char *body;
 
2290
  int hdr_size;
 
2291
  int bdy_size;
 
2292
  int timeout = URL_TIMEOUT;
 
2293
  INKInt ts_port = 8080;
 
2294
 
 
2295
  if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
 
2296
    goto END;
 
2297
 
 
2298
  if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
 
2299
    err = INK_ERR_FAIL;
 
2300
    goto END;
 
2301
  }
 
2302
  snprintf(request, BUFSIZE, "http://{cache}/lookup_url?url=%s", url);
 
2303
  if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2304
    goto END;
 
2305
 
 
2306
  memset(response, 0, URL_BUFSIZE);
 
2307
  if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2308
    goto END;
 
2309
 
 
2310
  if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
 
2311
    goto END;
 
2312
 
 
2313
  *info = xstrndup(body, bdy_size);
 
2314
 
 
2315
END:
 
2316
  return err;
 
2317
}
 
2318
 
 
2319
inkapi INKError
 
2320
INKLookupFromCacheUrlRegex(INKString url_regex, INKString * list)
 
2321
{
 
2322
  INKError err = INK_ERR_OKAY;
 
2323
  int fd = -1;
 
2324
  char request[BUFSIZE];
 
2325
  char response[URL_BUFSIZE];
 
2326
  char *header;
 
2327
  char *body;
 
2328
  int hdr_size;
 
2329
  int bdy_size;
 
2330
  int timeout = -1;
 
2331
  INKInt ts_port = 8080;
 
2332
 
 
2333
  if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
 
2334
    goto END;
 
2335
 
 
2336
  if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
 
2337
    err = INK_ERR_FAIL;
 
2338
    goto END;
 
2339
  }
 
2340
  snprintf(request, BUFSIZE, "http://{cache}/lookup_regex?url=%s", url_regex);
 
2341
  if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2342
    goto END;
 
2343
 
 
2344
  memset(response, 0, URL_BUFSIZE);
 
2345
  if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2346
    goto END;
 
2347
 
 
2348
  if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
 
2349
    goto END;
 
2350
 
 
2351
  *list = xstrndup(body, bdy_size);
 
2352
END:
 
2353
  return err;
 
2354
}
 
2355
 
 
2356
inkapi INKError
 
2357
INKDeleteFromCacheUrl(INKString url, INKString * info)
 
2358
{
 
2359
  INKError err = INK_ERR_OKAY;
 
2360
  int fd = -1;
 
2361
  char request[BUFSIZE];
 
2362
  char response[URL_BUFSIZE];
 
2363
  char *header;
 
2364
  char *body;
 
2365
  int hdr_size;
 
2366
  int bdy_size;
 
2367
  int timeout = URL_TIMEOUT;
 
2368
  INKInt ts_port = 8080;
 
2369
 
 
2370
  if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
 
2371
    goto END;
 
2372
 
 
2373
  if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
 
2374
    err = INK_ERR_FAIL;
 
2375
    goto END;
 
2376
  }
 
2377
  snprintf(request, BUFSIZE, "http://{cache}/delete_url?url=%s", url);
 
2378
  if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2379
    goto END;
 
2380
 
 
2381
  memset(response, 0, URL_BUFSIZE);
 
2382
  if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2383
    goto END;
 
2384
 
 
2385
  if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
 
2386
    goto END;
 
2387
 
 
2388
  *info = xstrndup(body, bdy_size);
 
2389
 
 
2390
END:
 
2391
  return err;
 
2392
}
 
2393
 
 
2394
inkapi INKError
 
2395
INKDeleteFromCacheUrlRegex(INKString url_regex, INKString * list)
 
2396
{
 
2397
  INKError err = INK_ERR_OKAY;
 
2398
  int fd = -1;
 
2399
  char request[BUFSIZE];
 
2400
  char response[URL_BUFSIZE];
 
2401
  char *header;
 
2402
  char *body;
 
2403
  int hdr_size;
 
2404
  int bdy_size;
 
2405
  int timeout = -1;
 
2406
  INKInt ts_port = 8080;
 
2407
 
 
2408
  if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
 
2409
    goto END;
 
2410
 
 
2411
  if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
 
2412
    err = INK_ERR_FAIL;
 
2413
    goto END;
 
2414
  }
 
2415
  snprintf(request, BUFSIZE, "http://{cache}/delete_regex?url=%s", url_regex);
 
2416
  if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2417
    goto END;
 
2418
 
 
2419
  memset(response, 0, URL_BUFSIZE);
 
2420
  if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2421
    goto END;
 
2422
 
 
2423
  if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
 
2424
    goto END;
 
2425
 
 
2426
  *list = xstrndup(body, bdy_size);
 
2427
END:
 
2428
  return err;
 
2429
}
 
2430
 
 
2431
inkapi INKError
 
2432
INKInvalidateFromCacheUrlRegex(INKString url_regex, INKString * list)
 
2433
{
 
2434
  INKError err = INK_ERR_OKAY;
 
2435
  int fd = -1;
 
2436
  char request[BUFSIZE];
 
2437
  char response[URL_BUFSIZE];
 
2438
  char *header;
 
2439
  char *body;
 
2440
  int hdr_size;
 
2441
  int bdy_size;
 
2442
  int timeout = -1;
 
2443
  INKInt ts_port = 8080;
 
2444
 
 
2445
  if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
 
2446
    goto END;
 
2447
 
 
2448
  if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
 
2449
    err = INK_ERR_FAIL;
 
2450
    goto END;
 
2451
  }
 
2452
  snprintf(request, BUFSIZE, "http://{cache}/invalidate_regex?url=%s", url_regex);
 
2453
  if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2454
    goto END;
 
2455
 
 
2456
  memset(response, 0, URL_BUFSIZE);
 
2457
  if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
 
2458
    goto END;
 
2459
 
 
2460
  if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
 
2461
    goto END;
 
2462
 
 
2463
  *list = xstrndup(body, bdy_size);
 
2464
END:
 
2465
  return err;
 
2466
}
 
2467
 
 
2468
/*--- snapshot operations -------------------------------------------------*/
 
2469
inkapi INKError
 
2470
INKSnapshotTake(char *snapshot_name)
 
2471
{
 
2472
  return SnapshotTake(snapshot_name);
 
2473
}
 
2474
 
 
2475
inkapi INKError
 
2476
INKSnapshotRestore(char *snapshot_name)
 
2477
{
 
2478
  return SnapshotRestore(snapshot_name);
 
2479
}
 
2480
 
 
2481
inkapi INKError
 
2482
INKSnapshotRemove(char *snapshot_name)
 
2483
{
 
2484
  return SnapshotRemove(snapshot_name);
 
2485
}
 
2486
 
 
2487
inkapi INKError
 
2488
INKSnapshotGetMlt(INKStringList snapshots)
 
2489
{
 
2490
  return SnapshotGetMlt((LLQ *) snapshots);
 
2491
}
 
2492
 
 
2493
/*--- events --------------------------------------------------------------*/
 
2494
inkapi INKError
 
2495
INKEventSignal(char *event_name, ...)
 
2496
{
 
2497
  va_list ap;
 
2498
  INKError ret;
 
2499
 
 
2500
  va_start(ap, event_name);     // initialize the argument pointer ap
 
2501
  ret = EventSignal(event_name, ap);
 
2502
  va_end(ap);
 
2503
  return ret;
 
2504
}
 
2505
 
 
2506
inkapi INKError
 
2507
INKEventResolve(char *event_name)
 
2508
{
 
2509
  return EventResolve(event_name);
 
2510
}
 
2511
 
 
2512
inkapi INKError
 
2513
INKActiveEventGetMlt(INKList active_events)
 
2514
{
 
2515
  return ActiveEventGetMlt((LLQ *) active_events);
 
2516
}
 
2517
 
 
2518
inkapi INKError
 
2519
INKEventIsActive(char *event_name, bool * is_current)
 
2520
{
 
2521
  return EventIsActive(event_name, is_current);
 
2522
}
 
2523
 
 
2524
inkapi INKError
 
2525
INKEventSignalCbRegister(char *event_name, INKEventSignalFunc func, void *data)
 
2526
{
 
2527
  return EventSignalCbRegister(event_name, func, data);
 
2528
}
 
2529
 
 
2530
inkapi INKError
 
2531
INKEventSignalCbUnregister(char *event_name, INKEventSignalFunc func)
 
2532
{
 
2533
  return EventSignalCbUnregister(event_name, func);
 
2534
}
 
2535
 
 
2536
/***************************************************************************
 
2537
 * API Helper Functions for Data Carrier Structures
 
2538
 ***************************************************************************/
 
2539
 
 
2540
/*--- abstracted file operations ------------------------------------------*/
 
2541
 
 
2542
/* calls teh CfgContext class constructor */
 
2543
inkapi INKCfgContext
 
2544
INKCfgContextCreate(INKFileNameT file)
 
2545
{
 
2546
  return ((void *) CfgContextCreate(file));
 
2547
}
 
2548
 
 
2549
/* calls the CfgContext class destructor */
 
2550
inkapi INKError
 
2551
INKCfgContextDestroy(INKCfgContext ctx)
 
2552
{
 
2553
  return (CfgContextDestroy((CfgContext *) ctx));
 
2554
}
 
2555
 
 
2556
inkapi INKError
 
2557
INKCfgContextCommit(INKCfgContext ctx, INKActionNeedT * action_need, INKIntList errRules)
 
2558
{
 
2559
  NOWARN_UNUSED(action_need);
 
2560
  return (CfgContextCommit((CfgContext *) ctx, (LLQ *) errRules));
 
2561
}
 
2562
 
 
2563
inkapi INKError
 
2564
INKCfgContextGet(INKCfgContext ctx)
 
2565
{
 
2566
  return (CfgContextGet((CfgContext *) ctx));
 
2567
}
 
2568
 
 
2569
/*--- helper operations ---------------------------------------------------*/
 
2570
/* returns number of ele's in the INKCfgContext */
 
2571
int
 
2572
INKCfgContextGetCount(INKCfgContext ctx)
 
2573
{
 
2574
  return CfgContextGetCount((CfgContext *) ctx);
 
2575
}
 
2576
 
 
2577
/* user must typecast the INKCfgEle to appropriate INKEle before using */
 
2578
INKCfgEle *
 
2579
INKCfgContextGetEleAt(INKCfgContext ctx, int index)
 
2580
{
 
2581
  return CfgContextGetEleAt((CfgContext *) ctx, index);
 
2582
}
 
2583
 
 
2584
/* iterator */
 
2585
INKCfgEle *
 
2586
INKCfgContextGetFirst(INKCfgContext ctx, INKCfgIterState * state)
 
2587
{
 
2588
  return CfgContextGetFirst((CfgContext *) ctx, state);
 
2589
}
 
2590
 
 
2591
INKCfgEle *
 
2592
INKCfgContextGetNext(INKCfgContext ctx, INKCfgIterState * state)
 
2593
{
 
2594
  return CfgContextGetNext((CfgContext *) ctx, state);
 
2595
}
 
2596
 
 
2597
INKError
 
2598
INKCfgContextMoveEleUp(INKCfgContext ctx, int index)
 
2599
{
 
2600
  return CfgContextMoveEleUp((CfgContext *) ctx, index);
 
2601
}
 
2602
 
 
2603
INKError
 
2604
INKCfgContextMoveEleDown(INKCfgContext ctx, int index)
 
2605
{
 
2606
  return CfgContextMoveEleDown((CfgContext *) ctx, index);
 
2607
}
 
2608
 
 
2609
 
 
2610
INKError
 
2611
INKCfgContextAppendEle(INKCfgContext ctx, INKCfgEle * ele)
 
2612
{
 
2613
  return CfgContextAppendEle((CfgContext *) ctx, ele);
 
2614
}
 
2615
 
 
2616
INKError
 
2617
INKCfgContextInsertEleAt(INKCfgContext ctx, INKCfgEle * ele, int index)
 
2618
{
 
2619
  return CfgContextInsertEleAt((CfgContext *) ctx, ele, index);
 
2620
}
 
2621
 
 
2622
INKError
 
2623
INKCfgContextRemoveEleAt(INKCfgContext ctx, int index)
 
2624
{
 
2625
  return CfgContextRemoveEleAt((CfgContext *) ctx, index);
 
2626
}
 
2627
 
 
2628
INKError
 
2629
INKCfgContextRemoveAll(INKCfgContext ctx)
 
2630
{
 
2631
  return CfgContextRemoveAll((CfgContext *) ctx);
 
2632
}
 
2633
 
 
2634
/* checks if the fields in the ele are all valid */
 
2635
bool
 
2636
INKIsValid(INKCfgEle * ele)
 
2637
{
 
2638
  CfgEleObj *ele_obj;
 
2639
 
 
2640
  if (!ele)
 
2641
    return false;
 
2642
 
 
2643
  ele_obj = create_ele_obj_from_ele(ele);
 
2644
  return (ele_obj->isValid());
 
2645
}
 
2646
 
 
2647
 
 
2648
/*--- External FTP tcl script operations --------------------------------*/
 
2649
 
 
2650
/* Process forking function for ftp.tcl helper */
 
2651
 
 
2652
static int
 
2653
ftpProcessSpawn(const char *args[], char *output)
 
2654
{
 
2655
  int status = 0;
 
2656
 
 
2657
#ifndef _WIN32
 
2658
  char buffer[1024];
 
2659
  size_t nbytes;
 
2660
  int stdoutPipe[2];
 
2661
  pid_t pid;
 
2662
  size_t output_size = 4096;
 
2663
  size_t count = 0;
 
2664
 
 
2665
  if (pipe(stdoutPipe) == -1)
 
2666
    fprintf(stderr, "[ftpProcessSpawn] unable to create stdout pipe\n");
 
2667
 
 
2668
  pid = fork();
 
2669
  if (pid == 0) {               // child process
 
2670
    dup2(stdoutPipe[1], STDOUT_FILENO);
 
2671
    close(stdoutPipe[0]);
 
2672
 
 
2673
    pid = execv(args[0], (char* const*)&args[0]);
 
2674
    if (pid == -1) {
 
2675
      fprintf(stderr, "[ftpProcessSpawn] unable to execv [%s,%s...]\n", args[0], args[1]);
 
2676
    }
 
2677
    _exit(1);
 
2678
  } else if (pid == -1) {       // failed to create child process
 
2679
    fprintf(stderr, "[ftpProcessSpawn] unable to fork [%d '%s']\n", errno, strerror(errno));
 
2680
    status = 1;
 
2681
  } else {                      // parent process
 
2682
    close(stdoutPipe[1]);
 
2683
    /* read the output from child script process */
 
2684
    while ((nbytes = read(stdoutPipe[0], buffer, 1024))) {
 
2685
      if ((count + nbytes) < output_size) {
 
2686
        strncpy(&output[count], buffer, nbytes);
 
2687
        count += nbytes;
 
2688
      } else {
 
2689
        break;
 
2690
      }
 
2691
    }
 
2692
    close(stdoutPipe[0]);
 
2693
 
 
2694
    waitpid(pid, &status, 0);
 
2695
    if (status) {
 
2696
      fprintf(stderr, "[ftpProcessSpawn] script %s returns non-zero status '%d'", args[0], status);
 
2697
      status = -1;
 
2698
    }
 
2699
  }
 
2700
 
 
2701
#endif
 
2702
  return status;
 
2703
}
 
2704
 
 
2705
/* Process forking function for tcl_checker.sh helper */
 
2706
 
 
2707
static int
 
2708
tclCheckProcessSpawn(char *args[], char *output)
 
2709
{
 
2710
  int status = 0;
 
2711
 
 
2712
#ifndef _WIN32
 
2713
  char buffer[1024];
 
2714
  size_t nbytes;
 
2715
  int stdoutPipe[2];
 
2716
  pid_t pid;
 
2717
  size_t output_size = 256;
 
2718
  size_t count = 0;
 
2719
 
 
2720
  if (pipe(stdoutPipe) == -1)
 
2721
    fprintf(stderr, "[tclCheckProcessSpawn] unable to create stdout pipe\n");
 
2722
 
 
2723
  pid = fork();
 
2724
  if (pid == 0) {               // child process
 
2725
    dup2(stdoutPipe[1], STDOUT_FILENO);
 
2726
    close(stdoutPipe[0]);
 
2727
 
 
2728
    pid = execv(args[0], &args[0]);
 
2729
    if (pid == -1) {
 
2730
      fprintf(stderr, "[tclCheckProcessSpawn] unable to execv [%s,%s...]\n", args[0], args[1]);
 
2731
    }
 
2732
    _exit(1);
 
2733
  } else if (pid == -1) {       // failed to create child process
 
2734
    fprintf(stderr, "[tclCheckProcessSpawn] unable to fork [%d '%s']\n", errno, strerror(errno));
 
2735
    status = 1;
 
2736
  } else {                      // parent process
 
2737
    close(stdoutPipe[1]);
 
2738
    /* read the output from child script process */
 
2739
    while ((nbytes = read(stdoutPipe[0], buffer, 1024))) {
 
2740
      if ((count + nbytes) < output_size) {
 
2741
        strncpy(&output[count], buffer, nbytes);
 
2742
        count += nbytes;
 
2743
      } else {
 
2744
        break;
 
2745
      }
 
2746
    }
 
2747
    close(stdoutPipe[0]);
 
2748
 
 
2749
    waitpid(pid, &status, 0);
 
2750
    if (status) {
 
2751
      fprintf(stderr, "[tclCheckProcessSpawn] script %s returns non-zero status '%d'", args[0], status);
 
2752
      status = -1;
 
2753
    }
 
2754
  }
 
2755
 
 
2756
#endif
 
2757
  return status;
 
2758
}
 
2759
 
 
2760
/* Snapshot Interface-centric function */
 
2761
 
 
2762
inkapi INKError
 
2763
INKMgmtFtp(const char *ftpCmd, const char *ftp_server_name, const char *ftp_login, const char *ftp_password, const char *local, const char *remote,
 
2764
           char *output)
 
2765
{
 
2766
  char script_path[1024];
 
2767
  char chk_script_path[1024];
 
2768
  int chk_status = 0;
 
2769
  int status = 0;
 
2770
  char *ui_path = NULL;
 
2771
  INKRecordGetString("proxy.config.admin.html_doc_root", &ui_path);
 
2772
  if (ui_path != NULL) {
 
2773
 
 
2774
    /* First we check to make sure we can use tcl on this plat */
 
2775
    snprintf(chk_script_path, sizeof(chk_script_path), "%s/configure/helper/INKMgmtAPICheckTcl.sh", ui_path);
 
2776
    char *chk_args[] = {
 
2777
      chk_script_path,
 
2778
      NULL
 
2779
    };
 
2780
    /* tclCheckProcessSpawn.sh sends nothing back on stdout if check OK... */
 
2781
    chk_status = tclCheckProcessSpawn(chk_args, output);
 
2782
    if (chk_status == 0) {
 
2783
      /* Go ahead and try the using the FTP .tcl script */
 
2784
      snprintf(script_path, sizeof(script_path), "%s/configure/helper/INKMgmtAPIFtp.tcl", ui_path);
 
2785
      const char *args[] = {
 
2786
        script_path,
 
2787
        ftpCmd,
 
2788
        ftp_server_name,
 
2789
        ftp_login,
 
2790
        ftp_password,
 
2791
        local,
 
2792
        remote,
 
2793
        NULL
 
2794
      };
 
2795
      status = ftpProcessSpawn(args, output);
 
2796
    } else {
 
2797
      status = -1;
 
2798
    }
 
2799
  }
 
2800
  if (status < 0)
 
2801
    return INK_ERR_FAIL;
 
2802
  return INK_ERR_OKAY;
 
2803
}
 
2804
 
 
2805
/* Network conifguration functions */
 
2806
 
 
2807
// close all file descriptors belong to process specified by pid
 
2808
void
 
2809
closeAllFds()
 
2810
{
 
2811
  const int BUFFLEN = 200;
 
2812
  char command[BUFFLEN];
 
2813
  char buffer[BUFFLEN];         // this is assumption.. so would break if some one try to hack this.
 
2814
  int num;
 
2815
 
 
2816
  // WARNING:  this part of code doesn't work yet.  for some strange reason, we can not upgrade
 
2817
  //           to root
 
2818
  if (getuid() != 0) {          // if not super user, need to upgrade to root
 
2819
    //printf("before upgrade:current uid%d, euid %d\n", getuid(), geteuid()); fflush(stdout);
 
2820
    seteuid(0);
 
2821
    setreuid(0, 0);
 
2822
    //printf("after upgrade:current uid %d, euid %d\n", getuid(), geteuid()); fflush(stdout);
 
2823
  }
 
2824
 
 
2825
  if (getuid() == 0 || geteuid() == 0) {        // only if it's successful
 
2826
    snprintf(command, sizeof(command), "/bin/ls -1 /proc/%" PRId64 "/fd", (int64_t)getpid());
 
2827
    FILE *fd = popen(command, "r");
 
2828
    if (fd) {
 
2829
      while (!feof(fd)) {
 
2830
        NOWARN_UNUSED_RETURN(fgets(buffer, BUFFLEN, fd));
 
2831
        num = atoi(buffer);
 
2832
        if (num != fileno(fd) && num != 0 && num != 1 && num != 2) {   // for out put
 
2833
          //printf("closing fd (%d)\n", num); fflush(stdout);
 
2834
          close(num);
 
2835
        }
 
2836
      }
 
2837
      pclose(fd);
 
2838
    }
 
2839
  }
 
2840
}
 
2841
 
 
2842
inkapi INKError rm_start_proxy()
 
2843
{
 
2844
 
 
2845
#if defined(linux)
 
2846
  static time_t rm_last_stop = 0;
 
2847
 
 
2848
  time_t time_diff = time(NULL) - rm_last_stop;
 
2849
 
 
2850
  if (time_diff > 60 || time_diff < 0) {        // wrap around??  shall never happen
 
2851
    pid_t pid;
 
2852
    const char *argv[3];
 
2853
    argv[0] = "net_config";
 
2854
    argv[1] = "7";
 
2855
    argv[2] = NULL;
 
2856
    char command_path[PATH_NAME_MAX + 1];
 
2857
    Layout::relative_to(command_path, sizeof(command_path),
 
2858
                        Layout::get()->bindir, "net_config");
 
2859
 
 
2860
    rm_last_stop = time(NULL);
 
2861
 
 
2862
    if ((pid = fork()) < 0) {
 
2863
      exit(1);
 
2864
    } else if (pid > 0) {
 
2865
      // do not wait
 
2866
    } else {
 
2867
      closeAllFds();
 
2868
      close(1);                 // close STDOUT
 
2869
      close(2);                 // close STDERR
 
2870
 
 
2871
      int res = execv(command_path, (char* const*)argv);
 
2872
      if (res != 0) {
 
2873
        perror("[rm_start_proxy] net_config stop_proxy failed! ");
 
2874
      }
 
2875
      _exit(res);
 
2876
    }
 
2877
  }                             // else already try to stop within 60s Window, skip
 
2878
#endif
 
2879
  return INK_ERR_OKAY;
 
2880
}
 
2881
 
 
2882
 
 
2883
/*****************************************************************
 
2884
* Traffic server changes necessary when network config is changed
 
2885
*****************************************************************/
 
2886
 
 
2887
inkapi INKError
 
2888
INKSetHostname(INKString hostname)
 
2889
{
 
2890
  INKActionNeedT action_need = INK_ACTION_UNDEFINED, top_action_req = INK_ACTION_UNDEFINED;
 
2891
  INKInt val = 0;
 
2892
 
 
2893
  /* Here we should handle these cases:
 
2894
   * rmserver.cfg - different API currently, records.config, mrtg, and hostname_FQ
 
2895
   */
 
2896
 
 
2897
  if (INKRecordGetInt("proxy.local.cluster.type", &val) == INK_ERR_OKAY) {      //If error??
 
2898
    if (val == 3) {
 
2899
      if (MgmtRecordSet("proxy.config.proxy_name", hostname, &action_need) != INK_ERR_OKAY)
 
2900
        return INK_ERR_FAIL;
 
2901
    }
 
2902
  }
 
2903
 
 
2904
  if (action_need < top_action_req)     // a more severe action
 
2905
    top_action_req = action_need;
 
2906
 
 
2907
  //FIXME - currently MRTG is all about hard coded hostname - this is where we should fix it
 
2908
  //Currently it is fixed in net_config
 
2909
 
 
2910
  //if (!(mrtg_update_hostname(hostname)))
 
2911
  //     return INK_ERR_WRITE_FILE;
 
2912
 
 
2913
  //Also, we use this variable sometimes - needs to be fixed
 
2914
 
 
2915
  if (MgmtRecordSet("proxy.node.hostname_FQ", hostname, &action_need) != INK_ERR_OKAY)
 
2916
    return INK_ERR_FAIL;
 
2917
 
 
2918
  //carry out the appropriate action
 
2919
  if (action_need < top_action_req)     // a more severe action
 
2920
    top_action_req = action_need;
 
2921
 
 
2922
  if (top_action_req != INK_ACTION_UNDEFINED) {
 
2923
    //return INKActionDo(top_action_req); //right now we mark this out as this is not needed and causes hangs - verify this FIX - bz49778
 
2924
    return INK_ERR_OKAY;
 
2925
  } else {
 
2926
    return INK_ERR_OKAY;
 
2927
  }
 
2928
}
 
2929
 
 
2930
inkapi INKError
 
2931
INKSetGateway(INKString gateway_ip)
 
2932
{
 
2933
  NOWARN_UNUSED(gateway_ip);
 
2934
  //Nothing to be done for now
 
2935
  return INK_ERR_OKAY;
 
2936
 
 
2937
}
 
2938
 
 
2939
inkapi INKError
 
2940
INKSetDNSServers(INKString dns_ips)
 
2941
{
 
2942
  NOWARN_UNUSED(dns_ips);
 
2943
  //Nothing to be done for now
 
2944
  return INK_ERR_OKAY;
 
2945
 
 
2946
}
 
2947
 
 
2948
inkapi INKError
 
2949
INKSetNICUp(INKString nic_name, bool static_ip, INKString ip, INKString old_ip, INKString netmask, bool onboot,
 
2950
            INKString gateway_ip)
 
2951
{
 
2952
  NOWARN_UNUSED(nic_name);
 
2953
  NOWARN_UNUSED(static_ip);
 
2954
  NOWARN_UNUSED(ip);
 
2955
  NOWARN_UNUSED(old_ip);
 
2956
  NOWARN_UNUSED(netmask);
 
2957
  NOWARN_UNUSED(onboot);
 
2958
  NOWARN_UNUSED(gateway_ip);
 
2959
  /* there is no ipnat conf file anymore,
 
2960
     commenting out the rest of this function */
 
2961
  return INK_ERR_READ_FILE;
 
2962
 
 
2963
  /*
 
2964
     INKCfgContext ctx;
 
2965
     INKIpFilterEle *ele, *ele_copy;
 
2966
     INKActionNeedT action_need=INK_ACTION_UNDEFINED;
 
2967
     int i, index;
 
2968
 
 
2969
     //ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
 
2970
 
 
2971
     if (!ctx) {
 
2972
     //Debug("config", "[INKSetNICUp] can't allocate ctx memory");
 
2973
     return INK_ERR_FAIL;
 
2974
     }
 
2975
 
 
2976
     if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
2977
     //if (ctx) INKCfgContextDestroy(ctx);
 
2978
     return INK_ERR_READ_FILE;
 
2979
     }
 
2980
 
 
2981
     if ((i =  INKCfgContextGetCount(ctx)) <=0 ) {
 
2982
     //if (ctx) INKCfgContextDestroy(ctx);
 
2983
     return INK_ERR_FAIL;
 
2984
     }
 
2985
 
 
2986
     if (strcmp(nic_name, "eth0") == 0) {  //currently we hard code it - should be changed
 
2987
     for (index=0 ; index<i ; index++) {
 
2988
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
2989
     if (ele != NULL) {
 
2990
     if (strcmp(ele->intr,nic_name) == 0) {
 
2991
     //if (strcmp(ele->dest_ip_addr, old_ip) == 0) //INKqa12486
 
2992
     ele->dest_ip_addr =  string_to_ip_addr(ip);
 
2993
     }
 
2994
     }
 
2995
     }
 
2996
     } else { //it is not eth0
 
2997
 
 
2998
     bool found = false;
 
2999
     for (index=0 ; index<i ; index++) {
 
3000
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
3001
     if (ele != NULL) {
 
3002
     if (strcmp(ele->intr,nic_name) == 0) {
 
3003
     found = true;
 
3004
     //if (strcmp(ele->dest_ip_addr, old_ip) == 0)  //INKqa12486
 
3005
     ele->dest_ip_addr =  string_to_ip_addr(ip);
 
3006
     }
 
3007
     }
 
3008
     }
 
3009
     if (!found) { //create the rules for the new NIC according to eth0
 
3010
     for (index=0 ; index<i ; index++) {
 
3011
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
3012
     if (ele != NULL) {
 
3013
     if (strcmp(ele->intr, "eth0") == 0) {
 
3014
     ele_copy = INKIpFilterEleCreate();
 
3015
     //copy the ele
 
3016
     ele_copy->intr =  xstrdup(nic_name); // ethernet interface
 
3017
     ele_copy->src_ip_addr = ele->src_ip_addr;  // from IP
 
3018
     ele_copy->src_cidr = ele->src_cidr;
 
3019
     ele_copy->src_port = ele->src_port;  // from port
 
3020
     ele_copy->dest_ip_addr =  string_to_ip_addr(ip); // to IP
 
3021
     ele_copy->dest_port = ele->dest_port;     // to port
 
3022
     ele_copy->type_con = ele->type_con;
 
3023
     ele_copy->protocol = ele->protocol;
 
3024
 
 
3025
     INKCfgContextAppendEle(ctx, (INKCfgEle*)ele_copy); // add new ele to end of list
 
3026
     }
 
3027
     }
 
3028
     }
 
3029
     }
 
3030
     }
 
3031
 
 
3032
     // commit the CfgContext to write a new version of the file
 
3033
     if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
 
3034
     //if (ctx) INKCfgContextDestroy(ctx);
 
3035
     return INK_ERR_FAIL;
 
3036
     }
 
3037
     //if (ctx) INKCfgContextDestroy(ctx);
 
3038
 
 
3039
 
 
3040
     if ( action_need != INK_ACTION_UNDEFINED ){
 
3041
     return INKActionDo(action_need);
 
3042
     }
 
3043
     else {
 
3044
     return INK_ERR_OKAY;
 
3045
     }
 
3046
   */
 
3047
}
 
3048
 
 
3049
inkapi INKError
 
3050
INKSetProxyPort(INKString proxy_port)
 
3051
{
 
3052
  NOWARN_UNUSED(proxy_port);
 
3053
  /* there is no ipnat.conf file anymore,
 
3054
     commenting out the rest of this function */
 
3055
  return INK_ERR_READ_FILE;
 
3056
 
 
3057
  /*
 
3058
     INKCfgContext ctx;
 
3059
     INKIpFilterEle *ele;
 
3060
     INKActionNeedT action_need=INK_ACTION_UNDEFINED;
 
3061
     int i, index;
 
3062
 
 
3063
     //ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
 
3064
     if (!ctx) {
 
3065
     //Debug("config", "[INKSetNICUp] can't allocate ctx memory");
 
3066
     return INK_ERR_FAIL;
 
3067
     }
 
3068
 
 
3069
     if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
3070
     //if (ctx) INKCfgContextDestroy(ctx);
 
3071
     return INK_ERR_READ_FILE;
 
3072
     }
 
3073
 
 
3074
     if ((i =  INKCfgContextGetCount(ctx)) <=0 ) {
 
3075
     //if (ctx) INKCfgContextDestroy(ctx);
 
3076
     return INK_ERR_FAIL;
 
3077
     }
 
3078
 
 
3079
     for (index=0 ; index<i ; index++) {
 
3080
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
3081
     if (ele != NULL) {
 
3082
     if (ele->src_port == 80) {
 
3083
     ele->dest_port = ink_atoi(proxy_port);
 
3084
     //  Debug("api2","[INKSetProxyPort] %d is the dest_port for port %d now.\n",ele->dest_port, ele->src_port);
 
3085
     }
 
3086
     }
 
3087
     }
 
3088
 
 
3089
     // commit the CfgContext to write a new version of the file
 
3090
     if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
 
3091
     //if (ctx) INKCfgContextDestroy(ctx);
 
3092
     return INK_ERR_FAIL;
 
3093
     }
 
3094
     //if (ctx) INKCfgContextDestroy(ctx);
 
3095
 
 
3096
     if ( action_need != INK_ACTION_UNDEFINED ){
 
3097
     return INKActionDo(action_need);
 
3098
     }
 
3099
     else {
 
3100
     return INK_ERR_OKAY;
 
3101
     }
 
3102
   */
 
3103
}
 
3104
 
 
3105
inkapi INKError
 
3106
INKSetNICDown(INKString nic_name, INKString ip_addrr)
 
3107
{
 
3108
  NOWARN_UNUSED(nic_name);
 
3109
  NOWARN_UNUSED(ip_addrr);
 
3110
  /* there is no ipnat.conf file anymore,
 
3111
     commenting out the rest of this function */
 
3112
  return INK_ERR_READ_FILE;
 
3113
 
 
3114
  /*
 
3115
     INKCfgContext ctx;
 
3116
     INKIpFilterEle *ele;
 
3117
     INKActionNeedT action_need = INK_ACTION_UNDEFINED;
 
3118
     int index;
 
3119
     // This isn't used any more, code commented out below. /leif
 
3120
     //INKCfgIterState ctx_state;
 
3121
     bool found;
 
3122
 
 
3123
     //ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
 
3124
 
 
3125
     if (!ctx) {
 
3126
     //Debug("config", "[INKSetNicDown] can't allocate ctx memory");
 
3127
     return INK_ERR_FAIL;
 
3128
     }
 
3129
 
 
3130
     if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
3131
     //if (ctx) INKCfgContextDestroy(ctx);
 
3132
     return INK_ERR_READ_FILE;
 
3133
     }
 
3134
 
 
3135
     ele = (INKIpFilterEle *)INKCfgContextGetFirst(ctx, &ctx_state);
 
3136
 
 
3137
     while (ele) {
 
3138
     if (strcmp(ele->intr, nic_name) == 0)  INKCfgContextRemoveEleAt (ctx, index);
 
3139
     ele = (INKIpFilterEle *)INKCfgContextGetNext(ctx, &ctx_state);
 
3140
 
 
3141
     }
 
3142
     found = true;
 
3143
     while (found) {
 
3144
     found = false;
 
3145
     for (index=0 ; index< INKCfgContextGetCount(ctx); index++) {
 
3146
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
3147
     if (ele != NULL) {
 
3148
     if (strcmp(ele->intr, nic_name) == 0)  {
 
3149
     INKCfgContextRemoveEleAt (ctx, index);
 
3150
     found = true;
 
3151
     }
 
3152
     }
 
3153
     }
 
3154
     }
 
3155
 
 
3156
     // commit the CfgContext to write a new version of the file
 
3157
     if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
 
3158
     //if (ctx) INKCfgContextDestroy(ctx);
 
3159
     return INK_ERR_FAIL;
 
3160
     }
 
3161
     //if (ctx) INKCfgContextDestroy(ctx);
 
3162
 
 
3163
     if ( action_need != INK_ACTION_UNDEFINED) {
 
3164
     return INKActionDo(action_need);
 
3165
     }
 
3166
     else {
 
3167
     return INK_ERR_OKAY;
 
3168
     }
 
3169
   */
 
3170
}
 
3171
 
 
3172
 
 
3173
inkapi INKError
 
3174
INKSetSearchDomain(const char *search_name)
 
3175
{
 
3176
  NOWARN_UNUSED(search_name);
 
3177
  //Nothing to be done for now
 
3178
  return INK_ERR_OKAY;
 
3179
}
 
3180
 
 
3181
/* The following 2 functions set the Realm field in rmserver.cfg file. */
 
3182
void
 
3183
resetHostName(INKRmServerEle * ele, const char *hostname, const char *tail)
 
3184
{
 
3185
  char buff[MAX_RULE_SIZE];
 
3186
  xfree(ele->str_val);
 
3187
  snprintf(buff, sizeof(buff), "%s.%s", hostname, tail);
 
3188
  ele->str_val = xstrdup(buff);
 
3189
  return;
 
3190
}
 
3191
 
 
3192
INKError
 
3193
INKSetRmRealm(const char *hostname)
 
3194
{
 
3195
 
 
3196
  INKCfgContext ctx;
 
3197
  INKRmServerEle *ele;
 
3198
  Tokenizer tokens("\n");
 
3199
  INKActionNeedT action_need;
 
3200
  INKError response;
 
3201
  INKError err = INK_ERR_OKAY;
 
3202
 
 
3203
 
 
3204
  ctx = INKCfgContextCreate(INK_FNAME_RMSERVER);
 
3205
  if (!ctx) {
 
3206
//    Debug("config", "[net_config:Config] can't allocate ctx memory");
 
3207
    goto Lerror;
 
3208
  }
 
3209
  if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
3210
//    Debug("config", "[net_config:Config] Failed to Get CfgContext");
 
3211
    goto Lerror;
 
3212
  }
 
3213
  ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_SCU_ADMIN_REALM);
 
3214
  resetHostName(ele, hostname, "AdminRealm");
 
3215
  ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_CNN_REALM);
 
3216
  resetHostName(ele, hostname, "ConnectRealm");
 
3217
  ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_ADMIN_FILE_REALM);
 
3218
  resetHostName(ele, hostname, "AdminRealm");
 
3219
  ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_AUTH_REALM);
 
3220
  resetHostName(ele, hostname, "ConnectRealm");
 
3221
  response = INKCfgContextCommit(ctx, &action_need, NULL);
 
3222
  if (response == INK_ERR_INVALID_CONFIG_RULE) {
 
3223
    //    MgmtAPI should return INK_ not WEB_
 
3224
    //    err = WEB_HTTP_ERR_INVALID_CFG_RULE;
 
3225
    err = INK_ERR_INVALID_CONFIG_RULE;
 
3226
  } else if (response != INK_ERR_OKAY) {
 
3227
    goto Lerror;
 
3228
  }
 
3229
  INKCfgContextDestroy(ctx);
 
3230
  return err;
 
3231
 
 
3232
Lerror:
 
3233
  if (ctx)
 
3234
    INKCfgContextDestroy(ctx);
 
3235
  return err;
 
3236
}
 
3237
 
 
3238
/* this function change the PNA_REDIREDT IP address of rmserver.cfg file. */
 
3239
INKError
 
3240
INKSetRmPNA_RDT_IP(const char *ip)
 
3241
{
 
3242
  INKCfgContext ctx;
 
3243
  INKRmServerEle *ele;
 
3244
  Tokenizer tokens("\n");
 
3245
  INKActionNeedT action_need;
 
3246
  INKError response;
 
3247
  INKError err = INK_ERR_OKAY;
 
3248
  char buff[MAX_RULE_SIZE];
 
3249
 
 
3250
  ctx = INKCfgContextCreate(INK_FNAME_RMSERVER);
 
3251
  if (!ctx) {
 
3252
//    Debug("config", "[net_config:Config] can't allocate ctx memory");
 
3253
    goto Lerror;
 
3254
  }
 
3255
  if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
3256
//    Debug("config", "[net_config:Config] Failed to Get CfgContext");
 
3257
    goto Lerror;
 
3258
  }
 
3259
  ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_PNA_RDT_IP);
 
3260
  if (ele->str_val)
 
3261
    xfree(ele->str_val);
 
3262
  snprintf(buff, sizeof(buff), "%s", ip);
 
3263
  ele->str_val = xstrdup(buff);
 
3264
 
 
3265
  response = INKCfgContextCommit(ctx, &action_need, NULL);
 
3266
  if (response == INK_ERR_INVALID_CONFIG_RULE) {
 
3267
    //    MgmtAPI should return INK_ not WEB_
 
3268
    //    err = WEB_HTTP_ERR_INVALID_CFG_RULE;
 
3269
    err = INK_ERR_INVALID_CONFIG_RULE;
 
3270
  } else if (response != INK_ERR_OKAY) {
 
3271
    goto Lerror;
 
3272
  }
 
3273
  //INKCfgContextDestroy(ctx);
 
3274
  return err;
 
3275
 
 
3276
Lerror:
 
3277
  if (ctx)
 
3278
    INKCfgContextDestroy(ctx);
 
3279
  return err;
 
3280
}
 
3281
 
 
3282
/* this function change the PNA_REDIRET port in  ipnat.conf file. */
 
3283
inkapi INKError
 
3284
INKSetPNA_RDT_Port(const int port)
 
3285
{
 
3286
  NOWARN_UNUSED(port);
 
3287
  /* there is no ipnat conf file anymore,
 
3288
     commenting out the rest of this function */
 
3289
  return INK_ERR_READ_FILE;
 
3290
 
 
3291
  /*
 
3292
     INKCfgContext ctx;
 
3293
     INKIpFilterEle *ele;
 
3294
     INKActionNeedT action_need=INK_ACTION_UNDEFINED;
 
3295
     int i, index;
 
3296
 
 
3297
 
 
3298
     //ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
 
3299
 
 
3300
     if (!ctx) {
 
3301
     return INK_ERR_FAIL;
 
3302
     }
 
3303
 
 
3304
     if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
 
3305
     return INK_ERR_READ_FILE;
 
3306
     }
 
3307
     if ((i =  INKCfgContextGetCount(ctx)) <=0 ) {
 
3308
     return INK_ERR_FAIL;
 
3309
     }
 
3310
 
 
3311
     for (index=0 ; index<i ; index++) {
 
3312
     ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
 
3313
     if (ele != NULL) {
 
3314
     if (ele->src_port == 7070) {
 
3315
     ele->dest_port = port;
 
3316
     break;
 
3317
     }
 
3318
     }
 
3319
     }
 
3320
 
 
3321
     // commit the CfgContext to write a new version of the file
 
3322
     if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
 
3323
     return INK_ERR_FAIL;
 
3324
     }
 
3325
 
 
3326
     if ( action_need != INK_ACTION_UNDEFINED) {
 
3327
     return INKActionDo(action_need);
 
3328
     }
 
3329
     else {
 
3330
     return INK_ERR_OKAY;
 
3331
     }
 
3332
   */
 
3333
}