source: EcnlProtoTool/trunk/openssl-1.1.0e/ssl/pqueue.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.8 KB
Line 
1/*
2 * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include "ssl_locl.h"
11#include <openssl/bn.h>
12
13struct pqueue_st {
14 pitem *items;
15 int count;
16};
17
18pitem *pitem_new(unsigned char *prio64be, void *data)
19{
20 pitem *item = OPENSSL_malloc(sizeof(*item));
21 if (item == NULL)
22 return NULL;
23
24 memcpy(item->priority, prio64be, sizeof(item->priority));
25
26 item->data = data;
27 item->next = NULL;
28
29 return item;
30}
31
32void pitem_free(pitem *item)
33{
34 OPENSSL_free(item);
35}
36
37pqueue *pqueue_new()
38{
39 pqueue *pq = OPENSSL_zalloc(sizeof(*pq));
40
41 return pq;
42}
43
44void pqueue_free(pqueue *pq)
45{
46 OPENSSL_free(pq);
47}
48
49pitem *pqueue_insert(pqueue *pq, pitem *item)
50{
51 pitem *curr, *next;
52
53 if (pq->items == NULL) {
54 pq->items = item;
55 return item;
56 }
57
58 for (curr = NULL, next = pq->items;
59 next != NULL; curr = next, next = next->next) {
60 /*
61 * we can compare 64-bit value in big-endian encoding with memcmp:-)
62 */
63 int cmp = memcmp(next->priority, item->priority, 8);
64 if (cmp > 0) { /* next > item */
65 item->next = next;
66
67 if (curr == NULL)
68 pq->items = item;
69 else
70 curr->next = item;
71
72 return item;
73 }
74
75 else if (cmp == 0) /* duplicates not allowed */
76 return NULL;
77 }
78
79 item->next = NULL;
80 curr->next = item;
81
82 return item;
83}
84
85pitem *pqueue_peek(pqueue *pq)
86{
87 return pq->items;
88}
89
90pitem *pqueue_pop(pqueue *pq)
91{
92 pitem *item = pq->items;
93
94 if (pq->items != NULL)
95 pq->items = pq->items->next;
96
97 return item;
98}
99
100pitem *pqueue_find(pqueue *pq, unsigned char *prio64be)
101{
102 pitem *next;
103 pitem *found = NULL;
104
105 if (pq->items == NULL)
106 return NULL;
107
108 for (next = pq->items; next->next != NULL; next = next->next) {
109 if (memcmp(next->priority, prio64be, 8) == 0) {
110 found = next;
111 break;
112 }
113 }
114
115 /* check the one last node */
116 if (memcmp(next->priority, prio64be, 8) == 0)
117 found = next;
118
119 if (!found)
120 return NULL;
121
122 return found;
123}
124
125pitem *pqueue_iterator(pqueue *pq)
126{
127 return pqueue_peek(pq);
128}
129
130pitem *pqueue_next(pitem **item)
131{
132 pitem *ret;
133
134 if (item == NULL || *item == NULL)
135 return NULL;
136
137 /* *item != NULL */
138 ret = *item;
139 *item = (*item)->next;
140
141 return ret;
142}
143
144int pqueue_size(pqueue *pq)
145{
146 pitem *item = pq->items;
147 int count = 0;
148
149 while (item != NULL) {
150 count++;
151 item = item->next;
152 }
153 return count;
154}
Note: See TracBrowser for help on using the repository browser.