IAX registration procedure in C++ - c++

I need to verify an IAX account in my C++ client and run third-party softphone if account's credentials are valid (or close an application if not).
So, the client's socket connects to Asterisk host via UDP (port 4569) and... What is the algorithm? The specification does not contains any examples and I can't understand the structure of registration procedure (headers, data order etc.)
Could somebody explain me the order and the structure of messages to perform IAX user authentication?

In the document you have pointed, you can see the procedure of registration in chapter 6.1
________________
| |
| Unregistered |<--------------------------\
|________________| |
| |
/Init | |
------------ | |
snd REGREQ | +--------+ |
| | | rec REGAUTH |
_______V____V___ | ----------- |
| | | snd REGREQ |
| Reg Sent +----+ |
|________________+----------+ |
| ^ | rec REGAUTH |
rec REGACK | | | /No Credentials|
------------ | | REG timeout | -------------- |
snd ack | | ------- | snd ack |
| | REGREQ __V___ |
_______V____|___ | | |
| | | No | |
| Registered | | Auth | |
|________________| |______| |
| ^ |
| | rec REGAUTH |
| release | /No Credentials|
| ------- | -------------- |
+-------+ | snd REGREL | snd ack |
rec REGAUTH | | | | |
----------- | _V_____V________ | |
snd REGREL | | |----------+ |
+-----+ Releasing |---------------------------+
|________________| rec ACK
-------
x
__________
rec REGREJ | |
---------- *->| Rejected |
snd ack |__________|
Messages REGAUTH, REGREQ, etc. are specified in paragraphs 6.1.2 to 6.1.5 as messasges containing Information elements.
Information elements are included in full frames that are specified in paragraph 8.1.1
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|F| Source Call Number |R| Destination Call Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| time-stamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OSeqno | ISeqno | Frame Type |C| Subclass |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
: Data :
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 5: Full Frame Binary Format
Frame type for REGREQ, etc. is IAX (8.2.6) and the classes of IAX frames, including registration messages are in 8.4
Information elements for registration are enumerated in 6.1.x and described in 8.6.x
Anyway, you can use wireshark if you want to see a dialog message to message

Related

Regular Expression for Census Tracts

I am working on making sure a form input is parsed correctly through google forms and I was trying to use my limited regex knowledge to make sure that people do not input tracts incorrectly.
usually a tract is given in an example such as 5129.01
All tracts in the county start with 5, have a second character that is either a 0 or a 1,and if it is a 1, the third character is either [0 - 3] else its [0-9].
I have a working expression but I would like to ensure that if the second character is a 1 the user wouldn't be able to enter a tract like 5150.01
This is what I have:
^5[0-1]([0-9]{2})(\.([0-9]{2}))?$
and this is what is not working:
^5[0-1](?(?<=1)\d|[0-3])(\.([0-9]{2}))?$
Any help would be appreciated thanks
I hope this answers your question, please comment and I can edit accordingly.
The pattern:
^(?:51[0-3]|50[0-9])[0-9](?:\.[0-9]{1,2})?$
A visual representation:
HTML implementation:
<input name="example" pattern="^(?:51[0-3]|50[0-9])[0-9](?:\.[0-9]{1,2})?$">
Value validation examples:
+----------+--------+
| Value | Status |
+----------+--------+
| 51 | fail |
| 510 | fail |
| 5101 | pass |
| 5111 | pass |
| 5121 | pass |
| 5131 | pass |
| 5141 | fail |
| 5102. | fail |
| 5102.1 | pass |
| 5102.12 | pass |
| 5102.123 | fail |
| 50 | fail |
| 500 | fail |
| 5001 | pass |
| 5011 | pass |
| 5021 | pass |
| 5031 | pass |
| 5041 | pass |
| 5051 | pass |
| 5061 | pass |
| 5071 | pass |
| 5081 | pass |
| 5091 | pass |
| 50911 | fail |
| 5092. | fail |
| 5092.1 | pass |
| 5092.12 | pass |
| 5092.123 | fail |
+----------+--------+

Create column to classify rows based on realted tables DAX PowerBI

I have simplified my problem to solve. Lets suppose I have three tables. One containing data and specific codes that identify objects lets say Apples.
+-------------+------------+-----------+
| Data picked | Color code | Size code |
+-------------+------------+-----------+
| 1-8-2018 | 1 | 1 |
| 1-8-2018 | 1 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 2 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 3 | 3 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 5 | 3 |
| 1-8-2018 | 6 | 1 |
| 1-8-2018 | 6 | 2 |
| 1-8-2018 | 6 | 2 |
+-------------+------------+-----------+
And i have two related helping tables to help understand the codes (their relationships are inactive in the model due to ambiguity with other tables in the real case).
+-----------+--------+
| Size code | Size |
+-----------+--------+
| 1 | Small |
| 2 | Medium |
| 3 | Large |
+-----------+--------+
and
+------------+----------------+-------+
| Color code | Color specific | Color |
+------------+----------------+-------+
| 1 | Light green | Green |
| 2 | Green | Green |
| 3 | Semi green | Green |
| 4 | Red | Red |
| 5 | Dark | Red |
| 6 | Pink | Red |
+------------+----------------+-------+
Lets say that I want to create an extra column in the original table to determine which apples are class A and class B given that medium green Apples are class A and large Red apples are class B, the other remain blank as the example below.
+-------------+------------+-----------+-------+
| Data picked | Color code | Size code | Class |
+-------------+------------+-----------+-------+
| 1-8-2018 | 1 | 1 | |
| 1-8-2018 | 1 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 2 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 3 | 3 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 5 | 3 | B |
| 1-8-2018 | 6 | 1 | |
| 1-8-2018 | 6 | 2 | |
| 1-8-2018 | 6 | 2 | |
+-------------+------------+-----------+-------+
What's the proper DAX to use given the relationships are initially inactive. Preferably solvable without creating any further additional columns in any table. I already tried codes like:
CALCULATE (
"A" ;
FILTER ( 'Size Table' ; 'Size Table'[Size] = "Medium");
FILTER ( 'Color Table' ; 'Color Table'[Color] = "Green")
)
And many variations on the same principle
Given that the relationships are inactive, I'd suggest using LOOKUPVALUE to match ID values on the other tables. You should be able to create a calculated column as follows:
Class =
VAR Size = LOOKUPVALUE('Size Table'[Size],
'Size Table'[Size code], 'Data Table'[Size code])
VAR Color = LOOKUPVALUE('Color Table'[Color],
'Color Table'[Color code], 'Data Table'[Color code])
RETURN SWITCH(TRUE(),
(Size = "Medium") && (Color = "Green"), "A",
(Size = "Large") && (Color = "Red"), "B", BLANK())
If your relationships are active, then you don't need the lookups:
Class = SWITCH(TRUE(),
(RELATED('Size Table'[Size]) = "Medium") &&
(RELATED('Color Table'[Color]) = "Green"),
"A",
(RELATED('Size Table'[Size]) = "Large") &&
(RELATED('Color Table'[Color]) = "Red"),
"B",
BLANK())
Or a bit more elegantly written (especially for more classes):
Class =
VAR SizeColor = RELATED('Size Table'[Size]) & " " & RELATED('Color Table'[Color])
RETURN SWITCH(TRUE(),
SizeColor = "Medium Green", "A",
SizeColor = "Large Red", "B",
BLANK())

django Queryset exclude() multiple data

