Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
baa56ae7
Commit
baa56ae7
authored
15 years ago
by
pierre-luc
Browse files
Options
Downloads
Patches
Plain Diff
[#1744] Adds thread safety features, compile() and setPattern() methods to the Regex class.
parent
24f86a02
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sflphone-common/src/sip/Regex.cpp
+25
-10
25 additions, 10 deletions
sflphone-common/src/sip/Regex.cpp
sflphone-common/src/sip/Regex.h
+37
-2
37 additions, 2 deletions
sflphone-common/src/sip/Regex.h
with
62 additions
and
12 deletions
sflphone-common/src/sip/Regex.cpp
+
25
−
10
View file @
baa56ae7
...
@@ -24,15 +24,28 @@ namespace sfl {
...
@@ -24,15 +24,28 @@ namespace sfl {
const
int
MAX_SUBSTRINGS
=
30
;
const
int
MAX_SUBSTRINGS
=
30
;
Regex
::
Regex
(
const
std
::
string
&
pattern
)
:
Regex
::
Regex
(
const
std
::
string
&
pattern
=
""
)
:
_pattern
(
pattern
)
_pattern
(
pattern
)
,
_re
(
NULL
)
,
_re
(
NULL
)
,
_pcreOutputVector
(
NULL
)
,
_pcreOutputVector
(
NULL
)
,
_reMutex
(
NULL
)
{
compile
();
}
Regex
::~
Regex
()
{
pcre_free
(
_re
);
delete
[]
_pcreOutputVector
;
}
void
Regex
::
compile
(
void
)
{
{
// Compile the pattern
// Compile the pattern
int
offset
;
int
offset
;
const
char
*
error
;
const
char
*
error
;
_reMutex
.
enterMutex
();
_re
=
pcre_compile
(
_pattern
.
c_str
(),
0
,
&
error
,
&
offset
,
NULL
);
_re
=
pcre_compile
(
_pattern
.
c_str
(),
0
,
&
error
,
&
offset
,
NULL
);
if
(
_re
==
NULL
)
{
if
(
_re
==
NULL
)
{
...
@@ -48,22 +61,22 @@ namespace sfl {
...
@@ -48,22 +61,22 @@ namespace sfl {
// Allocate space for
// Allocate space for
// the output vector
// the output vector
_pcreOutputVector
=
new
int
[
MAX_SUBSTRINGS
];
if
(
_pcreOutputVector
!=
NULL
)
{
}
Regex
::~
Regex
()
{
pcre_free
(
_re
);
delete
[]
_pcreOutputVector
;
delete
[]
_pcreOutputVector
;
}
}
_pcreOutputVector
=
new
int
[
MAX_SUBSTRINGS
];
_reMutex
.
leaveMutex
();
}
const
std
::
vector
<
std
::
string
>&
Regex
::
findall
(
const
std
::
string
&
subject
)
const
std
::
vector
<
std
::
string
>&
Regex
::
findall
(
const
std
::
string
&
subject
)
{
{
// Execute the PCRE regex
// Execute the PCRE regex
int
status
;
int
status
;
_reMutex
.
enterMutex
();
status
=
pcre_exec
(
_re
,
NULL
,
subject
.
c_str
(),
subject
.
length
(),
status
=
pcre_exec
(
_re
,
NULL
,
subject
.
c_str
(),
subject
.
length
(),
0
,
0
,
_pcreOutputVector
,
MAX_SUBSTRINGS
);
0
,
0
,
_pcreOutputVector
,
MAX_SUBSTRINGS
);
_reMutex
.
leaveMutex
();
// Handle error cases
// Handle error cases
if
(
status
<
0
)
{
if
(
status
<
0
)
{
...
@@ -107,6 +120,7 @@ namespace sfl {
...
@@ -107,6 +120,7 @@ namespace sfl {
int
count
=
status
;
int
count
=
status
;
const
char
**
stringlist
;
const
char
**
stringlist
;
_reMutex
.
enterMutex
();
status
=
pcre_get_substring_list
(
subject
.
c_str
(),
_pcreOutputVector
,
count
,
&
stringlist
);
status
=
pcre_get_substring_list
(
subject
.
c_str
(),
_pcreOutputVector
,
count
,
&
stringlist
);
if
(
status
<
0
)
{
if
(
status
<
0
)
{
fprintf
(
stderr
,
"Get substring list failed"
);
fprintf
(
stderr
,
"Get substring list failed"
);
...
@@ -121,6 +135,7 @@ namespace sfl {
...
@@ -121,6 +135,7 @@ namespace sfl {
pcre_free_substring_list
(
stringlist
);
pcre_free_substring_list
(
stringlist
);
}
}
_reMutex
.
leaveMutex
();
return
_outputVector
;
return
_outputVector
;
}
}
...
...
This diff is collapsed.
Click to expand it.
sflphone-common/src/sip/Regex.h
+
37
−
2
View file @
baa56ae7
...
@@ -19,9 +19,11 @@
...
@@ -19,9 +19,11 @@
#define __SFL_REGEX_H__
#define __SFL_REGEX_H__
#include
<stdexcept>
#include
<stdexcept>
#include
<ostream>
#include
<vector>
#include
<vector>
#include
<pcre.h>
#include
<pcre.h>
#include
<cc++/thread.h>
namespace
sfl
{
namespace
sfl
{
...
@@ -82,6 +84,33 @@ namespace sfl {
...
@@ -82,6 +84,33 @@ namespace sfl {
~
Regex
();
~
Regex
();
/**
* Set the regular expression
* to be used on subject strings
*
* @param The new pattern
*/
void
setPattern
(
const
std
::
string
&
pattern
)
{
_reMutex
.
enterMutex
();
_pattern
=
pattern
;
_reMutex
.
leaveMutex
();
}
/**
* Compile the regular expression
* from the pattern that was set for
* this object.
*/
void
compile
(
void
);
/**
* Get the currently set regular expression
* that is used on subject strings
*
* @return The currently set pattern
*/
std
::
string
getPattern
(
void
)
{
return
_pattern
;
}
/**
/**
* Match the given expression against
* Match the given expression against
* this pattern and returns a vector of
* this pattern and returns a vector of
...
@@ -138,6 +167,12 @@ namespace sfl {
...
@@ -138,6 +167,12 @@ namespace sfl {
*/
*/
std
::
vector
<
std
::
string
>
_outputVector
;
std
::
vector
<
std
::
string
>
_outputVector
;
/**
* Protects the above data from concurrent
* access.
*/
ost
::
Mutex
_reMutex
;
};
};
}
}
...
...
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