1
0

repl5_schedule.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* repl5_schedule.c */
  42. /*
  43. The schedule object implements the scheduling policy for a DS 5.0 replication
  44. supplier.
  45. Methods:
  46. schedule_set() - sets the schedule
  47. schedule_get() - gets the schedule
  48. schedule_in_window_now() - returns TRUE if a replication session
  49. should commence.
  50. schedule_next() - returns the next time that replication is
  51. scheduled to occur.
  52. schedule_notify() - called to inform the scheduler when entries
  53. have been updated.
  54. schedule_set_priority_attributes() - sets the attributes that are
  55. considered "high priority". A modification to one of these attributes
  56. will cause replication to commence asap, overriding the startup
  57. delay and maximum backlog. Also includes an additional parameter
  58. that controls whether priority attributes are propagated regardless
  59. of the scheduling window, e.g. it's possible to configure things
  60. so that password changes get propagated even if we're not in a
  61. replication window.
  62. schedule_set_startup_delay() - sets the time that replication should
  63. wait before commencing replication sessions.
  64. schedule_set_maximum_backlog() - sets the maximum number of updates
  65. which can occur before replication will commence. If the backlog
  66. threshhold is exceeded, then replication will commence ASAP,
  67. overriding the startup delay.
  68. */
  69. /* ONREPL - I made a simplifying assumption that a schedule item does not
  70. cross day boundaries. Implementing this is hard because we search
  71. for the items for a particular day only based on the item's staring time.
  72. For instance if the current time is tuesday morning, we would not consider
  73. the item that started on monday and continued through tuesday.
  74. To simulate an item that crosses day boundaries, you can create 2 items -
  75. one for the time in the first day and one for the time in the second.
  76. We could do this internally by allowing items do span 2 days and
  77. splitting them ourselves. This, however, is not currently implemented */
  78. #include "slapi-plugin.h"
  79. #include "repl5.h"
  80. #include <ctype.h> /* For isdigit() */
  81. /* from proto-slap.h */
  82. char *get_timestring(time_t *t);
  83. void free_timestring(char *timestr);
  84. typedef struct schedule_item {
  85. struct schedule_item *next;
  86. PRUint32 start; /* Start time, given as seconds after midnight */
  87. PRUint32 end; /* End time */
  88. unsigned char dow; /* Days of week, LSB = Sunday */
  89. } schedule_item;
  90. typedef struct schedule {
  91. const char *session_id;
  92. size_t max_backlog;
  93. size_t startup_delay;
  94. schedule_item *schedule_list; /* Linked list of schedule windows */
  95. char **prio_attrs; /* Priority attributes - start replication now */
  96. int prio_attrs_override_schedule;
  97. PRTime last_session_end;
  98. int last_session_status;
  99. PRTime last_successful_session_end;
  100. window_state_change_callback callback_fn; /* function to call when window opens/closes */
  101. void *callback_arg; /* argument to pass to the window state change callback */
  102. Slapi_Eq_Context pending_event; /* event scheduled with the event queue */
  103. PRLock *lock;
  104. } schedule;
  105. /* Forward declarations */
  106. static schedule_item *parse_schedule_value(const Slapi_Value *v);
  107. static void schedule_window_state_change_event (Schedule *sch);
  108. static void unschedule_window_state_change_event (Schedule *sch);
  109. static void window_state_changed (time_t when, void *arg);
  110. static int schedule_in_window_now_nolock(Schedule *sch);
  111. static time_t PRTime2time_t (PRTime tm);
  112. static PRTime schedule_next_nolock (Schedule *sch, PRBool start);
  113. static void free_schedule_list(schedule_item **schedule_list);
  114. #define SECONDS_PER_MINUTE 60
  115. #define SECONDS_PER_HOUR (60 * SECONDS_PER_MINUTE)
  116. #define SECONDS_PER_DAY (24 * SECONDS_PER_HOUR)
  117. #define DAYS_PER_WEEK 7
  118. #define ALL_DAYS 0x7F /* Bit mask */
  119. /*
  120. * Create a new schedule object and return a pointer to it.
  121. */
  122. Schedule*
  123. schedule_new(window_state_change_callback callback_fn, void *callback_arg, const char *session_id)
  124. {
  125. Schedule *sch = NULL;
  126. sch = (Schedule *)slapi_ch_calloc(1, sizeof(struct schedule));
  127. sch->session_id = session_id ? session_id : "";
  128. sch->callback_fn = callback_fn;
  129. sch->callback_arg = callback_arg;
  130. if ((sch->lock = PR_NewLock()) == NULL)
  131. {
  132. slapi_ch_free((void **)&sch);
  133. }
  134. return sch;
  135. }
  136. void
  137. schedule_destroy(Schedule *s)
  138. {
  139. int i;
  140. /* unschedule update window event if exists */
  141. unschedule_window_state_change_event (s);
  142. if (s->schedule_list)
  143. {
  144. free_schedule_list (&s->schedule_list);
  145. }
  146. if (NULL != s->prio_attrs)
  147. {
  148. for (i = 0; NULL != s->prio_attrs[i]; i++)
  149. {
  150. slapi_ch_free((void **)&(s->prio_attrs[i]));
  151. }
  152. slapi_ch_free((void **)&(s->prio_attrs));
  153. }
  154. PR_DestroyLock(s->lock);
  155. s->lock = NULL;
  156. slapi_ch_free((void **)&s);
  157. }
  158. static void
  159. free_schedule_list(schedule_item **schedule_list)
  160. {
  161. schedule_item *si = *schedule_list;
  162. schedule_item *tmp_si;
  163. while (NULL != si)
  164. {
  165. tmp_si = si->next;
  166. slapi_ch_free((void **)&si);
  167. si = tmp_si;
  168. }
  169. *schedule_list = NULL;
  170. }
  171. /*
  172. * Sets the schedule. Returns 0 if all of the schedule lines were
  173. * correctly parsed and the new schedule has been put into effect.
  174. * Returns -1 if one or more of the schedule items could not be
  175. * parsed. If -1 is returned, then no changes have been made to the
  176. * current schedule.
  177. */
  178. int
  179. schedule_set(Schedule *sch, Slapi_Attr *attr)
  180. {
  181. int return_value;
  182. schedule_item *si = NULL;
  183. schedule_item *new_schedule_list = NULL;
  184. int valid = 1;
  185. if (NULL != attr)
  186. {
  187. int ind;
  188. Slapi_Value *sval;
  189. ind = slapi_attr_first_value(attr, &sval);
  190. while (ind >= 0)
  191. {
  192. si = parse_schedule_value(sval);
  193. if (NULL == si)
  194. {
  195. valid = 0;
  196. break;
  197. }
  198. /* Put at head of linked list */
  199. si->next = new_schedule_list;
  200. new_schedule_list = si;
  201. ind = slapi_attr_next_value(attr, ind, &sval);
  202. }
  203. }
  204. if (!valid)
  205. {
  206. /* deallocate any new schedule items */
  207. free_schedule_list(&new_schedule_list);
  208. return_value = -1;
  209. }
  210. else
  211. {
  212. PR_Lock(sch->lock);
  213. /* if there is an update window event scheduled - unschedule it */
  214. unschedule_window_state_change_event (sch);
  215. free_schedule_list(&sch->schedule_list);
  216. sch->schedule_list = new_schedule_list;
  217. /* schedule an event to notify the caller about openning/closing of the update window */
  218. schedule_window_state_change_event (sch);
  219. PR_Unlock(sch->lock);
  220. return_value = 0;
  221. }
  222. return return_value;
  223. }
  224. /*
  225. * Returns the schedule.
  226. */
  227. char **
  228. schedule_get(Schedule *sch)
  229. {
  230. char **return_value = NULL;
  231. return return_value;
  232. }
  233. /*
  234. * Return an integer corresponding to the day of the week for
  235. * "when".
  236. */
  237. static PRInt32
  238. day_of_week(PRTime when)
  239. {
  240. PRExplodedTime exp;
  241. PR_ExplodeTime(when, PR_LocalTimeParameters, &exp);
  242. return(exp.tm_wday);
  243. }
  244. /*
  245. * Return the number of seconds between "when" and the
  246. * most recent midnight.
  247. */
  248. static PRUint32
  249. seconds_since_midnight(PRTime when)
  250. {
  251. PRExplodedTime exp;
  252. PR_ExplodeTime(when, PR_LocalTimeParameters, &exp);
  253. return(exp.tm_hour * 3600 + exp.tm_min * 60 + exp.tm_sec);
  254. }
  255. /*
  256. * Return 1 if "now" is within the schedule window
  257. * specified by "si", 0 otherwise.
  258. */
  259. static int
  260. time_in_window(PRTime now, schedule_item *si)
  261. {
  262. unsigned char dow = 1 << day_of_week(now);
  263. int return_value = 0;
  264. if (dow & si->dow)
  265. {
  266. PRUint32 nowsec = seconds_since_midnight(now);
  267. return_value = (nowsec >= si->start) && (nowsec <= si->end);
  268. }
  269. return return_value;
  270. }
  271. /*
  272. * Returns a non-zero value if the current time is within a
  273. * replication window and if scheduling constraints are all met.
  274. * Otherwise, returns zero.
  275. */
  276. int
  277. schedule_in_window_now (Schedule *sch)
  278. {
  279. int rc;
  280. PR_ASSERT(NULL != sch);
  281. PR_Lock(sch->lock);
  282. rc = schedule_in_window_now_nolock(sch);
  283. PR_Unlock(sch->lock);
  284. return rc;
  285. }
  286. /* Must be called under sch->lock */
  287. static int
  288. schedule_in_window_now_nolock(Schedule *sch)
  289. {
  290. int return_value = 0;
  291. if (NULL == sch->schedule_list)
  292. {
  293. /* Absence of a schedule is the same as 0000-2359 0123456 */
  294. return_value = 1;
  295. }
  296. else
  297. {
  298. schedule_item *si = sch->schedule_list;
  299. PRTime now;
  300. now = PR_Now();
  301. while (NULL != si)
  302. {
  303. if (time_in_window(now, si))
  304. {
  305. /* XXX check backoff timers??? */
  306. return_value = 1;
  307. break;
  308. }
  309. si = si->next;
  310. }
  311. }
  312. return return_value;
  313. }
  314. /*
  315. * Calculate the next time (expressed as a PRTime) when this
  316. * schedule item will change state (from open to close or vice versa).
  317. */
  318. static PRTime
  319. next_change_time(schedule_item *si, PRTime now, PRBool start)
  320. {
  321. PRUint32 nowsec = seconds_since_midnight(now);
  322. PRUint32 sec_til_change;
  323. PRUint32 change_time;
  324. PRExplodedTime exp;
  325. PRInt32 dow = day_of_week(now);
  326. unsigned char dow_bit = 1 << dow;
  327. unsigned char next_dow;
  328. if (start) /* we are looking for the next window opening */
  329. {
  330. change_time = si->start;
  331. }
  332. else /* we are looking for the next window closing */
  333. {
  334. /* open range is inclusive - so we need to add a minute if we are looking for close time */
  335. change_time = si->end + SECONDS_PER_MINUTE;
  336. }
  337. /* we are replicating today and next change is also today */
  338. if ((dow_bit & si->dow) && (nowsec < change_time))
  339. {
  340. sec_til_change = change_time - nowsec;
  341. }
  342. else /* not replicating today or the change already occured today */
  343. {
  344. int i;
  345. /* find next day when we replicate */
  346. for (i = 1; i <= DAYS_PER_WEEK; i++)
  347. {
  348. next_dow = 1 << ((dow + i) % DAYS_PER_WEEK);
  349. if (next_dow & si->dow)
  350. break;
  351. }
  352. sec_til_change = change_time + i * SECONDS_PER_DAY - nowsec;
  353. }
  354. PR_ExplodeTime(now, PR_LocalTimeParameters, &exp);
  355. exp.tm_sec += sec_til_change;
  356. PR_NormalizeTime(&exp, PR_LocalTimeParameters);
  357. return PR_ImplodeTime(&exp);
  358. }
  359. /*
  360. * Returns the next time that replication is scheduled to occur.
  361. * Returns 0 if there is no time in the future that replication
  362. * will begin (e.g. there's no schedule at all).
  363. */
  364. PRTime
  365. schedule_next(Schedule *sch)
  366. {
  367. PRTime tm;
  368. PR_ASSERT(NULL != sch);
  369. PR_Lock(sch->lock);
  370. tm = schedule_next_nolock (sch, PR_TRUE);
  371. PR_Unlock(sch->lock);
  372. return tm;
  373. }
  374. /* Must be called under sch->lock */
  375. static PRTime
  376. schedule_next_nolock (Schedule *sch, PRBool start)
  377. {
  378. PRTime closest_time = LL_Zero();
  379. if (NULL != sch->schedule_list)
  380. {
  381. schedule_item *si = sch->schedule_list;
  382. PRTime now = PR_Now();
  383. while (NULL != si)
  384. {
  385. PRTime tmp_time;
  386. /* Check if this item's change time is sooner than the others */
  387. tmp_time = next_change_time(si, now, start);
  388. if (LL_IS_ZERO(closest_time))
  389. {
  390. LL_ADD(closest_time, tmp_time, LL_Zero()); /* Really just an asignment */
  391. }
  392. else if (LL_CMP(tmp_time, <, closest_time))
  393. {
  394. LL_ADD(closest_time, tmp_time, LL_Zero()); /* Really just an asignment */
  395. }
  396. si = si->next;
  397. }
  398. }
  399. return closest_time;
  400. }
  401. /*
  402. * Called by the enclosing object (replsupplier) when a change within the
  403. * replicated area has occurred. This allows the scheduler to update its
  404. * internal counters, timers, etc. Returns a non-zero value if replication
  405. * should commence, zero if it should not.
  406. */
  407. int
  408. schedule_notify(Schedule *sch, Slapi_PBlock *pb)
  409. {
  410. int return_value = 0;
  411. return return_value;
  412. }
  413. /*
  414. * Provide a list of attributes which, if changed,
  415. * will cause replication to commence as soon as possible. There
  416. * is also a flag that tells the scheduler if the update of a
  417. * priority attribute should cause the schedule to be overridden,
  418. * e.g. if the administrator wants password changes to propagate
  419. * even if not in a replication window.
  420. *
  421. * This function consumes "prio_attrs" and assumes management
  422. * of the memory.
  423. */
  424. void
  425. schedule_set_priority_attributes(Schedule *sch, char **prio_attrs, int override_schedule)
  426. {
  427. PR_ASSERT(NULL != sch);
  428. PR_Lock(sch->lock);
  429. if (NULL != sch->prio_attrs)
  430. {
  431. int i;
  432. for (i = 0; NULL != prio_attrs[i]; i++) {
  433. slapi_ch_free((void **)&sch->prio_attrs[i]);
  434. }
  435. slapi_ch_free((void **)&sch->prio_attrs);
  436. }
  437. sch->prio_attrs = prio_attrs;
  438. sch->prio_attrs_override_schedule = override_schedule;
  439. PR_Unlock(sch->lock);
  440. }
  441. /*
  442. * Set the time, in seconds, that replication will wait after a change is
  443. * available before propagating it. This capability will allow multiple
  444. * updates to be coalesced into a single replication session.
  445. */
  446. void
  447. schedule_set_startup_delay(Schedule *sch, size_t startup_delay)
  448. {
  449. PR_ASSERT(NULL != sch);
  450. PR_Lock(sch->lock);
  451. sch->startup_delay = startup_delay;
  452. PR_Unlock(sch->lock);
  453. }
  454. /*
  455. * Set the maximum number of pending changes allowed to accumulate
  456. * before a replication session is begun.
  457. */
  458. void
  459. schedule_set_maximum_backlog(Schedule *sch, size_t max_backlog)
  460. {
  461. PR_ASSERT(NULL != sch);
  462. PR_Lock(sch->lock);
  463. sch->max_backlog = max_backlog;
  464. PR_Unlock(sch->lock);
  465. }
  466. /*
  467. * Notify the scheduler that a replication session completed at a certain
  468. * time. There is also a status argument that says more about the session's
  469. * termination (normal, abnormal), which the scheduler uses in determining
  470. * the backoff strategy.
  471. */
  472. void
  473. schedule_notify_session(Schedule *sch, PRTime session_end_time, unsigned int status)
  474. {
  475. PR_ASSERT(NULL != sch);
  476. PR_Lock(sch->lock);
  477. sch->last_session_end = session_end_time;
  478. sch->last_session_status = status;
  479. if (REPLICATION_SESSION_SUCCESS == status)
  480. {
  481. sch->last_successful_session_end = session_end_time;
  482. }
  483. PR_Unlock(sch->lock);
  484. }
  485. /* schedule an event that will fire the next time the update window state
  486. changes from open to closed or vice versa */
  487. static void
  488. schedule_window_state_change_event (Schedule *sch)
  489. {
  490. time_t wakeup_time;
  491. PRTime tm;
  492. int window_opened;
  493. char *timestr = NULL;
  494. /* if we have a schedule and a callback function is registerd -
  495. register an event with the event queue */
  496. if (sch->schedule_list && sch->callback_fn)
  497. {
  498. /* ONREPL what if the window is really small and by the time we are done
  499. with the computation - we cross window boundary.
  500. I think we should put some constrains on schedule to avoid that */
  501. window_opened = schedule_in_window_now_nolock(sch);
  502. tm = schedule_next_nolock(sch, !window_opened);
  503. wakeup_time = PRTime2time_t (tm);
  504. /* schedule the event */
  505. sch->pending_event = slapi_eq_once(window_state_changed, sch, wakeup_time);
  506. timestr = get_timestring(&wakeup_time);
  507. slapi_log_error (SLAPI_LOG_REPL, repl_plugin_name, "%s: Update window will %s at %s\n",
  508. sch->session_id,
  509. window_opened ? "close" : "open", timestr);
  510. free_timestring(timestr);
  511. timestr = NULL;
  512. }
  513. }
  514. /* this function is called by the even queue the next time
  515. the window is opened or closed */
  516. static void
  517. window_state_changed (time_t when, void *arg)
  518. {
  519. Schedule *sch = (Schedule*)arg;
  520. int open;
  521. PR_ASSERT (sch);
  522. PR_Lock(sch->lock);
  523. open = schedule_in_window_now_nolock(sch);
  524. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "%s: Update window is now %s\n",
  525. sch->session_id,
  526. open ? "open" : "closed");
  527. /* schedule next event */
  528. schedule_window_state_change_event (sch);
  529. /* notify the agreement */
  530. sch->callback_fn (sch->callback_arg, open);
  531. PR_Unlock(sch->lock);
  532. }
  533. /* cancel the event registered with the event queue */
  534. static void
  535. unschedule_window_state_change_event (Schedule *sch)
  536. {
  537. if (sch->pending_event)
  538. {
  539. slapi_eq_cancel(sch->pending_event);
  540. sch->pending_event = NULL;
  541. }
  542. }
  543. static time_t
  544. PRTime2time_t (PRTime tm)
  545. {
  546. PRInt64 rt;
  547. PR_ASSERT (tm);
  548. LL_DIV(rt, tm, PR_USEC_PER_SEC);
  549. return (time_t)rt;
  550. }
  551. /*
  552. * Parse a schedule line.
  553. * The format is:
  554. * <start>-<end> <day_of_week>
  555. * <start> and <end> are in 24-hour time
  556. * <day_of_week> is like cron(5): 0 = Sunday, 1 = Monday, etc.
  557. *
  558. * The schedule item "*" is equivalen to 0000-2359 0123456
  559. *
  560. * Returns a pointer to a schedule item on success, NULL if the
  561. * schedule item cannot be parsed.
  562. */
  563. static schedule_item *
  564. parse_schedule_value(const Slapi_Value *v)
  565. {
  566. #define RANGE_VALID(p, limit) \
  567. ((p + 9) < limit && \
  568. isdigit(p[0]) && \
  569. isdigit(p[1]) && \
  570. isdigit(p[2]) && \
  571. isdigit(p[3]) && \
  572. ('-' == p[4]) && \
  573. isdigit(p[5]) && \
  574. isdigit(p[6]) && \
  575. isdigit(p[7]) && \
  576. isdigit(p[8]))
  577. schedule_item *si = NULL;
  578. int valid = 0;
  579. const struct berval *sch_bval;
  580. if (NULL != v && (sch_bval = slapi_value_get_berval(v)) != NULL &&
  581. NULL != sch_bval && sch_bval->bv_len > 0 && NULL != sch_bval->bv_val )
  582. {
  583. char *p = sch_bval->bv_val;
  584. char *limit = p + sch_bval->bv_len;
  585. si = (schedule_item *)slapi_ch_malloc(sizeof(schedule_item));
  586. si->next = NULL;
  587. si->start = 0UL;
  588. si->end = SECONDS_PER_DAY;
  589. si->dow = ALL_DAYS;
  590. if (*p == '*')
  591. {
  592. valid = 1;
  593. goto done;
  594. }
  595. else
  596. {
  597. if (RANGE_VALID(p, limit))
  598. {
  599. si->start = ((strntoul(p, 2, 10) * 60) +
  600. strntoul(p + 2, 2, 10)) * 60;
  601. p += 5;
  602. si->end = ((strntoul(p, 2, 10) * 60) +
  603. strntoul(p + 2, 2, 10)) * 60;
  604. p += 4;
  605. /* ONREPL - for now wi don't allow items that span multiple days.
  606. See note in the beginning of the file for more details. */
  607. /* ONREPL - we should also decide on the minimum of the item size */
  608. if (si->start > si->end)
  609. {
  610. valid = 0;
  611. goto done;
  612. }
  613. if (p < limit && ' ' == *p)
  614. {
  615. /* Specific days of week */
  616. si->dow = 0;
  617. while (++p < limit)
  618. {
  619. if (!isdigit(*p))
  620. {
  621. valid = 0;
  622. goto done;
  623. }
  624. si->dow |= (1 << strntoul(p, 1, 10));
  625. }
  626. }
  627. valid = 1;
  628. }
  629. }
  630. }
  631. done:
  632. if (!valid)
  633. {
  634. slapi_ch_free((void **)&si);
  635. }
  636. return si;
  637. }