i have database scheme like this.
# periode
+------+--------------+--------------+
| id | from | to |
+------+--------------+--------------+
| 1 | 2018-04-12 | 2018-05-11 |
| 2 | 2018-05-12 | 2018-06-11 |
+------+--------------+--------------+
# foo
+------+---------+
| id | name |
+------+---------+
| 1 | John |
| 2 | Doe |
| 3 | Trodi |
| 4 | son |
| 5 | Alex |
+------+---------+
#bar
+------+---------------+--------------+
| id | employee_id | periode_id |
+------+---------------+--------------+
| 1 | 1 |1 |
| 2 | 2 |1 |
| 3 | 1 |2 |
| 4 | 3 |1 |
+------+---------------+--------------+
I need to show employee that not in salary.
for now I do like this
queryset=Bar.objects.all().filter(periode_id=1)
result=Foo.objects.exclude(id=queryset)
but its fail, how do filter employee list not in salary?...
Well here you basically want the foos such that there is no period_id=1 in the Bar table.
We can let this work with:
ex = Bar.objects.all().filter(periode_id=1).values_list('employee_id', flat=True)
result=Foo.objects.exclude(id__in=ex)

Count same field values in Django queryset

I have a Django model with three fields: product, condition and quantity with data such as:
| Product | Condition | Quantity |
+---------+-----------+----------+
| A | new | 2 |
| A | new | 3 |
| A | new | 4 |
| A | old | 1 |
| A | old | 2 |
| B | new | 2 |
| B | new | 3 |
| B | new | 1 |
| B | old | 4 |
| B | old | 2 |
I'd like to sum the quantities of the entries where product and condition are equal:
| Product | Condition | Quantity |
+---------+-----------+----------+
| A | new | 9 |
| A | old | 3 |
| B | new | 6 |
| B | old | 6 |
This answer helps to count entries with the same field value, but I need to count two fields.
How could I implement this?
from django.db.models import Sum
Model.objects.values('product', 'condition').order_by().annotate(Sum('quantity'))

IF MATCH multiple criteria

Table 1
| | 1 Jan 2018 | 2 Jan 2018 | 3 Jan 2018 | 4 Jan 2018 | 5 Jan 2018 |
|----|------------|------------|------------|------------|------------|
| A1 | | | | | |
| A2 | | | | | |
| A3 | | | | | |
| A4 | | | | | |
| A5 | | | | | |
| A6 | | | | | |
Table 2
|----|----------|-----------|-----------|-----------|-----------|
| A1 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A2 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A3 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A4 | 3-Jan-18 | 6-Jan-18 | 10-Jan-18 | 13-Jan-18 | 17-Jan-18 |
| A5 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
| A6 | 3-Jan-18 | 10-Jan-18 | 17-Jan-18 | 24-Jan-18 | 31-Jan-18 |
IF MATCH
=IF(MATCH(A2,$A$27:$A$54,0) & MATCH(C1,$B$27:$S$54,0),"1","")
Getting #N/A error out of it
Trying to get apply formula onto the cells in Table 1 to lookup values in Table 2
If it matches, output is 1, else 0
Table & Image above to clearly illustrate & experiment out.
Thanks in advance (:
Applied formula & Output
Firstly, MATCH() returns a number that represents the position of a found match so your formula says IF(1 & 1,"1","") for your first potential match, there is no logical here.
The first ammendment would be to force a True / False output: =IF(AND(ISNUMBER(MATCH()),ISNUMBER(MATCH())),"1","")
You still have the issue that the second match is referencing the entire range of resuts though, you really want this to only look through the row that meets the first criteria, for this we will use an array formula to build the array you want to use:
EDIT: You can't buld an array from Match as it returns a single integer:
=LARGE(IF(B$1=IF($A2=$A$27:$A$54,$B$27:$S$54),1,0),1)
This is an array formula, while still in the formula bar hit Ctrl+Shift+Enter
The Inner IF() statemnet is building an array of each row, providing values where column A matches and FALSE where it doesn't. The outter IF() statement is then evaluating 0 or 1 whether it finds the date in that new array...
I have wrapped this in a LARGE() to return the first largest number so if a single match is found it will return that 1. If you want the blank you can wrap the whole thing in another IF() statement; IF([formula]=0,"",1)