Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swen90006-a2-2019
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jin Peiwen
swen90006-a2-2019
Commits
88bad7c5
Commit
88bad7c5
authored
Sep 6, 2019
by
Toby Murray
Browse files
Options
Downloads
Patches
Plain Diff
working again
parent
70451048
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/passbook.c
+7
-38
7 additions, 38 deletions
src/passbook.c
with
7 additions
and
38 deletions
src/passbook.c
+
7
−
38
View file @
88bad7c5
...
...
@@ -64,12 +64,12 @@ static node_t *node_new(const char *url, const cred_t cred){
/* updates a node's credential in place:
replaces p's credential with that from q and frees q */
static
void
node_edit_cred
(
node_t
*
p
,
const
node_t
q
){
static
void
node_edit_cred
(
node_t
*
p
,
node_t
*
q
){
free
(
p
->
cred
.
username
);
free
(
p
->
cred
.
password
);
p
->
cred
.
username
=
q
->
username
;
p
->
cred
.
password
=
q
->
password
;
p
->
cred
.
username
=
q
->
cred
.
username
;
p
->
cred
.
password
=
q
->
cred
.
password
;
free
(
q
);
}
...
...
@@ -84,7 +84,7 @@ static void node_free(node_t *p){
we assume that if q has children then it cannot already
be present in p. Otherwise, if q has no children and we find its url in p,
then we edit the found entry in place while preserving its children */
static
node_t
*
node_insert
(
node_t
*
p
,
const
node_t
*
q
){
static
node_t
*
node_insert
(
node_t
*
p
,
node_t
*
q
){
if
(
p
==
NULL
){
return
q
;
}
...
...
@@ -94,10 +94,9 @@ static node_t * node_insert(node_t *p, const node_t *q){
node_t
**
new
=
NULL
;
node_t
*
const
start
=
p
;
while
(
new
==
NULL
)
{
int
ret
=
strcmp
(
p
->
url
,
p
->
url
);
int
ret
=
strcmp
(
q
->
url
,
p
->
url
);
if
(
ret
==
0
){
assert
(
q
->
left
==
NULL
&&
q
->
right
==
NULL
&&
"illegal insertion"
);
/* edit the node in place */
node_edit_cred
(
p
,
q
);
/* q is now freed so cannot be used anymore */
...
...
@@ -121,40 +120,10 @@ static node_t * node_insert(node_t *p, const node_t *q){
return
start
;
}
/* FIXME: UP TO HERE. Now need to make this use node_insert */
/* returns a pointer to the tree with the node added or with the existing
node updated if it was already present */
static
node_t
*
put
(
node_t
*
p
,
const
char
*
url
,
const
cred_t
cred
){
if
(
p
==
NULL
){
return
node_new
(
url
,
cred
);
}
/* we store a pointer to a node pointer that remembers where in the
tree the new node needs to be added */
node_t
**
new
=
NULL
;
node_t
*
const
start
=
p
;
while
(
new
==
NULL
)
{
int
ret
=
strcmp
(
url
,
p
->
url
);
if
(
ret
==
0
){
/* edit the node in place */
node_edit
(
p
,
cred
);
return
start
;
}
else
if
(
ret
<
0
){
if
(
p
->
left
==
NULL
){
new
=
&
(
p
->
left
);
}
else
{
p
=
p
->
left
;
}
}
else
{
if
(
p
->
right
==
NULL
){
new
=
&
(
p
->
right
);
}
else
{
p
=
p
->
right
;
}
}
}
*
new
=
node_new
(
url
,
cred
);
return
start
;
return
node_insert
(
p
,
node_new
(
url
,
cred
));
}
/* returns a pointer to the tree with the node removed (if it was present) */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment