Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
db84b798
Commit
db84b798
authored
Sep 04, 2011
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move extract_host_and_port to netops and add default port argument
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent
3d975abc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
32 deletions
+34
-32
src/netops.c
+30
-0
src/netops.h
+2
-0
src/transport_git.c
+2
-32
No files found.
src/netops.c
View file @
db84b798
...
...
@@ -161,3 +161,33 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
/* The select(2) interface is silly */
return
select
(
buf
->
fd
+
1
,
&
fds
,
NULL
,
NULL
,
&
tv
);
}
int
gitno_extract_host_and_port
(
char
**
host
,
char
**
port
,
const
char
*
url
,
const
char
*
default_port
)
{
char
*
colon
,
*
slash
,
*
delim
;
int
error
=
GIT_SUCCESS
;
colon
=
strchr
(
url
,
':'
);
slash
=
strchr
(
url
,
'/'
);
if
(
slash
==
NULL
)
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Malformed URL: missing /"
);
if
(
colon
==
NULL
)
{
*
port
=
git__strdup
(
default_port
);
}
else
{
*
port
=
git__strndup
(
colon
+
1
,
slash
-
colon
-
1
);
}
if
(
*
port
==
NULL
)
return
GIT_ENOMEM
;;
delim
=
colon
==
NULL
?
slash
:
colon
;
*
host
=
git__strndup
(
url
,
delim
-
url
);
if
(
*
host
==
NULL
)
{
free
(
*
port
);
error
=
GIT_ENOMEM
;
}
return
error
;
}
src/netops.h
View file @
db84b798
...
...
@@ -26,4 +26,6 @@ int gitno_connect(const char *host, const char *port);
int
gitno_send
(
int
s
,
const
char
*
msg
,
size_t
len
,
int
flags
);
int
gitno_select_in
(
gitno_buffer
*
buf
,
long
int
sec
,
long
int
usec
);
int
gitno_extract_host_and_port
(
char
**
host
,
char
**
port
,
const
char
*
url
,
const
char
*
default_port
);
#endif
src/transport_git.c
View file @
db84b798
...
...
@@ -102,37 +102,6 @@ cleanup:
return
error
;
}
/* The URL should already have been stripped of the protocol */
static
int
extract_host_and_port
(
char
**
host
,
char
**
port
,
const
char
*
url
)
{
char
*
colon
,
*
slash
,
*
delim
;
int
error
=
GIT_SUCCESS
;
colon
=
strchr
(
url
,
':'
);
slash
=
strchr
(
url
,
'/'
);
if
(
slash
==
NULL
)
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Malformed URL: missing /"
);
if
(
colon
==
NULL
)
{
*
port
=
git__strdup
(
GIT_DEFAULT_PORT
);
}
else
{
*
port
=
git__strndup
(
colon
+
1
,
slash
-
colon
-
1
);
}
if
(
*
port
==
NULL
)
return
GIT_ENOMEM
;;
delim
=
colon
==
NULL
?
slash
:
colon
;
*
host
=
git__strndup
(
url
,
delim
-
url
);
if
(
*
host
==
NULL
)
{
free
(
*
port
);
error
=
GIT_ENOMEM
;
}
return
error
;
}
/*
* Parse the URL and connect to a server, storing the socket in
* out. For convenience this also takes care of asking for the remote
...
...
@@ -148,9 +117,10 @@ static int do_connect(transport_git *t, const char *url)
if
(
!
git__prefixcmp
(
url
,
prefix
))
url
+=
strlen
(
prefix
);
error
=
extract_host_and_port
(
&
host
,
&
port
,
url
);
error
=
gitno_extract_host_and_port
(
&
host
,
&
port
,
url
,
GIT_DEFAULT_PORT
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
s
=
gitno_connect
(
host
,
port
);
connected
=
1
;
error
=
send_request
(
s
,
NULL
,
url
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment