Lines Matching full:s
79 xstrdup(const char *s)
82 if ((r = strdup(s)) == NULL)
130 rrdp_state_send(struct rrdp *s)
137 io_simple_buffer(b, &s->id, sizeof(s->id));
138 rrdp_session_buffer(b, s->current);
146 rrdp_clear_repo(struct rrdp *s)
153 io_simple_buffer(b, &s->id, sizeof(s->id));
161 rrdp_publish_file(struct rrdp *s, struct publish_xml *pxml,
168 if (s->file_failed == 0) {
171 io_simple_buffer(b, &s->id, sizeof(s->id));
178 s->file_pending++;
185 struct rrdp *s;
187 if ((s = calloc(1, sizeof(*s))) == NULL)
190 s->infd = -1;
191 s->id = id;
192 s->local = local;
193 s->notifyuri = notify;
194 s->repository = state;
195 if ((s->current = calloc(1, sizeof(*s->current))) == NULL)
198 s->state = RRDP_STATE_REQ;
199 if ((s->parser = XML_ParserCreate("US-ASCII")) == NULL)
202 s->nxml = new_notification_xml(s->parser, s->repository, s->current,
205 TAILQ_INSERT_TAIL(&states, s, entry);
209 rrdp_free(struct rrdp *s)
211 if (s == NULL)
214 TAILQ_REMOVE(&states, s, entry);
216 free_notification_xml(s->nxml);
217 free_snapshot_xml(s->sxml);
218 free_delta_xml(s->dxml);
220 if (s->parser)
221 XML_ParserFree(s->parser);
222 if (s->infd != -1)
223 close(s->infd);
224 free(s->notifyuri);
225 free(s->local);
226 free(s->last_mod);
227 rrdp_session_free(s->repository);
228 rrdp_session_free(s->current);
230 free(s);
236 struct rrdp *s;
238 TAILQ_FOREACH(s, &states, entry)
239 if (s->id == id)
241 return s;
245 rrdp_failed(struct rrdp *s)
247 unsigned int id = s->id;
250 s->file_failed = 0;
252 if (s->task == DELTA && !s->aborted) {
254 free_delta_xml(s->dxml);
255 s->dxml = NULL;
256 rrdp_clear_repo(s);
257 s->sxml = new_snapshot_xml(s->parser, s->current, s);
258 s->task = SNAPSHOT;
259 s->state = RRDP_STATE_REQ;
260 logx("%s: delta sync failed, fallback to snapshot", s->local);
267 rrdp_free(s);
273 rrdp_finished(struct rrdp *s)
275 unsigned int id = s->id;
278 if ((s->state & RRDP_STATE_DONE) != RRDP_STATE_DONE)
282 if (s->file_pending > 0)
285 if (s->state & RRDP_STATE_PARSE_ERROR || s->aborted) {
286 rrdp_failed(s);
290 if (s->res == HTTP_OK) {
291 XML_Parser p = s->parser;
300 warnx("%s: XML error at line %llu: %s", s->local,
303 rrdp_failed(s);
308 if (s->file_failed > 0) {
309 rrdp_failed(s);
313 switch (s->task) {
315 s->task = notification_done(s->nxml, s->last_mod);
316 s->last_mod = NULL;
317 switch (s->task) {
319 logx("%s: repository not modified (%s#%lld)",
320 s->local, s->repository->session_id,
321 s->repository->serial);
322 rrdp_state_send(s);
323 rrdp_free(s);
327 logx("%s: downloading snapshot (%s#%lld)",
328 s->local, s->current->session_id,
329 s->current->serial);
330 rrdp_clear_repo(s);
331 s->sxml = new_snapshot_xml(p, s->current, s);
332 s->state = RRDP_STATE_REQ;
335 logx("%s: downloading %lld deltas (%s#%lld)",
336 s->local,
337 s->repository->serial - s->current->serial,
338 s->current->session_id, s->current->serial);
339 s->dxml = new_delta_xml(p, s->current, s);
340 s->state = RRDP_STATE_REQ;
345 rrdp_state_send(s);
346 rrdp_free(s);
350 if (notification_delta_done(s->nxml)) {
352 rrdp_state_send(s);
353 rrdp_free(s);
357 free_delta_xml(s->dxml);
358 s->dxml = new_delta_xml(p, s->current, s);
359 s->state = RRDP_STATE_REQ;
363 } else if (s->res == HTTP_NOT_MOD && s->task == NOTIFICATION) {
364 logx("%s: notification file not modified (%s#%lld)", s->local,
365 s->repository->session_id, s->repository->serial);
367 rrdp_free(s);
370 rrdp_failed(s);
375 rrdp_abort_req(struct rrdp *s)
377 unsigned int id = s->id;
379 s->aborted = 1;
380 if (s->state == RRDP_STATE_REQ) {
382 rrdp_free(s);
386 if (s->state == RRDP_STATE_WAIT)
394 if (s->infd != -1) {
395 close(s->infd);
396 s->infd = -1;
397 s->state |= RRDP_STATE_PARSE_DONE | RRDP_STATE_PARSE_ERROR;
399 rrdp_finished(s);
407 struct rrdp *s;
426 s = rrdp_get(id);
427 if (s == NULL)
429 if (s->state != RRDP_STATE_WAIT)
430 errx(1, "%s: bad internal state", s->local);
431 s->infd = ibuf_fd_get(b);
432 if (s->infd == -1)
434 s->state = RRDP_STATE_PARSE;
435 if (s->aborted) {
436 rrdp_abort_req(s);
446 s = rrdp_get(id);
447 if (s == NULL)
449 if (!(s->state & RRDP_STATE_PARSE))
450 errx(1, "%s: bad internal state", s->local);
451 s->state |= RRDP_STATE_HTTP_DONE;
452 s->res = res;
453 free(s->last_mod);
454 s->last_mod = last_mod;
455 rrdp_finished(s);
458 s = rrdp_get(id);
459 if (s == NULL)
465 s->file_failed++;
466 s->file_pending--;
467 if (s->file_pending == 0)
468 rrdp_finished(s);
473 s = rrdp_get(id);
474 if (s != NULL)
475 rrdp_abort_req(s);
483 rrdp_data_handler(struct rrdp *s)
486 XML_Parser p = s->parser;
489 len = read(s->infd, buf, sizeof(buf));
491 warn("%s: read failure", s->local);
492 rrdp_abort_req(s);
495 if ((s->state & RRDP_STATE_PARSE) == 0)
496 errx(1, "%s: bad parser state", s->local);
499 close(s->infd);
500 s->infd = -1;
502 if (s->task != NOTIFICATION) {
505 SHA256_Final(h, &s->ctx);
506 if (memcmp(s->hash, h, sizeof(s->hash)) != 0) {
507 s->state |= RRDP_STATE_PARSE_ERROR;
508 warnx("%s: bad message digest", s->local);
512 s->state |= RRDP_STATE_PARSE_DONE;
513 rrdp_finished(s);
518 if (s->task != NOTIFICATION)
519 SHA256_Update(&s->ctx, buf, len);
520 if ((s->state & RRDP_STATE_PARSE_ERROR) == 0 &&
522 warnx("%s: parse error at line %llu: %s", s->local,
525 s->state |= RRDP_STATE_PARSE_ERROR;
533 struct rrdp *s, *ns;
547 TAILQ_FOREACH(s, &states, entry) {
550 s->pfd = NULL;
554 if (s->state == RRDP_STATE_REQ) {
556 switch (s->task) {
558 rrdp_http_req(s->id, s->notifyuri,
559 s->repository->last_mod);
563 uri = notification_get_next(s->nxml,
564 s->hash, sizeof(s->hash),
565 s->task);
566 SHA256_Init(&s->ctx);
567 rrdp_http_req(s->id, uri, NULL);
570 s->state = RRDP_STATE_WAIT;
572 s->pfd = pfds + i++;
573 s->pfd->fd = s->infd;
574 s->pfd->events = POLLIN;
615 TAILQ_FOREACH_SAFE(s, &states, entry, ns) {
616 if (s->pfd == NULL)
618 if (s->pfd->revents != 0)
619 rrdp_data_handler(s);