You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4380 lines
133 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. Copyright 2006 - 2011 Intel Corporation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #ifndef MICROSTACK_NO_STDAFX
  14. #include "stdafx.h"
  15. #endif
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <stddef.h>
  20. #include <string.h>
  21. #include <winioctl.h>
  22. #include <winsock2.h>
  23. #include <ws2tcpip.h>
  24. #include "ILibParsers.h"
  25. #include "ILibHTTPClient.h"
  26. #include "ILibSSDPClient.h"
  27. #include "ILibMiniWebServer.h"
  28. #include "RNDControlPoint.h"
  29. #define sem_t HANDLE
  30. #define sem_init(x,y,z) *x=CreateSemaphore(NULL,z,FD_SETSIZE,NULL)
  31. #define sem_destroy(x) (CloseHandle(*x)==0?1:0)
  32. #define sem_wait(x) WaitForSingleObject(*x,INFINITE)
  33. #define sem_trywait(x) ((WaitForSingleObject(*x,0)==WAIT_OBJECT_0)?0:1)
  34. #define sem_post(x) ReleaseSemaphore(*x,1,NULL)
  35. #define strncasecmp(x,y,z) _strnicmp(x,y,z)
  36. #define INVALID_DATA 0
  37. #define DEBUGSTATEMENT(x)
  38. #define LVL3DEBUG(x)
  39. const char *UPNPCP_SOAP_Header = "POST %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: WINDOWS, UPnP/1.0, Intel MicroStack/1.0.1189\r\nSOAPACTION: \"%s#%s\"\r\nContent-Type: text/xml\r\nContent-Length: %d\r\n\r\n";
  40. const char *UPNPCP_SOAP_BodyHead = "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:";
  41. const char *UPNPCP_SOAP_BodyTail = "></s:Body></s:Envelope>";
  42. void RNDRenew(void *state);
  43. void RNDSSDP_Sink(void *sender, char* UDN, int Alive, char* LocationURL, int Timeout,void *cp);
  44. struct CustomUserData
  45. {
  46. int Timeout;
  47. char* buffer;
  48. };
  49. struct RNDCP
  50. {
  51. void (*PreSelect)(void* object,fd_set *readset, fd_set *writeset, fd_set *errorset, int* blocktime);
  52. void (*PostSelect)(void* object,int slct, fd_set *readset, fd_set *writeset, fd_set *errorset);
  53. void (*Destroy)(void* object);
  54. void (*DiscoverSink)(struct UPnPDevice *device);
  55. void (*RemoveSink)(struct UPnPDevice *device);
  56. void (*EventCallback_ContentDirectory_TransferIDs)(struct UPnPService* Service,char* value);
  57. void (*EventCallback_ContentDirectory_ContainerUpdateIDs)(struct UPnPService* Service,char* value);
  58. void (*EventCallback_ContentDirectory_SystemUpdateID)(struct UPnPService* Service,unsigned int value);
  59. void (*EventCallback_ConnectionManager_SourceProtocolInfo)(struct UPnPService* Service,char* value);
  60. void (*EventCallback_ConnectionManager_SinkProtocolInfo)(struct UPnPService* Service,char* value);
  61. void (*EventCallback_ConnectionManager_CurrentConnectionIDs)(struct UPnPService* Service,char* value);
  62. struct UDNMapNode *UDN_Head;
  63. struct LifeTimeMonitorStruct *LifeTimeMonitor;
  64. void *HTTP;
  65. void *SSDP;
  66. void *WebServer;
  67. sem_t DeviceLock;
  68. void* SIDTable;
  69. void *Chain;
  70. int RecheckFlag;
  71. int AddressListLength;
  72. int *AddressList;
  73. };
  74. void (*RNDEventCallback_ContentDirectory_TransferIDs)(struct UPnPService* Service,char* value);
  75. void (*RNDEventCallback_ContentDirectory_ContainerUpdateIDs)(struct UPnPService* Service,char* value);
  76. void (*RNDEventCallback_ContentDirectory_SystemUpdateID)(struct UPnPService* Service,unsigned int value);
  77. void (*RNDEventCallback_ConnectionManager_SourceProtocolInfo)(struct UPnPService* Service,char* value);
  78. void (*RNDEventCallback_ConnectionManager_SinkProtocolInfo)(struct UPnPService* Service,char* value);
  79. void (*RNDEventCallback_ConnectionManager_CurrentConnectionIDs)(struct UPnPService* Service,char* value);
  80. struct InvokeStruct
  81. {
  82. struct UPnPService *Service;
  83. void *CallbackPtr;
  84. void *User;
  85. };
  86. struct UPnPServiceInfo
  87. {
  88. char* serviceType;
  89. char* SCPDURL;
  90. char* controlURL;
  91. char* eventSubURL;
  92. char* serviceId;
  93. struct UPnPServiceInfo *Next;
  94. };
  95. struct UPnP_Stack
  96. {
  97. void *data;
  98. struct UPnP_Stack *next;
  99. };
  100. struct UDNMapNode
  101. {
  102. char* UDN;
  103. char* RootUDN;
  104. long TimeStamp;
  105. struct UPnPDevice *device;
  106. struct UDNMapNode *Next;
  107. struct UDNMapNode *Previous;
  108. };
  109. void RNDDestructUPnPService(struct UPnPService *service)
  110. {
  111. struct UPnPAction *a1,*a2;
  112. struct UPnPStateVariable *sv1,*sv2;
  113. int i;
  114. a1 = service->Actions;
  115. while(a1!=NULL)
  116. {
  117. a2 = a1->Next;
  118. FREE(a1->Name);
  119. FREE(a1);
  120. a1 = a2;
  121. }
  122. sv1 = service->Variables;
  123. while(sv1!=NULL)
  124. {
  125. sv2 = sv1->Next;
  126. FREE(sv1->Name);
  127. if(sv1->Min!=NULL) {FREE(sv1->Min);}
  128. if(sv1->Max!=NULL) {FREE(sv1->Max);}
  129. if(sv1->Step!=NULL) {FREE(sv1->Step);}
  130. for(i=0;i<sv1->NumAllowedValues;++i)
  131. {
  132. FREE(sv1->AllowedValues[i]);
  133. }
  134. if(sv1->AllowedValues!=NULL) {FREE(sv1->AllowedValues);}
  135. FREE(sv1);
  136. sv1 = sv2;
  137. }
  138. if(service->ControlURL!=NULL) {FREE(service->ControlURL);}
  139. if(service->SCPDURL!=NULL) {FREE(service->SCPDURL);}
  140. if(service->ServiceId!=NULL) {FREE(service->ServiceId);}
  141. if(service->ServiceType!=NULL) {FREE(service->ServiceType);}
  142. if(service->SubscriptionURL!=NULL) {FREE(service->SubscriptionURL);}
  143. if(service->SubscriptionID!=NULL)
  144. {
  145. ILibLifeTime_Remove(((struct RNDCP*)service->Parent->CP)->LifeTimeMonitor,service);
  146. ILibDeleteEntry(((struct RNDCP*)service->Parent->CP)->SIDTable,service->SubscriptionID,(int)strlen(service->SubscriptionID));
  147. FREE(service->SubscriptionID);
  148. service->SubscriptionID = NULL;
  149. }
  150. FREE(service);
  151. }
  152. void RNDDestructUPnPDevice(struct UPnPDevice *device)
  153. {
  154. struct UPnPDevice *d1,*d2;
  155. struct UPnPService *s1,*s2;
  156. d1 = device->EmbeddedDevices;
  157. while(d1!=NULL)
  158. {
  159. d2 = d1->Next;
  160. RNDDestructUPnPDevice(d1);
  161. d1 = d2;
  162. }
  163. s1 = device->Services;
  164. while(s1!=NULL)
  165. {
  166. s2 = s1->Next;
  167. RNDDestructUPnPService(s1);
  168. s1 = s2;
  169. }
  170. LVL3DEBUG(printf("\r\n\r\nDevice Destructed\r\n");)
  171. if(device->PresentationURL!=NULL) {FREE(device->PresentationURL);}
  172. if(device->ManufacturerName!=NULL) {FREE(device->ManufacturerName);}
  173. if(device->ManufacturerURL!=NULL) {FREE(device->ManufacturerURL);}
  174. if(device->ModelName!=NULL) {FREE(device->ModelName);}
  175. if(device->ModelNumber!=NULL) {FREE(device->ModelNumber);}
  176. if(device->ModelURL!=NULL) {FREE(device->ModelURL);}
  177. if(device->DeviceType!=NULL) {FREE(device->DeviceType);}
  178. if(device->FriendlyName!=NULL) {FREE(device->FriendlyName);}
  179. if(device->LocationURL!=NULL) {FREE(device->LocationURL);}
  180. if(device->UDN!=NULL) {FREE(device->UDN);}
  181. if(device->InterfaceToHost!=NULL) {FREE(device->InterfaceToHost);}
  182. FREE(device);
  183. }
  184. void RNDAddRef(struct UPnPDevice *device)
  185. {
  186. struct RNDCP *CP = (struct RNDCP*)device->CP;
  187. struct UPnPDevice *d = device;
  188. sem_wait(&(CP->DeviceLock));
  189. while(d->Parent!=NULL) {d = d->Parent;}
  190. ++d->ReferenceCount;
  191. sem_post(&(CP->DeviceLock));
  192. }
  193. void RNDRelease(struct UPnPDevice *device)
  194. {
  195. struct RNDCP *CP = (struct RNDCP*)device->CP;
  196. struct UPnPDevice *d = device;
  197. sem_wait(&(CP->DeviceLock));
  198. while(d->Parent!=NULL) {d = d->Parent;}
  199. --d->ReferenceCount;
  200. if(d->ReferenceCount==0)
  201. {
  202. RNDDestructUPnPDevice(d);
  203. }
  204. sem_post(&(CP->DeviceLock));
  205. }
  206. void RNDPush(struct UPnP_Stack **pp_Top, void *data)
  207. {
  208. struct UPnP_Stack *frame = (struct UPnP_Stack*)MALLOC(sizeof(struct UPnP_Stack));
  209. frame->data = data;
  210. frame->next = *pp_Top;
  211. *pp_Top = frame;
  212. }
  213. void *RNDPop(struct UPnP_Stack **pp_Top)
  214. {
  215. struct UPnP_Stack *frame = *pp_Top;
  216. void *RetVal = NULL;
  217. if(frame!=NULL)
  218. {
  219. *pp_Top = frame->next;
  220. RetVal = frame->data;
  221. FREE(frame);
  222. }
  223. return(RetVal);
  224. }
  225. void *RNDPeek(struct UPnP_Stack **pp_Top)
  226. {
  227. struct UPnP_Stack *frame = *pp_Top;
  228. void *RetVal = NULL;
  229. if(frame!=NULL)
  230. {
  231. RetVal = (*pp_Top)->data;
  232. }
  233. return(RetVal);
  234. }
  235. void RNDFlush(struct UPnP_Stack **pp_Top)
  236. {
  237. while(RNDPop(pp_Top)!=NULL) {}
  238. *pp_Top = NULL;
  239. }
  240. void RNDAttachRootUDNToUDN(void *v_CP,char* UDN, char* RootUDN)
  241. {
  242. struct UDNMapNode *node;
  243. struct RNDCP* CP = (struct RNDCP*)v_CP;
  244. if(CP->UDN_Head==NULL) {return;}
  245. sem_wait(&(CP->DeviceLock));
  246. node = CP->UDN_Head;
  247. while(node!=NULL)
  248. {
  249. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  250. {
  251. if(node->RootUDN!=NULL)
  252. {
  253. FREE(node->RootUDN);
  254. }
  255. node->RootUDN = MALLOC(1+strlen(RootUDN));
  256. sprintf(node->RootUDN,"%s",RootUDN);
  257. break;
  258. }
  259. node=node->Next;
  260. }
  261. sem_post(&(CP->DeviceLock));
  262. }
  263. void RNDAttachDeviceToUDN(void *v_CP,char* UDN, struct UPnPDevice *device)
  264. {
  265. struct UDNMapNode *node;
  266. struct RNDCP* CP = (struct RNDCP*)v_CP;
  267. if(CP->UDN_Head==NULL) {return;}
  268. sem_wait(&(CP->DeviceLock));
  269. node = CP->UDN_Head;
  270. while(node!=NULL)
  271. {
  272. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  273. {
  274. node->device = device;
  275. ++device->ReferenceCount;
  276. break;
  277. }
  278. node=node->Next;
  279. }
  280. sem_post(&(CP->DeviceLock));
  281. }
  282. void RNDRemoveUDN(void *v_CP,char* UDN)
  283. {
  284. struct RNDCP* CP = (struct RNDCP*)v_CP;
  285. struct UPnPDevice *device = NULL;
  286. struct UDNMapNode *node,*prevNode;
  287. if(CP->UDN_Head==NULL) {return;}
  288. sem_wait(&(CP->DeviceLock));
  289. node = CP->UDN_Head;
  290. prevNode = NULL;
  291. while (node!=NULL)
  292. {
  293. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  294. {
  295. device = node->device;
  296. node->device = NULL;
  297. if(node->RootUDN!=NULL)
  298. {
  299. FREE(node->RootUDN);
  300. node->RootUDN = NULL;
  301. }
  302. if(prevNode!=NULL)
  303. {
  304. prevNode->Next = node->Next;
  305. if(node->Next!=NULL)
  306. {
  307. node->Next->Previous = prevNode;
  308. }
  309. }
  310. else
  311. {
  312. CP->UDN_Head = node->Next;
  313. if(node->Next!=NULL)
  314. {
  315. node->Next->Previous = NULL;
  316. }
  317. }
  318. FREE(node->UDN);
  319. FREE(node);
  320. break;
  321. }
  322. prevNode = node;
  323. node=node->Next;
  324. }
  325. sem_post(&(CP->DeviceLock));
  326. if(device!=NULL) {RNDRelease(device);}
  327. }
  328. void RNDAddUDN(void *v_CP,char *UDN)
  329. {
  330. struct RNDCP* CP = (struct RNDCP*)v_CP;
  331. struct UDNMapNode *node;
  332. int has = 0;
  333. sem_wait(&(CP->DeviceLock));
  334. node = CP->UDN_Head;
  335. while(node!=NULL)
  336. {
  337. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  338. {
  339. has = -1;
  340. break;
  341. }
  342. node=node->Next;
  343. }
  344. if(has==0)
  345. {
  346. node = (struct UDNMapNode*)MALLOC(sizeof(struct UDNMapNode));
  347. node->UDN = (char*)MALLOC((int)strlen(UDN)+1);
  348. memcpy(node->UDN,UDN,(int)strlen(UDN));
  349. node->UDN[(int)strlen(UDN)] = '\0';
  350. node->device = NULL;
  351. node->RootUDN = NULL;
  352. node->Next = CP->UDN_Head;
  353. CP->UDN_Head = node;
  354. CP->UDN_Head->Previous = NULL;
  355. if(CP->UDN_Head->Next!=NULL)
  356. {
  357. CP->UDN_Head->Next->Previous = CP->UDN_Head;
  358. }
  359. }
  360. sem_post(&(CP->DeviceLock));
  361. }
  362. struct UPnPDevice* RNDGetDeviceAtUDN(void *v_CP,char* UDN)
  363. {
  364. struct UDNMapNode *node;
  365. struct UPnPDevice *RetVal = NULL;
  366. struct RNDCP* CP = (struct RNDCP*)v_CP;
  367. if(CP->UDN_Head==NULL) {return(NULL);}
  368. sem_wait(&(CP->DeviceLock));
  369. node = CP->UDN_Head;
  370. while(node!=NULL)
  371. {
  372. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  373. {
  374. RetVal = node->device;
  375. if(RetVal!=NULL){++RetVal->ReferenceCount;}
  376. break;
  377. }
  378. node=node->Next;
  379. }
  380. sem_post(&(CP->DeviceLock));
  381. return(RetVal);
  382. }
  383. char* RNDGetRootUDNAtUDN(void *v_CP,char* UDN)
  384. {
  385. struct UDNMapNode *node;
  386. char *RetVal = NULL;
  387. struct RNDCP* CP = (struct RNDCP*)v_CP;
  388. if(CP->UDN_Head==NULL) {return(NULL);}
  389. sem_wait(&(CP->DeviceLock));
  390. node = CP->UDN_Head;
  391. while(node!=NULL)
  392. {
  393. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  394. {
  395. RetVal = node->RootUDN;
  396. break;
  397. }
  398. node=node->Next;
  399. }
  400. sem_post(&(CP->DeviceLock));
  401. return(RetVal);
  402. }
  403. int RNDHasUDN(void *v_CP,char *UDN)
  404. {
  405. struct UDNMapNode *node;
  406. struct RNDCP* CP = (struct RNDCP*)v_CP;
  407. int RetVal = 0;
  408. if(CP->UDN_Head==NULL) {return(0);}
  409. sem_wait(&(CP->DeviceLock));
  410. node = CP->UDN_Head;
  411. while(node!=NULL)
  412. {
  413. if(strncmp(node->UDN,UDN,(int)strlen(UDN))==0)
  414. {
  415. RetVal = -1;
  416. break;
  417. }
  418. node=node->Next;
  419. }
  420. sem_post(&(CP->DeviceLock));
  421. return(RetVal);
  422. }
  423. void RNDParseUri(char* URI, char** IP, unsigned short* Port, char** Path)
  424. {
  425. struct parser_result *result,*result2,*result3;
  426. char *TempString,*TempString2;
  427. int TempStringLength,TempStringLength2;
  428. result = ILibParseString(URI, 0, (int)strlen(URI), "://", 3);
  429. TempString = result->LastResult->data;
  430. TempStringLength = result->LastResult->datalength;
  431. /* Parse Path */
  432. result2 = ILibParseString(TempString,0,TempStringLength,"/",1);
  433. TempStringLength2 = TempStringLength-result2->FirstResult->datalength;
  434. *Path = (char*)MALLOC(TempStringLength2+1);
  435. memcpy(*Path,TempString+(result2->FirstResult->datalength),TempStringLength2);
  436. (*Path)[TempStringLength2] = '\0';
  437. /* Parse Port Number */
  438. result3 = ILibParseString(result2->FirstResult->data,0,result2->FirstResult->datalength,":",1);
  439. if(result3->NumResults==1)
  440. {
  441. *Port = 80;
  442. }
  443. else
  444. {
  445. TempString2 = (char*)MALLOC(result3->LastResult->datalength+1);
  446. memcpy(TempString2,result3->LastResult->data,result3->LastResult->datalength);
  447. TempString2[result3->LastResult->datalength] = '\0';
  448. *Port = (unsigned short)atoi(TempString2);
  449. FREE(TempString2);
  450. }
  451. /* Parse IP Address */
  452. TempStringLength2 = result3->FirstResult->datalength;
  453. *IP = (char*)MALLOC(TempStringLength2+1);
  454. memcpy(*IP,result3->FirstResult->data,TempStringLength2);
  455. (*IP)[TempStringLength2] = '\0';
  456. ILibDestructParserResults(result3);
  457. ILibDestructParserResults(result2);
  458. ILibDestructParserResults(result);
  459. }
  460. struct packetheader *RNDBuildPacket(char* IP, int Port, char* Path, char* cmd)
  461. {
  462. struct packetheader *RetVal = ILibCreateEmptyPacket();
  463. char* HostLine = (char*)MALLOC((int)strlen(IP)+7);
  464. int HostLineLength = sprintf(HostLine,"%s:%d",IP,Port);
  465. ILibSetDirective(RetVal,cmd,(int)strlen(cmd),Path,(int)strlen(Path));
  466. ILibAddHeaderLine(RetVal,"Host",4,HostLine,HostLineLength);
  467. ILibAddHeaderLine(RetVal,"User-Agent",10,"WINDOWS, UPnP/1.0, Intel MicroStack/1.0.1189",44);
  468. FREE(HostLine);
  469. return(RetVal);
  470. }
  471. void RNDRemoveServiceFromDevice(struct UPnPDevice *device, struct UPnPService *service)
  472. {
  473. struct UPnPService *s = device->Services;
  474. if(s==service)
  475. {
  476. device->Services = s->Next;
  477. RNDDestructUPnPService(service);
  478. return;
  479. }
  480. while(s->Next!=NULL)
  481. {
  482. if(s->Next == service)
  483. {
  484. s->Next = s->Next->Next;
  485. RNDDestructUPnPService(service);
  486. return;
  487. }
  488. s = s->Next;
  489. }
  490. }
  491. void RNDProcessDevice(struct UPnPDevice *device)
  492. {
  493. int OK = 0;
  494. struct UPnPService *s,*s2;
  495. struct UPnPDevice *EmbeddedDevice = device->EmbeddedDevices;
  496. while(EmbeddedDevice!=NULL)
  497. {
  498. RNDProcessDevice(EmbeddedDevice);
  499. EmbeddedDevice = EmbeddedDevice->Next;
  500. }
  501. if(strncmp(device->DeviceType,"urn:schemas-upnp-org:device:MediaServer:1",41)==0)
  502. {
  503. s = device->Services;
  504. while(s!=NULL)
  505. {
  506. OK = 0;
  507. if(strncmp(s->ServiceType,"urn:schemas-upnp-org:service:ContentDirectory:1",47)==0)
  508. {
  509. OK = 1;
  510. }
  511. if(strncmp(s->ServiceType,"urn:schemas-upnp-org:service:ConnectionManager:1",48)==0)
  512. {
  513. OK = 1;
  514. }
  515. s2 = s->Next;
  516. if(OK==0) {RNDRemoveServiceFromDevice(device,s);}
  517. s = s2;
  518. }
  519. }
  520. }
  521. void RNDPrintUPnPDevice(int indents, struct UPnPDevice *device)
  522. {
  523. struct UPnPService *s;
  524. struct UPnPDevice *d;
  525. struct UPnPAction *a;
  526. int x=0;
  527. for(x=0;x<indents;++x) {printf(" ");}
  528. printf("Device: %s\r\n",device->DeviceType);
  529. for(x=0;x<indents;++x) {printf(" ");}
  530. printf("Friendly: %s\r\n",device->FriendlyName);
  531. s = device->Services;
  532. while(s!=NULL)
  533. {
  534. for(x=0;x<indents;++x) {printf(" ");}
  535. printf(" Service: %s\r\n",s->ServiceType);
  536. a = s->Actions;
  537. while(a!=NULL)
  538. {
  539. for(x=0;x<indents;++x) {printf(" ");}
  540. printf(" Action: %s\r\n",a->Name);
  541. a = a->Next;
  542. }
  543. s = s->Next;
  544. }
  545. d = device->EmbeddedDevices;
  546. while(d!=NULL)
  547. {
  548. RNDPrintUPnPDevice(indents+5,d);
  549. d = d->Next;
  550. }
  551. }
  552. struct UPnPService *RNDGetService(struct UPnPDevice *device, char* ServiceName, int length)
  553. {
  554. struct UPnPService *RetService = NULL;
  555. struct UPnPService *s = device->Services;
  556. while(s!=NULL)
  557. {
  558. if((int)strlen(s->ServiceType)==length)
  559. {
  560. if(strncmp(s->ServiceType,ServiceName,length)==0)
  561. {
  562. RetService = s;
  563. break;
  564. }
  565. }
  566. s = s->Next;
  567. }
  568. return(RetService);
  569. }
  570. struct UPnPService *RNDGetService_ContentDirectory(struct UPnPDevice *device)
  571. {
  572. return(RNDGetService(device,"urn:schemas-upnp-org:service:ContentDirectory:1",47));
  573. }
  574. struct UPnPService *RNDGetService_ConnectionManager(struct UPnPDevice *device)
  575. {
  576. return(RNDGetService(device,"urn:schemas-upnp-org:service:ConnectionManager:1",48));
  577. }
  578. struct UPnPDevice *RNDGetDevice2(struct UPnPDevice *device, int index, int *c_Index)
  579. {
  580. struct UPnPDevice *RetVal = NULL;
  581. struct UPnPDevice *e_Device = NULL;
  582. int currentIndex = *c_Index;
  583. if(strncmp(device->DeviceType,"urn:schemas-upnp-org:device:MediaServer:1",41)==0)
  584. {
  585. ++currentIndex;
  586. if(currentIndex==index)
  587. {
  588. *c_Index = currentIndex;
  589. return(device);
  590. }
  591. }
  592. e_Device = device->EmbeddedDevices;
  593. while(e_Device!=NULL)
  594. {
  595. RetVal = RNDGetDevice2(e_Device,index,&currentIndex);
  596. if(RetVal!=NULL)
  597. {
  598. break;
  599. }
  600. e_Device = e_Device->Next;
  601. }
  602. *c_Index = currentIndex;
  603. return(RetVal);
  604. }
  605. struct UPnPDevice* RNDGetDevice1(struct UPnPDevice *device,int index)
  606. {
  607. int c_Index = -1;
  608. return(RNDGetDevice2(device,index,&c_Index));
  609. }
  610. int RNDGetDeviceCount(struct UPnPDevice *device)
  611. {
  612. int RetVal = 0;
  613. struct UPnPDevice *e_Device = device->EmbeddedDevices;
  614. while(e_Device!=NULL)
  615. {
  616. RetVal += RNDGetDeviceCount(e_Device);
  617. e_Device = e_Device->Next;
  618. }
  619. if(strncmp(device->DeviceType,"urn:schemas-upnp-org:device:MediaServer:1",41)==0)
  620. {
  621. ++RetVal;
  622. }
  623. return(RetVal);
  624. }
  625. int RNDGetErrorCode(char *buffer, int length)
  626. {
  627. int RetVal = 500;
  628. struct ILibXMLNode *xml,*rootXML;
  629. char *temp;
  630. int tempLength;
  631. rootXML = xml = ILibParseXML(buffer,0,length);
  632. ILibProcessXMLNodeList(xml);
  633. while(xml!=NULL)
  634. {
  635. if(xml->NameLength==8 && memcmp(xml->Name,"Envelope",8)==0)
  636. {
  637. xml = xml->Next;
  638. while(xml!=NULL)
  639. {
  640. if(xml->NameLength==4 && memcmp(xml->Name,"Body",4)==0)
  641. {
  642. xml = xml->Next;
  643. while(xml!=NULL)
  644. {
  645. if(xml->NameLength==5 && memcmp(xml->Name,"Fault",5)==0)
  646. {
  647. xml = xml->Next;
  648. while(xml!=NULL)
  649. {
  650. if(xml->NameLength==6 && memcmp(xml->Name,"detail",6)==0)
  651. {
  652. xml = xml->Next;
  653. while(xml!=NULL)
  654. {
  655. if(xml->NameLength==9 && memcmp(xml->Name,"UPnPError",9)==0)
  656. {
  657. xml = xml->Next;
  658. while(xml!=NULL)
  659. {
  660. if(xml->NameLength==9 && memcmp(xml->Name,"errorCode",9)==0)
  661. {
  662. tempLength = ILibReadInnerXML(xml,&temp);
  663. temp[tempLength] = 0;
  664. RetVal =atoi(temp);
  665. xml = NULL;
  666. }
  667. if(xml!=NULL) {xml = xml->Peer;}
  668. }
  669. }
  670. if(xml!=NULL) {xml = xml->Peer;}
  671. }
  672. }
  673. if(xml!=NULL) {xml = xml->Peer;}
  674. }
  675. }
  676. if(xml!=NULL) {xml = xml->Peer;}
  677. }
  678. }
  679. if(xml!=NULL) {xml = xml->Peer;}
  680. }
  681. }
  682. if(xml!=NULL) {xml = xml->Peer;}
  683. }
  684. ILibDestructXMLNodeList(rootXML);
  685. return(RetVal);
  686. }
  687. void RNDProcessSCPD(char* buffer, int length, struct UPnPService *service)
  688. {
  689. struct UPnPAction *action;
  690. struct UPnPStateVariable *sv = NULL;
  691. struct UPnPAllowedValue *av = NULL;
  692. struct UPnPAllowedValue *avs = NULL;
  693. struct ILibXMLNode *xml,*rootXML;
  694. int flg2,flg3,flg4;
  695. char* tempString;
  696. int tempStringLength;
  697. rootXML = xml = ILibParseXML(buffer,0,length);
  698. ILibProcessXMLNodeList(xml);
  699. xml = xml->Next;
  700. while(xml!=NULL)
  701. {
  702. if(xml->NameLength==10 && memcmp(xml->Name,"actionList",10)==0)
  703. {
  704. xml = xml->Next;
  705. flg2 = 0;
  706. while(flg2==0)
  707. {
  708. if(xml->NameLength==6 && memcmp(xml->Name,"action",6)==0)
  709. {
  710. action = (struct UPnPAction*)MALLOC(sizeof(struct UPnPAction));
  711. action->Name = NULL;
  712. action->Next = service->Actions;
  713. service->Actions = action;
  714. xml = xml->Next;
  715. flg3 = 0;
  716. while(flg3==0)
  717. {
  718. if(xml->NameLength==4 && memcmp(xml->Name,"name",4)==0)
  719. {
  720. tempStringLength = ILibReadInnerXML(xml,&tempString);
  721. action->Name = (char*)MALLOC(1+tempStringLength);
  722. memcpy(action->Name,tempString,tempStringLength);
  723. action->Name[tempStringLength] = '\0';
  724. }
  725. if(xml->Peer==NULL)
  726. {
  727. flg3 = -1;
  728. xml = xml->Parent;
  729. }
  730. else
  731. {
  732. xml = xml->Peer;
  733. }
  734. }
  735. }
  736. if(xml->Peer==NULL)
  737. {
  738. flg2 = -1;
  739. xml = xml->Parent;
  740. }
  741. else
  742. {
  743. xml = xml->Peer;
  744. }
  745. }
  746. }
  747. if(xml->NameLength==17 && memcmp(xml->Name,"serviceStateTable",17)==0)
  748. {
  749. if(xml->Next->StartTag!=0)
  750. {
  751. xml = xml->Next;
  752. flg2 = 0;
  753. while(flg2==0)
  754. {
  755. if(xml->NameLength==13 && memcmp(xml->Name,"stateVariable",13)==0)
  756. {
  757. sv = (struct UPnPStateVariable*)MALLOC(sizeof(struct UPnPStateVariable));
  758. sv->AllowedValues = NULL;
  759. sv->NumAllowedValues = 0;
  760. sv->Max = NULL;
  761. sv->Min = NULL;
  762. sv->Step = NULL;
  763. sv->Name = NULL;
  764. sv->Next = service->Variables;
  765. service->Variables = sv;
  766. sv->Parent = service;
  767. xml = xml->Next;
  768. flg3 = 0;
  769. while(flg3==0)
  770. {
  771. if(xml->NameLength==4 && memcmp(xml->Name,"name",4)==0)
  772. {
  773. tempStringLength = ILibReadInnerXML(xml,&tempString);
  774. sv->Name = (char*)MALLOC(1+tempStringLength);
  775. memcpy(sv->Name,tempString,tempStringLength);
  776. sv->Name[tempStringLength] = '\0';
  777. }
  778. if(xml->NameLength==16 && memcmp(xml->Name,"allowedValueList",16)==0)
  779. {
  780. if(xml->Next->StartTag!=0)
  781. {
  782. avs = NULL;
  783. xml = xml->Next;
  784. flg4 = 0;
  785. while(flg4==0)
  786. {
  787. if(xml->NameLength==12 && memcmp(xml->Name,"allowedValue",12)==0)
  788. {
  789. av = (struct UPnPAllowedValue*)MALLOC(sizeof(struct UPnPAllowedValue));
  790. av->Next = avs;
  791. avs = av;
  792. tempStringLength = ILibReadInnerXML(xml,&tempString);
  793. av->Value = (char*)MALLOC(1+tempStringLength);
  794. memcpy(av->Value,tempString,tempStringLength);
  795. av->Value[tempStringLength] = '\0';
  796. }
  797. if(xml->Peer!=NULL)
  798. {
  799. xml = xml->Peer;
  800. }
  801. else
  802. {
  803. xml = xml->Parent;
  804. flg4 = -1;
  805. }
  806. }
  807. av = avs;
  808. while(av!=NULL)
  809. {
  810. ++sv->NumAllowedValues;
  811. av = av->Next;
  812. }
  813. av = avs;
  814. sv->AllowedValues = (char**)MALLOC(sv->NumAllowedValues*sizeof(char*));
  815. for(flg4=0;flg4<sv->NumAllowedValues;++flg4)
  816. {
  817. sv->AllowedValues[flg4] = av->Value;
  818. av = av->Next;
  819. }
  820. av = avs;
  821. while(av!=NULL)
  822. {
  823. avs = av->Next;
  824. FREE(av);
  825. av = avs;
  826. }
  827. }
  828. }
  829. if(xml->NameLength==17 && memcmp(xml->Name,"allowedValueRange",17)==0)
  830. {
  831. if(xml->Next->StartTag!=0)
  832. {
  833. xml = xml->Next;
  834. flg4 = 0;
  835. while(flg4==0)
  836. {
  837. if(xml->NameLength==7)
  838. {
  839. if(memcmp(xml->Name,"minimum",7)==0)
  840. {
  841. tempStringLength = ILibReadInnerXML(xml,&tempString);
  842. sv->Min = (char*)MALLOC(1+tempStringLength);
  843. memcpy(sv->Min,tempString,tempStringLength);
  844. sv->Min[tempStringLength] = '\0';
  845. }
  846. else if(memcmp(xml->Name,"maximum",7)==0)
  847. {
  848. tempStringLength = ILibReadInnerXML(xml,&tempString);
  849. sv->Max = (char*)MALLOC(1+tempStringLength);
  850. memcpy(sv->Max,tempString,tempStringLength);
  851. sv->Max[tempStringLength] = '\0';
  852. }
  853. }
  854. if(xml->NameLength==4 && memcmp(xml->Name,"step",4)==0)
  855. {
  856. tempStringLength = ILibReadInnerXML(xml,&tempString);
  857. sv->Step = (char*)MALLOC(1+tempStringLength);
  858. memcpy(sv->Step,tempString,tempStringLength);
  859. sv->Step[tempStringLength] = '\0';
  860. }
  861. if(xml->Peer!=NULL)
  862. {
  863. xml = xml->Peer;
  864. }
  865. else
  866. {
  867. xml = xml->Parent;
  868. flg4 = -1;
  869. }
  870. }
  871. }
  872. }
  873. if(xml->Peer!=NULL)
  874. {
  875. xml = xml->Peer;
  876. }
  877. else
  878. {
  879. flg3 = -1;
  880. xml = xml->Parent;
  881. }
  882. }
  883. }
  884. if(xml->Peer!=NULL)
  885. {
  886. xml = xml->Peer;
  887. }
  888. else
  889. {
  890. xml = xml->Parent;
  891. flg2 = -1;
  892. }
  893. }
  894. }
  895. }
  896. xml = xml->Peer;
  897. }
  898. ILibDestructXMLNodeList(rootXML);
  899. }
  900. void RNDExpireRequests(struct UPnPDevice *device)
  901. {
  902. struct UPnPDevice *ed = device->EmbeddedDevices;
  903. struct UPnPService *s = device->Services;
  904. while(ed!=NULL)
  905. {
  906. RNDExpireRequests(ed);
  907. ed = ed->Next;
  908. }
  909. while(s!=NULL)
  910. {
  911. ILibDeleteRequests(((struct RNDCP*)s->Parent->CP)->HTTP,s);
  912. s = s->Next;
  913. }
  914. }
  915. void RNDDeviceExpired(struct UPnPDevice *device)
  916. {
  917. printf("Device[%s] failed to re-advertise in a timely manner\r\n",device->FriendlyName);
  918. RNDExpireRequests(device);
  919. RNDSSDP_Sink(NULL, device->UDN, 0, NULL, 0,device->CP);
  920. }
  921. void RNDFinishProcessingDevice(struct RNDCP* CP, struct UPnPDevice *RootDevice)
  922. {
  923. char *RootUDN = RootDevice->UDN;
  924. int Timeout = RootDevice->CacheTime;
  925. struct UPnPDevice *RetDevice;
  926. int i=0;
  927. RootDevice->ReferenceCount = 0;
  928. RNDAttachDeviceToUDN(CP,RootDevice->UDN,RootDevice);
  929. do
  930. {
  931. RetDevice = RNDGetDevice1(RootDevice,i++);
  932. if(RetDevice!=NULL)
  933. {
  934. RNDAddUDN(CP,RetDevice->UDN);
  935. RNDAttachRootUDNToUDN(CP,RetDevice->UDN,RootUDN);
  936. if(CP->DiscoverSink!=NULL)
  937. {
  938. CP->DiscoverSink(RetDevice);
  939. }
  940. }
  941. }while(RetDevice!=NULL);
  942. RetDevice = RNDGetDeviceAtUDN(CP,RootUDN);
  943. if(RetDevice!=NULL)
  944. {
  945. ILibLifeTime_Add(CP->LifeTimeMonitor,RetDevice,Timeout,&RNDDeviceExpired,NULL);
  946. RNDRelease(RetDevice);
  947. }
  948. }
  949. void RNDSCPD_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* dv, void* sv)
  950. {
  951. struct UPnPDevice *device;
  952. struct UPnPService *service = (struct UPnPService*)sv;
  953. struct RNDCP *CP = service->Parent->CP;
  954. if(!(header==NULL || header->StatusCode!=200) && done!=0)
  955. {
  956. RNDProcessSCPD(buffer,EndPointer, service);
  957. device = service->Parent;
  958. while(device->Parent!=NULL)
  959. {
  960. device = device->Parent;
  961. }
  962. --device->SCPDLeft;
  963. if(device->SCPDLeft==0)
  964. {
  965. RNDFinishProcessingDevice(CP,device);
  966. }
  967. }
  968. else
  969. {
  970. if(done!=0 && (header==NULL || header->StatusCode!=200))
  971. {
  972. ILibDeleteRequests(CP->HTTP,dv);
  973. RNDDestructUPnPDevice(dv);
  974. }
  975. }
  976. }
  977. void RNDCalculateSCPD_FetchCount(struct UPnPDevice *device)
  978. {
  979. int count = 0;
  980. struct UPnPDevice *root;
  981. struct UPnPDevice *e_Device = device->EmbeddedDevices;
  982. struct UPnPService *s;
  983. while(e_Device!=NULL)
  984. {
  985. RNDCalculateSCPD_FetchCount(e_Device);
  986. e_Device = e_Device->Next;
  987. }
  988. s = device->Services;
  989. while(s!=NULL)
  990. {
  991. ++count;
  992. s = s->Next;
  993. }
  994. root = device;
  995. while(root->Parent!=NULL)
  996. {
  997. root = root->Parent;
  998. }
  999. root->SCPDLeft += count;
  1000. }
  1001. void RNDSCPD_Fetch(struct UPnPDevice *device)
  1002. {
  1003. struct UPnPDevice *e_Device = device->EmbeddedDevices;
  1004. struct UPnPService *s;
  1005. char *IP,*Path;
  1006. unsigned short Port;
  1007. struct packetheader *p;
  1008. struct sockaddr_in addr;
  1009. while(e_Device!=NULL)
  1010. {
  1011. RNDSCPD_Fetch(e_Device);
  1012. e_Device = e_Device->Next;
  1013. }
  1014. s = device->Services;
  1015. while(s!=NULL)
  1016. {
  1017. RNDParseUri(s->SCPDURL,&IP,&Port,&Path);
  1018. DEBUGSTATEMENT(printf("SCPD: %s Port: %d Path: %s\r\n",IP,Port,Path));
  1019. p = RNDBuildPacket(IP,Port,Path,"GET");
  1020. memset((char *)&addr, 0,sizeof(addr));
  1021. addr.sin_family = AF_INET;
  1022. addr.sin_addr.s_addr = inet_addr(IP);
  1023. addr.sin_port = htons(Port);
  1024. ILibAddRequest(((struct RNDCP*)device->CP)->HTTP, p,&addr, &RNDSCPD_Sink, device, s);
  1025. FREE(IP);
  1026. FREE(Path);
  1027. s = s->Next;
  1028. }
  1029. }
  1030. struct UPnPDevice* RNDProcessDeviceXML_device(struct ILibXMLNode *xml, void *v_CP,const char *BaseURL, int Timeout, int RecvAddr)
  1031. {
  1032. struct ILibXMLNode *tempNode;
  1033. int flg,flg2;
  1034. char *tempString;
  1035. int tempStringLength;
  1036. struct parser_result *tpr;
  1037. char* ServiceType = NULL;
  1038. int ServiceTypeLength = 0;
  1039. char* SCPDURL = NULL;
  1040. int SCPDURLLength = 0;
  1041. char* EventSubURL = NULL;
  1042. int EventSubURLLength = 0;
  1043. char* ControlURL = NULL;
  1044. int ControlURLLength = 0;
  1045. struct UPnPDevice *tempDevice;
  1046. struct UPnPService *TempService;
  1047. struct UPnPDevice *device = (struct UPnPDevice*)MALLOC(sizeof(struct UPnPDevice));
  1048. device->CP = v_CP;
  1049. device->CacheTime = Timeout;
  1050. device->Tag = NULL;
  1051. device->InterfaceToHost = (char*)MALLOC(16);
  1052. sprintf(device->InterfaceToHost,"%d.%d.%d.%d",(RecvAddr&0xFF),((RecvAddr>>8)&0xFF),((RecvAddr>>16)&0xFF),((RecvAddr>>24)&0xFF));
  1053. device->DeviceType = NULL;
  1054. device->UDN = NULL;
  1055. device->LocationURL = NULL;
  1056. device->FriendlyName = NULL;
  1057. device->Parent = NULL;
  1058. device->EmbeddedDevices = NULL;
  1059. device->Services = NULL;
  1060. device->Next = NULL;
  1061. device->LocationURL = NULL;
  1062. device->PresentationURL = NULL;
  1063. device->FriendlyName = NULL;
  1064. device->ManufacturerName = NULL;
  1065. device->ManufacturerURL = NULL;
  1066. device->ModelName = NULL;
  1067. device->ModelDescription = NULL;
  1068. device->ModelNumber = NULL;
  1069. device->ModelURL = NULL;
  1070. device->SCPDLeft = 0;
  1071. xml = xml->Next;
  1072. while(xml!=NULL)
  1073. {
  1074. if(xml->NameLength==10 && memcmp(xml->Name,"deviceList",10)==0)
  1075. {
  1076. if(xml->Next->StartTag!=0)
  1077. {
  1078. xml = xml->Next;
  1079. flg2 = 0;
  1080. while(flg2==0)
  1081. {
  1082. if(xml->NameLength==6 && memcmp(xml->Name,"device",6)==0)
  1083. {
  1084. tempDevice = RNDProcessDeviceXML_device(xml,v_CP,BaseURL,Timeout, RecvAddr);
  1085. tempDevice->Parent = device;
  1086. tempDevice->Next = device->EmbeddedDevices;
  1087. device->EmbeddedDevices = tempDevice;
  1088. }
  1089. if(xml->Peer==NULL)
  1090. {
  1091. flg2 = 1;
  1092. xml = xml->Parent;
  1093. }
  1094. else
  1095. {
  1096. xml = xml->Peer;
  1097. }
  1098. }
  1099. }
  1100. } else
  1101. if(xml->NameLength==3 && memcmp(xml->Name,"UDN",3)==0)
  1102. {
  1103. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1104. if(tempStringLength>5)
  1105. {
  1106. if(memcmp(tempString,"uuid:",5)==0)
  1107. {
  1108. tempString += 5;
  1109. tempStringLength -= 5;
  1110. }
  1111. device->UDN = (char*)MALLOC(tempStringLength+1);
  1112. memcpy(device->UDN,tempString,tempStringLength);
  1113. device->UDN[tempStringLength] = '\0';
  1114. }
  1115. } else
  1116. if(xml->NameLength==10 && memcmp(xml->Name,"deviceType",10) == 0)
  1117. {
  1118. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1119. device->DeviceType = (char*)MALLOC(tempStringLength+1);
  1120. memcpy(device->DeviceType,tempString,tempStringLength);
  1121. device->DeviceType[tempStringLength] = '\0';
  1122. } else
  1123. if(xml->NameLength==12 && memcmp(xml->Name,"friendlyName",12) == 0)
  1124. {
  1125. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1126. device->FriendlyName = (char*)MALLOC(1+tempStringLength);
  1127. memcpy(device->FriendlyName,tempString,tempStringLength);
  1128. device->FriendlyName[tempStringLength] = '\0';
  1129. } else
  1130. if(xml->NameLength==12 && memcmp(xml->Name,"manufacturer",12) == 0)
  1131. {
  1132. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1133. device->ManufacturerName = (char*)MALLOC(1+tempStringLength);
  1134. memcpy(device->ManufacturerName,tempString,tempStringLength);
  1135. device->ManufacturerName[tempStringLength] = '\0';
  1136. } else
  1137. if(xml->NameLength==15 && memcmp(xml->Name,"manufacturerURL",15) == 0)
  1138. {
  1139. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1140. device->ManufacturerURL = (char*)MALLOC(1+tempStringLength);
  1141. memcpy(device->ManufacturerURL,tempString,tempStringLength);
  1142. device->ManufacturerURL[tempStringLength] = '\0';
  1143. } else
  1144. if(xml->NameLength==16 && memcmp(xml->Name,"modelDescription",16) == 0)
  1145. {
  1146. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1147. device->ModelDescription = (char*)MALLOC(1+tempStringLength);
  1148. memcpy(device->ModelDescription,tempString,tempStringLength);
  1149. device->ModelDescription[tempStringLength] = '\0';
  1150. } else
  1151. if(xml->NameLength==9 && memcmp(xml->Name,"modelName",9) == 0)
  1152. {
  1153. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1154. device->ModelName = (char*)MALLOC(1+tempStringLength);
  1155. memcpy(device->ModelName,tempString,tempStringLength);
  1156. device->ModelName[tempStringLength] = '\0';
  1157. } else
  1158. if(xml->NameLength==11 && memcmp(xml->Name,"modelNumber",11) == 0)
  1159. {
  1160. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1161. device->ModelNumber = (char*)MALLOC(1+tempStringLength);
  1162. memcpy(device->ModelNumber,tempString,tempStringLength);
  1163. device->ModelNumber[tempStringLength] = '\0';
  1164. } else
  1165. if(xml->NameLength==8 && memcmp(xml->Name,"modelURL",8) == 0)
  1166. {
  1167. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1168. device->ModelURL = (char*)MALLOC(1+tempStringLength);
  1169. memcpy(device->ModelURL,tempString,tempStringLength);
  1170. device->ModelURL[tempStringLength] = '\0';
  1171. } else
  1172. if(xml->NameLength==15 && memcmp(xml->Name,"presentationURL",15) == 0)
  1173. {
  1174. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1175. tempString[tempStringLength] = 0;
  1176. tpr = ILibParseString(tempString,0,tempStringLength,"://",3);
  1177. if(tpr->NumResults==1)
  1178. {
  1179. /* RelativeURL */
  1180. if(tempString[0]=='/')
  1181. {
  1182. device->PresentationURL = (char*)MALLOC(1+strlen(BaseURL)+tempStringLength);
  1183. memcpy(device->PresentationURL,BaseURL,strlen(BaseURL));
  1184. strcpy(device->PresentationURL+strlen(BaseURL),tempString+1);
  1185. }
  1186. else
  1187. {
  1188. device->PresentationURL = (char*)MALLOC(2+strlen(BaseURL)+tempStringLength);
  1189. memcpy(device->PresentationURL,BaseURL,strlen(BaseURL));
  1190. strcpy(device->PresentationURL+strlen(BaseURL),tempString);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. /* AbsoluteURL */
  1196. device->PresentationURL = (char*)MALLOC(1+tempStringLength);
  1197. memcpy(device->PresentationURL,tempString,tempStringLength);
  1198. device->PresentationURL[tempStringLength] = '\0';
  1199. }
  1200. ILibDestructParserResults(tpr);
  1201. } else
  1202. if(xml->NameLength==11 && memcmp(xml->Name,"serviceList",11)==0)
  1203. {
  1204. xml = xml->Next;
  1205. tempNode = xml;
  1206. while(xml!=NULL)
  1207. {
  1208. if(xml->NameLength==7 && memcmp(xml->Name,"service",7)==0)
  1209. {
  1210. ServiceType = NULL;
  1211. ServiceTypeLength = 0;
  1212. SCPDURL = NULL;
  1213. SCPDURLLength = 0;
  1214. EventSubURL = NULL;
  1215. EventSubURLLength = 0;
  1216. ControlURL = NULL;
  1217. ControlURLLength = 0;
  1218. xml = xml->Next;
  1219. flg = 0;
  1220. while(flg==0)
  1221. {
  1222. if(xml->NameLength==11 && memcmp(xml->Name,"serviceType",11)==0)
  1223. {
  1224. ServiceTypeLength = ILibReadInnerXML(xml,&ServiceType);
  1225. } else
  1226. if(xml->NameLength==7 && memcmp(xml->Name,"SCPDURL",7) == 0)
  1227. {
  1228. SCPDURLLength = ILibReadInnerXML(xml,&SCPDURL);
  1229. } else
  1230. if(xml->NameLength==10 && memcmp(xml->Name,"controlURL",10) == 0)
  1231. {
  1232. ControlURLLength = ILibReadInnerXML(xml,&ControlURL);
  1233. } else
  1234. if(xml->NameLength==11 && memcmp(xml->Name,"eventSubURL",11) == 0)
  1235. {
  1236. EventSubURLLength = ILibReadInnerXML(xml,&EventSubURL);
  1237. }
  1238. if(xml->Peer!=NULL)
  1239. {
  1240. xml = xml->Peer;
  1241. }
  1242. else
  1243. {
  1244. flg = 1;
  1245. xml = xml->Parent;
  1246. }
  1247. }
  1248. /* Finished Parsing the ServiceSection, build the Service */
  1249. ServiceType[ServiceTypeLength] = '\0';
  1250. SCPDURL[SCPDURLLength] = '\0';
  1251. EventSubURL[EventSubURLLength] = '\0';
  1252. ControlURL[ControlURLLength] = '\0';
  1253. TempService = (struct UPnPService*)MALLOC(sizeof(struct UPnPService));
  1254. TempService->SubscriptionID = NULL;
  1255. TempService->ServiceId = NULL;
  1256. TempService->Actions = NULL;
  1257. TempService->Variables = NULL;
  1258. TempService->Next = NULL;
  1259. TempService->Parent = device;
  1260. if(EventSubURLLength>=7 && memcmp(EventSubURL,"http://",6)==0)
  1261. {
  1262. /* Explicit */
  1263. TempService->SubscriptionURL = (char*)MALLOC(EventSubURLLength+1);
  1264. memcpy(TempService->SubscriptionURL,EventSubURL,EventSubURLLength);
  1265. TempService->SubscriptionURL[EventSubURLLength] = '\0';
  1266. }
  1267. else
  1268. {
  1269. /* Relative */
  1270. if(memcmp(EventSubURL,"/",1)!=0)
  1271. {
  1272. TempService->SubscriptionURL = (char*)MALLOC(EventSubURLLength+(int)strlen(BaseURL)+1);
  1273. memcpy(TempService->SubscriptionURL,BaseURL,(int)strlen(BaseURL));
  1274. memcpy(TempService->SubscriptionURL+(int)strlen(BaseURL),EventSubURL,EventSubURLLength);
  1275. TempService->SubscriptionURL[EventSubURLLength+(int)strlen(BaseURL)] = '\0';
  1276. }
  1277. else
  1278. {
  1279. TempService->SubscriptionURL = (char*)MALLOC(EventSubURLLength+(int)strlen(BaseURL)+1);
  1280. memcpy(TempService->SubscriptionURL,BaseURL,(int)strlen(BaseURL));
  1281. memcpy(TempService->SubscriptionURL+(int)strlen(BaseURL),EventSubURL+1,EventSubURLLength-1);
  1282. TempService->SubscriptionURL[EventSubURLLength+(int)strlen(BaseURL)-1] = '\0';
  1283. }
  1284. }
  1285. if(ControlURLLength>=7 && memcmp(ControlURL,"http://",6)==0)
  1286. {
  1287. /* Explicit */
  1288. TempService->ControlURL = (char*)MALLOC(ControlURLLength+1);
  1289. memcpy(TempService->ControlURL,ControlURL,ControlURLLength);
  1290. TempService->ControlURL[ControlURLLength] = '\0';
  1291. }
  1292. else
  1293. {
  1294. /* Relative */
  1295. if(memcmp(ControlURL,"/",1)!=0)
  1296. {
  1297. TempService->ControlURL = (char*)MALLOC(ControlURLLength+(int)strlen(BaseURL)+1);
  1298. memcpy(TempService->ControlURL,BaseURL,(int)strlen(BaseURL));
  1299. memcpy(TempService->ControlURL+(int)strlen(BaseURL),ControlURL,ControlURLLength);
  1300. TempService->ControlURL[ControlURLLength+(int)strlen(BaseURL)] = '\0';
  1301. }
  1302. else
  1303. {
  1304. TempService->ControlURL = (char*)MALLOC(ControlURLLength+(int)strlen(BaseURL)+1);
  1305. memcpy(TempService->ControlURL,BaseURL,(int)strlen(BaseURL));
  1306. memcpy(TempService->ControlURL+(int)strlen(BaseURL),ControlURL+1,ControlURLLength-1);
  1307. TempService->ControlURL[ControlURLLength+(int)strlen(BaseURL)-1] = '\0';
  1308. }
  1309. }
  1310. if(SCPDURLLength>=7 && memcmp(SCPDURL,"http://",6)==0)
  1311. {
  1312. /* Explicit */
  1313. TempService->SCPDURL = (char*)MALLOC(SCPDURLLength+1);
  1314. memcpy(TempService->SCPDURL,SCPDURL,SCPDURLLength);
  1315. TempService->SCPDURL[SCPDURLLength] = '\0';
  1316. }
  1317. else
  1318. {
  1319. /* Relative */
  1320. if(memcmp(SCPDURL,"/",1)!=0)
  1321. {
  1322. TempService->SCPDURL = (char*)MALLOC(SCPDURLLength+(int)strlen(BaseURL)+1);
  1323. memcpy(TempService->SCPDURL,BaseURL,(int)strlen(BaseURL));
  1324. memcpy(TempService->SCPDURL+(int)strlen(BaseURL),SCPDURL,SCPDURLLength);
  1325. TempService->SCPDURL[SCPDURLLength+(int)strlen(BaseURL)] = '\0';
  1326. }
  1327. else
  1328. {
  1329. TempService->SCPDURL = (char*)MALLOC(SCPDURLLength+(int)strlen(BaseURL)+1);
  1330. memcpy(TempService->SCPDURL,BaseURL,(int)strlen(BaseURL));
  1331. memcpy(TempService->SCPDURL+(int)strlen(BaseURL),SCPDURL+1,SCPDURLLength-1);
  1332. TempService->SCPDURL[SCPDURLLength+(int)strlen(BaseURL)-1] = '\0';
  1333. }
  1334. }
  1335. TempService->ServiceType = (char*)MALLOC(ServiceTypeLength+1);
  1336. sprintf(TempService->ServiceType,ServiceType,ServiceTypeLength);
  1337. TempService->Next = device->Services;
  1338. device->Services = TempService;
  1339. DEBUGSTATEMENT(printf("ServiceType: %s\r\nSCPDURL: %s\r\nEventSubURL: %s\r\nControl URL: %s\r\n",ServiceType,SCPDURL,EventSubURL,ControlURL));
  1340. }
  1341. xml = xml->Peer;
  1342. }
  1343. xml = tempNode;
  1344. } // End of ServiceList
  1345. xml = xml->Peer;
  1346. } // End of While
  1347. return(device);
  1348. }
  1349. void RNDProcessDeviceXML(void *v_CP,char* buffer, int BufferSize, char* LocationURL, int RecvAddr, int Timeout)
  1350. {
  1351. struct UPnPDevice *RootDevice = NULL;
  1352. char* IP;
  1353. unsigned short Port;
  1354. char* Path;
  1355. char* BaseURL = NULL;
  1356. struct ILibXMLNode *rootXML;
  1357. struct ILibXMLNode *xml;
  1358. char* tempString;
  1359. int tempStringLength;
  1360. rootXML = ILibParseXML(buffer,0,BufferSize);
  1361. ILibProcessXMLNodeList(rootXML);
  1362. xml = rootXML;
  1363. xml = xml->Next;
  1364. while(xml!=NULL)
  1365. {
  1366. if(xml->NameLength==7 && memcmp(xml->Name,"URLBase",7)==0)
  1367. {
  1368. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1369. if(tempString[tempStringLength-1]!='/')
  1370. {
  1371. BaseURL = (char*)MALLOC(2+tempStringLength);
  1372. memcpy(BaseURL,tempString,tempStringLength);
  1373. BaseURL[tempStringLength] = '/';
  1374. BaseURL[tempStringLength+1] = '\0';
  1375. }
  1376. else
  1377. {
  1378. BaseURL = (char*)MALLOC(1+tempStringLength);
  1379. memcpy(BaseURL,tempString,tempStringLength);
  1380. BaseURL[tempStringLength] = '\0';
  1381. }
  1382. break;
  1383. }
  1384. xml = xml->Peer;
  1385. }
  1386. if(BaseURL==NULL)
  1387. {
  1388. RNDParseUri(LocationURL,&IP,&Port,&Path);
  1389. BaseURL = (char*)MALLOC(18+(int)strlen(IP));
  1390. sprintf(BaseURL,"http://%s:%d/",IP,Port);
  1391. FREE(IP);
  1392. FREE(Path);
  1393. }
  1394. DEBUGSTATEMENT(printf("BaseURL: %s\r\n",BaseURL));
  1395. xml = rootXML;
  1396. xml = xml->Next;
  1397. while(xml->NameLength!=6 && memcmp(xml->Name,"device",6)!=0 && xml!=NULL)
  1398. {
  1399. xml = xml->Peer;
  1400. }
  1401. if(xml==NULL)
  1402. {
  1403. /* Error */
  1404. ILibDestructXMLNodeList(rootXML);
  1405. return;
  1406. }
  1407. RootDevice = RNDProcessDeviceXML_device(xml,v_CP,BaseURL,Timeout,RecvAddr);
  1408. FREE(BaseURL);
  1409. ILibDestructXMLNodeList(rootXML);
  1410. /* Add Root Device to UDNTable */
  1411. RNDAddUDN(v_CP,RootDevice->UDN);
  1412. /* Save reference to LocationURL in the RootDevice */
  1413. RootDevice->LocationURL = (char*)MALLOC(strlen(LocationURL)+1);
  1414. sprintf(RootDevice->LocationURL,"%s",LocationURL);
  1415. /* Trim Object Structure */
  1416. RNDProcessDevice(RootDevice);
  1417. RootDevice->SCPDLeft = 0;
  1418. RNDCalculateSCPD_FetchCount(RootDevice);
  1419. if(RootDevice->SCPDLeft==0)
  1420. {
  1421. RNDFinishProcessingDevice(v_CP,RootDevice);
  1422. }
  1423. else
  1424. {
  1425. RNDSCPD_Fetch(RootDevice);
  1426. }
  1427. }
  1428. void RNDHTTP_Sink_DeviceDescription(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* user, void* cp)
  1429. {
  1430. struct CustomUserData *customData = (struct CustomUserData*)user;
  1431. if(header!=NULL && done!=0)
  1432. {
  1433. RNDProcessDeviceXML(cp,buffer,EndPointer-(*p_BeginPointer),customData->buffer,header->ReceivingAddress,customData->Timeout);
  1434. }
  1435. if(done!=0)
  1436. {
  1437. FREE(customData->buffer);
  1438. FREE(user);
  1439. }
  1440. }
  1441. void RND_FlushRequest(struct UPnPDevice *device)
  1442. {
  1443. struct UPnPDevice *ed = device->EmbeddedDevices;
  1444. struct UPnPService *s = device->Services;
  1445. while(ed!=NULL)
  1446. {
  1447. RND_FlushRequest(ed);
  1448. ed = ed->Next;
  1449. }
  1450. while(s!=NULL)
  1451. {
  1452. ILibDeleteRequests(((struct RNDCP*)device->CP)->HTTP, s);
  1453. s = s->Next;
  1454. }
  1455. }
  1456. void RNDSSDP_Sink(void *sender, char* UDN, int Alive, char* LocationURL, int Timeout,void *cp)
  1457. {
  1458. struct CustomUserData *customData;
  1459. char* buffer;
  1460. char* IP;
  1461. unsigned short Port;
  1462. char* Path;
  1463. struct packetheader *p;
  1464. struct sockaddr_in addr;
  1465. struct UPnPDevice *device,*tempDevice;
  1466. int i=0;
  1467. if(Alive!=0)
  1468. {
  1469. /* Hello */
  1470. DEBUGSTATEMENT(printf("MediaServer Hello\r\n"));
  1471. DEBUGSTATEMENT(printf("LocationURL: %s\r\n",LocationURL));
  1472. if(RNDHasUDN(cp,LocationURL)==0)
  1473. {
  1474. RNDAddUDN(cp,LocationURL);
  1475. if(RNDHasUDN(cp,UDN)==0)
  1476. {
  1477. RNDAddUDN(cp,UDN);
  1478. RNDParseUri(LocationURL,&IP,&Port,&Path);
  1479. DEBUGSTATEMENT(printf("IP: %s Port: %d Path: %s\r\n",IP,Port,Path));
  1480. p = RNDBuildPacket(IP,Port,Path,"GET");
  1481. memset((char *)&addr, 0,sizeof(addr));
  1482. addr.sin_family = AF_INET;
  1483. addr.sin_addr.s_addr = inet_addr(IP);
  1484. addr.sin_port = htons(Port);
  1485. buffer = (char*)MALLOC((int)strlen(LocationURL)+1);
  1486. strcpy(buffer,LocationURL);
  1487. customData = (struct CustomUserData*)MALLOC(sizeof(struct CustomUserData));
  1488. customData->Timeout = Timeout;
  1489. customData->buffer = buffer;
  1490. ILibAddRequest(((struct RNDCP*)cp)->HTTP, p,&addr, &RNDHTTP_Sink_DeviceDescription, customData, cp);
  1491. FREE(IP);
  1492. FREE(Path);
  1493. }
  1494. }
  1495. else
  1496. {
  1497. // Periodic Notify Packets
  1498. if(RNDHasUDN(cp,UDN)!=0)
  1499. {
  1500. buffer = RNDGetRootUDNAtUDN(cp,UDN);
  1501. if(buffer!=NULL)
  1502. {
  1503. device = RNDGetDeviceAtUDN(cp,buffer);
  1504. if(device!=NULL)
  1505. {
  1506. //Extend LifetimeMonitor duration
  1507. ILibLifeTime_Remove(((struct RNDCP*)cp)->LifeTimeMonitor,device);
  1508. ILibLifeTime_Add(((struct RNDCP*)cp)->LifeTimeMonitor,device,Timeout,&RNDDeviceExpired,NULL);
  1509. RNDRelease(device);
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. else
  1516. {
  1517. /* Bye Bye */
  1518. DEBUGSTATEMENT(printf("MediaServer ByeBye\r\n"));
  1519. device = RNDGetDeviceAtUDN(cp,UDN);
  1520. if(device!=NULL)
  1521. {
  1522. ILibLifeTime_Remove(((struct RNDCP*)cp)->LifeTimeMonitor,device);
  1523. RNDRemoveUDN(cp,device->LocationURL);
  1524. do
  1525. {
  1526. tempDevice = RNDGetDevice1(device,i++);
  1527. if(tempDevice!=NULL)
  1528. {
  1529. RND_FlushRequest(tempDevice);
  1530. if(((struct RNDCP*)cp)->RemoveSink!=NULL)
  1531. {
  1532. ((struct RNDCP*)cp)->RemoveSink(tempDevice);
  1533. }
  1534. }
  1535. } while(tempDevice!=NULL);
  1536. RNDRelease(device);
  1537. RNDRemoveUDN(cp,UDN);
  1538. }
  1539. }
  1540. }
  1541. void RNDContentDirectory_EventSink(char* buffer, int bufferlength, struct UPnPService *service)
  1542. {
  1543. struct ILibXMLNode *xml,*rootXML;
  1544. char *tempString;
  1545. int tempStringLength;
  1546. int flg,flg2;
  1547. char* TransferIDs = 0;
  1548. char* ContainerUpdateIDs = 0;
  1549. unsigned int SystemUpdateID = 0;
  1550. unsigned long TempULong;
  1551. /* Parse SOAP */
  1552. rootXML = xml = ILibParseXML(buffer,0,bufferlength);
  1553. ILibProcessXMLNodeList(xml);
  1554. while(xml!=NULL)
  1555. {
  1556. if(xml->NameLength==11 && memcmp(xml->Name,"propertyset",11)==0)
  1557. {
  1558. if(xml->Next->StartTag!=0)
  1559. {
  1560. flg = 0;
  1561. xml = xml->Next;
  1562. while(flg==0)
  1563. {
  1564. if(xml->NameLength==8 && memcmp(xml->Name,"property",8)==0)
  1565. {
  1566. xml = xml->Next;
  1567. flg2 = 0;
  1568. while(flg2==0)
  1569. {
  1570. if(xml->NameLength==11 && memcmp(xml->Name,"TransferIDs",11) == 0)
  1571. {
  1572. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1573. tempString[tempStringLength] = '\0';
  1574. TransferIDs = tempString;
  1575. if(RNDEventCallback_ContentDirectory_TransferIDs != NULL)
  1576. {
  1577. RNDEventCallback_ContentDirectory_TransferIDs(service,TransferIDs);
  1578. }
  1579. }
  1580. if(xml->NameLength==18 && memcmp(xml->Name,"ContainerUpdateIDs",18) == 0)
  1581. {
  1582. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1583. tempString[tempStringLength] = '\0';
  1584. ContainerUpdateIDs = tempString;
  1585. if(RNDEventCallback_ContentDirectory_ContainerUpdateIDs != NULL)
  1586. {
  1587. RNDEventCallback_ContentDirectory_ContainerUpdateIDs(service,ContainerUpdateIDs);
  1588. }
  1589. }
  1590. if(xml->NameLength==14 && memcmp(xml->Name,"SystemUpdateID",14) == 0)
  1591. {
  1592. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1593. if(ILibGetULong(tempString,tempStringLength,&TempULong)==0)
  1594. {
  1595. SystemUpdateID = (unsigned int) TempULong;
  1596. }
  1597. if(RNDEventCallback_ContentDirectory_SystemUpdateID != NULL)
  1598. {
  1599. RNDEventCallback_ContentDirectory_SystemUpdateID(service,SystemUpdateID);
  1600. }
  1601. }
  1602. if(xml->Peer!=NULL)
  1603. {
  1604. xml = xml->Peer;
  1605. }
  1606. else
  1607. {
  1608. flg2 = -1;
  1609. xml = xml->Parent;
  1610. }
  1611. }
  1612. }
  1613. if(xml->Peer!=NULL)
  1614. {
  1615. xml = xml->Peer;
  1616. }
  1617. else
  1618. {
  1619. flg = -1;
  1620. xml = xml->Parent;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. xml = xml->Peer;
  1626. }
  1627. ILibDestructXMLNodeList(rootXML);
  1628. }
  1629. void RNDConnectionManager_EventSink(char* buffer, int bufferlength, struct UPnPService *service)
  1630. {
  1631. struct ILibXMLNode *xml,*rootXML;
  1632. char *tempString;
  1633. int tempStringLength;
  1634. int flg,flg2;
  1635. char* SourceProtocolInfo = 0;
  1636. char* SinkProtocolInfo = 0;
  1637. char* CurrentConnectionIDs = 0;
  1638. /* Parse SOAP */
  1639. rootXML = xml = ILibParseXML(buffer,0,bufferlength);
  1640. ILibProcessXMLNodeList(xml);
  1641. while(xml!=NULL)
  1642. {
  1643. if(xml->NameLength==11 && memcmp(xml->Name,"propertyset",11)==0)
  1644. {
  1645. if(xml->Next->StartTag!=0)
  1646. {
  1647. flg = 0;
  1648. xml = xml->Next;
  1649. while(flg==0)
  1650. {
  1651. if(xml->NameLength==8 && memcmp(xml->Name,"property",8)==0)
  1652. {
  1653. xml = xml->Next;
  1654. flg2 = 0;
  1655. while(flg2==0)
  1656. {
  1657. if(xml->NameLength==18 && memcmp(xml->Name,"SourceProtocolInfo",18) == 0)
  1658. {
  1659. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1660. tempString[tempStringLength] = '\0';
  1661. SourceProtocolInfo = tempString;
  1662. if(RNDEventCallback_ConnectionManager_SourceProtocolInfo != NULL)
  1663. {
  1664. RNDEventCallback_ConnectionManager_SourceProtocolInfo(service,SourceProtocolInfo);
  1665. }
  1666. }
  1667. if(xml->NameLength==16 && memcmp(xml->Name,"SinkProtocolInfo",16) == 0)
  1668. {
  1669. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1670. tempString[tempStringLength] = '\0';
  1671. SinkProtocolInfo = tempString;
  1672. if(RNDEventCallback_ConnectionManager_SinkProtocolInfo != NULL)
  1673. {
  1674. RNDEventCallback_ConnectionManager_SinkProtocolInfo(service,SinkProtocolInfo);
  1675. }
  1676. }
  1677. if(xml->NameLength==20 && memcmp(xml->Name,"CurrentConnectionIDs",20) == 0)
  1678. {
  1679. tempStringLength = ILibReadInnerXML(xml,&tempString);
  1680. tempString[tempStringLength] = '\0';
  1681. CurrentConnectionIDs = tempString;
  1682. if(RNDEventCallback_ConnectionManager_CurrentConnectionIDs != NULL)
  1683. {
  1684. RNDEventCallback_ConnectionManager_CurrentConnectionIDs(service,CurrentConnectionIDs);
  1685. }
  1686. }
  1687. if(xml->Peer!=NULL)
  1688. {
  1689. xml = xml->Peer;
  1690. }
  1691. else
  1692. {
  1693. flg2 = -1;
  1694. xml = xml->Parent;
  1695. }
  1696. }
  1697. }
  1698. if(xml->Peer!=NULL)
  1699. {
  1700. xml = xml->Peer;
  1701. }
  1702. else
  1703. {
  1704. flg = -1;
  1705. xml = xml->Parent;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. xml = xml->Peer;
  1711. }
  1712. ILibDestructXMLNodeList(rootXML);
  1713. }
  1714. void RNDOnEventSink(void *ReaderObject, struct packetheader *header, char* buffer, int *BeginPointer, int BufferSize, int done, void* user)
  1715. {
  1716. int type_length;
  1717. char* sid = NULL;
  1718. void* value = NULL;
  1719. struct UPnPService *service = NULL;
  1720. struct packetheader_field_node *field = NULL;
  1721. struct packetheader *resp;
  1722. if(done!=0)
  1723. {
  1724. resp = ILibCreateEmptyPacket();
  1725. ILibAddHeaderLine(resp,"Server",6,"WINDOWS, UPnP/1.0, Intel MicroStack/1.0.1189",44);
  1726. field = header->FirstField;
  1727. while(field!=NULL)
  1728. {
  1729. if(field->FieldLength==3)
  1730. {
  1731. if(strncasecmp(field->Field,"SID",3)==0)
  1732. {
  1733. sid = (char*)MALLOC(field->FieldDataLength+1);
  1734. sprintf(sid,"%s",field->FieldData);
  1735. value = ILibGetEntry(((struct RNDCP*)user)->SIDTable,field->FieldData,field->FieldDataLength);
  1736. break;
  1737. }
  1738. }
  1739. field = field->NextField;
  1740. }
  1741. if(value==NULL)
  1742. {
  1743. /* Not a valid SID */
  1744. ILibSetStatusCode(resp,412,"Failed",6);
  1745. if(sid!=NULL) {FREE(sid);}
  1746. }
  1747. else
  1748. {
  1749. ILibSetStatusCode(resp,200,"OK",2);
  1750. service = (struct UPnPService*)value;
  1751. type_length = (int)strlen(service->ServiceType);
  1752. if(type_length>46 && strncmp("urn:schemas-upnp-org:service:ContentDirectory:",service->ServiceType,46)==0)
  1753. {
  1754. RNDContentDirectory_EventSink(buffer, BufferSize, service);
  1755. }
  1756. else
  1757. if(type_length>47 && strncmp("urn:schemas-upnp-org:service:ConnectionManager:",service->ServiceType,47)==0)
  1758. {
  1759. RNDConnectionManager_EventSink(buffer, BufferSize, service);
  1760. }
  1761. }
  1762. ILibMiniWebServerSend(ReaderObject,resp);
  1763. ILibDestructPacket(resp);
  1764. ILibMiniWebServerCloseSession(ReaderObject);
  1765. }
  1766. }
  1767. void RNDOnSubscribeSink(void *ReaderObject, struct packetheader *header, char* buffer, int *BeginPointer, int BufferSize, int done, void* user, void *vcp)
  1768. {
  1769. struct UPnPService *s;
  1770. struct packetheader_field_node *field;
  1771. struct parser_result *p;
  1772. struct RNDCP *cp = (struct RNDCP*)vcp;
  1773. if(done!=0)
  1774. {
  1775. s = (struct UPnPService*)user;
  1776. if(header!=NULL)
  1777. {
  1778. if(header->StatusCode==200)
  1779. {
  1780. /* Successful */
  1781. field = header->FirstField;
  1782. while(field!=NULL)
  1783. {
  1784. if(field->FieldLength==3 && strncasecmp(field->Field,"SID",3)==0)
  1785. {
  1786. s->SubscriptionID = (char*)MALLOC(1+field->FieldDataLength);
  1787. strcpy(s->SubscriptionID,field->FieldData);
  1788. ILibAddEntry(cp->SIDTable,field->FieldData,field->FieldDataLength,s);
  1789. } else
  1790. if(field->FieldLength==7 && strncasecmp(field->Field,"TIMEOUT",7)==0)
  1791. {
  1792. p = ILibParseString(field->FieldData,0,field->FieldDataLength,"-",1);
  1793. p->LastResult->data[p->LastResult->datalength] = '\0';
  1794. RNDAddRef(s->Parent);
  1795. ILibLifeTime_Add(cp->LifeTimeMonitor,s,atoi(p->LastResult->data)/2,&RNDRenew,NULL);
  1796. ILibDestructParserResults(p);
  1797. }
  1798. field = field->NextField;
  1799. }
  1800. }
  1801. }
  1802. RNDRelease(s->Parent);
  1803. }
  1804. }
  1805. void RNDRenew(void *state)
  1806. {
  1807. struct UPnPService *service = (struct UPnPService*)state;
  1808. char *IP;
  1809. char *Path;
  1810. unsigned short Port;
  1811. struct packetheader *p;
  1812. char* TempString;
  1813. struct sockaddr_in destaddr;
  1814. RNDParseUri(service->SubscriptionURL,&IP,&Port,&Path);
  1815. p = ILibCreateEmptyPacket();
  1816. ILibSetDirective(p,"SUBSCRIBE",9,Path,(int)strlen(Path));
  1817. TempString = (char*)MALLOC((int)strlen(IP)+7);
  1818. sprintf(TempString,"%s:%d",IP,Port);
  1819. ILibAddHeaderLine(p,"HOST",4,TempString,(int)strlen(TempString));
  1820. FREE(TempString);
  1821. ILibAddHeaderLine(p,"SID",3,service->SubscriptionID,(int)strlen(service->SubscriptionID));
  1822. ILibAddHeaderLine(p,"TIMEOUT",7,"Second-180",10);
  1823. ILibAddHeaderLine(p,"User-Agent",10,"WINDOWS, UPnP/1.0, Intel MicroStack/1.0.1189",44);
  1824. memset((char *)&destaddr, 0,sizeof(destaddr));
  1825. destaddr.sin_family = AF_INET;
  1826. destaddr.sin_addr.s_addr = inet_addr(IP);
  1827. destaddr.sin_port = htons(Port);
  1828. ILibAddRequest(((struct RNDCP*)service->Parent->CP)->HTTP, p,&destaddr, &RNDOnSubscribeSink, (void*)service, service->Parent->CP);
  1829. FREE(IP);
  1830. FREE(Path);
  1831. }
  1832. struct UPnPDevice* RNDGetDevice(struct UPnPDevice *device, char* DeviceType, int number)
  1833. {
  1834. int counter = 0;
  1835. device = device->EmbeddedDevices;
  1836. while(device != NULL)
  1837. {
  1838. if(strlen(device->DeviceType)>=strlen(DeviceType))
  1839. {
  1840. if(memcmp(device->DeviceType,DeviceType,strlen(DeviceType))==0)
  1841. {
  1842. if(number == (++counter)) return(device);
  1843. }
  1844. }
  1845. device = device->Next;
  1846. }
  1847. return(NULL);
  1848. }
  1849. int RNDHasAction(struct UPnPService *s, char* action)
  1850. {
  1851. struct UPnPAction *a = s->Actions;
  1852. while(a!=NULL)
  1853. {
  1854. if(strcmp(action,a->Name)==0) return(-1);
  1855. a = a->Next;
  1856. }
  1857. return(0);
  1858. }
  1859. void RNDStopCP(void *v_CP)
  1860. {
  1861. int i;
  1862. struct UPnPDevice *RetDevice;
  1863. struct UDNMapNode *mn,*mn2;
  1864. struct RNDCP *CP= (struct RNDCP*)v_CP;
  1865. sem_destroy(&(CP->DeviceLock));
  1866. mn = CP->UDN_Head;
  1867. while(mn!=NULL)
  1868. {
  1869. mn2 = mn->Next;
  1870. if(mn->RootUDN!=NULL){FREE(mn->RootUDN);}
  1871. if(mn->device!=NULL)
  1872. {
  1873. i = 0;
  1874. if(CP->RemoveSink!=NULL)
  1875. {
  1876. do
  1877. {
  1878. RetDevice = RNDGetDevice1(mn->device,i++);
  1879. if(RetDevice!=NULL)
  1880. {
  1881. CP->RemoveSink(RetDevice);
  1882. }
  1883. }while(RetDevice!=NULL);
  1884. }
  1885. RNDDestructUPnPDevice(mn->device);
  1886. }
  1887. FREE(mn->UDN);
  1888. FREE(mn);
  1889. mn = mn2;
  1890. }
  1891. ILibDestroyHashTree(CP->SIDTable);
  1892. }
  1893. void RND_CP_IPAddressListChanged(void *CPToken)
  1894. {
  1895. ((struct RNDCP*)CPToken)->RecheckFlag = 1;
  1896. ILibForceUnBlockChain(((struct RNDCP*)CPToken)->Chain);
  1897. }
  1898. void RNDCP_ProcessDeviceRemoval(struct RNDCP* CP, struct UPnPDevice *device)
  1899. {
  1900. struct UPnPDevice *temp = device->EmbeddedDevices;
  1901. struct UPnPService *s;
  1902. while(temp!=NULL)
  1903. {
  1904. RNDCP_ProcessDeviceRemoval(CP,temp);
  1905. temp = temp->Next;
  1906. }
  1907. s = device->Services;
  1908. while(s!=NULL)
  1909. {
  1910. ILibLifeTime_Remove(CP->LifeTimeMonitor,s);
  1911. s = s->Next;
  1912. }
  1913. }
  1914. void RNDCP_PreSelect(void *CPToken,fd_set *readset, fd_set *writeset, fd_set *errorset, int *blocktime)
  1915. {
  1916. struct UDNMapNode *mn,*mn2;
  1917. struct RNDCP *CP= (struct RNDCP*)CPToken;
  1918. int *IPAddressList;
  1919. int NumAddressList;
  1920. int i;
  1921. int found;
  1922. if(CP->RecheckFlag!=0)
  1923. {
  1924. CP->RecheckFlag = 0;
  1925. NumAddressList = ILibGetLocalIPAddressList(&IPAddressList);
  1926. mn = CP->UDN_Head;
  1927. while(mn!=NULL)
  1928. {
  1929. mn2 = mn->Next;
  1930. found = 0;
  1931. for(i=0;i<NumAddressList;++i)
  1932. {
  1933. if(mn->device!=NULL && IPAddressList[i]==inet_addr(mn->device->InterfaceToHost))
  1934. {
  1935. found = 1;
  1936. break;
  1937. }
  1938. }
  1939. if(found==0)
  1940. {
  1941. // Clear LifeTime for services contained
  1942. RNDCP_ProcessDeviceRemoval(CP,mn->device);
  1943. CP->RemoveSink(mn->device);
  1944. RNDDestructUPnPDevice(mn->device);
  1945. if(mn->Previous==NULL)
  1946. {
  1947. // This is the head
  1948. CP->UDN_Head = mn->Next;
  1949. if(CP->UDN_Head!=NULL)
  1950. {
  1951. CP->UDN_Head->Previous = NULL;
  1952. }
  1953. }
  1954. else
  1955. {
  1956. mn->Previous->Next = mn->Next;
  1957. if(mn->Next!=NULL)
  1958. {
  1959. mn->Next->Previous = mn->Previous;
  1960. }
  1961. }
  1962. FREE(mn->UDN);
  1963. FREE(mn);
  1964. }
  1965. mn = mn2;
  1966. }
  1967. ILibSSDP_IPAddressListChanged(CP->SSDP);
  1968. FREE(CP->AddressList);
  1969. CP->AddressListLength = NumAddressList;
  1970. CP->AddressList = IPAddressList;
  1971. }
  1972. }
  1973. void *RNDCreateControlPoint(void *Chain, void(*A)(struct UPnPDevice*),void(*R)(struct UPnPDevice*))
  1974. {
  1975. struct RNDCP *cp = (struct RNDCP*)MALLOC(sizeof(struct RNDCP));
  1976. cp->Destroy = &RNDStopCP;
  1977. cp->PostSelect = NULL;
  1978. cp->PreSelect = &RNDCP_PreSelect;
  1979. cp->DiscoverSink = A;
  1980. cp->RemoveSink = R;
  1981. sem_init(&(cp->DeviceLock),0,1);
  1982. cp->UDN_Head = NULL;
  1983. cp->WebServer = ILibCreateMiniWebServer(Chain,5,&RNDOnEventSink,cp);
  1984. cp->SIDTable = ILibInitHashTree();
  1985. ILibAddToChain(Chain,cp);
  1986. cp->LifeTimeMonitor = ILibCreateLifeTime(Chain);
  1987. cp->SSDP = ILibCreateSSDPClientModule(Chain,"urn:schemas-upnp-org:device:MediaServer:1", 41, &RNDSSDP_Sink,cp);
  1988. cp->HTTP = ILibCreateHTTPClientModule(Chain,5);
  1989. cp->Chain = Chain;
  1990. cp->RecheckFlag = 0;
  1991. cp->AddressListLength = ILibGetLocalIPAddressList(&(cp->AddressList));
  1992. return((void*)cp);
  1993. }
  1994. void RNDInvoke_ContentDirectory_Search_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  1995. {
  1996. struct UPnPService *Service = (struct UPnPService*)_service;
  1997. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  1998. int ArgLeft = 4;
  1999. struct ILibXMLNode *xml;
  2000. struct ILibXMLNode *__xml;
  2001. char *tempBuffer;
  2002. int tempBufferLength;
  2003. unsigned long TempULong;
  2004. char* Result = NULL;
  2005. unsigned int NumberReturned = 0;
  2006. unsigned int TotalMatches = 0;
  2007. unsigned int UpdateID = 0;
  2008. if(done==0){return;}
  2009. if(_InvokeData->CallbackPtr==NULL)
  2010. {
  2011. RNDRelease(Service->Parent);
  2012. FREE(_InvokeData);
  2013. return;
  2014. }
  2015. else
  2016. {
  2017. if(header==NULL)
  2018. {
  2019. /* Connection Failed */
  2020. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2021. RNDRelease(Service->Parent);
  2022. FREE(_InvokeData);
  2023. return;
  2024. }
  2025. else if(header->StatusCode!=200)
  2026. {
  2027. /* SOAP Fault */
  2028. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2029. RNDRelease(Service->Parent);
  2030. FREE(_InvokeData);
  2031. return;
  2032. }
  2033. }
  2034. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2035. ILibProcessXMLNodeList(xml);
  2036. while(xml!=NULL)
  2037. {
  2038. if(xml->NameLength==14 && memcmp(xml->Name,"SearchResponse",14)==0)
  2039. {
  2040. xml = xml->Next;
  2041. while(xml!=NULL)
  2042. {
  2043. if(xml->NameLength==6 && memcmp(xml->Name,"Result",6) == 0)
  2044. {
  2045. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2046. --ArgLeft;
  2047. if(tempBufferLength!=0)
  2048. {
  2049. tempBuffer[tempBufferLength] = '\0';
  2050. Result = tempBuffer;
  2051. }
  2052. }
  2053. else
  2054. if(xml->NameLength==14 && memcmp(xml->Name,"NumberReturned",14) == 0)
  2055. {
  2056. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2057. --ArgLeft;
  2058. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  2059. {
  2060. NumberReturned = (unsigned int) TempULong;
  2061. }
  2062. }
  2063. else
  2064. if(xml->NameLength==12 && memcmp(xml->Name,"TotalMatches",12) == 0)
  2065. {
  2066. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2067. --ArgLeft;
  2068. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  2069. {
  2070. TotalMatches = (unsigned int) TempULong;
  2071. }
  2072. }
  2073. else
  2074. if(xml->NameLength==8 && memcmp(xml->Name,"UpdateID",8) == 0)
  2075. {
  2076. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2077. --ArgLeft;
  2078. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  2079. {
  2080. UpdateID = (unsigned int) TempULong;
  2081. }
  2082. }
  2083. xml = xml->Peer;
  2084. }
  2085. }
  2086. if(xml!=NULL) {xml = xml->Next;}
  2087. }
  2088. ILibDestructXMLNodeList(__xml);
  2089. if(ArgLeft!=0)
  2090. {
  2091. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2092. }
  2093. else
  2094. {
  2095. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,Result,NumberReturned,TotalMatches,UpdateID);
  2096. }
  2097. RNDRelease(Service->Parent);
  2098. FREE(_InvokeData);
  2099. }
  2100. void RNDInvoke_ContentDirectory_Search(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int), void* user, char* ContainerID, char* SearchCriteria, char* Filter, unsigned int StartingIndex, unsigned int RequestedCount, char* SortCriteria)
  2101. {
  2102. int headerLength;
  2103. char *headerBuffer;
  2104. char *SoapBodyTemplate;
  2105. char* buffer;
  2106. int bufferLength;
  2107. char* IP;
  2108. unsigned short Port;
  2109. char* Path;
  2110. struct sockaddr_in addr;
  2111. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2112. if(service==NULL)
  2113. {
  2114. FREE(invoke_data);
  2115. return;
  2116. }
  2117. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ContainerID)+(int)strlen(SearchCriteria)+(int)strlen(Filter)+(int)strlen(SortCriteria)+434);
  2118. SoapBodyTemplate = "%sSearch xmlns:u=\"%s\"><ContainerID>%s</ContainerID><SearchCriteria>%s</SearchCriteria><Filter>%s</Filter><StartingIndex>%u</StartingIndex><RequestedCount>%u</RequestedCount><SortCriteria>%s</SortCriteria></u:Search%s";
  2119. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ContainerID, SearchCriteria, Filter, StartingIndex, RequestedCount, SortCriteria,UPNPCP_SOAP_BodyTail);
  2120. RNDAddRef(service->Parent);
  2121. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2122. headerBuffer = (char*)MALLOC(161 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2123. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"Search",bufferLength);
  2124. memset((char *)&addr, 0, sizeof(addr));
  2125. addr.sin_family = AF_INET;
  2126. addr.sin_addr.s_addr = inet_addr(IP);
  2127. addr.sin_port = htons(Port);
  2128. invoke_data->CallbackPtr = CallbackPtr;
  2129. invoke_data->User = user;
  2130. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_Search_Sink, service, invoke_data);
  2131. FREE(IP);
  2132. FREE(Path);
  2133. }
  2134. void RNDInvoke_ContentDirectory_StopTransferResource_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2135. {
  2136. struct UPnPService *Service = (struct UPnPService*)_service;
  2137. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2138. if(done==0){return;}
  2139. if(_InvokeData->CallbackPtr==NULL)
  2140. {
  2141. RNDRelease(Service->Parent);
  2142. FREE(_InvokeData);
  2143. return;
  2144. }
  2145. else
  2146. {
  2147. if(header==NULL)
  2148. {
  2149. /* Connection Failed */
  2150. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User);
  2151. RNDRelease(Service->Parent);
  2152. FREE(_InvokeData);
  2153. return;
  2154. }
  2155. else if(header->StatusCode!=200)
  2156. {
  2157. /* SOAP Fault */
  2158. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User);
  2159. RNDRelease(Service->Parent);
  2160. FREE(_InvokeData);
  2161. return;
  2162. }
  2163. }
  2164. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User);
  2165. RNDRelease(Service->Parent);
  2166. FREE(_InvokeData);
  2167. }
  2168. void RNDInvoke_ContentDirectory_StopTransferResource(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*), void* user, unsigned int TransferID)
  2169. {
  2170. int headerLength;
  2171. char *headerBuffer;
  2172. char *SoapBodyTemplate;
  2173. char* buffer;
  2174. int bufferLength;
  2175. char* IP;
  2176. unsigned short Port;
  2177. char* Path;
  2178. struct sockaddr_in addr;
  2179. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2180. if(service==NULL)
  2181. {
  2182. FREE(invoke_data);
  2183. return;
  2184. }
  2185. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+307);
  2186. SoapBodyTemplate = "%sStopTransferResource xmlns:u=\"%s\"><TransferID>%u</TransferID></u:StopTransferResource%s";
  2187. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, TransferID,UPNPCP_SOAP_BodyTail);
  2188. RNDAddRef(service->Parent);
  2189. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2190. headerBuffer = (char*)MALLOC(175 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2191. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"StopTransferResource",bufferLength);
  2192. memset((char *)&addr, 0, sizeof(addr));
  2193. addr.sin_family = AF_INET;
  2194. addr.sin_addr.s_addr = inet_addr(IP);
  2195. addr.sin_port = htons(Port);
  2196. invoke_data->CallbackPtr = CallbackPtr;
  2197. invoke_data->User = user;
  2198. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_StopTransferResource_Sink, service, invoke_data);
  2199. FREE(IP);
  2200. FREE(Path);
  2201. }
  2202. void RNDInvoke_ContentDirectory_DestroyObject_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2203. {
  2204. struct UPnPService *Service = (struct UPnPService*)_service;
  2205. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2206. if(done==0){return;}
  2207. if(_InvokeData->CallbackPtr==NULL)
  2208. {
  2209. RNDRelease(Service->Parent);
  2210. FREE(_InvokeData);
  2211. return;
  2212. }
  2213. else
  2214. {
  2215. if(header==NULL)
  2216. {
  2217. /* Connection Failed */
  2218. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User);
  2219. RNDRelease(Service->Parent);
  2220. FREE(_InvokeData);
  2221. return;
  2222. }
  2223. else if(header->StatusCode!=200)
  2224. {
  2225. /* SOAP Fault */
  2226. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User);
  2227. RNDRelease(Service->Parent);
  2228. FREE(_InvokeData);
  2229. return;
  2230. }
  2231. }
  2232. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User);
  2233. RNDRelease(Service->Parent);
  2234. FREE(_InvokeData);
  2235. }
  2236. void RNDInvoke_ContentDirectory_DestroyObject(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*), void* user, char* ObjectID)
  2237. {
  2238. int headerLength;
  2239. char *headerBuffer;
  2240. char *SoapBodyTemplate;
  2241. char* buffer;
  2242. int bufferLength;
  2243. char* IP;
  2244. unsigned short Port;
  2245. char* Path;
  2246. struct sockaddr_in addr;
  2247. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2248. if(service==NULL)
  2249. {
  2250. FREE(invoke_data);
  2251. return;
  2252. }
  2253. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ObjectID)+279);
  2254. SoapBodyTemplate = "%sDestroyObject xmlns:u=\"%s\"><ObjectID>%s</ObjectID></u:DestroyObject%s";
  2255. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ObjectID,UPNPCP_SOAP_BodyTail);
  2256. RNDAddRef(service->Parent);
  2257. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2258. headerBuffer = (char*)MALLOC(168 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2259. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"DestroyObject",bufferLength);
  2260. memset((char *)&addr, 0, sizeof(addr));
  2261. addr.sin_family = AF_INET;
  2262. addr.sin_addr.s_addr = inet_addr(IP);
  2263. addr.sin_port = htons(Port);
  2264. invoke_data->CallbackPtr = CallbackPtr;
  2265. invoke_data->User = user;
  2266. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_DestroyObject_Sink, service, invoke_data);
  2267. FREE(IP);
  2268. FREE(Path);
  2269. }
  2270. void RNDInvoke_ContentDirectory_UpdateObject_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2271. {
  2272. struct UPnPService *Service = (struct UPnPService*)_service;
  2273. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2274. if(done==0){return;}
  2275. if(_InvokeData->CallbackPtr==NULL)
  2276. {
  2277. RNDRelease(Service->Parent);
  2278. FREE(_InvokeData);
  2279. return;
  2280. }
  2281. else
  2282. {
  2283. if(header==NULL)
  2284. {
  2285. /* Connection Failed */
  2286. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User);
  2287. RNDRelease(Service->Parent);
  2288. FREE(_InvokeData);
  2289. return;
  2290. }
  2291. else if(header->StatusCode!=200)
  2292. {
  2293. /* SOAP Fault */
  2294. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User);
  2295. RNDRelease(Service->Parent);
  2296. FREE(_InvokeData);
  2297. return;
  2298. }
  2299. }
  2300. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User);
  2301. RNDRelease(Service->Parent);
  2302. FREE(_InvokeData);
  2303. }
  2304. void RNDInvoke_ContentDirectory_UpdateObject(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*), void* user, char* ObjectID, char* CurrentTagValue, char* NewTagValue)
  2305. {
  2306. int headerLength;
  2307. char *headerBuffer;
  2308. char *SoapBodyTemplate;
  2309. char* buffer;
  2310. int bufferLength;
  2311. char* IP;
  2312. unsigned short Port;
  2313. char* Path;
  2314. struct sockaddr_in addr;
  2315. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2316. if(service==NULL)
  2317. {
  2318. FREE(invoke_data);
  2319. return;
  2320. }
  2321. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ObjectID)+(int)strlen(CurrentTagValue)+(int)strlen(NewTagValue)+339);
  2322. SoapBodyTemplate = "%sUpdateObject xmlns:u=\"%s\"><ObjectID>%s</ObjectID><CurrentTagValue>%s</CurrentTagValue><NewTagValue>%s</NewTagValue></u:UpdateObject%s";
  2323. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ObjectID, CurrentTagValue, NewTagValue,UPNPCP_SOAP_BodyTail);
  2324. RNDAddRef(service->Parent);
  2325. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2326. headerBuffer = (char*)MALLOC(167 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2327. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"UpdateObject",bufferLength);
  2328. memset((char *)&addr, 0, sizeof(addr));
  2329. addr.sin_family = AF_INET;
  2330. addr.sin_addr.s_addr = inet_addr(IP);
  2331. addr.sin_port = htons(Port);
  2332. invoke_data->CallbackPtr = CallbackPtr;
  2333. invoke_data->User = user;
  2334. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_UpdateObject_Sink, service, invoke_data);
  2335. FREE(IP);
  2336. FREE(Path);
  2337. }
  2338. void RNDInvoke_ContentDirectory_ExportResource_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2339. {
  2340. struct UPnPService *Service = (struct UPnPService*)_service;
  2341. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2342. int ArgLeft = 1;
  2343. struct ILibXMLNode *xml;
  2344. struct ILibXMLNode *__xml;
  2345. char *tempBuffer;
  2346. int tempBufferLength;
  2347. unsigned long TempULong;
  2348. unsigned int TransferID = 0;
  2349. if(done==0){return;}
  2350. if(_InvokeData->CallbackPtr==NULL)
  2351. {
  2352. RNDRelease(Service->Parent);
  2353. FREE(_InvokeData);
  2354. return;
  2355. }
  2356. else
  2357. {
  2358. if(header==NULL)
  2359. {
  2360. /* Connection Failed */
  2361. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  2362. RNDRelease(Service->Parent);
  2363. FREE(_InvokeData);
  2364. return;
  2365. }
  2366. else if(header->StatusCode!=200)
  2367. {
  2368. /* SOAP Fault */
  2369. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  2370. RNDRelease(Service->Parent);
  2371. FREE(_InvokeData);
  2372. return;
  2373. }
  2374. }
  2375. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2376. ILibProcessXMLNodeList(xml);
  2377. while(xml!=NULL)
  2378. {
  2379. if(xml->NameLength==22 && memcmp(xml->Name,"ExportResourceResponse",22)==0)
  2380. {
  2381. xml = xml->Next;
  2382. while(xml!=NULL)
  2383. {
  2384. if(xml->NameLength==10 && memcmp(xml->Name,"TransferID",10) == 0)
  2385. {
  2386. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2387. --ArgLeft;
  2388. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  2389. {
  2390. TransferID = (unsigned int) TempULong;
  2391. }
  2392. }
  2393. xml = xml->Peer;
  2394. }
  2395. }
  2396. if(xml!=NULL) {xml = xml->Next;}
  2397. }
  2398. ILibDestructXMLNodeList(__xml);
  2399. if(ArgLeft!=0)
  2400. {
  2401. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  2402. }
  2403. else
  2404. {
  2405. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,TransferID);
  2406. }
  2407. RNDRelease(Service->Parent);
  2408. FREE(_InvokeData);
  2409. }
  2410. void RNDInvoke_ContentDirectory_ExportResource(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,unsigned int), void* user, char* SourceURI, char* DestinationURI)
  2411. {
  2412. int headerLength;
  2413. char *headerBuffer;
  2414. char *SoapBodyTemplate;
  2415. char* buffer;
  2416. int bufferLength;
  2417. char* IP;
  2418. unsigned short Port;
  2419. char* Path;
  2420. struct sockaddr_in addr;
  2421. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2422. if(service==NULL)
  2423. {
  2424. FREE(invoke_data);
  2425. return;
  2426. }
  2427. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(SourceURI)+(int)strlen(DestinationURI)+316);
  2428. SoapBodyTemplate = "%sExportResource xmlns:u=\"%s\"><SourceURI>%s</SourceURI><DestinationURI>%s</DestinationURI></u:ExportResource%s";
  2429. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, SourceURI, DestinationURI,UPNPCP_SOAP_BodyTail);
  2430. RNDAddRef(service->Parent);
  2431. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2432. headerBuffer = (char*)MALLOC(169 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2433. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"ExportResource",bufferLength);
  2434. memset((char *)&addr, 0, sizeof(addr));
  2435. addr.sin_family = AF_INET;
  2436. addr.sin_addr.s_addr = inet_addr(IP);
  2437. addr.sin_port = htons(Port);
  2438. invoke_data->CallbackPtr = CallbackPtr;
  2439. invoke_data->User = user;
  2440. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_ExportResource_Sink, service, invoke_data);
  2441. FREE(IP);
  2442. FREE(Path);
  2443. }
  2444. void RNDInvoke_ContentDirectory_GetTransferProgress_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2445. {
  2446. struct UPnPService *Service = (struct UPnPService*)_service;
  2447. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2448. int ArgLeft = 3;
  2449. struct ILibXMLNode *xml;
  2450. struct ILibXMLNode *__xml;
  2451. char *tempBuffer;
  2452. int tempBufferLength;
  2453. char* TransferStatus = NULL;
  2454. char* TransferLength = NULL;
  2455. char* TransferTotal = NULL;
  2456. if(done==0){return;}
  2457. if(_InvokeData->CallbackPtr==NULL)
  2458. {
  2459. RNDRelease(Service->Parent);
  2460. FREE(_InvokeData);
  2461. return;
  2462. }
  2463. else
  2464. {
  2465. if(header==NULL)
  2466. {
  2467. /* Connection Failed */
  2468. ((void (*)(struct UPnPService*,int,void*,char*,char*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2469. RNDRelease(Service->Parent);
  2470. FREE(_InvokeData);
  2471. return;
  2472. }
  2473. else if(header->StatusCode!=200)
  2474. {
  2475. /* SOAP Fault */
  2476. ((void (*)(struct UPnPService*,int,void*,char*,char*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2477. RNDRelease(Service->Parent);
  2478. FREE(_InvokeData);
  2479. return;
  2480. }
  2481. }
  2482. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2483. ILibProcessXMLNodeList(xml);
  2484. while(xml!=NULL)
  2485. {
  2486. if(xml->NameLength==27 && memcmp(xml->Name,"GetTransferProgressResponse",27)==0)
  2487. {
  2488. xml = xml->Next;
  2489. while(xml!=NULL)
  2490. {
  2491. if(xml->NameLength==14 && memcmp(xml->Name,"TransferStatus",14) == 0)
  2492. {
  2493. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2494. --ArgLeft;
  2495. if(tempBufferLength!=0)
  2496. {
  2497. tempBuffer[tempBufferLength] = '\0';
  2498. TransferStatus = tempBuffer;
  2499. }
  2500. }
  2501. else
  2502. if(xml->NameLength==14 && memcmp(xml->Name,"TransferLength",14) == 0)
  2503. {
  2504. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2505. --ArgLeft;
  2506. if(tempBufferLength!=0)
  2507. {
  2508. tempBuffer[tempBufferLength] = '\0';
  2509. TransferLength = tempBuffer;
  2510. }
  2511. }
  2512. else
  2513. if(xml->NameLength==13 && memcmp(xml->Name,"TransferTotal",13) == 0)
  2514. {
  2515. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2516. --ArgLeft;
  2517. if(tempBufferLength!=0)
  2518. {
  2519. tempBuffer[tempBufferLength] = '\0';
  2520. TransferTotal = tempBuffer;
  2521. }
  2522. }
  2523. xml = xml->Peer;
  2524. }
  2525. }
  2526. if(xml!=NULL) {xml = xml->Next;}
  2527. }
  2528. ILibDestructXMLNodeList(__xml);
  2529. if(ArgLeft!=0)
  2530. {
  2531. ((void (*)(struct UPnPService*,int,void*,char*,char*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  2532. }
  2533. else
  2534. {
  2535. ((void (*)(struct UPnPService*,int,void*,char*,char*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,TransferStatus,TransferLength,TransferTotal);
  2536. }
  2537. RNDRelease(Service->Parent);
  2538. FREE(_InvokeData);
  2539. }
  2540. void RNDInvoke_ContentDirectory_GetTransferProgress(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*,char*,char*), void* user, unsigned int TransferID)
  2541. {
  2542. int headerLength;
  2543. char *headerBuffer;
  2544. char *SoapBodyTemplate;
  2545. char* buffer;
  2546. int bufferLength;
  2547. char* IP;
  2548. unsigned short Port;
  2549. char* Path;
  2550. struct sockaddr_in addr;
  2551. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2552. if(service==NULL)
  2553. {
  2554. FREE(invoke_data);
  2555. return;
  2556. }
  2557. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+305);
  2558. SoapBodyTemplate = "%sGetTransferProgress xmlns:u=\"%s\"><TransferID>%u</TransferID></u:GetTransferProgress%s";
  2559. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, TransferID,UPNPCP_SOAP_BodyTail);
  2560. RNDAddRef(service->Parent);
  2561. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2562. headerBuffer = (char*)MALLOC(174 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2563. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetTransferProgress",bufferLength);
  2564. memset((char *)&addr, 0, sizeof(addr));
  2565. addr.sin_family = AF_INET;
  2566. addr.sin_addr.s_addr = inet_addr(IP);
  2567. addr.sin_port = htons(Port);
  2568. invoke_data->CallbackPtr = CallbackPtr;
  2569. invoke_data->User = user;
  2570. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_GetTransferProgress_Sink, service, invoke_data);
  2571. FREE(IP);
  2572. FREE(Path);
  2573. }
  2574. void RNDInvoke_ContentDirectory_GetSearchCapabilities_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2575. {
  2576. struct UPnPService *Service = (struct UPnPService*)_service;
  2577. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2578. int ArgLeft = 1;
  2579. struct ILibXMLNode *xml;
  2580. struct ILibXMLNode *__xml;
  2581. char *tempBuffer;
  2582. int tempBufferLength;
  2583. char* SearchCaps = NULL;
  2584. if(done==0){return;}
  2585. if(_InvokeData->CallbackPtr==NULL)
  2586. {
  2587. RNDRelease(Service->Parent);
  2588. FREE(_InvokeData);
  2589. return;
  2590. }
  2591. else
  2592. {
  2593. if(header==NULL)
  2594. {
  2595. /* Connection Failed */
  2596. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  2597. RNDRelease(Service->Parent);
  2598. FREE(_InvokeData);
  2599. return;
  2600. }
  2601. else if(header->StatusCode!=200)
  2602. {
  2603. /* SOAP Fault */
  2604. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  2605. RNDRelease(Service->Parent);
  2606. FREE(_InvokeData);
  2607. return;
  2608. }
  2609. }
  2610. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2611. ILibProcessXMLNodeList(xml);
  2612. while(xml!=NULL)
  2613. {
  2614. if(xml->NameLength==29 && memcmp(xml->Name,"GetSearchCapabilitiesResponse",29)==0)
  2615. {
  2616. xml = xml->Next;
  2617. while(xml!=NULL)
  2618. {
  2619. if(xml->NameLength==10 && memcmp(xml->Name,"SearchCaps",10) == 0)
  2620. {
  2621. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2622. --ArgLeft;
  2623. if(tempBufferLength!=0)
  2624. {
  2625. tempBuffer[tempBufferLength] = '\0';
  2626. SearchCaps = tempBuffer;
  2627. }
  2628. }
  2629. xml = xml->Peer;
  2630. }
  2631. }
  2632. if(xml!=NULL) {xml = xml->Next;}
  2633. }
  2634. ILibDestructXMLNodeList(__xml);
  2635. if(ArgLeft!=0)
  2636. {
  2637. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  2638. }
  2639. else
  2640. {
  2641. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,SearchCaps);
  2642. }
  2643. RNDRelease(Service->Parent);
  2644. FREE(_InvokeData);
  2645. }
  2646. void RNDInvoke_ContentDirectory_GetSearchCapabilities(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*), void* user)
  2647. {
  2648. int headerLength;
  2649. char *headerBuffer;
  2650. char *SoapBodyTemplate;
  2651. char* buffer;
  2652. int bufferLength;
  2653. char* IP;
  2654. unsigned short Port;
  2655. char* Path;
  2656. struct sockaddr_in addr;
  2657. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2658. if(service==NULL)
  2659. {
  2660. FREE(invoke_data);
  2661. return;
  2662. }
  2663. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+274);
  2664. SoapBodyTemplate = "%sGetSearchCapabilities xmlns:u=\"%s\"></u:GetSearchCapabilities%s";
  2665. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType,UPNPCP_SOAP_BodyTail);
  2666. RNDAddRef(service->Parent);
  2667. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2668. headerBuffer = (char*)MALLOC(176 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2669. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetSearchCapabilities",bufferLength);
  2670. memset((char *)&addr, 0, sizeof(addr));
  2671. addr.sin_family = AF_INET;
  2672. addr.sin_addr.s_addr = inet_addr(IP);
  2673. addr.sin_port = htons(Port);
  2674. invoke_data->CallbackPtr = CallbackPtr;
  2675. invoke_data->User = user;
  2676. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_GetSearchCapabilities_Sink, service, invoke_data);
  2677. FREE(IP);
  2678. FREE(Path);
  2679. }
  2680. void RNDInvoke_ContentDirectory_GetSystemUpdateID_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2681. {
  2682. struct UPnPService *Service = (struct UPnPService*)_service;
  2683. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2684. int ArgLeft = 1;
  2685. struct ILibXMLNode *xml;
  2686. struct ILibXMLNode *__xml;
  2687. char *tempBuffer;
  2688. int tempBufferLength;
  2689. unsigned long TempULong;
  2690. unsigned int Id = 0;
  2691. if(done==0){return;}
  2692. if(_InvokeData->CallbackPtr==NULL)
  2693. {
  2694. RNDRelease(Service->Parent);
  2695. FREE(_InvokeData);
  2696. return;
  2697. }
  2698. else
  2699. {
  2700. if(header==NULL)
  2701. {
  2702. /* Connection Failed */
  2703. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  2704. RNDRelease(Service->Parent);
  2705. FREE(_InvokeData);
  2706. return;
  2707. }
  2708. else if(header->StatusCode!=200)
  2709. {
  2710. /* SOAP Fault */
  2711. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  2712. RNDRelease(Service->Parent);
  2713. FREE(_InvokeData);
  2714. return;
  2715. }
  2716. }
  2717. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2718. ILibProcessXMLNodeList(xml);
  2719. while(xml!=NULL)
  2720. {
  2721. if(xml->NameLength==25 && memcmp(xml->Name,"GetSystemUpdateIDResponse",25)==0)
  2722. {
  2723. xml = xml->Next;
  2724. while(xml!=NULL)
  2725. {
  2726. if(xml->NameLength==2 && memcmp(xml->Name,"Id",2) == 0)
  2727. {
  2728. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2729. --ArgLeft;
  2730. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  2731. {
  2732. Id = (unsigned int) TempULong;
  2733. }
  2734. }
  2735. xml = xml->Peer;
  2736. }
  2737. }
  2738. if(xml!=NULL) {xml = xml->Next;}
  2739. }
  2740. ILibDestructXMLNodeList(__xml);
  2741. if(ArgLeft!=0)
  2742. {
  2743. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  2744. }
  2745. else
  2746. {
  2747. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,Id);
  2748. }
  2749. RNDRelease(Service->Parent);
  2750. FREE(_InvokeData);
  2751. }
  2752. void RNDInvoke_ContentDirectory_GetSystemUpdateID(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,unsigned int), void* user)
  2753. {
  2754. int headerLength;
  2755. char *headerBuffer;
  2756. char *SoapBodyTemplate;
  2757. char* buffer;
  2758. int bufferLength;
  2759. char* IP;
  2760. unsigned short Port;
  2761. char* Path;
  2762. struct sockaddr_in addr;
  2763. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2764. if(service==NULL)
  2765. {
  2766. FREE(invoke_data);
  2767. return;
  2768. }
  2769. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+266);
  2770. SoapBodyTemplate = "%sGetSystemUpdateID xmlns:u=\"%s\"></u:GetSystemUpdateID%s";
  2771. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType,UPNPCP_SOAP_BodyTail);
  2772. RNDAddRef(service->Parent);
  2773. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2774. headerBuffer = (char*)MALLOC(172 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2775. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetSystemUpdateID",bufferLength);
  2776. memset((char *)&addr, 0, sizeof(addr));
  2777. addr.sin_family = AF_INET;
  2778. addr.sin_addr.s_addr = inet_addr(IP);
  2779. addr.sin_port = htons(Port);
  2780. invoke_data->CallbackPtr = CallbackPtr;
  2781. invoke_data->User = user;
  2782. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_GetSystemUpdateID_Sink, service, invoke_data);
  2783. FREE(IP);
  2784. FREE(Path);
  2785. }
  2786. void RNDInvoke_ContentDirectory_CreateObject_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2787. {
  2788. struct UPnPService *Service = (struct UPnPService*)_service;
  2789. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2790. int ArgLeft = 2;
  2791. struct ILibXMLNode *xml;
  2792. struct ILibXMLNode *__xml;
  2793. char *tempBuffer;
  2794. int tempBufferLength;
  2795. char* ObjectID = NULL;
  2796. char* Result = NULL;
  2797. if(done==0){return;}
  2798. if(_InvokeData->CallbackPtr==NULL)
  2799. {
  2800. RNDRelease(Service->Parent);
  2801. FREE(_InvokeData);
  2802. return;
  2803. }
  2804. else
  2805. {
  2806. if(header==NULL)
  2807. {
  2808. /* Connection Failed */
  2809. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA);
  2810. RNDRelease(Service->Parent);
  2811. FREE(_InvokeData);
  2812. return;
  2813. }
  2814. else if(header->StatusCode!=200)
  2815. {
  2816. /* SOAP Fault */
  2817. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA);
  2818. RNDRelease(Service->Parent);
  2819. FREE(_InvokeData);
  2820. return;
  2821. }
  2822. }
  2823. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2824. ILibProcessXMLNodeList(xml);
  2825. while(xml!=NULL)
  2826. {
  2827. if(xml->NameLength==20 && memcmp(xml->Name,"CreateObjectResponse",20)==0)
  2828. {
  2829. xml = xml->Next;
  2830. while(xml!=NULL)
  2831. {
  2832. if(xml->NameLength==8 && memcmp(xml->Name,"ObjectID",8) == 0)
  2833. {
  2834. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2835. --ArgLeft;
  2836. if(tempBufferLength!=0)
  2837. {
  2838. tempBuffer[tempBufferLength] = '\0';
  2839. ObjectID = tempBuffer;
  2840. }
  2841. }
  2842. else
  2843. if(xml->NameLength==6 && memcmp(xml->Name,"Result",6) == 0)
  2844. {
  2845. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2846. --ArgLeft;
  2847. if(tempBufferLength!=0)
  2848. {
  2849. tempBuffer[tempBufferLength] = '\0';
  2850. Result = tempBuffer;
  2851. }
  2852. }
  2853. xml = xml->Peer;
  2854. }
  2855. }
  2856. if(xml!=NULL) {xml = xml->Next;}
  2857. }
  2858. ILibDestructXMLNodeList(__xml);
  2859. if(ArgLeft!=0)
  2860. {
  2861. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA);
  2862. }
  2863. else
  2864. {
  2865. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,ObjectID,Result);
  2866. }
  2867. RNDRelease(Service->Parent);
  2868. FREE(_InvokeData);
  2869. }
  2870. void RNDInvoke_ContentDirectory_CreateObject(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*,char*), void* user, char* ContainerID, char* Elements)
  2871. {
  2872. int headerLength;
  2873. char *headerBuffer;
  2874. char *SoapBodyTemplate;
  2875. char* buffer;
  2876. int bufferLength;
  2877. char* IP;
  2878. unsigned short Port;
  2879. char* Path;
  2880. struct sockaddr_in addr;
  2881. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2882. if(service==NULL)
  2883. {
  2884. FREE(invoke_data);
  2885. return;
  2886. }
  2887. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ContainerID)+(int)strlen(Elements)+304);
  2888. SoapBodyTemplate = "%sCreateObject xmlns:u=\"%s\"><ContainerID>%s</ContainerID><Elements>%s</Elements></u:CreateObject%s";
  2889. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ContainerID, Elements,UPNPCP_SOAP_BodyTail);
  2890. RNDAddRef(service->Parent);
  2891. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2892. headerBuffer = (char*)MALLOC(167 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2893. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"CreateObject",bufferLength);
  2894. memset((char *)&addr, 0, sizeof(addr));
  2895. addr.sin_family = AF_INET;
  2896. addr.sin_addr.s_addr = inet_addr(IP);
  2897. addr.sin_port = htons(Port);
  2898. invoke_data->CallbackPtr = CallbackPtr;
  2899. invoke_data->User = user;
  2900. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_CreateObject_Sink, service, invoke_data);
  2901. FREE(IP);
  2902. FREE(Path);
  2903. }
  2904. void RNDInvoke_ContentDirectory_GetSortCapabilities_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  2905. {
  2906. struct UPnPService *Service = (struct UPnPService*)_service;
  2907. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  2908. int ArgLeft = 1;
  2909. struct ILibXMLNode *xml;
  2910. struct ILibXMLNode *__xml;
  2911. char *tempBuffer;
  2912. int tempBufferLength;
  2913. char* SortCaps = NULL;
  2914. if(done==0){return;}
  2915. if(_InvokeData->CallbackPtr==NULL)
  2916. {
  2917. RNDRelease(Service->Parent);
  2918. FREE(_InvokeData);
  2919. return;
  2920. }
  2921. else
  2922. {
  2923. if(header==NULL)
  2924. {
  2925. /* Connection Failed */
  2926. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  2927. RNDRelease(Service->Parent);
  2928. FREE(_InvokeData);
  2929. return;
  2930. }
  2931. else if(header->StatusCode!=200)
  2932. {
  2933. /* SOAP Fault */
  2934. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  2935. RNDRelease(Service->Parent);
  2936. FREE(_InvokeData);
  2937. return;
  2938. }
  2939. }
  2940. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  2941. ILibProcessXMLNodeList(xml);
  2942. while(xml!=NULL)
  2943. {
  2944. if(xml->NameLength==27 && memcmp(xml->Name,"GetSortCapabilitiesResponse",27)==0)
  2945. {
  2946. xml = xml->Next;
  2947. while(xml!=NULL)
  2948. {
  2949. if(xml->NameLength==8 && memcmp(xml->Name,"SortCaps",8) == 0)
  2950. {
  2951. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  2952. --ArgLeft;
  2953. if(tempBufferLength!=0)
  2954. {
  2955. tempBuffer[tempBufferLength] = '\0';
  2956. SortCaps = tempBuffer;
  2957. }
  2958. }
  2959. xml = xml->Peer;
  2960. }
  2961. }
  2962. if(xml!=NULL) {xml = xml->Next;}
  2963. }
  2964. ILibDestructXMLNodeList(__xml);
  2965. if(ArgLeft!=0)
  2966. {
  2967. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  2968. }
  2969. else
  2970. {
  2971. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,SortCaps);
  2972. }
  2973. RNDRelease(Service->Parent);
  2974. FREE(_InvokeData);
  2975. }
  2976. void RNDInvoke_ContentDirectory_GetSortCapabilities(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*), void* user)
  2977. {
  2978. int headerLength;
  2979. char *headerBuffer;
  2980. char *SoapBodyTemplate;
  2981. char* buffer;
  2982. int bufferLength;
  2983. char* IP;
  2984. unsigned short Port;
  2985. char* Path;
  2986. struct sockaddr_in addr;
  2987. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  2988. if(service==NULL)
  2989. {
  2990. FREE(invoke_data);
  2991. return;
  2992. }
  2993. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+270);
  2994. SoapBodyTemplate = "%sGetSortCapabilities xmlns:u=\"%s\"></u:GetSortCapabilities%s";
  2995. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType,UPNPCP_SOAP_BodyTail);
  2996. RNDAddRef(service->Parent);
  2997. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  2998. headerBuffer = (char*)MALLOC(174 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  2999. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetSortCapabilities",bufferLength);
  3000. memset((char *)&addr, 0, sizeof(addr));
  3001. addr.sin_family = AF_INET;
  3002. addr.sin_addr.s_addr = inet_addr(IP);
  3003. addr.sin_port = htons(Port);
  3004. invoke_data->CallbackPtr = CallbackPtr;
  3005. invoke_data->User = user;
  3006. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_GetSortCapabilities_Sink, service, invoke_data);
  3007. FREE(IP);
  3008. FREE(Path);
  3009. }
  3010. void RNDInvoke_ContentDirectory_Browse_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3011. {
  3012. struct UPnPService *Service = (struct UPnPService*)_service;
  3013. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3014. int ArgLeft = 4;
  3015. struct ILibXMLNode *xml;
  3016. struct ILibXMLNode *__xml;
  3017. char *tempBuffer;
  3018. int tempBufferLength;
  3019. unsigned long TempULong;
  3020. char* Result = NULL;
  3021. unsigned int NumberReturned = 0;
  3022. unsigned int TotalMatches = 0;
  3023. unsigned int UpdateID = 0;
  3024. if(done==0){return;}
  3025. if(_InvokeData->CallbackPtr==NULL)
  3026. {
  3027. RNDRelease(Service->Parent);
  3028. FREE(_InvokeData);
  3029. return;
  3030. }
  3031. else
  3032. {
  3033. if(header==NULL)
  3034. {
  3035. /* Connection Failed */
  3036. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3037. RNDRelease(Service->Parent);
  3038. FREE(_InvokeData);
  3039. return;
  3040. }
  3041. else if(header->StatusCode!=200)
  3042. {
  3043. /* SOAP Fault */
  3044. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3045. RNDRelease(Service->Parent);
  3046. FREE(_InvokeData);
  3047. return;
  3048. }
  3049. }
  3050. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3051. ILibProcessXMLNodeList(xml);
  3052. while(xml!=NULL)
  3053. {
  3054. if(xml->NameLength==14 && memcmp(xml->Name,"BrowseResponse",14)==0)
  3055. {
  3056. xml = xml->Next;
  3057. while(xml!=NULL)
  3058. {
  3059. if(xml->NameLength==6 && memcmp(xml->Name,"Result",6) == 0)
  3060. {
  3061. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3062. --ArgLeft;
  3063. if(tempBufferLength!=0)
  3064. {
  3065. tempBuffer[tempBufferLength] = '\0';
  3066. Result = tempBuffer;
  3067. }
  3068. }
  3069. else
  3070. if(xml->NameLength==14 && memcmp(xml->Name,"NumberReturned",14) == 0)
  3071. {
  3072. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3073. --ArgLeft;
  3074. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  3075. {
  3076. NumberReturned = (unsigned int) TempULong;
  3077. }
  3078. }
  3079. else
  3080. if(xml->NameLength==12 && memcmp(xml->Name,"TotalMatches",12) == 0)
  3081. {
  3082. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3083. --ArgLeft;
  3084. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  3085. {
  3086. TotalMatches = (unsigned int) TempULong;
  3087. }
  3088. }
  3089. else
  3090. if(xml->NameLength==8 && memcmp(xml->Name,"UpdateID",8) == 0)
  3091. {
  3092. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3093. --ArgLeft;
  3094. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  3095. {
  3096. UpdateID = (unsigned int) TempULong;
  3097. }
  3098. }
  3099. xml = xml->Peer;
  3100. }
  3101. }
  3102. if(xml!=NULL) {xml = xml->Next;}
  3103. }
  3104. ILibDestructXMLNodeList(__xml);
  3105. if(ArgLeft!=0)
  3106. {
  3107. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3108. }
  3109. else
  3110. {
  3111. ((void (*)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,Result,NumberReturned,TotalMatches,UpdateID);
  3112. }
  3113. RNDRelease(Service->Parent);
  3114. FREE(_InvokeData);
  3115. }
  3116. void RNDInvoke_ContentDirectory_Browse(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*,unsigned int,unsigned int,unsigned int), void* user, char* ObjectID, char* BrowseFlag, char* Filter, unsigned int StartingIndex, unsigned int RequestedCount, char* SortCriteria)
  3117. {
  3118. int headerLength;
  3119. char *headerBuffer;
  3120. char *SoapBodyTemplate;
  3121. char* buffer;
  3122. int bufferLength;
  3123. char* IP;
  3124. unsigned short Port;
  3125. char* Path;
  3126. struct sockaddr_in addr;
  3127. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3128. if(service==NULL)
  3129. {
  3130. FREE(invoke_data);
  3131. return;
  3132. }
  3133. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ObjectID)+(int)strlen(BrowseFlag)+(int)strlen(Filter)+(int)strlen(SortCriteria)+420);
  3134. SoapBodyTemplate = "%sBrowse xmlns:u=\"%s\"><ObjectID>%s</ObjectID><BrowseFlag>%s</BrowseFlag><Filter>%s</Filter><StartingIndex>%u</StartingIndex><RequestedCount>%u</RequestedCount><SortCriteria>%s</SortCriteria></u:Browse%s";
  3135. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria,UPNPCP_SOAP_BodyTail);
  3136. RNDAddRef(service->Parent);
  3137. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3138. headerBuffer = (char*)MALLOC(161 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3139. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"Browse",bufferLength);
  3140. memset((char *)&addr, 0, sizeof(addr));
  3141. addr.sin_family = AF_INET;
  3142. addr.sin_addr.s_addr = inet_addr(IP);
  3143. addr.sin_port = htons(Port);
  3144. invoke_data->CallbackPtr = CallbackPtr;
  3145. invoke_data->User = user;
  3146. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_Browse_Sink, service, invoke_data);
  3147. FREE(IP);
  3148. FREE(Path);
  3149. }
  3150. void RNDInvoke_ContentDirectory_ImportResource_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3151. {
  3152. struct UPnPService *Service = (struct UPnPService*)_service;
  3153. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3154. int ArgLeft = 1;
  3155. struct ILibXMLNode *xml;
  3156. struct ILibXMLNode *__xml;
  3157. char *tempBuffer;
  3158. int tempBufferLength;
  3159. unsigned long TempULong;
  3160. unsigned int TransferID = 0;
  3161. if(done==0){return;}
  3162. if(_InvokeData->CallbackPtr==NULL)
  3163. {
  3164. RNDRelease(Service->Parent);
  3165. FREE(_InvokeData);
  3166. return;
  3167. }
  3168. else
  3169. {
  3170. if(header==NULL)
  3171. {
  3172. /* Connection Failed */
  3173. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  3174. RNDRelease(Service->Parent);
  3175. FREE(_InvokeData);
  3176. return;
  3177. }
  3178. else if(header->StatusCode!=200)
  3179. {
  3180. /* SOAP Fault */
  3181. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  3182. RNDRelease(Service->Parent);
  3183. FREE(_InvokeData);
  3184. return;
  3185. }
  3186. }
  3187. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3188. ILibProcessXMLNodeList(xml);
  3189. while(xml!=NULL)
  3190. {
  3191. if(xml->NameLength==22 && memcmp(xml->Name,"ImportResourceResponse",22)==0)
  3192. {
  3193. xml = xml->Next;
  3194. while(xml!=NULL)
  3195. {
  3196. if(xml->NameLength==10 && memcmp(xml->Name,"TransferID",10) == 0)
  3197. {
  3198. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3199. --ArgLeft;
  3200. if(ILibGetULong(tempBuffer,tempBufferLength,&TempULong)==0)
  3201. {
  3202. TransferID = (unsigned int) TempULong;
  3203. }
  3204. }
  3205. xml = xml->Peer;
  3206. }
  3207. }
  3208. if(xml!=NULL) {xml = xml->Next;}
  3209. }
  3210. ILibDestructXMLNodeList(__xml);
  3211. if(ArgLeft!=0)
  3212. {
  3213. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  3214. }
  3215. else
  3216. {
  3217. ((void (*)(struct UPnPService*,int,void*,unsigned int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,TransferID);
  3218. }
  3219. RNDRelease(Service->Parent);
  3220. FREE(_InvokeData);
  3221. }
  3222. void RNDInvoke_ContentDirectory_ImportResource(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,unsigned int), void* user, char* SourceURI, char* DestinationURI)
  3223. {
  3224. int headerLength;
  3225. char *headerBuffer;
  3226. char *SoapBodyTemplate;
  3227. char* buffer;
  3228. int bufferLength;
  3229. char* IP;
  3230. unsigned short Port;
  3231. char* Path;
  3232. struct sockaddr_in addr;
  3233. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3234. if(service==NULL)
  3235. {
  3236. FREE(invoke_data);
  3237. return;
  3238. }
  3239. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(SourceURI)+(int)strlen(DestinationURI)+316);
  3240. SoapBodyTemplate = "%sImportResource xmlns:u=\"%s\"><SourceURI>%s</SourceURI><DestinationURI>%s</DestinationURI></u:ImportResource%s";
  3241. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, SourceURI, DestinationURI,UPNPCP_SOAP_BodyTail);
  3242. RNDAddRef(service->Parent);
  3243. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3244. headerBuffer = (char*)MALLOC(169 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3245. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"ImportResource",bufferLength);
  3246. memset((char *)&addr, 0, sizeof(addr));
  3247. addr.sin_family = AF_INET;
  3248. addr.sin_addr.s_addr = inet_addr(IP);
  3249. addr.sin_port = htons(Port);
  3250. invoke_data->CallbackPtr = CallbackPtr;
  3251. invoke_data->User = user;
  3252. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_ImportResource_Sink, service, invoke_data);
  3253. FREE(IP);
  3254. FREE(Path);
  3255. }
  3256. void RNDInvoke_ContentDirectory_CreateReference_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3257. {
  3258. struct UPnPService *Service = (struct UPnPService*)_service;
  3259. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3260. int ArgLeft = 1;
  3261. struct ILibXMLNode *xml;
  3262. struct ILibXMLNode *__xml;
  3263. char *tempBuffer;
  3264. int tempBufferLength;
  3265. char* NewID = NULL;
  3266. if(done==0){return;}
  3267. if(_InvokeData->CallbackPtr==NULL)
  3268. {
  3269. RNDRelease(Service->Parent);
  3270. FREE(_InvokeData);
  3271. return;
  3272. }
  3273. else
  3274. {
  3275. if(header==NULL)
  3276. {
  3277. /* Connection Failed */
  3278. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  3279. RNDRelease(Service->Parent);
  3280. FREE(_InvokeData);
  3281. return;
  3282. }
  3283. else if(header->StatusCode!=200)
  3284. {
  3285. /* SOAP Fault */
  3286. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  3287. RNDRelease(Service->Parent);
  3288. FREE(_InvokeData);
  3289. return;
  3290. }
  3291. }
  3292. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3293. ILibProcessXMLNodeList(xml);
  3294. while(xml!=NULL)
  3295. {
  3296. if(xml->NameLength==23 && memcmp(xml->Name,"CreateReferenceResponse",23)==0)
  3297. {
  3298. xml = xml->Next;
  3299. while(xml!=NULL)
  3300. {
  3301. if(xml->NameLength==5 && memcmp(xml->Name,"NewID",5) == 0)
  3302. {
  3303. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3304. --ArgLeft;
  3305. if(tempBufferLength!=0)
  3306. {
  3307. tempBuffer[tempBufferLength] = '\0';
  3308. NewID = tempBuffer;
  3309. }
  3310. }
  3311. xml = xml->Peer;
  3312. }
  3313. }
  3314. if(xml!=NULL) {xml = xml->Next;}
  3315. }
  3316. ILibDestructXMLNodeList(__xml);
  3317. if(ArgLeft!=0)
  3318. {
  3319. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  3320. }
  3321. else
  3322. {
  3323. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,NewID);
  3324. }
  3325. RNDRelease(Service->Parent);
  3326. FREE(_InvokeData);
  3327. }
  3328. void RNDInvoke_ContentDirectory_CreateReference(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*), void* user, char* ContainerID, char* ObjectID)
  3329. {
  3330. int headerLength;
  3331. char *headerBuffer;
  3332. char *SoapBodyTemplate;
  3333. char* buffer;
  3334. int bufferLength;
  3335. char* IP;
  3336. unsigned short Port;
  3337. char* Path;
  3338. struct sockaddr_in addr;
  3339. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3340. if(service==NULL)
  3341. {
  3342. FREE(invoke_data);
  3343. return;
  3344. }
  3345. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ContainerID)+(int)strlen(ObjectID)+310);
  3346. SoapBodyTemplate = "%sCreateReference xmlns:u=\"%s\"><ContainerID>%s</ContainerID><ObjectID>%s</ObjectID></u:CreateReference%s";
  3347. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ContainerID, ObjectID,UPNPCP_SOAP_BodyTail);
  3348. RNDAddRef(service->Parent);
  3349. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3350. headerBuffer = (char*)MALLOC(170 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3351. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"CreateReference",bufferLength);
  3352. memset((char *)&addr, 0, sizeof(addr));
  3353. addr.sin_family = AF_INET;
  3354. addr.sin_addr.s_addr = inet_addr(IP);
  3355. addr.sin_port = htons(Port);
  3356. invoke_data->CallbackPtr = CallbackPtr;
  3357. invoke_data->User = user;
  3358. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_CreateReference_Sink, service, invoke_data);
  3359. FREE(IP);
  3360. FREE(Path);
  3361. }
  3362. void RNDInvoke_ContentDirectory_DeleteResource_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3363. {
  3364. struct UPnPService *Service = (struct UPnPService*)_service;
  3365. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3366. if(done==0){return;}
  3367. if(_InvokeData->CallbackPtr==NULL)
  3368. {
  3369. RNDRelease(Service->Parent);
  3370. FREE(_InvokeData);
  3371. return;
  3372. }
  3373. else
  3374. {
  3375. if(header==NULL)
  3376. {
  3377. /* Connection Failed */
  3378. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User);
  3379. RNDRelease(Service->Parent);
  3380. FREE(_InvokeData);
  3381. return;
  3382. }
  3383. else if(header->StatusCode!=200)
  3384. {
  3385. /* SOAP Fault */
  3386. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User);
  3387. RNDRelease(Service->Parent);
  3388. FREE(_InvokeData);
  3389. return;
  3390. }
  3391. }
  3392. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User);
  3393. RNDRelease(Service->Parent);
  3394. FREE(_InvokeData);
  3395. }
  3396. void RNDInvoke_ContentDirectory_DeleteResource(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*), void* user, char* ResourceURI)
  3397. {
  3398. int headerLength;
  3399. char *headerBuffer;
  3400. char *SoapBodyTemplate;
  3401. char* buffer;
  3402. int bufferLength;
  3403. char* IP;
  3404. unsigned short Port;
  3405. char* Path;
  3406. struct sockaddr_in addr;
  3407. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3408. if(service==NULL)
  3409. {
  3410. FREE(invoke_data);
  3411. return;
  3412. }
  3413. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(ResourceURI)+287);
  3414. SoapBodyTemplate = "%sDeleteResource xmlns:u=\"%s\"><ResourceURI>%s</ResourceURI></u:DeleteResource%s";
  3415. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ResourceURI,UPNPCP_SOAP_BodyTail);
  3416. RNDAddRef(service->Parent);
  3417. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3418. headerBuffer = (char*)MALLOC(169 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3419. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"DeleteResource",bufferLength);
  3420. memset((char *)&addr, 0, sizeof(addr));
  3421. addr.sin_family = AF_INET;
  3422. addr.sin_addr.s_addr = inet_addr(IP);
  3423. addr.sin_port = htons(Port);
  3424. invoke_data->CallbackPtr = CallbackPtr;
  3425. invoke_data->User = user;
  3426. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ContentDirectory_DeleteResource_Sink, service, invoke_data);
  3427. FREE(IP);
  3428. FREE(Path);
  3429. }
  3430. void RNDInvoke_ConnectionManager_GetCurrentConnectionInfo_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3431. {
  3432. struct UPnPService *Service = (struct UPnPService*)_service;
  3433. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3434. int ArgLeft = 7;
  3435. struct ILibXMLNode *xml;
  3436. struct ILibXMLNode *__xml;
  3437. char *tempBuffer;
  3438. int tempBufferLength;
  3439. long TempLong;
  3440. int RcsID = 0;
  3441. int AVTransportID = 0;
  3442. char* ProtocolInfo = NULL;
  3443. char* PeerConnectionManager = NULL;
  3444. int PeerConnectionID = 0;
  3445. char* Direction = NULL;
  3446. char* Status = NULL;
  3447. if(done==0){return;}
  3448. if(_InvokeData->CallbackPtr==NULL)
  3449. {
  3450. RNDRelease(Service->Parent);
  3451. FREE(_InvokeData);
  3452. return;
  3453. }
  3454. else
  3455. {
  3456. if(header==NULL)
  3457. {
  3458. /* Connection Failed */
  3459. ((void (*)(struct UPnPService*,int,void*,int,int,char*,char*,int,char*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3460. RNDRelease(Service->Parent);
  3461. FREE(_InvokeData);
  3462. return;
  3463. }
  3464. else if(header->StatusCode!=200)
  3465. {
  3466. /* SOAP Fault */
  3467. ((void (*)(struct UPnPService*,int,void*,int,int,char*,char*,int,char*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3468. RNDRelease(Service->Parent);
  3469. FREE(_InvokeData);
  3470. return;
  3471. }
  3472. }
  3473. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3474. ILibProcessXMLNodeList(xml);
  3475. while(xml!=NULL)
  3476. {
  3477. if(xml->NameLength==32 && memcmp(xml->Name,"GetCurrentConnectionInfoResponse",32)==0)
  3478. {
  3479. xml = xml->Next;
  3480. while(xml!=NULL)
  3481. {
  3482. if(xml->NameLength==5 && memcmp(xml->Name,"RcsID",5) == 0)
  3483. {
  3484. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3485. --ArgLeft;
  3486. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3487. {
  3488. RcsID = (int) TempLong;
  3489. }
  3490. }
  3491. else
  3492. if(xml->NameLength==13 && memcmp(xml->Name,"AVTransportID",13) == 0)
  3493. {
  3494. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3495. --ArgLeft;
  3496. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3497. {
  3498. AVTransportID = (int) TempLong;
  3499. }
  3500. }
  3501. else
  3502. if(xml->NameLength==12 && memcmp(xml->Name,"ProtocolInfo",12) == 0)
  3503. {
  3504. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3505. --ArgLeft;
  3506. if(tempBufferLength!=0)
  3507. {
  3508. tempBuffer[tempBufferLength] = '\0';
  3509. ProtocolInfo = tempBuffer;
  3510. }
  3511. }
  3512. else
  3513. if(xml->NameLength==21 && memcmp(xml->Name,"PeerConnectionManager",21) == 0)
  3514. {
  3515. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3516. --ArgLeft;
  3517. if(tempBufferLength!=0)
  3518. {
  3519. tempBuffer[tempBufferLength] = '\0';
  3520. PeerConnectionManager = tempBuffer;
  3521. }
  3522. }
  3523. else
  3524. if(xml->NameLength==16 && memcmp(xml->Name,"PeerConnectionID",16) == 0)
  3525. {
  3526. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3527. --ArgLeft;
  3528. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3529. {
  3530. PeerConnectionID = (int) TempLong;
  3531. }
  3532. }
  3533. else
  3534. if(xml->NameLength==9 && memcmp(xml->Name,"Direction",9) == 0)
  3535. {
  3536. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3537. --ArgLeft;
  3538. if(tempBufferLength!=0)
  3539. {
  3540. tempBuffer[tempBufferLength] = '\0';
  3541. Direction = tempBuffer;
  3542. }
  3543. }
  3544. else
  3545. if(xml->NameLength==6 && memcmp(xml->Name,"Status",6) == 0)
  3546. {
  3547. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3548. --ArgLeft;
  3549. if(tempBufferLength!=0)
  3550. {
  3551. tempBuffer[tempBufferLength] = '\0';
  3552. Status = tempBuffer;
  3553. }
  3554. }
  3555. xml = xml->Peer;
  3556. }
  3557. }
  3558. if(xml!=NULL) {xml = xml->Next;}
  3559. }
  3560. ILibDestructXMLNodeList(__xml);
  3561. if(ArgLeft!=0)
  3562. {
  3563. ((void (*)(struct UPnPService*,int,void*,int,int,char*,char*,int,char*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3564. }
  3565. else
  3566. {
  3567. ((void (*)(struct UPnPService*,int,void*,int,int,char*,char*,int,char*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,RcsID,AVTransportID,ProtocolInfo,PeerConnectionManager,PeerConnectionID,Direction,Status);
  3568. }
  3569. RNDRelease(Service->Parent);
  3570. FREE(_InvokeData);
  3571. }
  3572. void RNDInvoke_ConnectionManager_GetCurrentConnectionInfo(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,int,int,char*,char*,int,char*,char*), void* user, int ConnectionID)
  3573. {
  3574. int headerLength;
  3575. char *headerBuffer;
  3576. char *SoapBodyTemplate;
  3577. char* buffer;
  3578. int bufferLength;
  3579. char* IP;
  3580. unsigned short Port;
  3581. char* Path;
  3582. struct sockaddr_in addr;
  3583. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3584. if(service==NULL)
  3585. {
  3586. FREE(invoke_data);
  3587. return;
  3588. }
  3589. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+320);
  3590. SoapBodyTemplate = "%sGetCurrentConnectionInfo xmlns:u=\"%s\"><ConnectionID>%d</ConnectionID></u:GetCurrentConnectionInfo%s";
  3591. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ConnectionID,UPNPCP_SOAP_BodyTail);
  3592. RNDAddRef(service->Parent);
  3593. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3594. headerBuffer = (char*)MALLOC(179 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3595. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetCurrentConnectionInfo",bufferLength);
  3596. memset((char *)&addr, 0, sizeof(addr));
  3597. addr.sin_family = AF_INET;
  3598. addr.sin_addr.s_addr = inet_addr(IP);
  3599. addr.sin_port = htons(Port);
  3600. invoke_data->CallbackPtr = CallbackPtr;
  3601. invoke_data->User = user;
  3602. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ConnectionManager_GetCurrentConnectionInfo_Sink, service, invoke_data);
  3603. FREE(IP);
  3604. FREE(Path);
  3605. }
  3606. void RNDInvoke_ConnectionManager_PrepareForConnection_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3607. {
  3608. struct UPnPService *Service = (struct UPnPService*)_service;
  3609. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3610. int ArgLeft = 3;
  3611. struct ILibXMLNode *xml;
  3612. struct ILibXMLNode *__xml;
  3613. char *tempBuffer;
  3614. int tempBufferLength;
  3615. long TempLong;
  3616. int ConnectionID = 0;
  3617. int AVTransportID = 0;
  3618. int RcsID = 0;
  3619. if(done==0){return;}
  3620. if(_InvokeData->CallbackPtr==NULL)
  3621. {
  3622. RNDRelease(Service->Parent);
  3623. FREE(_InvokeData);
  3624. return;
  3625. }
  3626. else
  3627. {
  3628. if(header==NULL)
  3629. {
  3630. /* Connection Failed */
  3631. ((void (*)(struct UPnPService*,int,void*,int,int,int))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3632. RNDRelease(Service->Parent);
  3633. FREE(_InvokeData);
  3634. return;
  3635. }
  3636. else if(header->StatusCode!=200)
  3637. {
  3638. /* SOAP Fault */
  3639. ((void (*)(struct UPnPService*,int,void*,int,int,int))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3640. RNDRelease(Service->Parent);
  3641. FREE(_InvokeData);
  3642. return;
  3643. }
  3644. }
  3645. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3646. ILibProcessXMLNodeList(xml);
  3647. while(xml!=NULL)
  3648. {
  3649. if(xml->NameLength==28 && memcmp(xml->Name,"PrepareForConnectionResponse",28)==0)
  3650. {
  3651. xml = xml->Next;
  3652. while(xml!=NULL)
  3653. {
  3654. if(xml->NameLength==12 && memcmp(xml->Name,"ConnectionID",12) == 0)
  3655. {
  3656. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3657. --ArgLeft;
  3658. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3659. {
  3660. ConnectionID = (int) TempLong;
  3661. }
  3662. }
  3663. else
  3664. if(xml->NameLength==13 && memcmp(xml->Name,"AVTransportID",13) == 0)
  3665. {
  3666. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3667. --ArgLeft;
  3668. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3669. {
  3670. AVTransportID = (int) TempLong;
  3671. }
  3672. }
  3673. else
  3674. if(xml->NameLength==5 && memcmp(xml->Name,"RcsID",5) == 0)
  3675. {
  3676. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3677. --ArgLeft;
  3678. if(ILibGetLong(tempBuffer,tempBufferLength,&TempLong)==0)
  3679. {
  3680. RcsID = (int) TempLong;
  3681. }
  3682. }
  3683. xml = xml->Peer;
  3684. }
  3685. }
  3686. if(xml!=NULL) {xml = xml->Next;}
  3687. }
  3688. ILibDestructXMLNodeList(__xml);
  3689. if(ArgLeft!=0)
  3690. {
  3691. ((void (*)(struct UPnPService*,int,void*,int,int,int))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA,INVALID_DATA);
  3692. }
  3693. else
  3694. {
  3695. ((void (*)(struct UPnPService*,int,void*,int,int,int))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,ConnectionID,AVTransportID,RcsID);
  3696. }
  3697. RNDRelease(Service->Parent);
  3698. FREE(_InvokeData);
  3699. }
  3700. void RNDInvoke_ConnectionManager_PrepareForConnection(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,int,int,int), void* user, char* RemoteProtocolInfo, char* PeerConnectionManager, int PeerConnectionID, char* Direction)
  3701. {
  3702. int headerLength;
  3703. char *headerBuffer;
  3704. char *SoapBodyTemplate;
  3705. char* buffer;
  3706. int bufferLength;
  3707. char* IP;
  3708. unsigned short Port;
  3709. char* Path;
  3710. struct sockaddr_in addr;
  3711. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3712. if(service==NULL)
  3713. {
  3714. FREE(invoke_data);
  3715. return;
  3716. }
  3717. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+(int)strlen(RemoteProtocolInfo)+(int)strlen(PeerConnectionManager)+(int)strlen(Direction)+431);
  3718. SoapBodyTemplate = "%sPrepareForConnection xmlns:u=\"%s\"><RemoteProtocolInfo>%s</RemoteProtocolInfo><PeerConnectionManager>%s</PeerConnectionManager><PeerConnectionID>%d</PeerConnectionID><Direction>%s</Direction></u:PrepareForConnection%s";
  3719. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, RemoteProtocolInfo, PeerConnectionManager, PeerConnectionID, Direction,UPNPCP_SOAP_BodyTail);
  3720. RNDAddRef(service->Parent);
  3721. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3722. headerBuffer = (char*)MALLOC(175 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3723. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"PrepareForConnection",bufferLength);
  3724. memset((char *)&addr, 0, sizeof(addr));
  3725. addr.sin_family = AF_INET;
  3726. addr.sin_addr.s_addr = inet_addr(IP);
  3727. addr.sin_port = htons(Port);
  3728. invoke_data->CallbackPtr = CallbackPtr;
  3729. invoke_data->User = user;
  3730. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ConnectionManager_PrepareForConnection_Sink, service, invoke_data);
  3731. FREE(IP);
  3732. FREE(Path);
  3733. }
  3734. void RNDInvoke_ConnectionManager_ConnectionComplete_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3735. {
  3736. struct UPnPService *Service = (struct UPnPService*)_service;
  3737. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3738. if(done==0){return;}
  3739. if(_InvokeData->CallbackPtr==NULL)
  3740. {
  3741. RNDRelease(Service->Parent);
  3742. FREE(_InvokeData);
  3743. return;
  3744. }
  3745. else
  3746. {
  3747. if(header==NULL)
  3748. {
  3749. /* Connection Failed */
  3750. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User);
  3751. RNDRelease(Service->Parent);
  3752. FREE(_InvokeData);
  3753. return;
  3754. }
  3755. else if(header->StatusCode!=200)
  3756. {
  3757. /* SOAP Fault */
  3758. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User);
  3759. RNDRelease(Service->Parent);
  3760. FREE(_InvokeData);
  3761. return;
  3762. }
  3763. }
  3764. ((void (*)(struct UPnPService*,int,void*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User);
  3765. RNDRelease(Service->Parent);
  3766. FREE(_InvokeData);
  3767. }
  3768. void RNDInvoke_ConnectionManager_ConnectionComplete(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*), void* user, int ConnectionID)
  3769. {
  3770. int headerLength;
  3771. char *headerBuffer;
  3772. char *SoapBodyTemplate;
  3773. char* buffer;
  3774. int bufferLength;
  3775. char* IP;
  3776. unsigned short Port;
  3777. char* Path;
  3778. struct sockaddr_in addr;
  3779. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3780. if(service==NULL)
  3781. {
  3782. FREE(invoke_data);
  3783. return;
  3784. }
  3785. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+308);
  3786. SoapBodyTemplate = "%sConnectionComplete xmlns:u=\"%s\"><ConnectionID>%d</ConnectionID></u:ConnectionComplete%s";
  3787. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType, ConnectionID,UPNPCP_SOAP_BodyTail);
  3788. RNDAddRef(service->Parent);
  3789. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3790. headerBuffer = (char*)MALLOC(173 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3791. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"ConnectionComplete",bufferLength);
  3792. memset((char *)&addr, 0, sizeof(addr));
  3793. addr.sin_family = AF_INET;
  3794. addr.sin_addr.s_addr = inet_addr(IP);
  3795. addr.sin_port = htons(Port);
  3796. invoke_data->CallbackPtr = CallbackPtr;
  3797. invoke_data->User = user;
  3798. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ConnectionManager_ConnectionComplete_Sink, service, invoke_data);
  3799. FREE(IP);
  3800. FREE(Path);
  3801. }
  3802. void RNDInvoke_ConnectionManager_GetProtocolInfo_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3803. {
  3804. struct UPnPService *Service = (struct UPnPService*)_service;
  3805. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3806. int ArgLeft = 2;
  3807. struct ILibXMLNode *xml;
  3808. struct ILibXMLNode *__xml;
  3809. char *tempBuffer;
  3810. int tempBufferLength;
  3811. char* Source = NULL;
  3812. char* Sink = NULL;
  3813. if(done==0){return;}
  3814. if(_InvokeData->CallbackPtr==NULL)
  3815. {
  3816. RNDRelease(Service->Parent);
  3817. FREE(_InvokeData);
  3818. return;
  3819. }
  3820. else
  3821. {
  3822. if(header==NULL)
  3823. {
  3824. /* Connection Failed */
  3825. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA,INVALID_DATA);
  3826. RNDRelease(Service->Parent);
  3827. FREE(_InvokeData);
  3828. return;
  3829. }
  3830. else if(header->StatusCode!=200)
  3831. {
  3832. /* SOAP Fault */
  3833. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA,INVALID_DATA);
  3834. RNDRelease(Service->Parent);
  3835. FREE(_InvokeData);
  3836. return;
  3837. }
  3838. }
  3839. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3840. ILibProcessXMLNodeList(xml);
  3841. while(xml!=NULL)
  3842. {
  3843. if(xml->NameLength==23 && memcmp(xml->Name,"GetProtocolInfoResponse",23)==0)
  3844. {
  3845. xml = xml->Next;
  3846. while(xml!=NULL)
  3847. {
  3848. if(xml->NameLength==6 && memcmp(xml->Name,"Source",6) == 0)
  3849. {
  3850. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3851. --ArgLeft;
  3852. if(tempBufferLength!=0)
  3853. {
  3854. tempBuffer[tempBufferLength] = '\0';
  3855. Source = tempBuffer;
  3856. }
  3857. }
  3858. else
  3859. if(xml->NameLength==4 && memcmp(xml->Name,"Sink",4) == 0)
  3860. {
  3861. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3862. --ArgLeft;
  3863. if(tempBufferLength!=0)
  3864. {
  3865. tempBuffer[tempBufferLength] = '\0';
  3866. Sink = tempBuffer;
  3867. }
  3868. }
  3869. xml = xml->Peer;
  3870. }
  3871. }
  3872. if(xml!=NULL) {xml = xml->Next;}
  3873. }
  3874. ILibDestructXMLNodeList(__xml);
  3875. if(ArgLeft!=0)
  3876. {
  3877. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA,INVALID_DATA);
  3878. }
  3879. else
  3880. {
  3881. ((void (*)(struct UPnPService*,int,void*,char*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,Source,Sink);
  3882. }
  3883. RNDRelease(Service->Parent);
  3884. FREE(_InvokeData);
  3885. }
  3886. void RNDInvoke_ConnectionManager_GetProtocolInfo(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*,char*), void* user)
  3887. {
  3888. int headerLength;
  3889. char *headerBuffer;
  3890. char *SoapBodyTemplate;
  3891. char* buffer;
  3892. int bufferLength;
  3893. char* IP;
  3894. unsigned short Port;
  3895. char* Path;
  3896. struct sockaddr_in addr;
  3897. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  3898. if(service==NULL)
  3899. {
  3900. FREE(invoke_data);
  3901. return;
  3902. }
  3903. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+262);
  3904. SoapBodyTemplate = "%sGetProtocolInfo xmlns:u=\"%s\"></u:GetProtocolInfo%s";
  3905. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType,UPNPCP_SOAP_BodyTail);
  3906. RNDAddRef(service->Parent);
  3907. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  3908. headerBuffer = (char*)MALLOC(170 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  3909. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetProtocolInfo",bufferLength);
  3910. memset((char *)&addr, 0, sizeof(addr));
  3911. addr.sin_family = AF_INET;
  3912. addr.sin_addr.s_addr = inet_addr(IP);
  3913. addr.sin_port = htons(Port);
  3914. invoke_data->CallbackPtr = CallbackPtr;
  3915. invoke_data->User = user;
  3916. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ConnectionManager_GetProtocolInfo_Sink, service, invoke_data);
  3917. FREE(IP);
  3918. FREE(Path);
  3919. }
  3920. void RNDInvoke_ConnectionManager_GetCurrentConnectionIDs_Sink(void *reader, struct packetheader *header, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* _service, void *state)
  3921. {
  3922. struct UPnPService *Service = (struct UPnPService*)_service;
  3923. struct InvokeStruct *_InvokeData = (struct InvokeStruct*)state;
  3924. int ArgLeft = 1;
  3925. struct ILibXMLNode *xml;
  3926. struct ILibXMLNode *__xml;
  3927. char *tempBuffer;
  3928. int tempBufferLength;
  3929. char* ConnectionIDs = NULL;
  3930. if(done==0){return;}
  3931. if(_InvokeData->CallbackPtr==NULL)
  3932. {
  3933. RNDRelease(Service->Parent);
  3934. FREE(_InvokeData);
  3935. return;
  3936. }
  3937. else
  3938. {
  3939. if(header==NULL)
  3940. {
  3941. /* Connection Failed */
  3942. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-1,_InvokeData->User,INVALID_DATA);
  3943. RNDRelease(Service->Parent);
  3944. FREE(_InvokeData);
  3945. return;
  3946. }
  3947. else if(header->StatusCode!=200)
  3948. {
  3949. /* SOAP Fault */
  3950. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,RNDGetErrorCode(buffer,EndPointer-(*p_BeginPointer)),_InvokeData->User,INVALID_DATA);
  3951. RNDRelease(Service->Parent);
  3952. FREE(_InvokeData);
  3953. return;
  3954. }
  3955. }
  3956. __xml = xml = ILibParseXML(buffer,0,EndPointer-(*p_BeginPointer));
  3957. ILibProcessXMLNodeList(xml);
  3958. while(xml!=NULL)
  3959. {
  3960. if(xml->NameLength==31 && memcmp(xml->Name,"GetCurrentConnectionIDsResponse",31)==0)
  3961. {
  3962. xml = xml->Next;
  3963. while(xml!=NULL)
  3964. {
  3965. if(xml->NameLength==13 && memcmp(xml->Name,"ConnectionIDs",13) == 0)
  3966. {
  3967. tempBufferLength = ILibReadInnerXML(xml,&tempBuffer);
  3968. --ArgLeft;
  3969. if(tempBufferLength!=0)
  3970. {
  3971. tempBuffer[tempBufferLength] = '\0';
  3972. ConnectionIDs = tempBuffer;
  3973. }
  3974. }
  3975. xml = xml->Peer;
  3976. }
  3977. }
  3978. if(xml!=NULL) {xml = xml->Next;}
  3979. }
  3980. ILibDestructXMLNodeList(__xml);
  3981. if(ArgLeft!=0)
  3982. {
  3983. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,-2,_InvokeData->User,INVALID_DATA);
  3984. }
  3985. else
  3986. {
  3987. ((void (*)(struct UPnPService*,int,void*,char*))_InvokeData->CallbackPtr)(Service,0,_InvokeData->User,ConnectionIDs);
  3988. }
  3989. RNDRelease(Service->Parent);
  3990. FREE(_InvokeData);
  3991. }
  3992. void RNDInvoke_ConnectionManager_GetCurrentConnectionIDs(struct UPnPService *service,void (*CallbackPtr)(struct UPnPService*,int,void*,char*), void* user)
  3993. {
  3994. int headerLength;
  3995. char *headerBuffer;
  3996. char *SoapBodyTemplate;
  3997. char* buffer;
  3998. int bufferLength;
  3999. char* IP;
  4000. unsigned short Port;
  4001. char* Path;
  4002. struct sockaddr_in addr;
  4003. struct InvokeStruct *invoke_data = (struct InvokeStruct*)MALLOC(sizeof(struct InvokeStruct));
  4004. if(service==NULL)
  4005. {
  4006. FREE(invoke_data);
  4007. return;
  4008. }
  4009. buffer = (char*)MALLOC((int)strlen(service->ServiceType)+278);
  4010. SoapBodyTemplate = "%sGetCurrentConnectionIDs xmlns:u=\"%s\"></u:GetCurrentConnectionIDs%s";
  4011. bufferLength = sprintf(buffer,SoapBodyTemplate,UPNPCP_SOAP_BodyHead,service->ServiceType,UPNPCP_SOAP_BodyTail);
  4012. RNDAddRef(service->Parent);
  4013. RNDParseUri(service->ControlURL,&IP,&Port,&Path);
  4014. headerBuffer = (char*)MALLOC(178 + (int)strlen(Path) + (int)strlen(IP) + (int)strlen(service->ServiceType));
  4015. headerLength = sprintf(headerBuffer,UPNPCP_SOAP_Header,Path,IP,Port,service->ServiceType,"GetCurrentConnectionIDs",bufferLength);
  4016. memset((char *)&addr, 0, sizeof(addr));
  4017. addr.sin_family = AF_INET;
  4018. addr.sin_addr.s_addr = inet_addr(IP);
  4019. addr.sin_port = htons(Port);
  4020. invoke_data->CallbackPtr = CallbackPtr;
  4021. invoke_data->User = user;
  4022. ILibAddRequest_DirectEx(((struct RNDCP*)service->Parent->CP)->HTTP, headerBuffer,headerLength,buffer,bufferLength,&addr, &RNDInvoke_ConnectionManager_GetCurrentConnectionIDs_Sink, service, invoke_data);
  4023. FREE(IP);
  4024. FREE(Path);
  4025. }
  4026. void RNDSubscribeForUPnPEvents(struct UPnPService *service, void(*callbackPtr)(struct UPnPService* service,int OK))
  4027. {
  4028. char* callback;
  4029. char *IP;
  4030. char *Path;
  4031. unsigned short Port;
  4032. struct packetheader *p;
  4033. char* TempString;
  4034. struct sockaddr_in destaddr;
  4035. RNDParseUri(service->SubscriptionURL,&IP,&Port,&Path);
  4036. p = ILibCreateEmptyPacket();
  4037. ILibSetDirective(p,"SUBSCRIBE",9,Path,(int)strlen(Path));
  4038. TempString = (char*)MALLOC((int)strlen(IP)+7);
  4039. sprintf(TempString,"%s:%d",IP,Port);
  4040. ILibAddHeaderLine(p,"HOST",4,TempString,(int)strlen(TempString));
  4041. FREE(TempString);
  4042. ILibAddHeaderLine(p,"NT",2,"upnp:event",10);
  4043. ILibAddHeaderLine(p,"TIMEOUT",7,"Second-180",10);
  4044. ILibAddHeaderLine(p,"User-Agent",10,"WINDOWS, UPnP/1.0, Intel MicroStack/1.0.1189",44);
  4045. callback = (char*)MALLOC(10+(int)strlen(service->Parent->InterfaceToHost)+6+(int)strlen(Path));
  4046. sprintf(callback,"<http://%s:%d%s>",service->Parent->InterfaceToHost,ILibGetMiniWebServerPortNumber(((struct RNDCP*)service->Parent->CP)->WebServer),Path);
  4047. ILibAddHeaderLine(p,"CALLBACK",8,callback,(int)strlen(callback));
  4048. FREE(callback);
  4049. memset((char *)&destaddr, 0,sizeof(destaddr));
  4050. destaddr.sin_family = AF_INET;
  4051. destaddr.sin_addr.s_addr = inet_addr(IP);
  4052. destaddr.sin_port = htons(Port);
  4053. RNDAddRef(service->Parent);
  4054. ILibAddRequest(((struct RNDCP*)service->Parent->CP)->HTTP, p,&destaddr, &RNDOnSubscribeSink, (void*)service,service->Parent->CP);
  4055. FREE(IP);
  4056. FREE(Path);
  4057. }